void lot_recache_collection(char subname[]) { { char collpath[LINE_MAX]; FILE *fp; lot_get_closed_collections_file(collpath); fp = fopen(collpath, "a"); if (fp == NULL) { warn("fopen(%s, append)", collpath); } else { flock(fileno(fp), LOCK_EX); fseek(fp, 0, SEEK_END); fprintf(fp, "%s\n", subname); flock(fileno(fp), LOCK_UN); fclose(fp); } } { int pid; char pidpath[LINE_MAX]; FILE *fp; sbfile(pidpath, "var/searchd.pid"); if ((fp = fopen(pidpath, "r")) == NULL) { warn("Unable to open pidfile for searchdbb: fopen(%s)", pidpath); } else { int scanc = fscanf(fp, "%d", &pid); if (scanc != 1) { fprintf(stderr,"Unable to get a valid pid from %s\n",pidpath); } else { printf("pid %i, scanc %i\n", pid, scanc); kill(pid, SIGUSR2); } fclose(fp); } } }
void cache_indexes_all(void) { DIR *dirp; size_t len; int i; size_t *cached; DIR *colls; char *coll; FILE *fp; char collpath[2048]; lot_get_closed_collections_file(collpath); if ((fp = fopen(collpath, "r+")) == NULL) { bblog_errno(WARN, "Unable to open collection list: fopen(%s)", collpath); } else { flock(fileno(fp), LOCK_EX); ftruncate(fileno(fp), 0); flock(fileno(fp), LOCK_UN); /* * Release the lock, so that indexes updated while running the * cache step will not block. We can recache it later. */ fclose(fp); } cached = indexcachescached; indexcachehash = create_hashtable(1023, ht_stringhash, ht_stringcmp); cached[0] = cached[1] = 0; if ((colls = listAllColl_start()) == NULL) { bblog(ERROR, "Can't listAllColl_start()"); return; } while ((coll = listAllColl_next(colls))) { cache_indexes_collection(coll); } listAllColl_close(colls); }
void cache_indexes(int action) { if (action == 0) { /* All collections */ cache_indexes_all(); } else if (action == 1) { if (indexcachehash == NULL) { bblog(WARN, "Unable to run an incremental index cache when there has not been done a full one"); } else { FILE *fp; char collpath[2048]; lot_get_closed_collections_file(collpath); if ((fp = fopen(collpath, "r+")) == NULL) { bblog_errno(ERROR, "Unable to open collection list: fopen(%s)", collpath); } else { char line[2048]; flock(fileno(fp), LOCK_EX); while (fgets(line, sizeof(line), fp) != NULL) { line[strlen(line)-1] = '\0'; /* Remove trailing newline */ bblog(INFO, "Got updated collection: %s", line); cache_indexes_collection(line); } ftruncate(fileno(fp), 0); flock(fileno(fp), LOCK_UN); fclose(fp); bblog(INFO, "done"); } } } else { bblog(WARN, "Unknown cache index action: %d", action); } }