]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: shortcut get_process_state() for our own process 14145/head
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Nov 2019 13:59:01 +0000 (14:59 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Nov 2019 18:23:31 +0000 (19:23 +0100)
src/basic/process-util.c

index 003aecbc49ba7771cfe308e59787e6b7f1a779e5..9b6c4c31f713da377515ddf797900fe887b462ab 100644 (file)
 #define COMM_MAX_LEN 128
 
 static int get_process_state(pid_t pid) {
+        _cleanup_free_ char *line = NULL;
         const char *p;
         char state;
         int r;
-        _cleanup_free_ char *line = NULL;
 
         assert(pid >= 0);
 
+        /* Shortcut: if we are enquired about our own state, we are obviously running */
+        if (pid == 0 || pid == getpid_cached())
+                return (unsigned char) 'R';
+
         p = procfs_file_alloca(pid, "stat");
 
         r = read_one_line_file(p, &line);