session_policy_local: Create policy directory if necessary
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 6 Dec 2012 07:37:11 +0000 (08:37 +0100)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 10 Dec 2012 11:01:05 +0000 (13:01 +0200)
Create the policy directory as first thing. If we don't do this
adding a watch on the non existing directory will fail and the
whole plugin is not loaded.

We need to figure out later how permissive the MODE of the directory
should be. Currently, we play safe and have it tied down.

plugins/session_policy_local.c

index 7fa3166..11b1665 100644 (file)
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/inotify.h>
+#include <sys/stat.h>
 
 #include <glib.h>
 
@@ -40,6 +41,9 @@
 
 #define POLICYDIR STORAGEDIR "/session_policy_local"
 
+#define MODE           (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
+                       S_IXGRP | S_IROTH | S_IXOTH)
+
 static DBusConnection *connection;
 
 static GHashTable *policy_hash;
@@ -464,6 +468,14 @@ static int session_policy_local_init(void)
 {
        int err;
 
+       /* If the dir doesn't exist, create it */
+       if (g_file_test(POLICYDIR, G_FILE_TEST_IS_DIR) == FALSE) {
+               if (mkdir(POLICYDIR, MODE) < 0) {
+                       if (errno != EEXIST)
+                               return -errno;
+               }
+       }
+
        connection = connman_dbus_get_connection();
        if (connection == NULL)
                return -EIO;