policycoreutils/SOURCES/0029-restorecond-Add-F-for-run-in-foreground.patch
2026-08-24 09:32:59 -04:00

95 lines
2.6 KiB
Diff

From 7e91c46817f113898d79326cf7b3ba8228894e42 Mon Sep 17 00:00:00 2001
From: Petr Lautrbach <lautrbach@redhat.com>
Date: Thu, 2 Apr 2026 17:17:12 +0200
Subject: [PATCH] restorecond: Add -F for run in foreground
Content-type: text/plain
Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
---
restorecond/restorecond.8 | 5 ++++-
restorecond/restorecond.c | 13 ++++++++-----
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/restorecond/restorecond.8 b/restorecond/restorecond.8
index bf8ec87562f8..bb99b24a2d69 100644
--- a/restorecond/restorecond.8
+++ b/restorecond/restorecond.8
@@ -3,7 +3,7 @@
restorecond \- daemon that watches for file creation and then sets the default SELinux file context
.SH "SYNOPSIS"
-.B restorecond [\-d] [-h] [\-f restorecond_file ] [\-u] [\-v]
+.B restorecond [\-d] [-h] [\-f restorecond_file ] [\-F] [\-u] [\-v]
.P
.SH "DESCRIPTION"
@@ -26,6 +26,9 @@ Print usage statement.
.B \-f restorecond_file
Use alternative restorecond.conf file.
.TP
+.B \-F
+Run in foreground, do not become a daemon.
+.TP
.B \-u
Turns on user mode. Runs restorecond in the user session and reads /etc/selinux/restorecond_user.conf. Uses dbus to make sure only one restorecond is running per user session.
.TP
diff --git a/restorecond/restorecond.c b/restorecond/restorecond.c
index d5f70fc2e2c1..36f82ae5e9cb 100644
--- a/restorecond/restorecond.c
+++ b/restorecond/restorecond.c
@@ -76,6 +76,7 @@ int debug_mode = 0;
int terminate = 0;
int master_wd = -1;
int run_as_user = 0;
+int foreground_mode = 0;
static void done(void) {
watch_list_free(master_fd);
@@ -124,7 +125,7 @@ static void term_handler(int s __attribute__ ((unused)))
static void usage(char *program)
{
- printf("%s [-d] [-f restorecond_file ] [-u] [-v] \n", program);
+ printf("%s [-d] [-f restorecond_file ] [-F] [-n] [-u] [-v] \n", program);
}
void exitApp(const char *msg)
@@ -165,7 +166,7 @@ int main(int argc, char **argv)
sigaction(SIGTERM, &sa, NULL);
atexit( done );
- while ((opt = getopt(argc, argv, "hdf:uv")) > 0) {
+ while ((opt = getopt(argc, argv, "hdf:Fuv")) > 0) {
switch (opt) {
case 'd':
debug_mode = 1;
@@ -173,6 +174,9 @@ int main(int argc, char **argv)
case 'f':
watch_file = optarg;
break;
+ case 'F':
+ foreground_mode = 1;
+ break;
case 'u':
run_as_user = 1;
break;
@@ -209,13 +213,12 @@ int main(int argc, char **argv)
read_config(master_fd, watch_file);
- if (!debug_mode) {
+ if (!debug_mode && !foreground_mode) {
if (daemon(0, 0) < 0)
exitApp("daemon");
+ write_pid_file();
}
- write_pid_file();
-
while (watch(master_fd, watch_file) == 0) {
}
--
2.53.0