Update to latest write_pid semantics and don't write pidfile by default.
There was no way to disable writing pidfiles before. pidfiles are an unreliable method of tracking processes, anyway; process supervisors are strongly recommended. If a pidfile is really needed, it can be explicitly specified.
This commit is contained in:
parent
a47a2feea1
commit
04ec7c8f4b
@ -57,6 +57,7 @@ struct cfgparse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
action pidfile {
|
action pidfile {
|
||||||
|
write_pid_enabled = true;
|
||||||
copy_cmdarg(pidfile, ccfg.buf, sizeof pidfile, "pidfile");
|
copy_cmdarg(pidfile, ccfg.buf, sizeof pidfile, "pidfile");
|
||||||
}
|
}
|
||||||
action hostname {
|
action hostname {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#ifndef NDHC_DEFINES_H_
|
#ifndef NDHC_DEFINES_H_
|
||||||
#define 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 NDHC_VERSION "2.0"
|
||||||
#define MAX_BUF 1024
|
#define MAX_BUF 1024
|
||||||
|
|
||||||
|
14
src/ndhc.c
14
src/ndhc.c
@ -423,13 +423,14 @@ static void do_ndhc_work(void)
|
|||||||
char state_dir[PATH_MAX] = "/etc/ndhc";
|
char state_dir[PATH_MAX] = "/etc/ndhc";
|
||||||
char chroot_dir[PATH_MAX] = "";
|
char chroot_dir[PATH_MAX] = "";
|
||||||
char resolv_conf_d[PATH_MAX] = "";
|
char resolv_conf_d[PATH_MAX] = "";
|
||||||
char pidfile[PATH_MAX] = PID_FILE_DEFAULT;
|
char pidfile[PATH_MAX] = "";
|
||||||
uid_t ndhc_uid = 0;
|
uid_t ndhc_uid = 0;
|
||||||
gid_t ndhc_gid = 0;
|
gid_t ndhc_gid = 0;
|
||||||
int ifchSock[2];
|
int ifchSock[2];
|
||||||
int sockdSock[2];
|
int sockdSock[2];
|
||||||
int ifchStream[2];
|
int ifchStream[2];
|
||||||
int sockdStream[2];
|
int sockdStream[2];
|
||||||
|
bool write_pid_enabled = false;
|
||||||
|
|
||||||
static void create_ifch_ipc_sockets(void) {
|
static void create_ifch_ipc_sockets(void) {
|
||||||
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, ifchSock) < 0)
|
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);
|
cs.rfkillFd = rfkill_open(&client_config.enable_rfkill);
|
||||||
|
|
||||||
if (client_config.foreground && !client_config.background_if_no_lease) {
|
if (write_pid_enabled &&
|
||||||
if (file_exists(pidfile, "w") < 0)
|
client_config.foreground && !client_config.background_if_no_lease)
|
||||||
suicide("%s: can't open pidfile '%s' for write!",
|
|
||||||
__func__, pidfile);
|
|
||||||
write_pid(pidfile);
|
write_pid(pidfile);
|
||||||
}
|
|
||||||
|
|
||||||
open_leasefile();
|
open_leasefile();
|
||||||
|
|
||||||
@ -520,9 +518,7 @@ void background(void)
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file_exists(pidfile, "w") < 0) {
|
if (write_pid_enabled)
|
||||||
log_warning("Cannot open pidfile for write!");
|
|
||||||
} else
|
|
||||||
write_pid(pidfile);
|
write_pid(pidfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ extern char resolv_conf_d[PATH_MAX];
|
|||||||
extern char pidfile[PATH_MAX];
|
extern char pidfile[PATH_MAX];
|
||||||
extern uid_t ndhc_uid;
|
extern uid_t ndhc_uid;
|
||||||
extern gid_t ndhc_gid;
|
extern gid_t ndhc_gid;
|
||||||
|
extern bool write_pid_enabled;
|
||||||
|
|
||||||
void set_client_addr(const char v[static 1]);
|
void set_client_addr(const char v[static 1]);
|
||||||
void show_usage(void);
|
void show_usage(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user