[hackers] [skvm] Mainly bug fixes (making sure to log failures when a syscall || Dimitrios Papastamos

From: <hg_AT_suckless.org>
Date: Fri, 1 May 2009 17:02:41 +0000 (UTC)

changeset: 5:8b4f4992bf52
tag: tip
user: Dimitrios Papastamos <stateless [at] archlinux.us>
date: Fri May 01 18:02:07 2009 -0700
files: skvm.c
description:
Mainly bug fixes (making sure to log failures when a syscall
sets errno). Code cleanup.

diff -r 20771e40b9c5 -r 8b4f4992bf52 skvm.c
--- a/skvm.c Fri May 01 17:41:36 2009 -0700
+++ b/skvm.c Fri May 01 18:02:07 2009 -0700
@@ -610,24 +610,25 @@
 static int
 is_running(void) {
    char buf[16];
+ int serrno;
 
    pid_fd = open(LOCKFILE, O_RDWR | O_CREAT, LOCKMODE);
- if (pid_fd < 0)
- goto out;
-
- if (flock(pid_fd, LOCK_EX | LOCK_NB) < 0)
- goto out;
-
- if (ftruncate(pid_fd, 0) < 0)
+ if (pid_fd < 0 || flock(pid_fd, LOCK_EX | LOCK_NB) < 0
+ || ftruncate(pid_fd, 0) < 0)
       goto out;
 
    snprintf(buf, sizeof(buf), "%jd\n", (intmax_t)getpid());
- write(pid_fd, buf, strlen(buf));
+ if (write(pid_fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
+ goto out;
    return 0;
 
 out:
+ serrno = errno;
    if (pid_fd != -1)
- close(pid_fd);
+ if (close(pid_fd) < 0)
+ syslog(LOG_ERR, "%s:%d %s", __FILE__, __LINE__,
+ strerror(errno));
+ errno = serrno;
    pid_fd = -1;
    syslog(LOG_ERR, "%s:%d %s", __FILE__, __LINE__,
           strerror(errno));
Received on Fri May 01 2009 - 17:02:41 UTC

This archive was generated by hypermail 2.2.0 : Fri May 01 2009 - 17:12:04 UTC