Skip to contentSkip to conversation

restorecond: Do not unlink pidfile if not used

PATCH In review Petr Lautrbach 2 participants 4 messages May 25 – May 26 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 restorecond: Do not unlink pidfile if not used

With -F or -d, restorecond does not create nor use pidfile and therefore it should not try to remove it.

---
 restorecond/restorecond.c | 2 ++
 1 file changed, 2 insertions(+)
restorecond/restorecond.c +2 -0
index 36f82ae5e9cb..6353b3b72798 100644
@@ -217,6 +217,8 @@ int main(int argc, char **argv)
 		if (daemon(0, 0) < 0)
 			exitApp("daemon");
 		write_pid_file();
+	} else {
+		pidfile = 0;
 	}
 
 	while (watch(master_fd, watch_file) == 0) {
Signature · 1 line
2.54.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Petr Lautrbach

With -F or -d, restorecond does not create nor use pidfile and therefore it should not try to remove it.

Is there a reason we are using 0 instead of NULL for pidfile despite it being a pointer?

Otherwise,

Quoted 21 lines
---
 restorecond/restorecond.c | 2 ++
 1 file changed, 2 insertions(+)
restorecond/restorecond.c +2 -1
index 36f82ae5e9cb..6353b3b72798 100644
@@ -217,6 +217,8 @@ int main(int argc, char **argv)
                if (daemon(0, 0) < 0)
                        exitApp("daemon");
                write_pid_file();
+       } else {
+               pidfile = 0;
        }
 
        while (watch(master_fd, watch_file) == 0) {
--

2.54.0

#2 lore raw
Quoted 9 lines · Stephen Smalley
Quoted 5 lines · Petr Lautrbach

With -F or -d, restorecond does not create nor use pidfile and therefore it should not try to remove it.

Is there a reason we are using 0 instead of NULL for pidfile despite it being a pointer?

I wanted to be consistent with the rest of the code in in write_pid():

	if (len < 0) {
		syslog(LOG_ERR, "Pid error (%s)", strerror(errno));
		pidfile = 0;
		return 1;
	}
	pidfd = open(pidfile, O_CREAT | O_TRUNC | O_NOFOLLOW | O_WRONLY, 0644);
	if (pidfd < 0) {
		syslog(LOG_ERR, "Unable to set pidfile (%s)", strerror(errno));
		pidfile = 0;
		return 1;
	}
Quoted 24 lines

Otherwise,

Quoted 21 lines
---
 restorecond/restorecond.c | 2 ++
 1 file changed, 2 insertions(+)
restorecond/restorecond.c +2 -1
index 36f82ae5e9cb..6353b3b72798 100644
@@ -217,6 +217,8 @@ int main(int argc, char **argv)
                if (daemon(0, 0) < 0)
                        exitApp("daemon");
                write_pid_file();
+       } else {
+               pidfile = 0;
        }
 
        while (watch(master_fd, watch_file) == 0) {
--

2.54.0