diff options
author | Mattias Andrée <maandree@kth.se> | 2016-07-11 23:49:07 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-07-11 23:49:07 +0200 |
commit | 9ad1decbb80792220dae648e411e2213252b46da (patch) | |
tree | e536fb34615de5b489540697fb49b91c7d501f6b /src | |
parent | Update usage() (diff) | |
download | coopgammad-9ad1decbb80792220dae648e411e2213252b46da.tar.gz coopgammad-9ad1decbb80792220dae648e411e2213252b46da.tar.bz2 coopgammad-9ad1decbb80792220dae648e411e2213252b46da.tar.xz |
Conditionally store realpath(argv0) so we can reexecute even if argv0 is relative
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/gammad.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/gammad.c b/src/gammad.c index 708e5df..6dcb31f 100644 --- a/src/gammad.c +++ b/src/gammad.c @@ -43,6 +43,12 @@ char* argv0; /** + * The real pathname of the process's binary, + * `NULL` if `argv0` is satisfactory + */ +char* argv0_real = NULL; + +/** * Array of all outputs */ struct output* outputs = NULL; @@ -674,6 +680,12 @@ static int initialise(int method, const char *sitename, int preserve, int foregr if (listen(socketfd, SOMAXCONN) < 0) goto fail; + /* Get the real pathname of the process's binary, in case + * it is relative, so we can re-execute without problem. */ + if ((*argv0 != '/') && strchr(argv0, '/')) + if (!(argv0_real = realpath(argv0, NULL))) + goto fail; + /* Change directory to / to avoid blocking umounting */ if (chdir("/") < 0) perror(argv0); @@ -860,6 +872,7 @@ static void destroy(void) if (pidpath) unlink(pidpath); free(pidpath); + free(argv0_real); } @@ -876,6 +889,9 @@ static void usage(void) /** * Must not be started without stdin, stdout, or stderr (may be /dev/null) * + * argv[0] must refer to the real command name or pathname, + * otherwise, re-execute will not work + * * The process closes stdout when the socket has been created * * @signal SIGUSR1 Re-execute to updated process image |