]> andersk Git - moira.git/blobdiff - update/update_server.c
Add support for get_host_by_account_number query.
[moira.git] / update / update_server.c
index dd4818b551ef3402c1ff67e5e5da471a56199a95..f50fb525b1433dab9d3d0cc96970a15dd6bba544 100644 (file)
 
 #include <sys/stat.h>
 #include <sys/utsname.h>
+#include <sys/wait.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>
 
 #include <des.h>
 #include "update.h"
@@ -33,6 +36,10 @@ int have_authorization = 0;
 des_cblock session;
 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 *);
@@ -52,6 +59,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 +87,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 +120,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 +141,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 +226,24 @@ 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;
+  int bufsiz = 1024;
+
+  buf = malloc(bufsiz + 1);
+  buf[bufsiz] = '\0';
+
+  vsnprintf(buf, bufsiz, fmt, args);
+  syslog(LOG_NOTICE, "%s", buf);
+}
This page took 0.034865 seconds and 4 git commands to generate.