$OpenBSD: patch-src_main_c,v 1.4 2012/10/12 14:55:42 ajacoutot Exp $ From Debian: Cleanup console tag files on application startup and shutdown. --- src/main.c.orig Tue Oct 26 16:34:03 2010 +++ src/main.c Sun Dec 5 09:01:12 2010 @@ -148,6 +148,43 @@ 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); + } +} + +static void +cleanup (void) +{ + delete_console_tags (); + delete_pid (); +} + /* copied from nautilus */ static int debug_log_pipes[2]; @@ -228,7 +265,7 @@ create_pid_file (void) snprintf (pid, sizeof (pid), "%lu\n", (long unsigned) getpid ()); written = write (pf, pid, strlen (pid)); close (pf); - g_atexit (delete_pid); + g_atexit (cleanup); } else { g_warning ("Unable to write pid file %s: %s", CONSOLE_KIT_PID_FILE, @@ -316,6 +353,8 @@ main (int argc, g_warning ("Could not acquire name; bailing out"); goto out; } + + delete_console_tags (); create_pid_file ();