2013-09-29 10:12:01 +02:00
|
|
|
/*
|
|
|
|
* pilerreload.c, SJ
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <piler.h>
|
|
|
|
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
|
|
|
|
char *configfile = CONFIG_FILE;
|
|
|
|
struct __config cfg;
|
|
|
|
|
|
|
|
|
|
|
|
void fatal(char *s){
|
2013-09-29 10:24:05 +02:00
|
|
|
syslog(LOG_PRIORITY, "fatal: %s", s);
|
2013-09-29 10:12:01 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv){
|
|
|
|
char buf[SMALLBUFSIZE];
|
|
|
|
int pid;
|
|
|
|
FILE *f;
|
|
|
|
|
2013-09-29 10:24:05 +02:00
|
|
|
(void) openlog("pilerreload", LOG_PID, LOG_MAIL);
|
|
|
|
|
2013-09-29 10:12:01 +02:00
|
|
|
cfg = read_config(CONFIG_FILE);
|
|
|
|
|
|
|
|
f = fopen(cfg.pidfile, "r");
|
|
|
|
if(!f) fatal("cannot open pidfile");
|
|
|
|
|
|
|
|
if(fgets(buf, sizeof(buf)-2, f) == NULL) fatal("cannot read pidfile");
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
pid = atoi(buf);
|
|
|
|
|
2013-09-29 10:24:05 +02:00
|
|
|
if(pid > 1){
|
|
|
|
if(kill(pid, SIGHUP) == 0) syslog(LOG_PRIORITY, "reloaded");
|
|
|
|
else syslog(LOG_PRIORITY, "failed to reload");
|
|
|
|
}
|
|
|
|
else fatal("invalid pid");
|
2013-09-29 10:12:01 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|