diff --git a/rhnsd.c b/rhnsd.c index 5f0711d..ad2100d 100644 --- a/rhnsd.c +++ b/rhnsd.c @@ -49,6 +49,9 @@ static int write_pid (const char *file); static void print_version (FILE *stream, struct argp_state *state); void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; +/* Current rhn_check pid */ +pid_t rhn_check_pid; + /* Definitions of arguments for argp functions. */ static const struct argp_option options[] = { @@ -145,16 +148,35 @@ int main (int argc, char **argv) if (!foreground) { int i; - if (fork ()) - exit (0); + pid_t pid; + pid = fork(); + if (pid < 0) + exit (EXIT_FAILURE); + + if (pid > 0) + exit(EXIT_SUCCESS); + for (i = 0; i < getdtablesize(); i++) close (i); - if (fork ()) - exit (0); + /* read from /dev/null */ + int devnull = open("/dev/null", O_RDONLY); + if ((devnull >= 0) && (devnull != STDIN_FILENO)) { + dup2(devnull, STDIN_FILENO); + close(devnull); + } + + pid = fork(); + if (pid < 0) + exit (EXIT_FAILURE); + + if (pid > 0) + exit(EXIT_SUCCESS); - setsid(); + if (setsid() < 0) + exit(EXIT_FAILURE); + umask(0); chdir ("/"); @@ -252,11 +274,13 @@ Written by %s.\n\ static void termination_handler (int signum) { syslog(LOG_NOTICE, "Exiting"); - + /* Send SIGTERM to current running rhn_check + * and wait for it to exit. */ + kill(rhn_check_pid, SIGTERM); + wait(NULL); /* Clean up pid file. */ unlink (_PATH_RHNDPID); - - exit (EXIT_SUCCESS); + exit(EXIT_SUCCESS); } /* Returns 1 if the process in pid file FILE is running, 0 if not. */ @@ -383,10 +407,11 @@ static int rhn_do_action(void) dup2(STDOUT_FILENO, STDERR_FILENO); /* syslog for safekeeping */ - syslog(LOG_DEBUG, "running program %s", RHN_CHECK); + syslog(LOG_NOTICE, "running program %s with PID %d", RHN_CHECK, getpid()); unset_signal_handlers (); /* exec binary helper */ + rhn_check_pid = getpid(); args[0] = RHN_CHECK; execv(RHN_CHECK, args); @@ -396,6 +421,7 @@ static int rhn_do_action(void) strerror(errno)); exit(errno); } else if (child > 0) { + set_signal_handlers(); int ret = 1; char *buf, buffer[10]; int bufsize = 0; diff --git a/rhnsd.init b/rhnsd.init index ee3e811..dead8bf 100644 --- a/rhnsd.init +++ b/rhnsd.init @@ -53,7 +53,7 @@ start() { stop() { echo -n $"Stopping Spacewalk Daemon: " - killproc rhnsd + killproc rhnsd -TERM RETVAL=$? echo if [ $RETVAL -eq 0 ]; then diff --git a/rhnsd.spec b/rhnsd.spec index ee6085f..f893a8d 100644 --- a/rhnsd.spec +++ b/rhnsd.spec @@ -5,7 +5,7 @@ Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar. URL: https://fedorahosted.org/spacewalk Name: rhnsd Version: 5.0.13 -Release: 5%{?dist} +Release: 6%{?dist} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: gettext @@ -138,6 +138,10 @@ rm -fr $RPM_BUILD_ROOT %doc LICENSE %changelog +* Mon Mar 06 2017 Gennadii Altukhov 5.0.13-6 +- 1260527 RHEL7 rhnsd reload doesn't work (jdostal@redhat.com) +- 1260527,1409570 - Reboot loop - rhn_check, rhnsd (jdostal@redhat.com) + * Thu Jun 25 2015 Grant Gainey 5.0.13-5 - Bump release to get past weirdness in brew-tags (ggainey@redhat.com) - Related: #1138939 - up2date and systemid files are managed by rhnsd itself,