diff options
author | David Timber <mieabby@gmail.com> | 2020-09-22 17:05:06 +0930 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2020-09-22 17:05:06 +0930 |
commit | c1ae3eef633237525443d48622bb6f633392d2f6 (patch) | |
tree | 4e3c3aaf481a6c67fc830291272e6746f2ecf725 | |
parent | a90806846e881c0894726e89e1584540457a168d (diff) |
* Add proone exit codes as macro defs
* Lock file acquisition failure is not an error
-rw-r--r-- | src/bne.c | 29 | ||||
-rw-r--r-- | src/proone.c | 6 | ||||
-rw-r--r-- | src/protocol.h | 5 |
3 files changed, 31 insertions, 9 deletions
@@ -1202,10 +1202,17 @@ static bool bne_sh_setup ( if (PRNE_DEBUG && PRNE_VERBOSE >= PRNE_VL_DBG0) { const char *arch_str = prne_arch_tostr(ctx->result.arch); - prne_dbgpf( - "bne@%"PRIxPTR"\t: arch: %s\n", - (uintptr_t)ctx, - arch_str == NULL ? "?" : arch_str); + if (arch_str == NULL) { + prne_dbgpf( + "bne@%"PRIxPTR"\t: arch detection failed\n", + (uintptr_t)ctx); + } + else { + prne_dbgpf( + "bne@%"PRIxPTR"\t: arch: %s\n", + (uintptr_t)ctx, + arch_str); + } } ret = ctx->result.arch != PRNE_ARCH_NONE; @@ -1559,7 +1566,7 @@ static bool bne_sh_run_exec ( char *cmd; bne_sh_parser_t parser; int ec = -1; - bool ret; + bool ret = false; bne_init_sh_parser(&parser); parser.ctx = &ec; @@ -1571,7 +1578,17 @@ static bool bne_sh_run_exec ( return false; } - ret = bne_sh_runcmd_line(s_ctx, &parser, cmd) && ec == 0; + if (bne_sh_runcmd_line(s_ctx, &parser, cmd)) { + switch (ec) { + case PRNE_PROONE_EC_OK: + // successful launch + case PRNE_PROONE_EC_LOCK: + // failed to acquire lock + // assume that a process is already running + ret = true; + break; + } + } prne_free(cmd); return ret; diff --git a/src/proone.c b/src/proone.c index 35c11a1..d480696 100644 --- a/src/proone.c +++ b/src/proone.c @@ -306,7 +306,7 @@ static int proone_main (void) { pth_kill(); libssh2_exit(); - return 0; + return PRNE_PROONE_EC_OK; } static void close_blackhole (void) { @@ -1046,7 +1046,7 @@ int main (const int argc, const char **args) { init_ids(); if (!init_shared_global()) { prne_dbgpf("*** Another instance detected.\n"); - exit_code = 1; + exit_code = PRNE_PROONE_EC_LOCK; goto END; } delete_myself(args[0]); @@ -1062,7 +1062,7 @@ int main (const int argc, const char **args) { const pid_t f_ret = fork(); if (f_ret < 0) { - exit_code = 2; + exit_code = PRNE_PROONE_EC_FAIL; goto END; } else if (f_ret == 0) { diff --git a/src/protocol.h b/src/protocol.h index b0b964e..6813729 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -7,6 +7,11 @@ #include <netinet/in.h> +#define PRNE_PROONE_EC_OK 0 +#define PRNE_PROONE_EC_FAIL 1 +#define PRNE_PROONE_EC_LOCK 3 + + typedef struct prne_net_endpoint prne_net_endpoint_t; typedef struct prne_ip_addr prne_ip_addr_t; typedef struct prne_host_cred prne_host_cred_t; |