X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fyaz-proxy-main.cpp;h=62bc87e7f9a18c92314beba9a18e771adb25e937;hb=624453e6dc1e47c287d44a7692cfc0e645698e74;hp=8a37ada713ae6b7f74d76fde16a4e62f56bb47fd;hpb=1cf760aa1600199b8a9acb4ccaded655f6903d62;p=yazpp-moved-to-github.git diff --git a/src/yaz-proxy-main.cpp b/src/yaz-proxy-main.cpp index 8a37ada..62bc87e 100644 --- a/src/yaz-proxy-main.cpp +++ b/src/yaz-proxy-main.cpp @@ -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 @@ -19,13 +19,14 @@ 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");