-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Should be revoked, first time we ran within systemd we needed a pid file to run properly, but adding the -f patch allows us to run mcstransd without forking, and systemd can handle this. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk/JEa4ACgkQrlYvE4MpobOPpACgtl2VlqjHBroa6NXPAzXsM7nt tgQAn267F2KS4+SejwoWPNoLYvq9MsvP =1WTz -----END PGP SIGNATURE-----
>From 1eaa4c1bb484333bc79c71f249b67e2bd93198ee Mon Sep 17 00:00:00 2001 From: Dan Walsh <dwalsh@xxxxxxxxxx> Date: Wed, 1 Feb 2012 15:53:33 -0500 Subject: [PATCH 16/90] policycoreutils: mcstransd: write a pid file FIXME [WHY] ? NOT-Signed-off-by: Eric Paris <eparis@xxxxxxxxxx> --- policycoreutils/mcstrans/src/mcstransd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/policycoreutils/mcstrans/src/mcstransd.c b/policycoreutils/mcstrans/src/mcstransd.c index 26d9be8..dd910bd 100644 --- a/policycoreutils/mcstrans/src/mcstransd.c +++ b/policycoreutils/mcstrans/src/mcstransd.c @@ -556,6 +556,30 @@ void dropprivs(void) cap_free(new_caps); } +static const char *pidfile = "/var/run/mcstransd.pid"; + +static int write_pid_file(void) +{ + int pidfd, len; + char val[16]; + + len = snprintf(val, sizeof(val), "%u\n", getpid()); + 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; + } + (void)write(pidfd, val, (unsigned int)len); + close(pidfd); + return 0; +} + int main(int UNUSED(argc), char *argv[]) { @@ -582,6 +606,8 @@ main(int UNUSED(argc), char *argv[]) } #endif + write_pid_file(); + syslog(LOG_NOTICE, "%s initialized", argv[0]); process_connections(); -- 1.7.10.2