mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-04 06:20:17 +01:00
shared: minor cleanup of nm_utils_get_start_time_for_pid()
This commit is contained in:
parent
fd9f1b7cdd
commit
f11bb3d93d
2 changed files with 22 additions and 7 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue