summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2009-03-13 09:56:58 -0400
committerSimo Sorce <ssorce@redhat.com>2009-03-13 13:47:38 -0400
commit4de71c3e5451082da25e9da57f470defc3cedc03 (patch)
tree571c93d4e5ff452204879fde20575d3657e80c31
parentdd4d867835a1443cb5a10b7a678d1d12400690d6 (diff)
downloadsssd-4de71c3e5451082da25e9da57f470defc3cedc03.tar.gz
sssd-4de71c3e5451082da25e9da57f470defc3cedc03.tar.bz2
sssd-4de71c3e5451082da25e9da57f470defc3cedc03.zip
Better error reporting for pidfile()
This should help understanding what's going on if the server fails to create a pid file.
-rw-r--r--server/util/server.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/server/util/server.c b/server/util/server.c
index 0ae2b0a1..ecd4d9bc 100644
--- a/server/util/server.c
+++ b/server/util/server.c
@@ -93,11 +93,12 @@ int pidfile(const char *path, const char *name)
pid_t pid;
char *file;
int fd;
- int ret;
+ int ret, err;
asprintf(&file, "%s/%s.pid", path, name);
fd = open(file, O_RDONLY, 0644);
+ err = errno;
if (fd != -1) {
pid_str[sizeof(pid_str) -1] = '\0';
@@ -122,16 +123,17 @@ int pidfile(const char *path, const char *name)
unlink(file);
} else {
- if (errno != ENOENT) {
+ if (err != ENOENT) {
free(file);
- return EIO;
+ return err;
}
}
fd = open(file, O_CREAT | O_WRONLY | O_EXCL, 0644);
+ err = errno;
if (fd == -1) {
free(file);
- return EIO;
+ return err;
}
free(file);
@@ -139,9 +141,10 @@ int pidfile(const char *path, const char *name)
snprintf(pid_str, sizeof(pid_str) -1, "%u\n", (unsigned int) getpid());
ret = write(fd, pid_str, strlen(pid_str));
+ err = errno;
if (ret != strlen(pid_str)) {
close(fd);
- return EIO;
+ return err;
}
close(fd);
@@ -251,8 +254,9 @@ int server_setup(const char *name, int flags,
if (flags & FLAGS_PID_FILE) {
ret = pidfile(PID_PATH, name);
if (ret != EOK) {
- DEBUG(0, ("ERROR: PID File reports daemon already running!\n"));
- return EEXIST;
+ DEBUG(0, ("Error creating pidfile! (%d [%s])\n",
+ ret, strerror(ret)));
+ return ret;
}
}