From owner-svn-src-head@freebsd.org Sun Nov 12 08:42:45 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7AA66E6C68F; Sun, 12 Nov 2017 08:42:45 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 54B5981965; Sun, 12 Nov 2017 08:42:45 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vAC8giYx010781; Sun, 12 Nov 2017 08:42:44 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vAC8giCL010776; Sun, 12 Nov 2017 08:42:44 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201711120842.vAC8giCL010776@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Sun, 12 Nov 2017 08:42:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325740 - head/sbin/dhclient X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/sbin/dhclient X-SVN-Commit-Revision: 325740 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Nov 2017 08:42:45 -0000 Author: oshogbo Date: Sun Nov 12 08:42:43 2017 New Revision: 325740 URL: https://svnweb.freebsd.org/changeset/base/325740 Log: Use syslog service in dhclient(8). dhclient(8) is failing during boot to connect to the syslog service, because syslog daemon is started after dhclient(8). This can be reproduced by stooping syslog daemon and ktrace the dhclient or use kern.trap_enotcap sysctl and boot the machine. Using the Casper syslog service fix the problem. Reviewed by: bapt@ Differential Revision: https://reviews.freebsd.org/D12825 Modified: head/sbin/dhclient/Makefile head/sbin/dhclient/dhclient.c head/sbin/dhclient/dhcpd.h head/sbin/dhclient/dispatch.c head/sbin/dhclient/errwarn.c Modified: head/sbin/dhclient/Makefile ============================================================================== --- head/sbin/dhclient/Makefile Sun Nov 12 08:34:25 2017 (r325739) +++ head/sbin/dhclient/Makefile Sun Nov 12 08:42:43 2017 (r325740) @@ -44,6 +44,12 @@ MAN= dhclient.8 dhclient.conf.5 dhclient.leases.5 dhcp dhclient-script.8 LIBADD= util +.if ${MK_CASPER} != "no" && !defined(RESCUE) +LIBADD+= casper +LIBADD+= cap_syslog +CFLAGS+=-DWITH_CASPER +.endif + WARNS?= 2 HAS_TESTS= Modified: head/sbin/dhclient/dhclient.c ============================================================================== --- head/sbin/dhclient/dhclient.c Sun Nov 12 08:34:25 2017 (r325739) +++ head/sbin/dhclient/dhclient.c Sun Nov 12 08:42:43 2017 (r325740) @@ -84,6 +84,8 @@ __FBSDID("$FreeBSD$"); #define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" +cap_channel_t *capsyslog; + time_t cur_time; time_t default_lease_time = 43200; /* 12 hours... */ @@ -345,6 +347,21 @@ die: exit(1); } +static void +init_casper(void) +{ + cap_channel_t *casper; + + casper = cap_init(); + if (casper == NULL) + error("unable to start casper"); + + capsyslog = cap_service_open(casper, "system.syslog"); + cap_close(casper); + if (capsyslog == NULL) + error("unable to open system.syslog service"); +} + int main(int argc, char *argv[]) { @@ -356,9 +373,11 @@ main(int argc, char *argv[]) pid_t otherpid; cap_rights_t rights; + init_casper(); + /* Initially, log errors to stderr as well as to syslogd. */ - openlog(__progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY); - setlogmask(LOG_UPTO(LOG_DEBUG)); + cap_openlog(capsyslog, __progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY); + cap_setlogmask(capsyslog, LOG_UPTO(LOG_DEBUG)); while ((ch = getopt(argc, argv, "bc:dl:p:qu")) != -1) switch (ch) { @@ -518,7 +537,7 @@ main(int argc, char *argv[]) setproctitle("%s", ifi->name); - if (cap_enter() < 0 && errno != ENOSYS) + if (CASPER_SUPPORT && cap_enter() < 0 && errno != ENOSYS) error("can't enter capability mode: %m"); if (immediate_daemon) Modified: head/sbin/dhclient/dhcpd.h ============================================================================== --- head/sbin/dhclient/dhcpd.h Sun Nov 12 08:34:25 2017 (r325739) +++ head/sbin/dhclient/dhcpd.h Sun Nov 12 08:42:43 2017 (r325740) @@ -73,6 +73,9 @@ #include #include +#include +#include + #include "dhcp.h" #include "tree.h" @@ -352,6 +355,7 @@ int addr_eq(struct iaddr, struct iaddr); char *piaddr(struct iaddr); /* dhclient.c */ +extern cap_channel_t *capsyslog; extern char *path_dhclient_conf; extern char *path_dhclient_db; extern time_t cur_time; Modified: head/sbin/dhclient/dispatch.c ============================================================================== --- head/sbin/dhclient/dispatch.c Sun Nov 12 08:34:25 2017 (r325739) +++ head/sbin/dhclient/dispatch.c Sun Nov 12 08:42:43 2017 (r325740) @@ -298,7 +298,8 @@ interface_status(struct interface_info *ifinfo) memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) { - syslog(LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m", ifname); + cap_syslog(capsyslog, LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m", + ifname); goto inactive; } @@ -316,9 +317,8 @@ interface_status(struct interface_info *ifinfo) strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { if (errno != EINVAL) { - syslog(LOG_DEBUG, "ioctl(SIOCGIFMEDIA) on %s: %m", - ifname); - + cap_syslog(capsyslog, LOG_DEBUG, + "ioctl(SIOCGIFMEDIA) on %s: %m", ifname); ifinfo->noifmedia = 1; goto active; } @@ -479,8 +479,8 @@ interface_link_status(char *ifname) if (ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmr) == -1) { /* EINVAL -> link state unknown. treat as active */ if (errno != EINVAL) - syslog(LOG_DEBUG, "ioctl(SIOCGIFMEDIA) on %s: %m", - ifname); + cap_syslog(capsyslog, LOG_DEBUG, + "ioctl(SIOCGIFMEDIA) on %s: %m", ifname); close(sock); return (1); } Modified: head/sbin/dhclient/errwarn.c ============================================================================== --- head/sbin/dhclient/errwarn.c Sun Nov 12 08:34:25 2017 (r325739) +++ head/sbin/dhclient/errwarn.c Sun Nov 12 08:42:43 2017 (r325740) @@ -69,7 +69,7 @@ error(char *fmt, ...) va_end(list); #ifndef DEBUG - syslog(log_priority | LOG_ERR, "%s", mbuf); + cap_syslog(capsyslog, log_priority | LOG_ERR, "%s", mbuf); #endif /* Also log it to stderr? */ @@ -78,7 +78,7 @@ error(char *fmt, ...) write(2, "\n", 1); } - syslog(LOG_CRIT, "exiting."); + cap_syslog(capsyslog, LOG_CRIT, "exiting."); if (log_perror) { fprintf(stderr, "exiting.\n"); fflush(stderr); @@ -103,7 +103,7 @@ warning(char *fmt, ...) va_end(list); #ifndef DEBUG - syslog(log_priority | LOG_ERR, "%s", mbuf); + cap_syslog(capsyslog, log_priority | LOG_ERR, "%s", mbuf); #endif if (log_perror) { @@ -129,7 +129,7 @@ note(char *fmt, ...) va_end(list); #ifndef DEBUG - syslog(log_priority | LOG_INFO, "%s", mbuf); + cap_syslog(capsyslog, log_priority | LOG_INFO, "%s", mbuf); #endif if (log_perror) { @@ -155,7 +155,7 @@ debug(char *fmt, ...) va_end(list); #ifndef DEBUG - syslog(log_priority | LOG_DEBUG, "%s", mbuf); + cap_syslog(capsyslog, log_priority | LOG_DEBUG, "%s", mbuf); #endif if (log_perror) { @@ -217,10 +217,10 @@ parse_warn(char *fmt, ...) va_end(list); #ifndef DEBUG - syslog(log_priority | LOG_ERR, "%s", mbuf); - syslog(log_priority | LOG_ERR, "%s", token_line); + cap_syslog(capsyslog, log_priority | LOG_ERR, "%s", mbuf); + cap_syslog(capsyslog, log_priority | LOG_ERR, "%s", token_line); if (lexline < 81) - syslog(log_priority | LOG_ERR, + cap_syslog(capsyslog, log_priority | LOG_ERR, "%s^", &spaces[sizeof(spaces) - lexchar]); #endif