busybox/libbb/pidfile.c
Denis Vlasenko 80edead5ea udhcp: slight shrink
udhcpd_main                                         1171    1208     +37
udhcpc_main                                         2363    2387     +24
dhcprelay_main                                      1145    1146      +1
dhcprelay_stopflag                                     4       1      -3
dhcprelay_signal_handler                              11       8      -3
client_background                                     46      42      -4
udhcp_read_interface                                 230     211     -19
udhcp_make_pidfile                                    76       -     -76
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 3/4 up/down: 62/-105)           Total: -43 bytes
   text    data     bss     dec     hex filename
 770052    1096   11228  782376   bf028 busybox_old
 769980    1096   11228  782304   befe0 busybox_unstripped
2007-08-02 22:31:05 +00:00

33 lines
713 B
C

/* vi: set sw=4 ts=4: */
/*
* pid file routines
*
* Copyright (C) 2007 by Stephane Billiart <stephane.billiart@gmail.com>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* Override ENABLE_FEATURE_PIDFILE */
#define WANT_PIDFILE 1
#include "libbb.h"
int write_pidfile(const char *path)
{
int pid_fd;
char *end;
char buf[sizeof(int)*3 + 2];
if (!path)
return 1;
/* we will overwrite stale pidfile */
pid_fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (pid_fd < 0)
return 0;
/* few bytes larger, but doesn't use stdio */
end = utoa_to_buf(getpid(), buf, sizeof(buf));
*end = '\n';
full_write(pid_fd, buf, end - buf + 1);
close(pid_fd);
return 1;
}