summary refs log tree commit diff
path: root/src/libnm-glib-aux/nm-shared-utils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2022-10-18 11:56:48 +0200
committerMichael Biebl <biebl@debian.org>2022-10-18 11:56:48 +0200
commit9f101839d9e64df832e9e43c5181887369c46a7e (patch)
tree3e23589a9d4e9e7c32ce41b634ccf26af3f0d45e /src/libnm-glib-aux/nm-shared-utils.c
parentab0efddcdb48d800e2f938da54cfe3074640792e (diff)
New upstream version 1.40.2 upstream/1.40.2
Diffstat (limited to 'src/libnm-glib-aux/nm-shared-utils.c')
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c
index 624f9a3e..d0885477 100644
--- a/src/libnm-glib-aux/nm-shared-utils.c
+++ b/src/libnm-glib-aux/nm-shared-utils.c
@@ -6621,19 +6621,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);
 }
 
 /*****************************************************************************/