summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-05-25 15:38:21 +0200
committerThomas Haller <thaller@redhat.com>2018-05-26 20:11:04 +0200
commitf11bb3d93d3557847018871cacf918ea24664ddf (patch)
treef7a9d39286754a649c08f3e4129b03816f02ddaf
parentfd9f1b7cdd86286b2239e4f771e759c8a5b82aad (diff)
downloadNetworkManager-f11bb3d93d3557847018871cacf918ea24664ddf.tar.gz
shared: minor cleanup of nm_utils_get_start_time_for_pid()
-rw-r--r--libnm-core/tests/test-general.c18
-rw-r--r--shared/nm-utils/nm-shared-utils.c11
2 files changed, 22 insertions, 7 deletions
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index 0f04aee99b..c853754da0 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -6873,6 +6873,22 @@ test_nm_set_out (void)
/*****************************************************************************/
+static void
+test_get_start_time_for_pid (void)
+{
+ guint64 x_start_time;
+ char x_state;
+ pid_t x_ppid;
+
+ x_start_time = nm_utils_get_start_time_for_pid (getpid (), &x_state, &x_ppid);
+
+ g_assert (x_start_time > 0);
+ g_assert (x_ppid == getppid ());
+ g_assert (!NM_IN_SET (x_state, '\0', ' '));
+}
+
+/*****************************************************************************/
+
NMTST_DEFINE ();
int main (int argc, char **argv)
@@ -7026,6 +7042,8 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/route_attributes/parse", test_route_attributes_parse);
g_test_add_func ("/core/general/route_attributes/format", test_route_attributes_format);
+ g_test_add_func ("/core/general/get_start_time_for_pid", test_get_start_time_for_pid);
+
return g_test_run ();
}
diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c
index 96e5da350b..d0019c1174 100644
--- a/shared/nm-utils/nm-shared-utils.c
+++ b/shared/nm-utils/nm-shared-utils.c
@@ -1371,8 +1371,7 @@ nm_utils_get_start_time_for_pid (pid_t pid, char *out_state, pid_t *out_ppid)
char filename[256];
gs_free gchar *contents = NULL;
size_t length;
- gs_strfreev gchar **tokens = NULL;
- guint num_tokens;
+ gs_free const char **tokens = NULL;
gchar *p;
char state = ' ';
gint64 ppid = 0;
@@ -1392,7 +1391,7 @@ nm_utils_get_start_time_for_pid (pid_t pid, char *out_state, pid_t *out_ppid)
* processes trying to fool us
*/
p = strrchr (contents, ')');
- if (p == NULL)
+ if (!p)
goto fail;
p += 2; /* skip ') ' */
if (p - contents >= (int) length)
@@ -1400,11 +1399,9 @@ nm_utils_get_start_time_for_pid (pid_t pid, char *out_state, pid_t *out_ppid)
state = p[0];
- tokens = g_strsplit (p, " ", 0);
+ tokens = nm_utils_strsplit_set (p, " ");
- num_tokens = g_strv_length (tokens);
-
- if (num_tokens < 20)
+ if (NM_PTRARRAY_LEN (tokens) < 20)
goto fail;
if (out_ppid) {