52 lines
1.2 KiB
Diff
52 lines
1.2 KiB
Diff
|
diff -up mcstrans-0.3.2/src/mcstransd.c.writepid mcstrans-0.3.2/src/mcstransd.c
|
||
|
--- mcstrans-0.3.2/src/mcstransd.c.writepid 2011-01-05 10:32:25.000000000 -0500
|
||
|
+++ mcstrans-0.3.2/src/mcstransd.c 2012-02-01 16:14:02.085806490 -0500
|
||
|
@@ -4,6 +4,7 @@
|
||
|
#include <sys/socket.h>
|
||
|
#include <sys/poll.h>
|
||
|
#include <sys/stat.h>
|
||
|
+#include <fcntl.h>
|
||
|
#include <sys/un.h>
|
||
|
#include <errno.h>
|
||
|
#include <stdint.h>
|
||
|
@@ -556,6 +557,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 +607,8 @@ main(int UNUSED(argc), char *argv[])
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
+ write_pid_file();
|
||
|
+
|
||
|
syslog(LOG_NOTICE, "%s initialized", argv[0]);
|
||
|
process_connections();
|
||
|
|