]> andersk Git - moira.git/blobdiff - update/update_server.c
- Don't ifdef out auth_002; it breaks backward compatability.
[moira.git] / update / update_server.c
index 22c26f69ec428b0ac96d15dd180e310616e6f5a8..63be9f773dfc74e568c4a78017a875cd25e43265 100644 (file)
 
 #include <sys/stat.h>
 #include <sys/utsname.h>
+#include <sys/wait.h>
 
-#include <arpa/inet.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 
 #include <errno.h>
 #include <pwd.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <syslog.h>
 
+#ifdef HAVE_KRB4
 #include <des.h>
+#endif
 #include "update.h"
 
 RCSID("$Header$");
@@ -30,14 +35,21 @@ RCSID("$Header$");
 char *whoami, *hostname;
 
 int have_authorization = 0;
+#ifdef HAVE_KRB4
 des_cblock session;
+#endif
 int uid = 0;
 
+void child_handler(int signal);
+static void syslog_com_err_proc(const char *progname, long code,
+                               const char *fmt, va_list args);
+
 struct _dt {
   char *str;
   void (*proc)(int, char *);
 } dispatch_table[] = {
   { "AUTH_002", auth_002 },
+  { "AUTH_003", auth_003 },
   { "XFER_002", xfer_002 },
   { "XFER_003", xfer_003 },
   { "EXEC_002", exec_002 },
@@ -52,6 +64,7 @@ int main(int argc, char **argv)
   struct _dt *d;
   struct utsname name;
   int s, conn;
+  struct sigaction sa;
 
   whoami = strrchr(argv[0], '/');
   if (whoami)
@@ -79,6 +92,11 @@ int main(int argc, char **argv)
   umask(0022);
   mr_init();
 
+  sigemptyset(&sa.sa_mask);
+  sa.sa_flags = SA_RESTART;
+  sa.sa_handler = child_handler;
+  sigaction(SIGCHLD, &sa, NULL);
+
   /* If the config file contains a line "user username", the
    * daemon will run with that user's UID.
    */
@@ -107,6 +125,9 @@ int main(int argc, char **argv)
       exit(1);
     }
 
+  set_com_err_hook(syslog_com_err_proc);
+  openlog(whoami, LOG_PID, LOG_DAEMON);
+
   /* now loop waiting for connections */
   while (1)
     {
@@ -125,6 +146,8 @@ int main(int argc, char **argv)
 
       if (config_lookup("nofork") || (fork() <= 0))
        break;
+
+      close(conn);
     }
 
   /* If the config file contains a line "chroot /dir/name", the
@@ -208,3 +231,23 @@ void fail(int conn, int err, char *msg)
   close(conn);
   exit(1);
 }
+
+void child_handler(int signal)
+{
+  int status;
+
+  while (waitpid(-1, &status, WNOHANG) > 0)
+    ;
+}
+
+static void syslog_com_err_proc(const char *progname, long code,
+                               const char *fmt, va_list args)
+{
+  char buf[BUFSIZ + 1];
+
+  buf[BUFSIZ] = '\0';
+
+  vsnprintf(buf, BUFSIZ, fmt, args);
+  syslog(LOG_NOTICE, "%s: %s %s", progname ? progname : "",
+        code ? error_message(code) : "", buf);
+}
This page took 0.055654 seconds and 4 git commands to generate.