summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorWilliam Jon McCann <jmccann@redhat.com>2008-02-25 19:19:31 -0500
committerWilliam Jon McCann <jmccann@redhat.com>2008-02-25 19:19:31 -0500
commit9e78825cef3db4e13cffbfd024bda365403aa6ba (patch)
tree53ea184b8e5accd21d353d1d3a55eb156501663a /src/main.c
parent414f7cc1e62474da69058884c5b683dc20e3a8f6 (diff)
always create the directories we need
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/main.c b/src/main.c
index 50698ed..adc0d71 100644
--- a/src/main.c
+++ b/src/main.c
@@ -252,6 +252,42 @@ setup_debug_log (gboolean debug)
setup_debug_log_signals ();
}
+static void
+create_pid_file (void)
+{
+ char *dirname;
+ int res;
+ int pf;
+ ssize_t written;
+ char pid[9];
+
+ /* remove old pid file */
+ unlink (CONSOLE_KIT_PID_FILE);
+
+ dirname = g_path_get_dirname (CONSOLE_KIT_PID_FILE);
+ 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);
+
+ /* make a new pid file */
+ if ((pf = open (CONSOLE_KIT_PID_FILE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644)) > 0) {
+ snprintf (pid, sizeof (pid), "%lu\n", (long unsigned) getpid ());
+ written = write (pf, pid, strlen (pid));
+ close (pf);
+ g_atexit (delete_pid);
+ } else {
+ g_warning ("Unable to write pid file %s: %s",
+ CONSOLE_KIT_PID_FILE,
+ g_strerror (errno));
+ }
+}
+
int
main (int argc,
char **argv)
@@ -263,9 +299,6 @@ main (int argc,
DBusGConnection *connection;
GError *error;
int ret;
- int pf;
- ssize_t written;
- char pid[9];
gboolean res;
static gboolean debug = FALSE;
static gboolean no_daemon = FALSE;
@@ -330,16 +363,7 @@ main (int argc,
g_debug ("initializing console-kit-daemon %s", VERSION);
- /* remove old pid file */
- unlink (CONSOLE_KIT_PID_FILE);
-
- /* make a new pid file */
- if ((pf = open (CONSOLE_KIT_PID_FILE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644)) > 0) {
- snprintf (pid, sizeof (pid), "%lu\n", (long unsigned) getpid ());
- written = write (pf, pid, strlen (pid));
- close (pf);
- g_atexit (delete_pid);
- }
+ create_pid_file ();
manager = ck_manager_new ();