[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/16] proc: add proc_mark_important server code
From: |
Justus Winter |
Subject: |
[PATCH 05/16] proc: add proc_mark_important server code |
Date: |
Mon, 5 Aug 2013 12:06:29 +0200 |
This is based on a fragment of Guillem Jovers patch presented here:
http://lists.gnu.org/archive/html/bug-hurd/2006-02/msg00081.html
It has been refreshed, updated and the copyright year is adjusted
properly. It has been complemented with the necessary features to
address the issues the original patch set out to address, namely
that killall5 freezes the proc translator before it tries to walk
over /proc/*/stat to decide which process to kill. Prior to this
patch (and the one marking the procfs server as important
process), killall5 would deadlock trying to walk over the proc
file system.
Ironically it would not have killed any process later on even if
it had the chance, since two values obtained from /proc/*/stat
are currently hardcoded to zero in our procfs. Patches addressing
the problem as a whole are prepared and will be sent as a follow
up.
* proc/proc.h (struct proc): Add p_important field.
* proc/pgrp.c (S_proc_getpgrppids): Exclude important system processes.
(S_proc_mark_important): New function.
* proc/mgt.c (create_startup_proc): Mark init as important.
---
proc/mgt.c | 35 +++++++++++++++++++++++++++++++++++
proc/pgrp.c | 7 ++++---
proc/proc.h | 1 +
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/proc/mgt.c b/proc/mgt.c
index cea9a41..6e72233 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -594,6 +594,8 @@ create_init_proc (void)
p->p_deadmsg = 1; /* Force initial "re-"fetch of msgport. */
+ p->p_important = 1;
+
p->p_noowner = 0;
p->p_id = make_ids (&zero, 1);
assert (p->p_id);
@@ -904,3 +906,36 @@ S_proc_set_init_task(struct proc *callerp,
return 0;
}
+
+/* Implement proc_mark_important as described in <hurd/process.defs>. */
+kern_return_t
+S_proc_mark_important (struct proc *p)
+{
+ if (!p)
+ return EOPNOTSUPP;
+
+ /* Only root may use this interface. Any children of startup_proc
+ exempt from this restriction, as startup_proc calls this on their
+ behalf. The kernel process is a notable example of an process
+ that needs this exemption. That is not an problem however, since
+ all children of /hurd/init are important and we mark them as such
+ anyway. */
+ if (! check_uid (p, 0) && ! check_owner (startup_proc, p))
+ return EPERM;
+
+ p->p_important = 1;
+ return 0;
+}
+
+/* Implement proc_is_important as described in <hurd/process.defs>. */
+error_t
+S_proc_is_important (struct proc *callerp,
+ boolean_t *essential)
+{
+ if (!callerp)
+ return EOPNOTSUPP;
+
+ *essential = callerp->p_important;
+
+ return 0;
+}
diff --git a/proc/pgrp.c b/proc/pgrp.c
index 2d6ca93..d4ea9ee 100644
--- a/proc/pgrp.c
+++ b/proc/pgrp.c
@@ -1,5 +1,5 @@
/* Session and process group manipulation
- Copyright (C) 1992,93,94,95,96,99,2001,02 Free Software Foundation, Inc.
+ Copyright (C) 1992,93,94,95,96,99,2001,02,13 Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -265,7 +265,7 @@ S_proc_getpgrppids (struct proc *callerp,
count = 0;
for (p = pg->pg_plist; p; p = p->p_gnext)
- if (++count <= npids)
+ if (!p->p_important && ++count <= npids)
*pp++ = p->p_pid;
if (count > npids)
@@ -278,7 +278,8 @@ S_proc_getpgrppids (struct proc *callerp,
pp = *pids;
for (p = pg->pg_plist; p; p = p->p_gnext)
- *pp++ = p->p_pid;
+ if (!p->p_important)
+ *pp++ = p->p_pid;
/* Dealloc ? XXX */
}
*npidsp = count;
diff --git a/proc/proc.h b/proc/proc.h
index 0af84fc..1073045 100644
--- a/proc/proc.h
+++ b/proc/proc.h
@@ -85,6 +85,7 @@ struct proc
unsigned int p_noowner:1; /* has no owner known */
unsigned int p_loginleader:1; /* leader of login collection */
unsigned int p_dead:1; /* process is dead */
+ unsigned int p_important:1; /* has called proc_mark_important */
};
typedef struct proc *pstruct_t;
--
1.7.10.4
- Make sysvinit pid 1, fix killall5, Justus Winter, 2013/08/05
- [PATCH 02/16] Define and use symbolic names for important processes, Justus Winter, 2013/08/05
- [PATCH 01/16] hurd: add missing routines in process_reply.defs, Justus Winter, 2013/08/05
- [PATCH 04/16] proc: make the function check_owner available, Justus Winter, 2013/08/05
- [PATCH 03/16] Add proc_set_init_task, make runsystem pid 1, Justus Winter, 2013/08/05
- [PATCH 05/16] proc: add proc_mark_important server code,
Justus Winter <=
- [PATCH 06/16] hurd: add proc_mark_important, Justus Winter, 2013/08/05
- [PATCH 07/16] init: Mark all of inits children and init itself as important, Justus Winter, 2013/08/05
- [PATCH 08/16] libdiskfs: register libdiskfs-based translators as important, Justus Winter, 2013/08/05
- [PATCH 09/16] libnetfs: register libnetfs-based translators as important, Justus Winter, 2013/08/05
- [PATCH 10/16] libtrivfs: register libtrivfs-based translators as important, Justus Winter, 2013/08/05
- [PATCH 11/16] mach-defpager: register mach-defpager translators as important, Justus Winter, 2013/08/05
- [PATCH 12/16] trans: register symlink translators as important, Justus Winter, 2013/08/05
- [PATCH 13/16] proc: keep track of {start,end}_code, Justus Winter, 2013/08/05
- [PATCH 14/16] hurd: add proc_{get,set}_code, Justus Winter, 2013/08/05
- [PATCH 15/16] exec: keep track of the range where executable segments are mapped, Justus Winter, 2013/08/05