shill: Pass a parameter to dhcp client to request a hostname
This will enable dynamic DNS, or at the very least allow DHCP
requests to be identified and distinguished at the server side.
BUG=chromium-os:23741
TEST=New unit tests monitor hostname arg passed to dhcpcd,
and to assure values are being loaded/saved. Also double
checked on real system by doing a dbus-send to set manager.HostName
and checked that the name was persisted, and that the next
DHCP server we connected to stored this hostname.
CQ-DEPEND=Ic807a2235e0cdcb32a08f9c2c760a86c3579431c
Change-Id: Ic127b65d8563b15e55549a0f029385d0632eaf6c
Reviewed-on: https://gerrit.chromium.org/gerrit/14045
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
diff --git a/dhcp_config.cc b/dhcp_config.cc
index 8b4732b..3acefc0 100644
--- a/dhcp_config.cc
+++ b/dhcp_config.cc
@@ -48,10 +48,12 @@
EventDispatcher *dispatcher,
DHCPProvider *provider,
const string &device_name,
+ const string &request_hostname,
GLib *glib)
: IPConfig(control_interface, device_name, kType),
proxy_factory_(ProxyFactory::GetInstance()),
provider_(provider),
+ request_hostname_(request_hostname),
pid_(0),
child_watch_tag_(0),
root_("/"),
@@ -145,17 +147,20 @@
bool DHCPConfig::Start() {
VLOG(2) << __func__ << ": " << device_name();
- char *argv[4] = {
- const_cast<char *>(kDHCPCDPath),
- const_cast<char *>("-B"), // foreground
- const_cast<char *>(device_name().c_str()),
- NULL
- };
+ vector<char *> args;
+ args.push_back(const_cast<char *>(kDHCPCDPath));
+ args.push_back(const_cast<char *>("-B")); // foreground
+ args.push_back(const_cast<char *>(device_name().c_str()));
+ if (!request_hostname_.empty()) {
+ args.push_back(const_cast<char *>("-h")); // request hostname
+ args.push_back(const_cast<char *>(request_hostname_.c_str()));
+ }
+ args.push_back(NULL);
char *envp[1] = { NULL };
CHECK(!pid_);
if (!glib_->SpawnAsync(NULL,
- argv,
+ args.data(),
envp,
G_SPAWN_DO_NOT_REAP_CHILD,
NULL,