am 9363b7d5: dhcp: Add hostname support

Merge commit '9363b7d5da7e17842432251384f8dc46902ac323' into eclair-mr2-plus-aosp

* commit '9363b7d5da7e17842432251384f8dc46902ac323':
  dhcp: Add hostname support
This commit is contained in:
Dmitry Shmidt 2009-12-14 16:41:43 -08:00 committed by Android Git Automerger
commit 2ed5a4570f
1 changed files with 11 additions and 3 deletions

View File

@ -24,8 +24,9 @@
#include <cutils/properties.h>
static const char DAEMON_NAME[] = "dhcpcd";
static const char DAEMON_PROP_NAME[] = "init.svc.dhcpcd";
static const char DAEMON_NAME[] = "dhcpcd";
static const char DAEMON_PROP_NAME[] = "init.svc.dhcpcd";
static const char HOSTNAME_PROP_NAME[] = "net.hostname";
static const char DHCP_PROP_NAME_PREFIX[] = "dhcp";
static const int NAP_TIME = 1; /* wait for 1 second at a time */
/* when polling for property values */
@ -129,6 +130,7 @@ int dhcp_do_request(const char *interface,
{
char result_prop_name[PROPERTY_KEY_MAX];
char prop_value[PROPERTY_VALUE_MAX] = {'\0'};
char daemon_cmd[PROPERTY_VALUE_MAX * 2];
const char *ctrl_prop = "ctl.start";
const char *desired_status = "running";
@ -139,7 +141,13 @@ int dhcp_do_request(const char *interface,
property_set(result_prop_name, "");
/* Start the daemon and wait until it's ready */
property_set(ctrl_prop, DAEMON_NAME);
if (property_get(HOSTNAME_PROP_NAME, prop_value, NULL) && (prop_value[0] != '\0'))
snprintf(daemon_cmd, sizeof(daemon_cmd), "%s:-h %s %s", DAEMON_NAME,
prop_value, interface);
else
snprintf(daemon_cmd, sizeof(daemon_cmd), "%s:%s", DAEMON_NAME, interface);
memset(prop_value, '\0', PROPERTY_VALUE_MAX);
property_set(ctrl_prop, daemon_cmd);
if (wait_for_property(DAEMON_PROP_NAME, desired_status, 10) < 0) {
snprintf(errmsg, sizeof(errmsg), "%s", "Timed out waiting for dhcpcd to start");
return -1;