From 6a1409b12d47f823a6e77b78823525d5ae65ee7b Mon Sep 17 00:00:00 2001
From: Miles Bader <miles@gnu.org>
Date: Wed, 20 Dec 1995 22:44:06 +0000
Subject: (proc_stat_set_flags): If there's no owner, set the uid to -1 (and
 the owner   to null), instead of failing. (proc_stat_set_flags): Add support
 for PROC_OWNER_UID. (add_preconditions): Add preconditions for owner_uid (&
 owner).

---
 libps/procstat.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

(limited to 'libps/procstat.c')

diff --git a/libps/procstat.c b/libps/procstat.c
index f53acc5f..100a275b 100644
--- a/libps/procstat.c
+++ b/libps/procstat.c
@@ -177,6 +177,10 @@ add_preconditions (ps_flags_t flags)
     flags |= PSTAT_CTTYID;
   if (flags & PSTAT_STATE)
     flags |= PSTAT_PROC_INFO | PSTAT_THREAD_BASIC;
+  if (flags & PSTAT_OWNER)
+    flags |= PSTAT_OWNER_UID;
+  if (flags & PSTAT_OWNER_UID)
+    flags |= PSTAT_PROC_INFO;
   if (flags & PSTAT_SUSPEND_COUNT)
     /* We just request the resources require for both the thread and task
        versions, as the extraneous info won't be possible to aquire anyway. */
@@ -684,9 +688,23 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags)
   MP_MGET(PSTAT_UMASK, PSTAT_TASK,
 	  msg_get_init_int(ps->msgport, ps->task, INIT_UMASK, &ps->umask));
 
+  if ((need & PSTAT_OWNER_UID) && (have & PSTAT_PROC_INFO))
+    {
+      if (ps->proc_info->state & PI_NOTOWNED)
+	ps->owner_uid = -1;
+      else
+	ps->owner_uid = ps->proc_info->owner;
+      have |= PSTAT_OWNER_UID;
+    }
+
   /* A ps_user_t object for the process's owner.  */
-  if ((need & PSTAT_OWNER) && (have & PSTAT_PROC_INFO))
-    if (! ps_context_find_user(ps->context, ps->proc_info->owner, &ps->owner))
+  if ((need & PSTAT_OWNER) && (have & PSTAT_OWNER_UID))
+    if (ps->owner_uid < 0)
+      {
+	ps->owner = 0;
+	have |= PSTAT_OWNER;
+      }
+    else if (! ps_context_find_user(ps->context, ps->owner_uid, &ps->owner))
       have |= PSTAT_OWNER;
 
   /* A ps_tty_t for the process's controlling terminal, or NULL if it
-- 
cgit v1.2.3