@@ -2289,11 +2289,15 @@ main(int argc, char **argv, char **envp)
22892289 default :
22902290 per = "" ;
22912291 }
2292- snprintf (ctx .pidfile , sizeof (ctx .pidfile ), PIDFILE ,
2293- ifname , per , "." );
2292+ if (asprintf (& ctx .pidfile , PIDFILE , ifname , per , "." ) == -1 ) {
2293+ logerr ("%s: asprintf" , __func__ );
2294+ goto exit_failure ;
2295+ }
22942296 } else {
2295- snprintf (ctx .pidfile , sizeof (ctx .pidfile ), PIDFILE , "" ,
2296- "" , "" );
2297+ if (asprintf (& ctx .pidfile , PIDFILE , "" , "" , "" ) == -1 ) {
2298+ logerr ("%s: asprintf" , __func__ );
2299+ goto exit_failure ;
2300+ }
22972301 ctx .options |= DHCPCD_MANAGER ;
22982302
22992303 /*
@@ -2582,6 +2586,18 @@ main(int argc, char **argv, char **envp)
25822586#endif
25832587 goto exit_failure ;
25842588 }
2589+ #ifdef PRIVSEP_RIGHTS
2590+ {
2591+ cap_rights_t rights ;
2592+
2593+ cap_rights_init (& rights , CAP_READ , CAP_SEEK , CAP_FTRUNCATE );
2594+ if (cap_rights_limit (pidfile_fd (), & rights ) == -1 &&
2595+ errno != ENOSYS ) {
2596+ logerr ("%s: cap_rights_limit" , __func__ );
2597+ goto exit_failure ;
2598+ }
2599+ }
2600+ #endif
25852601#endif
25862602
25872603 os_init ();
@@ -2817,6 +2833,7 @@ main(int argc, char **argv, char **envp)
28172833 }
28182834#endif
28192835
2836+ free (ctx .pidfile );
28202837 eloop_free (ctx .eloop );
28212838 logclose ();
28222839 free (ctx .logfile );
@@ -2826,9 +2843,5 @@ main(int argc, char **argv, char **envp)
28262843 setproctitle_fini ();
28272844#endif
28282845
2829- #ifdef USE_SIGNALS
2830- if (ctx .options & (DHCPCD_FORKED | DHCPCD_PRIVSEP ))
2831- _exit (i ); /* so atexit won't remove our pidfile */
2832- #endif
28332846 return i ;
28342847}
0 commit comments