From: Lennart Poettering Date: Mon, 25 Nov 2019 13:59:01 +0000 (+0100) Subject: process-util: shortcut get_process_state() for our own process X-Git-Tag: v244~24^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14145%2Fhead;p=thirdparty%2Fsystemd.git process-util: shortcut get_process_state() for our own process --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 003aecbc49b..9b6c4c31f71 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -52,13 +52,17 @@ #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);