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:02:46.670139198 -0500 @@ -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();