| 182 | } |
| 183 | |
| 184 | static void |
| 185 | clean_old_logs (void) |
| 186 | { |
| 187 | #if !defined(_WIN32) |
| 188 | const gchar *file; |
| 189 | gchar *config; |
| 190 | |
| 191 | config = ghb_get_user_config_dir(NULL); |
| 192 | |
| 193 | if (g_file_test(config, G_FILE_TEST_IS_DIR)) |
| 194 | { |
| 195 | GDir *gdir = g_dir_open(config, 0, NULL); |
| 196 | file = g_dir_read_name(gdir); |
| 197 | while (file) |
| 198 | { |
| 199 | if (strncmp(file, "Activity.log.", 13) == 0) |
| 200 | { |
| 201 | gchar *path; |
| 202 | int fd, lock = 1; |
| 203 | int pid; |
| 204 | |
| 205 | sscanf(file, "Activity.log.%d", &pid); |
| 206 | |
| 207 | path = g_strdup_printf("%s/ghb.pid.%d", config, pid); |
| 208 | if (g_file_test(path, G_FILE_TEST_EXISTS)) |
| 209 | { |
| 210 | fd = open(path, O_RDWR); |
| 211 | if (fd >= 0) |
| 212 | { |
| 213 | lock = lockf(fd, F_TLOCK, 0); |
| 214 | } |
| 215 | g_free(path); |
| 216 | close(fd); |
| 217 | if (lock == 0) |
| 218 | { |
| 219 | path = g_strdup_printf("%s/%s", config, file); |
| 220 | g_unlink(path); |
| 221 | g_free(path); |
| 222 | } |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | g_free(path); |
| 227 | path = g_strdup_printf("%s/%s", config, file); |
| 228 | g_unlink(path); |
| 229 | g_free(path); |
| 230 | } |
| 231 | } |
| 232 | file = g_dir_read_name(gdir); |
| 233 | } |
| 234 | g_dir_close(gdir); |
| 235 | } |
| 236 | g_free(config); |
| 237 | #else |
| 238 | const gchar *file; |
| 239 | gchar *config; |
| 240 | |
| 241 | config = ghb_get_user_config_dir(NULL); |
no test coverage detected