diff options
-rw-r--r-- | ChangeLog.txt | 6 | ||||
-rw-r--r-- | pseudo.c | 29 | ||||
-rw-r--r-- | pseudo_client.c | 1 |
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. @@ -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); |