/*
* This file is part of DisOrder.
- * Copyright (C) 2004-2009 Richard Kettlewell
+ * Copyright (C) 2004-2012 Richard Kettlewell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
{ "log", required_argument, 0, 'l' },
{ "pidfile", required_argument, 0, 'P' },
{ "wide-open", no_argument, 0, 'w' },
+ { "wait-for-root", no_argument, 0, 'W' },
{ "syslog", no_argument, 0, 's' },
{ 0, 0, 0, 0 }
};
/* display usage message and terminate */
-static void help(void) {
+static void attribute((noreturn)) help(void) {
xprintf("Usage:\n"
" disorderd [OPTIONS]\n"
"Options:\n"
/* periodic actions --------------------------------------------------------- */
+/** @brief A job executed periodically by the server */
struct periodic_data {
+ /** @brief Callback to process job */
void (*callback)(ev_source *);
+
+ /** @brief Period of job in seconds */
int period;
};
disorder_info("%s", newpath);
}
+/* Used by test scripts to wait for things to get ready */
+static void wait_for_root(void) {
+ const char *password;
+
+ while(!trackdb_readable()) {
+ disorder_info("waiting for trackdb...");
+ sleep(1);
+ }
+ trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE);
+ for(;;) {
+ trackdb_open(TRACKDB_READ_ONLY);
+ password = trackdb_get_password("root");
+ trackdb_close();
+ if(password)
+ break;
+ disorder_info("waiting for root user to be created...");
+ sleep(1);
+ }
+ trackdb_deinit(NULL);
+}
+
int main(int argc, char **argv) {
- int n, background = 1, logsyslog = 0;
+ int n, background = 1, logsyslog = 0, wfr = 0;
const char *pidfile = 0;
struct rlimit rl[1];
if(!setlocale(LC_CTYPE, ""))
disorder_fatal(errno, "error calling setlocale");
/* garbage-collect PCRE's memory */
- pcre_malloc = xmalloc;
- pcre_free = xfree;
- while((n = getopt_long(argc, argv, "hVc:dfP:Ns", options, 0)) >= 0) {
+ regexp_setup();
+ while((n = getopt_long(argc, argv, "hVc:dfP:NsW", options, 0)) >= 0) {
switch(n) {
case 'h': help();
case 'V': version("disorderd");
case 'P': pidfile = optarg; break;
case 's': logsyslog = 1; break;
case 'w': wideopen = 1; break;
+ case 'W': wfr = 1; break;
default: disorder_fatal(0, "invalid option");
}
}
+ config_per_user = 0;
+ if(wfr) {
+ if(config_read(1, NULL))
+ disorder_fatal(0, "cannot read configuration");
+ wait_for_root();
+ return 0;
+ }
/* go into background if necessary */
if(background)
daemonize(progname, LOG_DAEMON, pidfile);
openlog(progname, LOG_PID, LOG_DAEMON);
log_default = &log_syslog;
}
- disorder_info("process ID %lu", (unsigned long)getpid());
+ disorder_info("version "VERSION" process ID %lu", (unsigned long)getpid());
fix_path();
srand(xtime(0)); /* don't start the same every time */
/* gcrypt initialization */
recent_read();
/* Arrange timeouts for schedule actions */
schedule_init(ev);
- /* pull in old users */
- trackdb_old_users();
/* create a root login */
trackdb_create_root();
/* create sockets */
create_periodic(ev, periodic_play_check, 1, 0);
/* Try adding a random track immediately and once every two seconds */
create_periodic(ev, periodic_add_random, 2, 1);
+ /* Issue a rescan when devices are mounted or unmouted */
+ create_periodic(ev, periodic_mount_check, MOUNT_CHECK_INTERVAL, 1);
/* enter the event loop */
n = ev_run(ev);
/* if we exit the event loop, something must have gone wrong */