mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 16:58:02 +02:00
glib-aux: add nm_utils_get_process_exit_status_desc_buf() helper
This commit is contained in:
parent
cd2f8945c9
commit
95e6ebec66
2 changed files with 33 additions and 10 deletions
|
|
@ -6100,19 +6100,38 @@ nm_crypto_md5_hash(const guint8 *salt,
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
const char *
|
||||||
|
nm_utils_get_process_exit_status_desc_buf(int status, char *buf, gsize buf_len)
|
||||||
|
{
|
||||||
|
const char *buf0 = buf;
|
||||||
|
|
||||||
|
nm_assert(buf_len == 0 || buf);
|
||||||
|
|
||||||
|
/* This should give a partial sentence, it it can be combined with
|
||||||
|
* prinft("command XYZ %s.\n", desc) */
|
||||||
|
|
||||||
|
if (WIFEXITED(status))
|
||||||
|
nm_strbuf_append(&buf, &buf_len, "exited with status %d", WEXITSTATUS(status));
|
||||||
|
else if (WIFSIGNALED(status))
|
||||||
|
nm_strbuf_append(&buf, &buf_len, "killed by signal %d", WTERMSIG(status));
|
||||||
|
else if (WIFSTOPPED(status))
|
||||||
|
nm_strbuf_append(&buf, &buf_len, "stopped by signal %d", WSTOPSIG(status));
|
||||||
|
else if (WIFCONTINUED(status))
|
||||||
|
nm_strbuf_append(&buf, &buf_len, "resumed by SIGCONT");
|
||||||
|
else
|
||||||
|
nm_strbuf_append(&buf, &buf_len, "exited with unknown status 0x%x", status);
|
||||||
|
|
||||||
|
return buf0;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
nm_utils_get_process_exit_status_desc(int status)
|
nm_utils_get_process_exit_status_desc(int status)
|
||||||
{
|
{
|
||||||
if (WIFEXITED(status))
|
char buf[NM_UTILS_GET_PROCESS_EXIT_STATUS_BUF_LEN];
|
||||||
return g_strdup_printf("exited with status %d", WEXITSTATUS(status));
|
|
||||||
else if (WIFSIGNALED(status))
|
nm_utils_get_process_exit_status_desc_buf(status, buf, sizeof(buf));
|
||||||
return g_strdup_printf("killed by signal %d", WTERMSIG(status));
|
|
||||||
else if (WIFSTOPPED(status))
|
return g_strdup(buf);
|
||||||
return g_strdup_printf("stopped by signal %d", WSTOPSIG(status));
|
|
||||||
else if (WIFCONTINUED(status))
|
|
||||||
return g_strdup("resumed by SIGCONT)");
|
|
||||||
else
|
|
||||||
return g_strdup_printf("exited with unknown status 0x%x", status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -3067,6 +3067,10 @@ void nm_crypto_md5_hash(const guint8 *salt,
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
#define NM_UTILS_GET_PROCESS_EXIT_STATUS_BUF_LEN 41
|
||||||
|
|
||||||
|
const char *nm_utils_get_process_exit_status_desc_buf(int status, char *buf, gsize buf_len);
|
||||||
|
|
||||||
char *nm_utils_get_process_exit_status_desc(int status);
|
char *nm_utils_get_process_exit_status_desc(int status);
|
||||||
|
|
||||||
gboolean nm_utils_validate_hostname(const char *hostname);
|
gboolean nm_utils_validate_hostname(const char *hostname);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue