diff --git a/src/cfg.rl b/src/cfg.rl index f3fa1b1..23ff81b 100644 --- a/src/cfg.rl +++ b/src/cfg.rl @@ -57,6 +57,7 @@ struct cfgparse { } } action pidfile { + write_pid_enabled = true; copy_cmdarg(pidfile, ccfg.buf, sizeof pidfile, "pidfile"); } action hostname { diff --git a/src/ndhc-defines.h b/src/ndhc-defines.h index 4f04672..e4b3740 100644 --- a/src/ndhc-defines.h +++ b/src/ndhc-defines.h @@ -1,8 +1,6 @@ #ifndef NDHC_DEFINES_H_ #define NDHC_DEFINES_H_ -#define PID_FILE_DEFAULT "/var/run/ndhc.pid" -#define PID_FILE_IFCH_DEFAULT "/var/run/ifchd.pid" #define NDHC_VERSION "2.0" #define MAX_BUF 1024 diff --git a/src/ndhc.c b/src/ndhc.c index 56f29f0..7b7c75d 100644 --- a/src/ndhc.c +++ b/src/ndhc.c @@ -423,13 +423,14 @@ static void do_ndhc_work(void) char state_dir[PATH_MAX] = "/etc/ndhc"; char chroot_dir[PATH_MAX] = ""; char resolv_conf_d[PATH_MAX] = ""; -char pidfile[PATH_MAX] = PID_FILE_DEFAULT; +char pidfile[PATH_MAX] = ""; uid_t ndhc_uid = 0; gid_t ndhc_gid = 0; int ifchSock[2]; int sockdSock[2]; int ifchStream[2]; int sockdStream[2]; +bool write_pid_enabled = false; static void create_ifch_ipc_sockets(void) { if (socketpair(AF_UNIX, SOCK_DGRAM, 0, ifchSock) < 0) @@ -489,12 +490,9 @@ static void ndhc_main(void) { cs.rfkillFd = rfkill_open(&client_config.enable_rfkill); - if (client_config.foreground && !client_config.background_if_no_lease) { - if (file_exists(pidfile, "w") < 0) - suicide("%s: can't open pidfile '%s' for write!", - __func__, pidfile); + if (write_pid_enabled && + client_config.foreground && !client_config.background_if_no_lease) write_pid(pidfile); - } open_leasefile(); @@ -520,9 +518,7 @@ void background(void) exit(EXIT_SUCCESS); } } - if (file_exists(pidfile, "w") < 0) { - log_warning("Cannot open pidfile for write!"); - } else + if (write_pid_enabled) write_pid(pidfile); } diff --git a/src/ndhc.h b/src/ndhc.h index 76a4e6c..d9624af 100644 --- a/src/ndhc.h +++ b/src/ndhc.h @@ -80,6 +80,7 @@ extern char resolv_conf_d[PATH_MAX]; extern char pidfile[PATH_MAX]; extern uid_t ndhc_uid; extern gid_t ndhc_gid; +extern bool write_pid_enabled; void set_client_addr(const char v[static 1]); void show_usage(void);