[ConsoleKit] [PATCH] ck-log-system-start: always create log directory

Daniel Drake dsd at laptop.org
Tue Sep 27 14:02:02 PDT 2011


Some embedded setups (like OLPC) don't disk-back /var/log (e.g. enabled
by Fedora's readonly-root functionality), so this will be empty on
every boot.

In this setup, ck-log-system-start fails because /var/log/ConsoleKit
doesn't exist.

Fix this by copying in mkdir code from ck-event-logger.c:open_log_file
which already correctly handles this situation.
---
 tools/ck-log-system-start.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/tools/ck-log-system-start.c b/tools/ck-log-system-start.c
index 0860429..7cc72cc 100644
--- a/tools/ck-log-system-start.c
+++ b/tools/ck-log-system-start.c
@@ -51,6 +51,8 @@ open_log_file (const char *filename,
 {
         int      flags;
         int      fd;
+        int      res;
+        char    *dirname;
         FILE    *file;
         gboolean ret;
 
@@ -64,6 +66,20 @@ open_log_file (const char *filename,
         flags |= O_NOFOLLOW;
 #endif
 
+        dirname = g_path_get_dirname (filename);
+        /* always make sure we have a directory */
+        errno = 0;
+        res = g_mkdir_with_parents (dirname,
+                                    S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+        if (res < 0) {
+                g_warning ("Unable to create directory %s (%s)",
+                           dirname,
+                           g_strerror (errno));
+                g_free (dirname);
+                return FALSE;
+        }
+        g_free (dirname);
+
 retry:
         fd = g_open (filename, flags, 0600);
         if (fd < 0) {
-- 
1.7.6.2



More information about the ConsoleKit mailing list