aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-11 13:43:37 +0200
committerMattias Andrée <maandree@kth.se>2016-07-11 13:43:37 +0200
commit9ee315c4a06e9a2f83a3461e69befc94fed2ef16 (patch)
treed460b824063ff64cede8949da6f00baa6ccdf200 /src
parentRetry once if pid file is empty (diff)
downloadcoopgammad-9ee315c4a06e9a2f83a3461e69befc94fed2ef16.tar.gz
coopgammad-9ee315c4a06e9a2f83a3461e69befc94fed2ef16.tar.bz2
coopgammad-9ee315c4a06e9a2f83a3461e69befc94fed2ef16.tar.xz
Use exit value 2 to indicate that the service is already running
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/gammad.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/gammad.c b/src/gammad.c
index fe1b004..ad4d255 100644
--- a/src/gammad.c
+++ b/src/gammad.c
@@ -294,7 +294,8 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
* Create PID file
*
* @param pidfile The pathname of the PID file
- * @return Zero on success, -1 on error
+ * @return Zero on success, -1 on error,
+ * -2 if the service is already running
*/
static int create_pidfile(char* pidfile)
{
@@ -340,7 +341,7 @@ static int create_pidfile(char* pidfile)
goto fail;
fprintf(stderr, "%s: service is already running\n", argv0);
errno = 0;
- return -1;
+ return -2;
}
/* Write PID to PID file. */
@@ -371,9 +372,14 @@ static void usage(void)
}
+/**
+ * @return 0: Successful
+ * 1: An error occurred
+ * 2: Already running
+ */
int main(int argc, char** argv)
{
- int method = -1, gerror, rc = 1, preserve = 0;
+ int method = -1, gerror, rc = 1, preserve = 0, r;
char* sitename = NULL;
libgamma_site_state_t site;
libgamma_partition_state_t* partitions = NULL;
@@ -419,9 +425,10 @@ int main(int argc, char** argv)
goto fail;
/* Create PID file */
- if (create_pidfile(pidpath) < 0)
+ if ((r = create_pidfile(pidpath)) < 0)
{
free(pidpath), pidpath = NULL;
+ rc = -r;
goto fail;
}