aboutsummaryrefslogtreecommitdiff
path: root/sbin/dhclient/dhclient.c
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2013-07-03 22:05:36 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2013-07-03 22:05:36 +0000
commit0bbe83068e3e3cadf15088ede7329bc505b92953 (patch)
tree9aba4ff0b5ab8ba59d112d7491841188a895e9b6 /sbin/dhclient/dhclient.c
parentc786bc908936cd6aa6ced03268fe6a727a82b8c2 (diff)
downloadsrc-0bbe83068e3e3cadf15088ede7329bc505b92953.tar.gz
src-0bbe83068e3e3cadf15088ede7329bc505b92953.zip
MFp4 @229477:
The gethostname(3) function won't work in capability mode, because reading kern.hostname sysctl is not permitted there. Cache hostname early and use cached value later. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
Notes
Notes: svn path=/head/; revision=252623
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r--sbin/dhclient/dhclient.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index fa9a49b06ade..038002058315 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -91,6 +91,8 @@ int log_perror = 1;
int privfd;
int nullfd = -1;
+char hostname[_POSIX_HOST_NAME_MAX + 1];
+
struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
struct in_addr inaddr_any, inaddr_broadcast;
@@ -446,6 +448,13 @@ main(int argc, char *argv[])
error("no such user: nobody");
}
+ /*
+ * Obtain hostname before entering capability mode - it won't be
+ * possible then, as reading kern.hostname is not permitted.
+ */
+ if (gethostname(hostname, sizeof(hostname)) < 0)
+ hostname[0] = '\0';
+
if (pipe(pipe_fd) == -1)
error("pipe");
@@ -1525,9 +1534,8 @@ make_discover(struct interface_info *ip, struct client_lease *lease)
}
/* send host name if not set via config file. */
- char hostname[_POSIX_HOST_NAME_MAX+1];
if (!options[DHO_HOST_NAME]) {
- if (gethostname(hostname, sizeof(hostname)) == 0) {
+ if (hostname[0] != '\0') {
size_t len;
char* posDot = strchr(hostname, '.');
if (posDot != NULL)
@@ -1649,9 +1657,8 @@ make_request(struct interface_info *ip, struct client_lease * lease)
}
/* send host name if not set via config file. */
- char hostname[_POSIX_HOST_NAME_MAX+1];
if (!options[DHO_HOST_NAME]) {
- if (gethostname(hostname, sizeof(hostname)) == 0) {
+ if (hostname[0] != '\0') {
size_t len;
char* posDot = strchr(hostname, '.');
if (posDot != NULL)