MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / ghb_find_pid_file

Function ghb_find_pid_file

gtk/src/presets.c:950–1006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

948}
949
950int
951ghb_find_pid_file (void)
952{
953 const gchar *file;
954 gchar *config;
955
956 config = ghb_get_user_config_dir(NULL);
957
958 if (g_file_test(config, G_FILE_TEST_IS_DIR))
959 {
960 GDir *gdir;
961 gdir = g_dir_open(config, 0, NULL);
962 file = g_dir_read_name(gdir);
963 while (file)
964 {
965 if (strncmp(file, "ghb.pid.", 8) == 0)
966 {
967 gchar *path;
968 int pid;
969
970 sscanf(file, "ghb.pid.%d", &pid);
971 path = g_strdup_printf("%s/%s", config, file);
972
973#if !defined(_WIN32)
974 int fd, lock = 1;
975
976 fd = open(path, O_RDWR);
977 if (fd >= 0)
978 {
979 lock = lockf(fd, F_TLOCK, 0);
980 }
981 if (lock == 0)
982 {
983 close(fd);
984 g_dir_close(gdir);
985 g_unlink(path);
986 g_free(path);
987 g_free(config);
988 return pid;
989 }
990 g_free(path);
991 close(fd);
992#else
993 g_dir_close(gdir);
994 g_unlink(path);
995 g_free(path);
996 g_free(config);
997 return pid;
998#endif
999 }
1000 file = g_dir_read_name(gdir);
1001 }
1002 g_dir_close(gdir);
1003 }
1004 g_free(config);
1005 return -1;
1006}
1007

Callers 1

ghb_reload_queueFunction · 0.85

Calls 1

ghb_get_user_config_dirFunction · 0.85

Tested by

no test coverage detected