comparison src/dhcpcd.c @ 5526:b1a3d9055662 draft

privsep: Allow logfile reopening in a chroot Now that only the privileged actioneer does the actual logging we can safely reopen the file we are logging to. This also closes and re-opens the syslog connection.
author Roy Marples <roy@marples.name>
date Fri, 30 Oct 2020 14:19:16 +0000
parents 26b5d9bc2985
children 071a9ea18363
comparison
equal deleted inserted replaced
5525:26b5d9bc2985 5526:b1a3d9055662
1420 loginfox(sigmsg, "SIGUSR1", "renewing"); 1420 loginfox(sigmsg, "SIGUSR1", "renewing");
1421 dhcpcd_renew(ctx); 1421 dhcpcd_renew(ctx);
1422 return; 1422 return;
1423 case SIGUSR2: 1423 case SIGUSR2:
1424 loginfox(sigmsg, "SIGUSR2", "reopening log"); 1424 loginfox(sigmsg, "SIGUSR2", "reopening log");
1425 /* XXX This may not work that well in a chroot */ 1425 if (IN_PRIVSEP(ctx)) {
1426 logclose(); 1426 if (ps_root_logreopen(ctx) == -1)
1427 if (logopen(ctx->logfile) == -1) 1427 logerr("ps_root_logreopen");
1428 logerr(__func__); 1428 } else {
1429 logclose();
1430 if (logopen(ctx->logfile) == -1)
1431 logerr("logopen");
1432 }
1429 return; 1433 return;
1430 case SIGCHLD: 1434 case SIGCHLD:
1431 while (waitpid(-1, NULL, WNOHANG) > 0) 1435 while (waitpid(-1, NULL, WNOHANG) > 0)
1432 ; 1436 ;
1433 return; 1437 return;
1858 #ifdef DHCP6 1862 #ifdef DHCP6
1859 ctx.dhcp6_rfd = -1; 1863 ctx.dhcp6_rfd = -1;
1860 ctx.dhcp6_wfd = -1; 1864 ctx.dhcp6_wfd = -1;
1861 #endif 1865 #endif
1862 #ifdef PRIVSEP 1866 #ifdef PRIVSEP
1863 ctx.ps_root_fd = ctx.ps_syslog_fd = ctx.ps_data_fd = -1; 1867 ctx.ps_root_fd = ctx.ps_log_fd = ctx.ps_data_fd = -1;
1864 ctx.ps_inet_fd = ctx.ps_control_fd = -1; 1868 ctx.ps_inet_fd = ctx.ps_control_fd = -1;
1865 TAILQ_INIT(&ctx.ps_processes); 1869 TAILQ_INIT(&ctx.ps_processes);
1866 #endif 1870 #endif
1867 1871
1868 /* Check our streams for validity */ 1872 /* Check our streams for validity */
2326 } 2330 }
2327 2331
2328 /* We have now forked, setsid, forked once more. 2332 /* We have now forked, setsid, forked once more.
2329 * From this point on, we are the controlling daemon. */ 2333 * From this point on, we are the controlling daemon. */
2330 ctx.options |= DHCPCD_STARTED; 2334 ctx.options |= DHCPCD_STARTED;
2335 logdebugx("spawned master process on PID %d", getpid());
2331 if ((pid = pidfile_lock(ctx.pidfile)) != 0) { 2336 if ((pid = pidfile_lock(ctx.pidfile)) != 0) {
2332 logerr("%s: pidfile_lock %d", __func__, pid); 2337 logerr("%s: pidfile_lock %d", __func__, pid);
2333 #ifdef PRIVSEP 2338 #ifdef PRIVSEP
2334 /* privsep has not started ... */ 2339 /* privsep has not started ... */
2335 ctx.options &= ~DHCPCD_PRIVSEP; 2340 ctx.options &= ~DHCPCD_PRIVSEP;