summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-09-27 18:05:51 +0200
committerThomas Haller <thaller@redhat.com>2022-09-29 14:41:58 +0200
commit95e6ebec66f173c8b958ebbbbfb745fa41d5f83c (patch)
tree2cf389953d196db61b219248bd8872bfadd6d499
parentcd2f8945c942e591af03ff867ebfedc5f74f32e9 (diff)
glib-aux: add nm_utils_get_process_exit_status_desc_buf() helper
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.c33
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h4
2 files changed, 30 insertions, 7 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c
index 6f56a4fe95..e02803a6ea 100644
--- a/src/libnm-glib-aux/nm-shared-utils.c
+++ b/src/libnm-glib-aux/nm-shared-utils.c
@@ -6100,19 +6100,38 @@ nm_crypto_md5_hash(const guint8 *salt,
/*****************************************************************************/
-char *
-nm_utils_get_process_exit_status_desc(int status)
+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))
- return g_strdup_printf("exited with status %d", WEXITSTATUS(status));
+ nm_strbuf_append(&buf, &buf_len, "exited with status %d", WEXITSTATUS(status));
else if (WIFSIGNALED(status))
- return g_strdup_printf("killed by signal %d", WTERMSIG(status));
+ nm_strbuf_append(&buf, &buf_len, "killed by signal %d", WTERMSIG(status));
else if (WIFSTOPPED(status))
- return g_strdup_printf("stopped by signal %d", WSTOPSIG(status));
+ nm_strbuf_append(&buf, &buf_len, "stopped by signal %d", WSTOPSIG(status));
else if (WIFCONTINUED(status))
- return g_strdup("resumed by SIGCONT)");
+ nm_strbuf_append(&buf, &buf_len, "resumed by SIGCONT");
else
- return g_strdup_printf("exited with unknown status 0x%x", status);
+ nm_strbuf_append(&buf, &buf_len, "exited with unknown status 0x%x", status);
+
+ return buf0;
+}
+
+char *
+nm_utils_get_process_exit_status_desc(int status)
+{
+ char buf[NM_UTILS_GET_PROCESS_EXIT_STATUS_BUF_LEN];
+
+ nm_utils_get_process_exit_status_desc_buf(status, buf, sizeof(buf));
+
+ return g_strdup(buf);
}
/*****************************************************************************/
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index 3d32f0d21a..ce00a5e953 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -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);
gboolean nm_utils_validate_hostname(const char *hostname);