+clean_old_logs()
+{
+#if !defined(_WIN32)
+ const gchar *file;
+ gchar *config;
+
+ config = ghb_get_user_config_dir(NULL);
+
+ if (g_file_test(config, G_FILE_TEST_IS_DIR))
+ {
+ GDir *gdir = g_dir_open(config, 0, NULL);
+ file = g_dir_read_name(gdir);
+ while (file)
+ {
+ if (strncmp(file, "Activity.log.", 13) == 0)
+ {
+ gchar *path;
+ int fd, lock = 1;
+ int pid;
+
+ sscanf(file, "Activity.log.%d", &pid);
+
+ path = g_strdup_printf("%s/ghb.pid.%d", config, pid);
+ if (g_file_test(path, G_FILE_TEST_EXISTS))
+ {
+ fd = open(path, O_RDWR);
+ if (fd >= 0)
+ {
+ lock = lockf(fd, F_TLOCK, 0);
+ }
+ g_free(path);
+ close(fd);
+ if (lock == 0)
+ {
+ path = g_strdup_printf("%s/%s", config, file);
+ g_unlink(path);
+ g_free(path);
+ }
+ }
+ else
+ {
+ g_free(path);
+ path = g_strdup_printf("%s/%s", config, file);
+ g_unlink(path);
+ g_free(path);
+ }
+ }
+ file = g_dir_read_name(gdir);
+ }
+ g_dir_close(gdir);
+ }
+ g_free(config);
+#else
+ const gchar *file;
+ gchar *config;
+
+ config = ghb_get_user_config_dir(NULL);
+
+ if (g_file_test(config, G_FILE_TEST_IS_DIR))
+ {
+ GDir *gdir = g_dir_open(config, 0, NULL);
+ file = g_dir_read_name(gdir);
+ while (file)
+ {
+ if (strncmp(file, "Activity.log.", 13) == 0)
+ {
+ gchar *path;
+ int pid;
+
+ sscanf(file, "Activity.log.%d", &pid);
+
+#if 0
+ int fd, lock = 1;
+
+ path = g_strdup_printf("%s/ghb.pid.%d", config, pid);
+ if (g_file_test(path, G_FILE_TEST_EXISTS))
+ {
+ fd = open(path, O_RDWR);
+ if (fd >= 0)
+ {
+ lock = lockf(fd, F_TLOCK, 0);
+ }
+ g_free(path);
+ close(fd);
+ if (lock == 0)
+ {
+ path = g_strdup_printf("%s/%s", config, file);
+ g_unlink(path);
+ g_free(path);
+ }
+ }
+ else
+#endif
+ {
+ //g_free(path);
+ path = g_strdup_printf("%s/%s", config, file);
+ g_unlink(path);
+ g_free(path);
+ }
+ }
+ file = g_dir_read_name(gdir);
+ }
+ g_dir_close(gdir);
+ }
+ g_free(config);
+#endif
+}
+
+static void