(desirable_utmp_entry): Implement new flag: READ_UTMP_USER_PROCESS.
[pspp] / lib / readutmp.c
index cf29572f093ee28629c268cd15e0ad399dd239cf..aec1fee449a0f6f7b0e06f4ad10693a93123d479 100644 (file)
@@ -69,10 +69,15 @@ extract_trimmed_name (const STRUCT_UTMP *ut)
 static inline bool
 desirable_utmp_entry (STRUCT_UTMP const *u, int options)
 {
-  return ! (options & READ_UTMP_CHECK_PIDS
-           && IS_USER_PROCESS (u)
-           && (UT_PID (u) <= 0
-               || (kill (UT_PID (u), 0) < 0 && errno == ESRCH)));
+  int up = IS_USER_PROCESS (u);
+  if ((options & READ_UTMP_USER_PROCESS) && !up)
+    return false;
+  if ((options & READ_UTMP_CHECK_PIDS)
+      && up
+      && (UT_PID (u) <= 0
+         || (kill (UT_PID (u), 0) < 0 && errno == ESRCH)))
+    return false;
+  return true;
 }
 
 /* Read the utmp entries corresponding to file FILE into freshly-