Improved writepid function

pull/11/head
Ashish Kumar Yadav 4 years ago
parent ca53638a17
commit 03d6a25af7

@ -255,9 +255,7 @@ void
writepid() writepid()
{ {
int fd; int fd;
char buf[8]; /* maximum possible pid in linux is 4194304 */
struct flock fl; struct flock fl;
ssize_t len;
fd = open(LOCKFILE, O_RDWR|O_CREAT, 0644); fd = open(LOCKFILE, O_RDWR|O_CREAT, 0644);
if (fd == -1) { if (fd == -1) {
@ -280,10 +278,8 @@ writepid()
perror("writepid - ftruncate"); perror("writepid - ftruncate");
exit(1); exit(1);
} }
snprintf(buf, sizeof buf, "%ld", (long)getpid()); if (dprintf(fd, "%ld", (long)getpid()) < 0) {
len = strlen(buf); perror("writepid - dprintf");
if (write(fd, buf, len) != len) {
perror("writepid - write");
exit(1); exit(1);
} }
} }

Loading…
Cancel
Save