Blame SOURCES/rhnsd-5.0.13-5-el7-to-rhnsd-5.0.13-6-el7.patch

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