diff options
author | Lennart Poettering <lennart@poettering.net> | 2003-12-23 00:05:15 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2003-12-23 00:05:15 +0000 |
commit | 33f01df1c95b43b66e2f0bab2b972dd9e03faeb5 (patch) | |
tree | 053f3bcff15d9161e6b2f0c942941052de5fb14f /src/lock.c | |
parent | 51c0330ea15a28d2d7c83a746458dfd5cf1770bc (diff) |
it compiles and works basically
git-svn-id: file:///home/lennart/svn/public/ivam2/trunk@9 dbf6933d-3bce-0310-9bcc-ed052ba35b35
Diffstat (limited to 'src/lock.c')
-rw-r--r-- | src/lock.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -7,17 +7,20 @@ #include <signal.h> #include <stdlib.h> #include <string.h> +#include <inttypes.h> #include <libdaemon/dlog.h> #include "lock.h" +#include "util.h" +#include "main.h" /* Where do lockfiles reside? */ #define LOCK_PATH "/var/lock" static const char *lockfile(const char *dev) { static char lockfile[PATH_MAX]; - snprintf(lockfile, sizeof(lockfile), "%s/LCK..%s", LOCK_PATH, basename(dev)); + snprintf(lockfile, sizeof(lockfile), "%s/LCK..%s", LOCK_PATH, basename((char*) dev)); return lockfile; } @@ -30,7 +33,7 @@ static const char *tempfile(const char *path) { int device_lock(const char *dev) { struct stat st; int fd; - char *path, *temp; + const char *path, *temp; char buf[100]; if (stat(LOCK_PATH, &st) != 0 || !S_ISDIR(st.st_mode)) { @@ -57,7 +60,7 @@ int device_lock(const char *dev) { close(fd); if (n < 0) { - close(fd) + close(fd); daemon_log(LOG_ERR, "Failed to read from lock file: %s", strerror(errno)); return -1; } @@ -68,13 +71,15 @@ int device_lock(const char *dev) { if (n == 4) pid = (pid_t) *((uint32_t*) buf); else { + unsigned long v; buf[n] = 0; - sscanf(buf, "%lu", &pid); + sscanf(buf, "%lu", &v); + pid = (pid_t) v; } if (pid > 0) { if (kill(pid, 0) < 0 && errno == ESRCH) { - daemon_log(LOG_WARN, "Lockfile is stale. Overriding it."); + daemon_log(LOG_WARNING, "Lockfile is stale. Overriding it."); /* Yes, here is a race condition */ unlink(path); } else @@ -90,7 +95,7 @@ int device_lock(const char *dev) { snprintf(buf, sizeof(buf), "%10lu %s %.20s\n", (unsigned long) getpid(), appname, username); if (loop_write(fd, buf, strlen(buf)) < 0) { - daemon_log(LOG_ERR, "Failed to write to temporary lock file: %s", sterror(errno)); + daemon_log(LOG_ERR, "Failed to write to temporary lock file: %s", strerror(errno)); close(fd); return -1; } @@ -104,6 +109,7 @@ int device_lock(const char *dev) { daemon_log(LOG_ERR, "Failed to link temporary lock file: %s", strerror(errno)); } + unlink(temp); return 0; } |