diff options
| author | Michael Biebl <biebl@debian.org> | 2022-10-18 11:56:48 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2022-10-18 11:56:48 +0200 |
| commit | 9f101839d9e64df832e9e43c5181887369c46a7e (patch) | |
| tree | 3e23589a9d4e9e7c32ce41b634ccf26af3f0d45e /src/libnm-glib-aux | |
| parent | ab0efddcdb48d800e2f938da54cfe3074640792e (diff) | |
New upstream version 1.40.2 upstream/1.40.2
Diffstat (limited to 'src/libnm-glib-aux')
| -rw-r--r-- | src/libnm-glib-aux/nm-keyfile-aux.c | 2 | ||||
| -rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.c | 33 | ||||
| -rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.h | 8 | ||||
| -rw-r--r-- | src/libnm-glib-aux/nm-str-buf.h | 9 | ||||
| -rw-r--r-- | src/libnm-glib-aux/tests/test-shared-general.c | 10 |
5 files changed, 51 insertions, 11 deletions
diff --git a/src/libnm-glib-aux/nm-keyfile-aux.c b/src/libnm-glib-aux/nm-keyfile-aux.c index 1cae28b4..20a4690f 100644 --- a/src/libnm-glib-aux/nm-keyfile-aux.c +++ b/src/libnm-glib-aux/nm-keyfile-aux.c @@ -442,7 +442,7 @@ nm_key_file_db_prune(NMKeyFileDB *self, _LOGD("prune keyfile of old entries: \"%s\"", self->filename); if (!self->groups_pruned) { - /* When we prune the first time, we swap the GKeyfile instance. + /* When we prune the first time, we swap the GKeyFile instance. * The instance loaded from disk might have unrelated groups and * comments. Let's get rid of them by creating a new instance. * 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); } /*****************************************************************************/ diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 3d8eaced..fe7c59f3 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -809,6 +809,8 @@ gssize _nm_strv_find_first(const char *const *list, gssize len, const char *need #define nm_strv_find_first(list, len, needle) \ _nm_strv_find_first(NM_CAST_STRV_CC(list), (len), (needle)) +#define nm_strv_contains(list, len, needle) (nm_strv_find_first((list), (len), (needle)) >= 0) + gboolean nm_strv_has_duplicate(const char *const *list, gssize len, gboolean is_sorted); const char **nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated); @@ -1318,6 +1320,8 @@ typedef enum { NM_UTILS_ERROR_INVALID_ARGUMENT, /*< nick=InvalidArgument >*/ NM_UTILS_ERROR_NOT_READY, /*< nick=NotReady >*/ + NM_UTILS_ERROR_COMMAND_FAILED, /*< nick=CommandFailed >*/ + NM_UTILS_ERROR_AMBIGUOUS, /*< nick=Ambiguous >*/ /* the following codes have a special meaning and are exactly used for @@ -3403,6 +3407,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); diff --git a/src/libnm-glib-aux/nm-str-buf.h b/src/libnm-glib-aux/nm-str-buf.h index 652bc96b..e8b51208 100644 --- a/src/libnm-glib-aux/nm-str-buf.h +++ b/src/libnm-glib-aux/nm-str-buf.h @@ -78,14 +78,14 @@ NM_STR_BUF_INIT(gsize allocated, gboolean do_bzero_mem) ? (size) \ : 0, \ FALSE, \ - (do_bzero_mem)); + (do_bzero_mem)) #define NM_STR_BUF_INIT_ARR(arr, do_bzero_mem) \ NM_STR_BUF_INIT_FULL((arr), \ 0, \ NM_STATIC_ASSERT_EXPR_1(sizeof(arr) > sizeof(char *)) ? sizeof(arr) : 0, \ FALSE, \ - (do_bzero_mem)); + (do_bzero_mem)) void _nm_str_buf_ensure_size(NMStrBuf *strbuf, gsize new_size, gboolean reserve_exact); @@ -530,7 +530,10 @@ nm_str_buf_finalize(NMStrBuf *strbuf, gsize *out_len) char *str = g_steal_pointer(&strbuf->_priv_str); char *result; - result = g_strndup(str, strbuf->_priv_len); + result = g_new(char, strbuf->_priv_len + 1u); + memcpy(result, str, strbuf->_priv_len); + result[strbuf->_priv_len] = '\0'; + if (strbuf->_priv_do_bzero_mem) nm_explicit_bzero(str, strbuf->_priv_len); return result; diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c index 7d36d64a..cfe70b58 100644 --- a/src/libnm-glib-aux/tests/test-shared-general.c +++ b/src/libnm-glib-aux/tests/test-shared-general.c @@ -970,6 +970,16 @@ test_nm_str_buf(void) } else g_assert(stack_buf != nm_str_buf_get_str(&strbuf)); } + + { + nm_auto_str_buf NMStrBuf s1 = NM_STR_BUF_INIT_A(10, nmtst_get_rand_bool()); + gs_free char *str = NULL; + gsize l; + + nm_str_buf_append_len(&s1, "a\0b", 3); + str = nm_str_buf_finalize(&s1, &l); + g_assert_cmpmem(str, l + 1, "a\0b", 4); + } } /*****************************************************************************/ |