Non-zero exit code makes pazpar2 stop completely.
-/* $Id: pazpar2.c,v 1.88 2007-06-08 13:58:46 adam Exp $
+/* $Id: pazpar2.c,v 1.89 2007-06-12 13:02:38 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
void child_handler(void *data)
{
- yaz_log(YLOG_LOG, "child_handler");
-
start_proxy();
init_settings();
pazpar2_event_loop();
+
}
int main(int argc, char **argv)
int ret;
char *arg;
const char *pidfile = "pazpar2.pid";
+ const char *uid = 0;
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
yaz_log_init_prefix("pazpar2");
- while ((ret = options("f:h:p:t:l:dX", argv, argc, &arg)) != -2)
+ while ((ret = options("f:h:p:t:u:l:dX", argv, argc, &arg)) != -2)
{
switch (ret)
{
strcpy(global_parameters.listener_override, arg);
break;
case 'p':
- strcpy(global_parameters.proxy_override, arg);
+ pidfile = arg;
break;
case 't':
strcpy(global_parameters.settings_path_override, arg);
- break;
+ break;
+ case 'u':
+ uid = arg;
+ break;
case 'd':
global_parameters.dump_records = 1;
break;
fprintf(stderr, "Usage: pazpar2\n"
" -f configfile\n"
" -h [host:]port (REST protocol listener)\n"
- " -p hostname[:portno] (HTTP proxy)\n"
- " -z hostname[:portno] (Z39.50 proxy)\n"
+ " -p pidfile PID file\n"
" -t settings\n"
+ " -u uid\n"
" -d (show internal records)\n"
" -l file log to file\n"
" -X debug mode\n"
global_parameters.server = config->servers;
start_http_listener();
- pazpar2_process(global_parameters.debug_mode, 0, child_handler, 0,
- pidfile, 0);
+ pazpar2_process(global_parameters.debug_mode,
+ child_handler, 0 /* child_data */,
+ pidfile, uid);
return 0;
}
-/* $Id: pazpar2.h,v 1.38 2007-06-08 13:57:19 adam Exp $
+/* $Id: pazpar2.h,v 1.39 2007-06-12 13:02:38 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
void session_alert_watch(struct session *s, int what);
void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num);
-int pazpar2_process(int debug, int flags,
+int pazpar2_process(int debug,
void (*work)(void *data), void *data,
const char *pidfile, const char *uid);
-/* $Id: process.c,v 1.1 2007-06-08 13:57:19 adam Exp $
+/* $Id: process.c,v 1.2 2007-06-12 13:02:38 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
+#include <sys/types.h>
+#include <pwd.h>
#include <yaz/log.h>
kill(child_pid, num);
}
-int pazpar2_process(int debug, int flags,
+int pazpar2_process(int debug,
void (*work)(void *data), void *data,
const char *pidfile, const char *uid /* not yet used */)
{
+ struct passwd *pw = 0;
int run = 1;
int cont = 1;
void (*old_sighup)(int);
work(data);
exit(0);
}
+
/* running in production mode. */
+ if (uid)
+ {
+ yaz_log(YLOG_LOG, "getpwnam");
+ // OK to use the non-thread version here
+ if (!(pw = getpwnam(uid)))
+ {
+ yaz_log(YLOG_FATAL, "%s: Unknown user", uid);
+ exit(1);
+ }
+ }
+
/* keep signals in their original state and make sure that some signals
to parent process also gets sent to the child.. Normally this
signal(SIGTERM, old_sigterm);/* restore */
write_pidfile(pidfile);
+
+ if (pw)
+ {
+ if (setuid(pw->pw_uid) < 0)
+ {
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "setuid");
+ exit(1);
+ }
+ }
+
work(data);
exit(0);
}
else if (status == 0)
cont = 0; /* child exited normally */
else
- { /* child exited in an abnormal way */
+ { /* child exited with error */
yaz_log(YLOG_LOG, "Exit %d from child %ld", status, (long) p);
- cont = 1;
+ cont = 0;
}
if (cont) /* respawn slower as we get more errors */
sleep(1 + run/5);