chiark / gitweb /
Regenerated formatted documentation (spec.ps, spec.html).
[userv.git] / process.c
index 64afd5c419aba03a85e2e29c6b0b2123fc78c1e0..636255a286f18209d2eed766e18d42bf260ec169 100644 (file)
--- a/process.c
+++ b/process.c
@@ -271,8 +271,18 @@ void NONRETURNING disconnect(int exitstatus) {
   _exit(exitstatus);
 }
 
   _exit(exitstatus);
 }
 
-static void NONRETURNING sighandler_chld(int ignored) {
+static void reporttermination(int status) {
   struct progress_msg progress_mbuf;
   struct progress_msg progress_mbuf;
+  
+  memset(&progress_mbuf,0,sizeof(progress_mbuf));
+  progress_mbuf.magic= PROGRESS_MAGIC;
+  progress_mbuf.type= pt_terminated;
+  progress_mbuf.data.terminated.status= status;
+  xfwrite(&progress_mbuf,sizeof(progress_mbuf),swfile);
+  xfflush(swfile);
+}
+
+static void NONRETURNING sighandler_chld(int ignored) {
   int status;
   pid_t returned;
 
   int status;
   pid_t returned;
 
@@ -282,13 +292,7 @@ static void NONRETURNING sighandler_chld(int ignored) {
   if (returned!=child) syscallerror("spurious child process");
   child= childtokill= -1;
 
   if (returned!=child) syscallerror("spurious child process");
   child= childtokill= -1;
 
-  memset(&progress_mbuf,0,sizeof(progress_mbuf));
-  progress_mbuf.magic= PROGRESS_MAGIC;
-  progress_mbuf.type= pt_terminated;
-  progress_mbuf.data.terminated.status= status;
-  xfwrite(&progress_mbuf,sizeof(progress_mbuf),swfile);
-  xfflush(swfile);
-
+  reporttermination(status);
   syslog(LOG_INFO,"service completed (status %d %d)",(status>>8)&0x0ff,status&0x0ff);
   _exit(0);
 }
   syslog(LOG_INFO,"service completed (status %d %d)",(status>>8)&0x0ff,status&0x0ff);
   _exit(0);
 }
@@ -746,6 +750,18 @@ void servicerequest(int sfd) {
   getevent(&event_mbuf);
   assert(event_mbuf.type == et_confirm);
 
   getevent(&event_mbuf);
   assert(event_mbuf.type == et_confirm);
 
+  if (execbuiltin == bisexec_shutdown && !serviceuser_uid) {
+    /* The check for the uid is just so we can give a nice
+     * error message (in the actual code for bisexec_shutdown).
+     * If this is spoofed somehow then the unlink() will simply fail.
+     */
+    r= unlink(RENDEZVOUSPATH);
+    if (r) syscallfailure("remove rendezvous socket %s",RENDEZVOUSPATH);
+    syslog(LOG_NOTICE,"arranging for termination, due to client request");
+    reporttermination(0);
+    _exit(10);
+  }
+
   fork_service_synch();
   
   getevent(&event_mbuf);
   fork_service_synch();
   
   getevent(&event_mbuf);