apmanager: update dnsmasq configuration

By default, dnsmasq process will create another process to run the dnsmasq
task in the background, which results in the background process to run
forever, since the apmanager daemon have no knowledge of that process.
Set the "keep-in-foreground" flag for dnsmasq to prevent it from creating
another process to run in the background.

Also the dnsmasq process runs under "nobody" by default, which might cause
some security concerns. Set the user to "root" for now until we figure out
the privileges required for apmanager daemone and switch over to "apmanager"
user.

BUG=chromium:438836
TEST=unittests
Manual Test:
1. Start an AP service using apmanager, verify only one dnsmasq process is
   running and ran as "root".
2. Terminate the AP service, verify no dnsmasq process is running.

Change-Id: Icf2c77cbeceb35d51a0b098a68d7072692f7cdc9
Reviewed-on: https://chromium-review.googlesource.com/233761
Tested-by: Peter Qiu <zqiu@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
diff --git a/dhcp_server.cc b/dhcp_server.cc
index 5f7f6f8..c60bd32 100644
--- a/dhcp_server.cc
+++ b/dhcp_server.cc
@@ -98,6 +98,18 @@
   config += "port=0\n";
   config += "bind-interfaces\n";
   config += "log-dhcp\n";
+  // By default, dnsmasq process will spawn off another process to run the
+  // dnsmasq task in the "background" and exit the current process immediately.
+  // This means the daemon would not have any knowledge of the background
+  // dnsmasq process, and it will continue to run even after the AP service is
+  // terminated. Configure dnsmasq to run in "foreground" so no extra process
+  // will be spawned.
+  config += "keep-in-foreground\n";
+  // TODO(zqiu): by default, dnsmasq process will be started under "nobody".
+  // Set the user to "root" for now, since both the daemon and hostapd are
+  // running under "root". Update the user once we switch the daemon and
+  // hostapd over to "apmanager" user.
+  config += "user=root\n";
   base::StringAppendF(
       &config, "dhcp-range=%s,%s\n", address_low.c_str(), address_high.c_str());
   base::StringAppendF(&config, "interface=%s\n", interface_name_.c_str());