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

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