diff --git a/common.c b/common.c index bcebf28..e045e9a 100644 --- a/common.c +++ b/common.c @@ -48,8 +48,6 @@ uint8_t restarting = 0; uint8_t exit_ok = 0; pid_t pid = 0; -char *self_abs_path; - char *debug_names[] = { "error", "warn", "info", "debug"}; int syslog_error_map[] = { @@ -332,7 +330,7 @@ hgd_restart_myself() { DPRINTF(HGD_D_WARN, "Caught SIGHUP, restarting"); - if (execv(self_abs_path, cmd_line_args) < 0) { + if (execv(cmd_line_args[0], cmd_line_args) < 0) { DPRINTF(HGD_D_ERROR, "Failed to restart" ", is %s in your path?: %s", hgd_component, SERROR); } @@ -345,16 +343,20 @@ hgd_restart_myself() DPRINTF(HGD_D_ERROR, "%s was interrupted or crashed", hgd_component); } - int -hgd_cache_abs_path(char *inv) +hgd_cache_exec_context(char **argv) { - if (*inv != '/') { + if (*(argv[0]) != '/') { DPRINTF(HGD_D_ERROR, - "HGD daemons must be started with an absolute path"); + "HGD daemons must be started with an absolute path. " + "You passed '%s'", argv[0]); return (HGD_FAIL); } - self_abs_path = inv; + //self_abs_path = argv[0]; + cmd_line_args = argv; + + DPRINTF(HGD_D_INFO, "daemon='%s'", argv[0]); + return (HGD_OK); } diff --git a/hgd-netd.c b/hgd-netd.c index f6d9573..997d578 100644 --- a/hgd-netd.c +++ b/hgd-netd.c @@ -1249,11 +1249,6 @@ main(int argc, char **argv) char *config_path[4] = {NULL, NULL, NULL, NULL}; int num_config = 2; - cmd_line_args = argv; /* cache this incase of SIGHUP */ - - if (hgd_cache_abs_path(argv[0]) != HGD_OK) - hgd_exit_nicely(); - /* as early as possible */ HGD_INIT_SYSLOG_DAEMON(); @@ -1302,8 +1297,13 @@ main(int argc, char **argv) } } + RESET_GETOPT(); + /* cache HUP info */ + if (hgd_cache_exec_context(argv) != HGD_OK) + hgd_exit_nicely(); + hgd_read_config(config_path + num_config); DPRINTF(HGD_D_DEBUG, "Parsing options:2"); diff --git a/hgd-playd.c b/hgd-playd.c index a6cffdf..bd782bb 100644 --- a/hgd-playd.c +++ b/hgd-playd.c @@ -362,11 +362,6 @@ main(int argc, char **argv) char *config_path[4] = {NULL, NULL, NULL, NULL}; int num_config = 2; - cmd_line_args = argv; /* cache for restart */ - - if (hgd_cache_abs_path(argv[0]) != HGD_OK) - hgd_exit_nicely(); - /* early as possible */ HGD_INIT_SYSLOG_DAEMON(); @@ -425,6 +420,9 @@ main(int argc, char **argv) RESET_GETOPT(); + if (hgd_cache_exec_context(argv) != HGD_OK) + hgd_exit_nicely(); + DPRINTF(HGD_D_DEBUG, "Parsing options"); while ((ch = getopt(argc, argv, "Bc:Cd:hpP:qvx:")) != -1) { switch (ch) { diff --git a/hgd.h b/hgd.h index 9f97a19..3928597 100644 --- a/hgd.h +++ b/hgd.h @@ -101,7 +101,6 @@ extern char *debug_names[]; extern int syslog_error_map[]; extern pid_t pid; extern const char *hgd_component; -extern char *self_abs_path; extern char *state_path; extern char *filestore_path; @@ -251,6 +250,6 @@ int hgd_readpassphrase_confirmed( char buf[HGD_MAX_PASS_SZ]); int hgd_daemonise(void); void hgd_restart_myself(void); -int hgd_cache_abs_path(char *inv); +int hgd_cache_exec_context(char **args); #endif