-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This patch looks good to me. acked. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk/I+HUACgkQrlYvE4MpobPyBwCg6ShemGTPghRzei0TFj/2T2qB X7MAoLI0NYzdyOFU2ULrvQKNp++az06M =gHmZ -----END PGP SIGNATURE-----
>From c04656d8566163d11be7beae2e3ff78ab0a48da0 Mon Sep 17 00:00:00 2001 From: Dan Walsh <dwalsh@xxxxxxxxxx> Date: Tue, 27 Mar 2012 14:00:35 -0400 Subject: [PATCH 30/90] policycoreutils: mcstrans: add -f to run in foreground Add an -f option to run mcstransd in the foreground. This will allow better integration into systemd. Signed-off-by: Eric Paris <eparis@xxxxxxxxxx> --- policycoreutils/mcstrans/man/man8/mcstransd.8 | 9 +++++++- policycoreutils/mcstrans/src/mcstransd.c | 28 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/policycoreutils/mcstrans/man/man8/mcstransd.8 b/policycoreutils/mcstrans/man/man8/mcstransd.8 index 4c63965..0be6468 100644 --- a/policycoreutils/mcstrans/man/man8/mcstransd.8 +++ b/policycoreutils/mcstrans/man/man8/mcstransd.8 @@ -3,7 +3,7 @@ mcstransd \- MCS (Multiple Category System) daemon. Translates SELinux MCS/MLS labels to human readable form. .SH "SYNOPSIS" -.B mcstransd +.B mcstransd [-f] [-h] .P .SH "DESCRIPTION" @@ -12,6 +12,13 @@ This manual page describes the program. .P This daemon reads /etc/selinux/{SELINUXTYPE}/setrans.conf configuration file, and communicates with libselinux via a socket in /var/run/setrans. +.SH "OPTIONS" +.TP +-f +Run mcstransd in the foreground. Do not run as a daemon. +.TP +-h +Output a short summary of available command line options\&. .SH "AUTHOR" This man page was written by Dan Walsh <dwalsh@xxxxxxxxxx>. diff --git a/policycoreutils/mcstrans/src/mcstransd.c b/policycoreutils/mcstrans/src/mcstransd.c index 26d9be8..a65076d 100644 --- a/policycoreutils/mcstrans/src/mcstransd.c +++ b/policycoreutils/mcstrans/src/mcstransd.c @@ -1,5 +1,4 @@ /* Copyright (c) 2006 Trusted Computer Solutions, Inc. */ - #include <sys/types.h> #include <sys/socket.h> #include <sys/poll.h> @@ -13,6 +12,7 @@ #include <signal.h> #include <string.h> #include <syslog.h> +#include <unistd.h> #include <selinux/selinux.h> #include <sys/types.h> #include <sys/capability.h> @@ -556,9 +556,31 @@ void dropprivs(void) cap_free(new_caps); } +static void usage(char *program) +{ + printf("%s [-f] [-h] \n", program); +} + int -main(int UNUSED(argc), char *argv[]) +main(int argc, char *argv[]) { + int opt; + int do_fork = 1; + while ((opt = getopt(argc, argv, "hf")) > 0) { + switch (opt) { + case 'f': + do_fork = 0; + break; + case 'h': + usage(argv[0]); + exit(0); + break; + case '?': + usage(argv[0]); + exit(-1); + } + } + #ifndef DEBUG /* Make sure we are root */ if (getuid() != 0) { @@ -576,7 +598,7 @@ main(int UNUSED(argc), char *argv[]) dropprivs(); /* run in the background as a daemon */ - if (daemon(0, 0)) { + if (do_fork && daemon(0, 0)) { syslog(LOG_ERR, "daemon() failed: %m"); cleanup_exit(1); } -- 1.7.10.2