summaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-10-20 16:58:13 +0000
committerRoy Marples <roy@marples.name>2007-10-20 16:58:13 +0000
commitcfbd159f4963a70033562a1ac16c7d0d932497ab (patch)
tree6cdf887e6464e3e12796c41797cf6b1ec28d07d3 /common.c
parent6b37baaad11ddf85817aaaea5aaac4259b77866f (diff)
downloaddhcpcd-cfbd159f4963a70033562a1ac16c7d0d932497ab.tar.xz
Write the pidfile before we fork so we can easily be stopped by other processes.
Diffstat (limited to 'common.c')
-rw-r--r--common.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/common.c b/common.c
index 517ab677..1fb50187 100644
--- a/common.c
+++ b/common.c
@@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#ifdef __linux__
+# define _XOPEN_SOURCE 500 /* needed for pwrite */
+#endif
+
#include <sys/time.h>
#include <errno.h>
#include <fcntl.h>
@@ -131,6 +135,18 @@ time_t uptime (void)
return (tp.tv_sec);
}
+void writepid (int fd, pid_t pid)
+{
+ char spid[16];
+ if (ftruncate (fd, 0) == -1) {
+ logger (LOG_ERR, "ftruncate: %s", strerror (errno));
+ } else {
+ snprintf (spid, sizeof (spid), "%u", pid);
+ if (pwrite (fd, spid, strlen (spid), 0) != (ssize_t) strlen (spid))
+ logger (LOG_ERR, "pwrite: %s", strerror (errno));
+ }
+}
+
void *xmalloc (size_t s)
{
void *value = malloc (s);