diff options
author | Eric Koegel <eric.koegel@gmail.com> | 2014-10-01 19:59:22 +0300 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2014-10-01 19:59:22 +0300 |
commit | 0384eaca1ad3e4d6b24aa658471c5d2c4ac83559 (patch) | |
tree | c8726f81e6dbfdd4e03f4d0858b3cec0e39ffa52 | |
parent | c8765dd16251b6362eb4a2f4e5aab34fd178c260 (diff) | |
download | ConsoleKit2-0384eaca1ad3e4d6b24aa658471c5d2c4ac83559.tar.gz |
Cleanup console tag files on application startup and shutdown.
-rw-r--r-- | src/main.c | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -148,6 +148,44 @@ delete_pid (void) unlink (CONSOLE_KIT_PID_FILE); } +#define CONSOLE_TAGS_DIR "/var/run/console" + +static void +delete_console_tags (void) +{ + GDir *dir; + GError *error = NULL; + const gchar *name; + + g_debug ("Cleaning up %s", CONSOLE_TAGS_DIR); + + dir = g_dir_open (CONSOLE_TAGS_DIR, 0, &error); + if (dir == NULL) { + g_debug ("Couldn't open directory %s: %s", CONSOLE_TAGS_DIR, + error->message); + g_error_free (error); + return; + } + while ((name = g_dir_read_name (dir)) != NULL) { + gchar *file; + file = g_build_filename (CONSOLE_TAGS_DIR, name, NULL); + + g_debug ("Removing tag file: %s", file); + if (unlink (file) == -1) { + g_warning ("Couldn't delete tag file: %s", file); + } + g_free (file); + } + g_dir_close (dir); +} + +static void +cleanup (void) +{ + delete_console_tags (); + delete_pid (); +} + /* copied from nautilus */ static int debug_log_pipes[2]; @@ -232,7 +270,7 @@ create_pid_file (void) CONSOLE_KIT_PID_FILE, g_strerror (errno)); } - g_atexit (delete_pid); + g_atexit (cleanup); close (pf); } else { g_warning ("Unable to write pid file %s: %s", @@ -328,6 +366,8 @@ main (int argc, goto out; } + delete_console_tags (); + create_pid_file (); loop = g_main_loop_new (NULL, FALSE); |