Skip to content

Commit

Permalink
cache the whole lot in that func
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Jul 24, 2011
1 parent 3a9a3ce commit 869db0a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
18 changes: 10 additions & 8 deletions common.c
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
10 changes: 5 additions & 5 deletions hgd-netd.c
Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down
8 changes: 3 additions & 5 deletions hgd-playd.c
Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions hgd.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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

0 comments on commit 869db0a

Please sign in to comment.