static void _win_populate_job(void *data) { Win *w = data; w->job.populate = NULL; if (w->db) { db_close(w->db); w->db = NULL; } if (access(w->db_path, F_OK|X_OK) == 0) w->db = db_open(w->db_path); if (!w->db) { char tmpdir[PATH_MAX]; lms_t *lms = lms_new(w->db_path); if (!lms) goto no_lms; enjoy_lms_charsets_add(lms); if (!enjoy_lms_parsers_add(lms)) goto no_parsers; snprintf(tmpdir, sizeof(tmpdir), "%s/tmpdir-nomusic", enjoy_cache_dir_get()); ecore_file_mkpath(tmpdir); if (lms_process_single_process(lms, tmpdir) != 0) CRITICAL("Failed to scan empty directory %s", tmpdir); ecore_file_rmdir(tmpdir); lms_free(lms); w->db = db_open(w->db_path); if (!w->db) goto no_lms; goto populate; no_parsers: CRITICAL("could not add any lightmediascanner parser!"); lms_free(lms); no_lms: CRITICAL("could not create database at %s!", w->db_path); exit(-1); } populate: ecore_event_add(ENJOY_EVENT_DB_UNLOCKED, NULL, NULL, NULL); list_populate(w->list, w->db); }
int main(int argc, char *argv[]) { int r; lms_t *lms; char *term; term = getenv("TERM"); if (term && (strncmp(term, "xterm", sizeof("xterm") - 1) == 0 || strncmp(term, "linux", sizeof("linux") - 1) == 0)) color = 1; r = handle_options_independent(argc, argv); if (r != 0) return r; if (optind >= argc) { fputs("ERROR: missing database path after options!\n", stderr); return -1; } lms = lms_new(argv[optind]); if (!lms) { fprintf(stderr, "ERROR: cannot open/create database %s\n", argv[optind]); return -1; } r = handle_options_setup(lms, argc, argv); if (r != 0) goto end; r = handle_options_work(lms, argc, argv); if (r != 0) goto end; fputs("success!\n", stderr); end: if (r) fputs("errors occurred, check out messages!\n", stderr); lms_free(lms); return r; }
int lms_create_slave(struct pinfo *pinfo, int (*work)(struct pinfo *pinfo)) { int r; pinfo->child = fork(); if (pinfo->child == -1) { perror("fork"); return -1; } if (pinfo->child > 0) return 0; _close_fds(&pinfo->master); nice(19); r = work(pinfo); lms_free(pinfo->common.lms); _exit(r); return r; /* shouldn't reach anyway... */ }