From: Steven Barth Date: Fri, 28 Nov 2014 09:20:35 +0000 (+0100) Subject: Cleanup pidfile-gerneration X-Git-Tag: debian/1.1+git20160131-1~40 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=045d7158852d86a4b190267a252f32c2f15034aa;p=odhcp6c.git Cleanup pidfile-gerneration --- diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 89dfd36..8149738 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -254,19 +254,15 @@ int main(_unused int argc, char* const argv[]) return 4; } - char pidbuf[128]; if (!pidfile) { - snprintf(pidbuf, sizeof(pidbuf), - "/var/run/odhcp6c.%s.pid", ifname); - pidfile = pidbuf; + snprintf((char*)buf, sizeof(buf), "/var/run/odhcp6c.%s.pid", ifname); + pidfile = (char*)buf; } - int fd = open(pidfile, O_WRONLY | O_CREAT, 0644); - if (fd >= 0) { - char buf[8]; - int len = snprintf(buf, sizeof(buf), "%i\n", getpid()); - write(fd, buf, len); - close(fd); + FILE *fp = fopen(pidfile, "w"); + if (fp) { + fprintf(fp, "%i\n", getpid()); + fclose(fp); } }