#include <sys/resource.h>
#include <time.h>
#include <arpa/inet.h>
+#include <sys/wait.h>
#include "event.h"
#include "mem.h"
static pid_t subprogram(ev_source *ev, const char *prog,
int outputfd) {
pid_t pid;
- int lfd;
/* If we're in the background then trap subprocess stdout/stderr */
- if(!isatty(2))
- lfd = logfd(ev, prog);
- else
- lfd = -1;
if(!(pid = xfork())) {
exitfn = _exit;
ev_signal_atfork(ev);
signal(SIGPIPE, SIG_DFL);
- if(lfd != -1) {
- xdup2(lfd, 1);
- xdup2(lfd, 2);
- xclose(lfd);
- }
if(outputfd != -1) {
xdup2(outputfd, 1);
xclose(outputfd);
setpriority(PRIO_PROCESS, 0, 0);
execlp(prog, prog, "--config", configfile,
debugging ? "--debug" : "--no-debug",
+ log_default == &log_syslog ? "--syslog" : "--no-syslog",
(char *)0);
fatal(errno, "error invoking %s", prog);
}
- if(lfd != -1) xclose(lfd);
return pid;
}
static int stats_read(ev_source attribute((unused)) *ev,
ev_reader *reader,
- int attribute((unused)) fd,
void *ptr,
size_t bytes,
int eof,
}
static int stats_error(ev_source attribute((unused)) *ev,
- int attribute((unused)) fd,
int errno_value,
void *u) {
struct stats_details *const d = u;
}
void trackdb_rescan(ev_source *ev) {
+ int w;
if(rescan_pid != -1) {
error(0, "rescan already underway");
return;
}
rescan_pid = subprogram(ev, RESCAN, -1);
- ev_child(ev, rescan_pid, 0, reap_rescan, 0);
- D(("started rescanner"));
-
+ if(ev) {
+ ev_child(ev, rescan_pid, 0, reap_rescan, 0);
+ D(("started rescanner"));
+ } else {
+ /* This is the first rescan, we block until it is complete */
+ while(waitpid(rescan_pid, &w, 0) < 0 && errno == EINTR)
+ ;
+ reap_rescan(0, rescan_pid, w, 0, 0);
+ }
}
int trackdb_rescan_cancel(void) {