about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-07-23 11:16:54 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-07-23 11:16:54 +0000
commit22854731920f5fa3927f24efb719083d38214693 (patch)
tree371eafd28e82bd6111f50ffb69b06bf0b3b861c4
parent7810b15cfd35f0defc4bec25cc2072e39306a2d6 (diff)
downloadbtpd-22854731920f5fa3927f24efb719083d38214693.tar.gz
btpd-22854731920f5fa3927f24efb719083d38214693.zip
Make sure btpd_dir contains an absolute path. If btpd was started with
'-d some/releative/path' it would fail to set up the ipc socket correctly.
Reported by Arnaud Bergeron.

-rw-r--r--btpd/main.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/btpd/main.c b/btpd/main.c
index 42df946..65b0662 100644
--- a/btpd/main.c
+++ b/btpd/main.c
@@ -31,11 +31,14 @@ setup_daemon(int daemonize, const char *dir, const char *log)
     if (log == NULL)
         log = "log";
 
-    if (dir == NULL)
+    if (dir == NULL) {
         if ((dir = find_btpd_dir()) == NULL)
             errx(1, "Cannot find the btpd directory");
-
-    btpd_dir = dir;
+        else if (dir[0] != '/')
+            errx(1, "got non absolute path '%s' from system environment.",
+                dir);
+        btpd_dir = dir;
+    }
 
     if (mkdir(dir, 0777) == -1 && errno != EEXIST)
         err(1, "Couldn't create home '%s'", dir);
@@ -52,6 +55,13 @@ setup_daemon(int daemonize, const char *dir, const char *log)
     if (flock(pidfd, LOCK_NB|LOCK_EX) == -1)
         errx(1, "Another instance of btpd is probably running in %s.", dir);
 
+    if (btpd_dir == NULL) {
+        char wd[PATH_MAX];
+        if (getcwd(wd, PATH_MAX) == NULL)
+            err(1, "couldn't get working directory");
+        btpd_dir = strdup(wd);
+    }
+
     if (daemonize) {
         if (daemon(1, 1) != 0)
             err(1, "Failed to daemonize");