diff --git a/rhnsd.c b/rhnsd.c
index ad2100d..896b433 100644
--- a/rhnsd.c
+++ b/rhnsd.c
@@ -176,7 +176,6 @@ int main (int argc, char **argv)
if (setsid() < 0)
exit(EXIT_FAILURE);
- umask(0);
chdir ("/");
@@ -310,8 +309,12 @@ static int write_pid (const char *file)
FILE *fp;
fp = fopen (file, "w");
- if (fp == NULL)
- return -1;
+ if (fp == NULL) {
+ return -1;
+ } else if (chmod (file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0) {
+ fclose(fp);
+ return -1;
+ }
fprintf (fp, "%d\n", getpid ());
if (fflush (fp) || ferror (fp)) {
@@ -397,6 +400,10 @@ static int rhn_do_action(void)
/* close the read end of the pipe */
close(fds[0]);
+
+ /* close syslog file descriptor */
+ closelog();
+
/* redirect stdout */
if (fds[1] != STDOUT_FILENO) {
dup2(fds[1], STDOUT_FILENO);
@@ -406,6 +413,9 @@ static int rhn_do_action(void)
/* make sure this child has a stderr */
dup2(STDOUT_FILENO, STDERR_FILENO);
+ /* open a new syslog connection for the child */
+ openlog("rhnsd", LOG_CONS | LOG_ODELAY | LOG_PID, LOG_DAEMON);
+
/* syslog for safekeeping */
syslog(LOG_NOTICE, "running program %s with PID %d", RHN_CHECK, getpid());
diff --git a/rhnsd.spec b/rhnsd.spec
index 333a555..42ad138 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: 7%{?dist}
+Release: 8%{?dist}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: gettext
@@ -138,6 +138,13 @@ rm -fr $RPM_BUILD_ROOT
%doc LICENSE
%changelog
+* Wed Sep 20 2017 Tomas Kasparek <tkasparek@redhat.com> 5.0.13-8
+- Resolves: #1480306 - change permissions for rhnsd.pid (grinrag@gmail.com)
+- Resolves: #1489989 - umask(0) does not reset to default umask
+ (tkasparek@redhat.com)
+- Resolves: #1475039 - close and reopen syslog when redirecting child output
+ (martin.matuska@axelspringer.de)
+
* Mon Mar 06 2017 Gennadii Altukhov <galt@redhat.com> 5.0.13-7
- Resolves: #1409562 - fix BZ IDs in spec file (galt@redhat.com)