Commit f11bb3d9 authored by Thomas Haller's avatar Thomas Haller

shared: minor cleanup of nm_utils_get_start_time_for_pid()

parent fd9f1b7c
......@@ -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 ();
}
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment