diff options
author | William Jon McCann <jmccann@redhat.com> | 2008-02-25 19:19:31 -0500 |
---|---|---|
committer | William Jon McCann <jmccann@redhat.com> | 2008-02-25 19:19:31 -0500 |
commit | 9e78825cef3db4e13cffbfd024bda365403aa6ba (patch) | |
tree | 53ea184b8e5accd21d353d1d3a55eb156501663a /src/ck-manager.c | |
parent | 414f7cc1e62474da69058884c5b683dc20e3a8f6 (diff) |
always create the directories we need
Diffstat (limited to 'src/ck-manager.c')
-rw-r--r-- | src/ck-manager.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/ck-manager.c b/src/ck-manager.c index 6775e20..bf4926f 100644 --- a/src/ck-manager.c +++ b/src/ck-manager.c @@ -182,41 +182,56 @@ out: static void ck_manager_dump (CkManager *manager) { + int fd; + int res; const char *filename = LOCALSTATEDIR "/run/ConsoleKit/database"; const char *filename_tmp = LOCALSTATEDIR "/run/ConsoleKit/database~"; - if (manager != NULL) { - int fd; - fd = g_open (filename_tmp, O_CREAT | O_WRONLY, 0600); - if (fd == -1) { - g_warning ("Cannot create file %s: %s", filename_tmp, g_strerror (errno)); - goto error; - } + if (manager == NULL) { + return; + } - if (! do_dump (manager, fd)) { - g_warning ("Cannot write to file %s", filename_tmp); - close (fd); - goto error; - } - again: - if (close (fd) != 0) { - if (errno == EINTR) - goto again; - else { - g_warning ("Cannot close fd for %s: %s", filename_tmp, g_strerror (errno)); - goto error; - } - } + /* always make sure we have a directory */ + errno = 0; + res = g_mkdir_with_parents (LOCALSTATEDIR "/run/ConsoleKit", + S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (res < 0) { + g_warning ("Unable to create directory %s (%s)", + LOCALSTATEDIR "/run/ConsoleKit", + g_strerror (errno)); + return; + } + + fd = g_open (filename_tmp, O_CREAT | O_WRONLY, 0600); + if (fd == -1) { + g_warning ("Cannot create file %s: %s", filename_tmp, g_strerror (errno)); + goto error; + } - if (g_rename (filename_tmp, filename) != 0) { - g_warning ("Cannot rename %s to %s: %s", filename_tmp, filename, g_strerror (errno)); + if (! do_dump (manager, fd)) { + g_warning ("Cannot write to file %s", filename_tmp); + close (fd); + goto error; + } + again: + if (close (fd) != 0) { + if (errno == EINTR) + goto again; + else { + g_warning ("Cannot close fd for %s: %s", filename_tmp, g_strerror (errno)); goto error; } } + if (g_rename (filename_tmp, filename) != 0) { + g_warning ("Cannot rename %s to %s: %s", filename_tmp, filename, g_strerror (errno)); + goto error; + } + return; error: - /* For security reasons; unlink the existing file since it contains outdated information */ + /* For security reasons; unlink the existing file since it + contains outdated information */ if (g_unlink (filename) != 0) { g_warning ("Cannot unlink %s: %s", filename, g_strerror (errno)); } |