[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 41/73] policycoreutils: mcstransd: write a pid file FIXME



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


   This patch looks good to me. acked.

systemd expects a pid file to be written by unit services.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9x4YEACgkQrlYvE4MpobPLGwCgverG61aQYgrYV3P5BCISw+QO
ZP4An3ahmMsngAp0CxVDDbIirCGdLdzY
=wQig
-----END PGP SIGNATURE-----
>From 33c85d21cc54ead423468d0765c8fa01b40ecef9 Mon Sep 17 00:00:00 2001
From: Dan Walsh <dwalsh@xxxxxxxxxx>
Date: Wed, 1 Feb 2012 15:53:33 -0500
Subject: [PATCH 41/73] 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.9.3


[Fedora Users]     [Fedora Legacy]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite News]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

Powered by Linux