bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/7] proc: implement proc_notify_new_processes


From: Justus Winter
Subject: [PATCH 6/7] proc: implement proc_notify_new_processes
Date: Thu, 5 Sep 2013 18:38:42 +0200

XXX

XXX
---
 proc/Makefile |    5 +++--
 proc/main.c   |    1 +
 proc/mgt.c    |   37 +++++++++++++++++++++++++++++++++++++
 proc/proc.h   |    6 ++++++
 4 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/proc/Makefile b/proc/Makefile
index 2eed13c..4f3be81 100644
--- a/proc/Makefile
+++ b/proc/Makefile
@@ -29,9 +29,10 @@ MIGSFLAGS="-DPROCESS_INTRAN=pstruct_t reqport_find 
(process_t)" \
        "-DPROCESS_IMPORTS=import \"proc.h\";"
 
 MIGSTUBS = processServer.o notifyServer.o \
-       ourmsgUser.o proc_excUser.o proc_excServer.o
+       ourmsgUser.o proc_excUser.o proc_excServer.o \
+       process_notifyUser.o
 OBJS = $(SRCS:.c=.o) $(MIGSTUBS)
-HURDLIBS = ihash ports shouldbeinlibc
+HURDLIBS = ihash ports shouldbeinlibc notify
 OTHERLIBS = -lpthread
 
 include ../Makeconf
diff --git a/proc/main.c b/proc/main.c
index 73abbc0..481c813 100644
--- a/proc/main.c
+++ b/proc/main.c
@@ -80,6 +80,7 @@ main (int argc, char **argv, char **envp)
   ports_create_port (generic_port_class, proc_bucket,
                     sizeof (struct port_info), &genport);
   generic_port = ports_get_right (genport);
+  hurd_notify_create (&notify_on_new_processes, do_notify_process_changed);
 
   /* Create the initial proc object for init (PID 1).  */
   startup_proc = create_startup_proc ();
diff --git a/proc/mgt.c b/proc/mgt.c
index 6a10e91..f1e924a 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -210,6 +210,11 @@ S_proc_child (struct proc *parentp,
                            childp->p_parent->p_pid, childp->p_pgrp->pg_pgid,
                            !childp->p_pgrp->pg_orphcnt);
   childp->p_parentset = 1;
+
+  /* XXX do the notification here in the mean time.  */
+  /* Notify any process change listeners.  */
+  hurd_notify_do_notify (notify_on_new_processes, (void *) childp);
+
   return 0;
 }
 
@@ -688,6 +693,10 @@ new_proc (task_t task)
   p = allocate_proc (task);
   if (p)
     complete_proc (p, genpid ());
+
+  /* XXX: once the kernel provides the parent task, do the
+     notification here */
+
   return p;
 }
 
@@ -765,6 +774,9 @@ process_has_exited (struct proc *p)
 
   /* Cancel any outstanding RPCs done on behalf of the dying process.  */
   ports_interrupt_rpcs (p);
+
+  /* Notify any process change listeners.  */
+  hurd_notify_do_notify (notify_on_new_processes, (void *) p);
 }
 
 void
@@ -903,3 +915,28 @@ S_proc_is_important (struct proc *callerp,
 
   return 0;
 }
+
+/* XXX */
+error_t
+S_proc_request_process_change_notification (struct proc *callerp,
+                                            mach_port_t notify)
+{
+  if (!callerp)
+    return EOPNOTSUPP;
+
+  return hurd_notify_add (notify_on_new_processes, notify, (void *) 1);
+}
+
+error_t
+do_notify_process_changed (mach_port_t port,
+                           mach_port_t reply_port,
+                           void *data,
+                           void *common_data)
+{
+  struct proc *p = common_data;
+  return notify_process_changed (port,
+                                 p->p_pid,
+                                 p->p_parent->p_pid,
+                                 p->p_dead);
+}
+
diff --git a/proc/proc.h b/proc/proc.h
index 4369abf..dc46ed7 100644
--- a/proc/proc.h
+++ b/proc/proc.h
@@ -26,6 +26,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 
02139, USA.  */
 #include <sys/mman.h>
 #include <hurd/ports.h>
 #include <hurd/ihash.h>
+#include <hurd/notify.h>
 #include <pthread.h>
 
 struct proc
@@ -138,6 +139,7 @@ struct port_bucket *proc_bucket;
 struct port_class *proc_class;
 struct port_class *generic_port_class;
 struct port_class *exc_class;
+struct hurd_notify *notify_on_new_processes;
 
 mach_port_t master_host_port;
 mach_port_t master_device_port;
@@ -211,5 +213,9 @@ void initialize_version_info (void);
 
 void send_signal (mach_port_t, int, mach_port_t);
 
+error_t do_notify_process_changed (mach_port_t port,
+                                   mach_port_t reply_port,
+                                   void *data,
+                                   void *common_data);
 
 #endif
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]