aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2011-02-10 20:15:11 -0600
committerPeter Seebach <peter.seebach@windriver.com>2011-02-10 20:15:11 -0600
commit96f54bda80a5692c5c85e3aa74ffbd791c5b89d1 (patch)
tree752d628a5d371bf43793c78014c707f0cc49d99c
parentec9aa1874a760bd64c4d770aef7161e7a539af28 (diff)
downloadpseudo-96f54bda80a5692c5c85e3aa74ffbd791c5b89d1.tar.gz
pseudo-96f54bda80a5692c5c85e3aa74ffbd791c5b89d1.tar.bz2
pseudo-96f54bda80a5692c5c85e3aa74ffbd791c5b89d1.zip
Whoops! If LOCALSTATEDIR doesn't exist, and you invoke pseudo
directly rather than via an on-demand spawn from the client, the directory is never created.
-rw-r--r--ChangeLog.txt6
-rw-r--r--pseudo.c29
-rw-r--r--pseudo_client.c1
3 files changed, 36 insertions, 0 deletions
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 6fbde57..1b88f7b 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,3 +1,9 @@
+2011-02-10:
+ * (seebs) pseudo_client_shutdown(), and the pseudo server, have to
+ be smart enough to make the local state directory in case the
+ pseudo binary is invoked directly by a user before being spawned
+ by the client.
+
2011-02-09:
* (seebs) the long-awaited cleanup of the database initialization
code. it's not really beautiful but it's quite a bit better.
diff --git a/pseudo.c b/pseudo.c
index 0814344..7d3c90a 100644
--- a/pseudo.c
+++ b/pseudo.c
@@ -66,6 +66,28 @@ usage(int status) {
exit(status);
}
+/* helper function to make a directory, just like mkdir -p.
+ * Can't use system() because the child shell would end up trying
+ * to do the same thing...
+ */
+static void
+mkdir_p(char *path) {
+ size_t len = strlen(path);
+ size_t i;
+
+ for (i = 1; i < len; ++i) {
+ /* try to create all the directories in path, ignoring
+ * failures
+ */
+ if (path[i] == '/') {
+ path[i] = '\0';
+ (void) mkdir(path, 0755);
+ path[i] = '/';
+ }
+ }
+ (void) mkdir(path, 0755);
+}
+
/* main server process */
int
main(int argc, char *argv[]) {
@@ -76,6 +98,7 @@ main(int argc, char *argv[]) {
int rc;
char opts[pseudo_path_max()], *optptr = opts;
char *lockname;
+ char *lockpath;
opts[0] = '\0';
@@ -371,6 +394,12 @@ main(int argc, char *argv[]) {
pseudo_new_pid();
pseudo_debug(3, "opening lock.\n");
+ lockpath = pseudo_localstatedir_path(NULL);
+ if (!lockpath) {
+ pseudo_diag("Couldn't allocate a file path.\n");
+ exit(EXIT_FAILURE);
+ }
+ mkdir_p(lockpath);
lockname = pseudo_localstatedir_path(PSEUDO_LOCKFILE);
if (!lockname) {
pseudo_diag("Couldn't allocate a file path.\n");
diff --git a/pseudo_client.c b/pseudo_client.c
index 507796f..5bc0b12 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -860,6 +860,7 @@ pseudo_client_shutdown(void) {
}
}
pseudo_path = pseudo_localstatedir_path(NULL);
+ mkdir_p(pseudo_path);
if (pseudo_localstate_dir_fd == -1) {
if (pseudo_path) {
pseudo_localstate_dir_fd = open(pseudo_path, O_RDONLY);