From b9a873b5153749282920b45f1bf934b2366ee90e Mon Sep 17 00:00:00 2001 From: Thibault Godouet Date: Sat, 7 Jul 2001 17:30:32 +0000 Subject: [PATCH] added fcronsighup --- Makefile.in | 20 ++++--- fcrontab.c | 147 +++++++--------------------------------------------- 2 files changed, 34 insertions(+), 133 deletions(-) diff --git a/Makefile.in b/Makefile.in index 5c936a3..af9b510 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,7 +4,7 @@ # @configure_input@ -# $Id: Makefile.in,v 1.72 2001-06-24 13:23:35 thib Exp $ +# $Id: Makefile.in,v 1.73 2001-07-07 17:32:49 thib Exp $ # The following should not be edited manually (use configure options) # If you must do it, BEWARE : some of the following is also defined @@ -15,6 +15,8 @@ SRCDIR = @srcdir@ # Where should we install it ? prefix = @prefix@ +# We set exec_prefix to $prefix (if you change this, you should also change +# it in configure.in) exec_prefix = @exec_prefix@ DESTSBIN = @sbindir@ DESTBIN = @bindir@ @@ -56,10 +58,12 @@ CFLAGS = $(OPTIM) $(OPTION) $(DEFS) $(CPPFLAGS) OBJSD = fcron.o subs.o log.o database.o job.o conf.o $(LIBOBJS) OBJS = fcrontab.o subs.o log.o fileconf.o allow.o OBJCONV = convert-fcrontab.o subs.o log.o +OBJSIG = fcronsighup.o subs.o log.o allow.o HEADERSALL = config.h $(SRCDIR)/global.h $(SRCDIR)/log.h $(SRCDIR)/subs.h $(SRCDIR)/save.h $(SRCDIR)/option.h HEADERSD = $(HEADERSALL) $(SRCDIR)/fcron.h $(SRCDIR)/getloadavg.h $(SRCDIR)/database.h $(SRCDIR)/conf.h $(SRCDIR)/job.h HEADERS = $(HEADERSALL) $(SRCDIR)/fcrontab.h $(SRCDIR)/allow.h $(SRCDIR)/fileconf.h HEADERSCONV = $(HEADERSALL) $(SRCDIR)/convert-fcrontab.h +HEADERSSIG = $(HEADERSALL) $(SRCDIR)/allow.h # this is two regular expressions RCSNOLOG=.*\(.html\|VERSION\|MANIFEST\|configure\|install.sh\) @@ -68,13 +72,16 @@ REXP_MANPAGES=.*[158] all: fcron fcrontab convert-fcrontab files/fcron.conf fcron: $(OBJSD) $(HEADERSD) - $(CC) $(CFLAGS) $(LIBS) -o $@ $(OBJSD) + $(CC) $(CFLAGS) -o $@ $(OBJSD) $(LIBS) -fcrontab: $(OBJS) $(HEADERS) - $(CC) $(CFLAGS) $(LIBS) -o $@ $(OBJS) +fcrontab: fcronsighup $(OBJS) $(HEADERS) + $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) + +fcronsighup: $(OBJSIG) $(HEADERSSIG) + $(CC) $(CFLAGS) -o $@ $(OBJSIG) $(LIBS) convert-fcrontab: $(OBJCONV) $(HEADERSCONV) - $(CC) $(CFLAGS) $(LIBS) -o $@ $(OBJCONV) + $(CC) $(CFLAGS) -o $@ $(OBJCONV) $(LIBS) %.o: $(SRCDIR)/%.c $(HEADERSALL) $(SRCDIR)/%.h $(CC) $(CFLAGS) -c $< @@ -100,6 +107,7 @@ install: all $(INSTALL) -g $(ROOTGROUP) -o $(ROOTNAME) -m 110 -s fcron $(DESTSBIN) $(INSTALL) -g $(GROUPNAME) -o $(USERNAME) -m 6111 -s fcrontab $(DESTBIN) + $(INSTALL) -g $(ROOTGROUP) -o $(ROOTNAME) -m 6111 -s fcronsighup $(DESTBIN) test -f $(ETC)/fcron.allow || test -f $(ETC)/fcron.deny || $(INSTALL) -m 640 -o $(ROOTNAME) -g $(GROUPNAME) $(SRCDIR)/files/fcron.allow $(SRCDIR)/files/fcron.deny $(ETC) test -f $(ETC)/fcron.conf || $(INSTALL) -m 640 -o $(ROOTNAME) -g $(GROUPNAME) $(SRCDIR)/files/fcron.conf $(ETC) $(INSTALL) -m 644 -o $(ROOTNAME) $(SRCDIR)/doc/fcron.8 $(DESTMAN)/man8 @@ -142,7 +150,7 @@ uninstall: clean: rm -f *.o - rm -f fcron fcrontab convert-fcrontab files/fcron.conf + rm -f fcron fcrontab fcronsighup convert-fcrontab files/fcron.conf vclean: clean find ./ -name "*~" -exec rm -f {} \; diff --git a/fcrontab.c b/fcrontab.c index a6c894f..06d9cf5 100644 --- a/fcrontab.c +++ b/fcrontab.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fcrontab.c,v 1.41 2001-07-04 17:29:30 thib Exp $ */ + /* $Id: fcrontab.c,v 1.42 2001-07-07 17:30:32 thib Exp $ */ /* * The goal of this program is simple : giving a user interface to fcron @@ -42,12 +42,10 @@ #include "fcrontab.h" -char rcs_info[] = "$Id: fcrontab.c,v 1.41 2001-07-04 17:29:30 thib Exp $"; +char rcs_info[] = "$Id: fcrontab.c,v 1.42 2001-07-07 17:30:32 thib Exp $"; void info(void); void usage(void); -void sig_daemon(void); -pid_t read_pid(void); /* used in temp_file() */ @@ -128,135 +126,30 @@ usage(void) } -pid_t -read_pid(void) - /* return fcron daemon's pid if running. - * otherwise return 0 */ -{ - FILE *fp = NULL; - pid_t pid = 0; - - if ((fp = fopen(pidfile, "r")) != NULL) { - fscanf(fp, "%d", (int *) &pid); - fclose(fp); - } - - return pid; -} - - void -sig_daemon(void) - /* send SIGHUP to daemon to tell him configuration has changed */ - /* SIGHUP is sent once 10s before the next minute to avoid - * some bad users to block daemon by sending it SIGHUP all the time */ +xexit(int exit_val) + /* launch signal if needed and exit */ { - /* we don't need to make root wait */ - if (uid != 0) { - time_t t = 0; - int sl = 0; - FILE *fp = NULL; - int fd = 0; - struct tm *tm = NULL; - char sigfile[PATH_LEN]; - - t = time(NULL); - tm = localtime(&t); - - if ( (sl = 60 - (t % 60) - 10) < 0 ) { - if ( (tm->tm_min = tm->tm_min + 2) >= 60 ) { - tm->tm_hour++; - tm->tm_min -= 60; - } - snprintf(buf, sizeof(buf), "%02dh%02d", tm->tm_hour, tm->tm_min); - sl = 60 - (t % 60) + 50; - } else { - if ( ++tm->tm_min >= 60 ) { - tm->tm_hour++; - tm->tm_min -= 60; - } - snprintf(buf, sizeof(buf), "%02dh%02d", tm->tm_hour, tm->tm_min); - } - fprintf(stderr, "Modifications will be taken into account" - " at %s.\n", buf); - - snprintf(sigfile, sizeof(sigfile), "%s/fcrontab.sig", fcrontabs); - -#if defined(HAVE_SETREGID) && defined(HAVE_SETREUID) - if (seteuid(fcrontab_uid) != 0) - die_e("seteuid(fcrontab_uid[%d])", fcrontab_uid); -#endif - - switch ( fork() ) { - case -1: - remove(sigfile); - die_e("could not fork : daemon has not been signaled"); - break; + pid_t pid = 0; + if ( need_sig == 1 ) { + /* fork and exec fcronsighup */ + switch ( pid = fork() ) { case 0: /* child */ + execl(BINDIREX "/fcronsighup", BINDIREX "/fcronsighup", + fcronconf, NULL); + die_e("Could not exec " BINDIREX " fcronsighup"); break; - default: - /* parent */ - return; - } - foreground = 0; + case -1: + die_e("Could not fork (fcron has not been signaled)"); + break; - /* try to create a lock file */ - if ((fd = open(sigfile, O_RDWR|O_CREAT, 0644)) == -1 - || ((fp = fdopen(fd, "r+")) == NULL) ) - die_e("can't open or create %s", sigfile); - -#ifdef HAVE_FLOCK - if ( flock(fd, LOCK_EX|LOCK_NB) != 0 ) { - debug("fcrontab is already waiting for signalling the daemon :" - " exiting."); - return; - } -#else /* HAVE_FLOCK */ - if ( lockf(fd, F_TLOCK, 0) != 0 ) { - debug("fcrontab is already waiting for signalling the daemon :" - " exiting."); - return; + default: + /* parent */ + waitpid(pid, NULL, 0); + break; } -#endif /* ! HAVE_FLOCK */ - - sleep(sl); - - fclose(fp); - close(fd); - - remove(sigfile); - } - else - fprintf(stderr, "Modifications will be taken into account" - " right now.\n"); - - if ( (daemon_pid = read_pid()) == 0 ) - /* daemon is not running any longer : we exit */ - return ; - - foreground = 1; - - if ( kill(daemon_pid, SIGHUP) != 0) - die_e("could not send SIGHUP to daemon (pid %d)", daemon_pid); - -} - - - -void -xexit(int exit_val) - /* launch signal if needed and exit */ -{ - if ( need_sig == 1 ) { - /* check if daemon is running */ - if ( (daemon_pid = read_pid()) != 0 ) - /* warning : we change euid to fcrontab_iud in sig_daemon() */ - sig_daemon(); - else - fprintf(stderr, "fcron is not running :\n modifications will" - " be taken into account at its next execution.\n"); } exit(exit_val); @@ -876,7 +769,7 @@ main(int argc, char **argv) if (strrchr(argv[0],'/')==NULL) prog_name = argv[0]; else prog_name = strrchr(argv[0],'/')+1; - + uid = getuid(); /* get current dir */ @@ -991,6 +884,6 @@ main(int argc, char **argv) - /* never reach */ + /* never reached */ return EXIT_OK; } -- 2.47.3