Drop confusing leading / in sig2str() and code2str()

This was added for the benefit of `initctl status foo`, but we have
other users of these functions that don't expect a leading slash.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-11-08 22:37:13 +01:00
1 parent 4709394ae6
commit bd5cf7c9eb
2 files changed
+12 -12

No files matched your search

+10 -4
View File
@@ -738,15 +738,21 @@ static char *svc_environ(svc_t *svc, char *buf, size_t len)
static char *exit_status(svc_t *svc, char *buf, size_t len) static char *exit_status(svc_t *svc, char *buf, size_t len)
{ {
int rc, sig; int rc, sig;
char *str;
rc = WEXITSTATUS(svc->status); rc = WEXITSTATUS(svc->status);
sig = WTERMSIG(svc->status); sig = WTERMSIG(svc->status);
if (WIFEXITED(svc->status)) if (WIFEXITED(svc->status)) {
snprintf(buf, len, " (code=exited, status=%d%s%s)", rc, code2str(rc), str = code2str(rc);
snprintf(buf, len, " (code=exited, status=%d%s%s%s)", rc,
str[0] ? "/" : "", str,
svc->manual ? ", manual=yes" : ""); svc->manual ? ", manual=yes" : "");
else if (WIFSIGNALED(svc->status)) }
snprintf(buf, len, " (code=signal, status=%d%s)", sig, sig2str(sig)); else if (WIFSIGNALED(svc->status)) {
str = sig2str(sig);
snprintf(buf, len, " (code=signal, status=%d%s%s)", sig, str[0] ? "/" : "", str);
}
return buf; return buf;
} }
+2 -8
View File
@@ -304,13 +304,10 @@ int strtobytes(char *arg)
char *sig2str(int signo) char *sig2str(int signo)
{ {
static char signame[8];
if (signo < 1 || signo >= (int)NELEMS(signames)) if (signo < 1 || signo >= (int)NELEMS(signames))
return ""; return "";
snprintf(signame, sizeof(signame), "/%s", signames[signo]); return signames[signo];
return signame;
} }
/** /**
@@ -337,13 +334,10 @@ int str2sig(char *sig)
char *code2str(int code) char *code2str(int code)
{ {
static char codename[20];
if (code < 0 || code >= (int)NELEMS(exitcodes)) if (code < 0 || code >= (int)NELEMS(exitcodes))
return ""; return "";
snprintf(codename, sizeof(codename), "/%s", exitcodes[code]); return exitcodes[code];
return codename;
} }