Slightly changes options usage
[yazpp-moved-to-github.git] / src / yaz-proxy-main.cpp
index 8a37ada..62bc87e 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1998-2003, Index Data.
  * See the file LICENSE for details.
  * 
- * $Id: yaz-proxy-main.cpp,v 1.22 2003-10-23 11:45:08 adam Exp $
+ * $Id: yaz-proxy-main.cpp,v 1.26 2003-10-24 12:19:23 adam Exp $
  */
 
 #include <signal.h>
 
 void usage(char *prog)
 {
-    fprintf (stderr, "%s: [-c config] [-a log] [-m num] [-v level] [-t target] [-i sec] "
-             "[-u uid] [-p pidfile] [-o optlevel] @:port\n", prog);
+    fprintf (stderr, "%s: [-c config] [-l log] [-a log] [-v level] [-t target] "
+             "[-u uid] [-p pidfile] @:port\n", prog);
     exit (1);
 }
 
 static char *pid_fname = 0;
 static char *uid = 0;
+static char *log_file = 0;
 
 int args(Yaz_Proxy *proxy, int argc, char **argv)
 {
@@ -77,6 +78,7 @@ int args(Yaz_Proxy *proxy, int argc, char **argv)
            break;
        case 'l':
            yaz_log_init_file (arg);
+           log_file = xstrdup(arg);
            break;
        case 'm':
            proxy->set_max_clients(atoi(arg));
@@ -102,6 +104,7 @@ int args(Yaz_Proxy *proxy, int argc, char **argv)
     }
     if (addr)
     {
+       yaz_log(LOG_LOG, "Starting proxy pid=%ld", (long) getpid());
        if (proxy->server(addr))
        {
            yaz_log(LOG_FATAL|LOG_ERRNO, "listen %s", addr);
@@ -119,6 +122,7 @@ int args(Yaz_Proxy *proxy, int argc, char **argv)
 static Yaz_Proxy *static_yaz_proxy = 0;
 static void sighup_handler(int num)
 {
+    signal(SIGHUP, sighup_handler);
     if (static_yaz_proxy)
        static_yaz_proxy->reconfig();
 }
@@ -150,12 +154,18 @@ int main(int argc, char **argv)
     if (uid)
     {
        struct passwd *pw;
-       
+
        if (!(pw = getpwnam(uid)))
        {
            yaz_log(LOG_FATAL, "%s: Unknown user", uid);
            exit(3);
        }
+       if (log_file)
+       {
+           chown(log_file, pw->pw_uid,  pw->pw_gid);
+           xfree(log_file);
+       }
+
        if (setuid(pw->pw_uid) < 0)
        {
            yaz_log(LOG_FATAL|LOG_ERRNO, "setuid");