Skip to content

Commit

Permalink
make HUP restart independent of path
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Jul 24, 2011
1 parent 241e73a commit 3a9a3ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ 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[] = {
Expand Down Expand Up @@ -328,8 +330,9 @@ hgd_daemonise()
void
hgd_restart_myself()
{
DPRINTF(HGD_D_INFO, "Caught SIGHUP, restarting");
if (execvp(hgd_component, cmd_line_args) < 0) {
DPRINTF(HGD_D_WARN, "Caught SIGHUP, restarting");

if (execv(self_abs_path, cmd_line_args) < 0) {
DPRINTF(HGD_D_ERROR, "Failed to restart"
", is %s in your path?: %s", hgd_component, SERROR);
}
Expand All @@ -341,3 +344,17 @@ hgd_restart_myself()
*/
DPRINTF(HGD_D_ERROR, "%s was interrupted or crashed", hgd_component);
}


int
hgd_cache_abs_path(char *inv)
{
if (*inv != '/') {
DPRINTF(HGD_D_ERROR,
"HGD daemons must be started with an absolute path");
return (HGD_FAIL);
}

self_abs_path = inv;
return (HGD_OK);
}
3 changes: 3 additions & 0 deletions hgd-netd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,9 @@ main(int argc, char **argv)

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();

Expand Down
3 changes: 3 additions & 0 deletions hgd-playd.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ main(int argc, char **argv)

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();

Expand Down
2 changes: 2 additions & 0 deletions hgd.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ 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;
Expand Down Expand Up @@ -250,5 +251,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);

#endif

0 comments on commit 3a9a3ce

Please sign in to comment.