From 2e9ba080dd30434f3e8f88e63029280889586a32 Mon Sep 17 00:00:00 2001 Message-Id: <2e9ba080dd30434f3e8f88e63029280889586a32.1714325485.git.mdw@distorted.org.uk> From: Mark Wooding Date: Fri, 20 Nov 2009 15:18:51 +0000 Subject: [PATCH] error/fatal/info -> disorder_error/fatal/info Organization: Straylight/Edgeware From: Richard Kettlewell --- cgi/actions.c | 30 ++--- cgi/cgimain.c | 4 +- cgi/login.c | 2 +- cgi/macros-disorder.c | 2 +- cgi/options.c | 10 +- clients/authorize.c | 24 ++-- clients/disorder.c | 33 ++--- clients/disorderfm.c | 57 ++++---- clients/playrtp.c | 102 ++++++++------- clients/rtpmon.c | 40 +++--- disobedience/disobedience.c | 8 +- disobedience/help.c | 2 +- disobedience/misc.c | 4 +- disobedience/rtp.c | 16 +-- disobedience/settings.c | 12 +- lib/addr.c | 17 +-- lib/asprintf.c | 2 +- lib/authhash.c | 2 +- lib/cgi.c | 36 ++--- lib/charset.c | 4 +- lib/client-common.c | 2 +- lib/client.c | 58 ++++----- lib/configuration.c | 253 +++++++++++++++++++----------------- lib/cookies.c | 22 ++-- lib/coreaudio.c | 2 +- lib/dateparse.c | 6 +- lib/eclient.c | 2 +- lib/event.c | 41 +++--- lib/hex.c | 5 +- lib/hostname.c | 4 +- lib/ifreq.c | 2 +- lib/inputline.c | 4 +- lib/log.c | 13 +- lib/log.h | 14 +- lib/logfd.c | 10 +- lib/macros-builtin.c | 20 +-- lib/macros.c | 46 +++---- lib/mem.c | 16 +-- lib/mem.h | 4 +- lib/mime.c | 20 +-- lib/queue.c | 8 +- lib/random.c | 6 +- lib/regsub.c | 2 +- lib/rights.c | 4 +- lib/sendmail.c | 28 ++-- lib/sink.c | 2 +- lib/speaker-protocol.c | 5 +- lib/syscalls.c | 10 +- lib/trackdb-playlists.c | 30 ++--- lib/trackdb.c | 248 ++++++++++++++++++----------------- lib/trackname.c | 2 +- lib/uaudio-alsa.c | 53 ++++---- lib/uaudio-apis.c | 2 +- lib/uaudio-command.c | 14 +- lib/uaudio-oss.c | 24 ++-- lib/uaudio-rtp.c | 51 ++++---- lib/uaudio-thread.c | 4 +- lib/url.c | 6 +- lib/user.c | 37 ++++-- libtests/t-cgi.c | 2 +- libtests/t-unicode.c | 8 +- libtests/test.c | 3 +- server/background.c | 6 +- server/choose.c | 16 +-- server/daemonize.c | 12 +- server/dbparams.c | 22 ++-- server/dbupgrade.c | 84 ++++++------ server/deadlock.c | 12 +- server/decode.c | 74 ++++++----- server/disorderd.c | 51 ++++---- server/dump.c | 100 +++++++------- server/normalize.c | 42 +++--- server/play.c | 36 ++--- server/plugin.c | 13 +- server/queue-ops.c | 6 +- server/rescan.c | 60 ++++----- server/schedule.c | 65 ++++----- server/server-queue.c | 19 +-- server/server.c | 98 +++++++------- server/speaker.c | 64 ++++----- server/state.c | 14 +- server/stats.c | 6 +- server/trackname.c | 15 ++- tests/udplog.c | 16 +-- 84 files changed, 1201 insertions(+), 1130 deletions(-) diff --git a/cgi/actions.c b/cgi/actions.c index ab52c2d..30ddba1 100644 --- a/cgi/actions.c +++ b/cgi/actions.c @@ -44,7 +44,7 @@ static void redirect(const char *url) { if(printf("Location: %s\n" "%s\n" "\n", url, dcgi_cookie_header()) < 0) - fatal(errno, "error writing to stdout"); + disorder_fatal(errno, "error writing to stdout"); } /*$ playing @@ -101,7 +101,7 @@ static void act_playing(void) { url = config->url; if(printf("Refresh: %ld;url=%s\n", refresh, url) < 0) - fatal(errno, "error writing to stdout"); + disorder_fatal(errno, "error writing to stdout"); dcgi_expand("playing", 1); } @@ -176,12 +176,12 @@ static void act_remove(void) { if(dcgi_client) { if(!(id = cgi_get("id"))) - error(0, "missing 'id' argument"); + disorder_error(0, "missing 'id' argument"); else if(!(q = dcgi_findtrack(id))) - error(0, "unknown queue id %s", id); + disorder_error(0, "unknown queue id %s", id); else if(q->origin == origin_scratch) /* can't scratch scratches */ - error(0, "does not make sense to scratch or remove %s", id); + disorder_error(0, "does not make sense to scratch or remove %s", id); else if(q->state == playing_paused || q->state == playing_started) /* removing the playing track = scratching */ @@ -191,7 +191,7 @@ static void act_remove(void) { disorder_remove(dcgi_client, id); else /* various error states */ - error(0, "does not make sense to scratch or remove %s", id); + disorder_error(0, "does not make sense to scratch or remove %s", id); } redirect(0); } @@ -208,18 +208,18 @@ static void act_move(void) { if(dcgi_client) { if(!(id = cgi_get("id"))) - error(0, "missing 'id' argument"); + disorder_error(0, "missing 'id' argument"); else if(!(delta = cgi_get("delta"))) - error(0, "missing 'delta' argument"); + disorder_error(0, "missing 'delta' argument"); else if(!(q = dcgi_findtrack(id))) - error(0, "unknown queue id %s", id); + disorder_error(0, "unknown queue id %s", id); else switch(q->state) { case playing_random: /* unplayed randomly chosen track */ case playing_unplayed: /* haven't played this track yet */ disorder_move(dcgi_client, id, atol(delta)); break; default: - error(0, "does not make sense to scratch %s", id); + disorder_error(0, "does not make sense to scratch %s", id); break; } } @@ -438,7 +438,7 @@ static void act_register(void) { "\n" "%s?c=%s\n", config->url, urlencodestring(confirm)); if(!(text = mime_encode_text(text, &charset, &encoding))) - fatal(0, "cannot encode email"); + disorder_fatal(0, "cannot encode email"); byte_xasprintf(&content_type, "text/plain;charset=%s", quote822(charset, 0)); sendmail("", config->mail_sender, email, "Welcome to DisOrder", @@ -726,19 +726,19 @@ void dcgi_expand(const char *name, int header) { mx_expand_file(found, sink_discard(), 0); /* For unknown actions check that they aren't evil */ if(!dcgi_valid_action(name)) - fatal(0, "invalid action name '%s'", name); + disorder_fatal(0, "invalid action name '%s'", name); byte_xasprintf((char **)&p, "%s.tmpl", name); if(!(found = mx_find(p, 0/*report*/))) - fatal(errno, "cannot find %s", p); + disorder_fatal(errno, "cannot find %s", p); if(header) { if(printf("Content-Type: text/html; charset=UTF-8\n" "%s\n" "\n", dcgi_cookie_header()) < 0) - fatal(errno, "error writing to stdout"); + disorder_fatal(errno, "error writing to stdout"); } if(mx_expand_file(found, sink_stdio("stdout", stdout), 0) == -1 || fflush(stdout) < 0) - fatal(errno, "error writing to stdout"); + disorder_fatal(errno, "error writing to stdout"); } /** @brief Execute a web action diff --git a/cgi/cgimain.c b/cgi/cgimain.c index e4c7220..4ea98ec 100644 --- a/cgi/cgimain.c +++ b/cgi/cgimain.c @@ -65,7 +65,7 @@ int main(int argc, char **argv) { mx_search_path(pkgdatadir); /* Never cache anythging */ if(printf("Cache-Control: no-cache\n") < 0) - fatal(errno, "error writing to stdout"); + disorder_fatal(errno, "error writing to stdout"); /* Create the initial connection, trying the cookie if we found a suitable * one. */ dcgi_login(); @@ -74,7 +74,7 @@ int main(int argc, char **argv) { /* In practice if a write fails that probably means the web server went away, * but we log it anyway. */ if(fclose(stdout) < 0) - fatal(errno, "error closing stdout"); + disorder_fatal(errno, "error closing stdout"); return 0; } diff --git a/cgi/login.c b/cgi/login.c index a7a6dc0..c57be06 100644 --- a/cgi/login.c +++ b/cgi/login.c @@ -82,7 +82,7 @@ void dcgi_get_cookie(void) { if(best_cookie != -1) dcgi_cookie = cd.cookies[best_cookie].value; } else - error(0, "could not parse cookie field '%s'", cookie_env); + disorder_error(0, "could not parse cookie field '%s'", cookie_env); } } diff --git a/cgi/macros-disorder.c b/cgi/macros-disorder.c index c0eee5d..30614c1 100644 --- a/cgi/macros-disorder.c +++ b/cgi/macros-disorder.c @@ -978,7 +978,7 @@ static int exp_breadcrumbs(int attribute((unused)) nargs, return rc; /* Reject relative paths */ if(dir[0] != '/') { - error(0, "breadcrumbs: '%s' is a relative path", dir); + disorder_error(0, "breadcrumbs: '%s' is a relative path", dir); return 0; } /* Skip the root */ diff --git a/cgi/options.c b/cgi/options.c index 05712c2..fca5801 100644 --- a/cgi/options.c +++ b/cgi/options.c @@ -72,7 +72,7 @@ static void option__split_error(const char *msg, void *u) { struct read_options_state *cs = u; - error(0, "%s:%d: %s", cs->name, cs->line, msg); + disorder_error(0, "%s:%d: %s", cs->name, cs->line, msg); } static void option__readfile(const char *name) { @@ -84,7 +84,7 @@ static void option__readfile(const char *name) { if(!(cs.name = mx_find(name, 1/*report*/))) return; if(!(fp = fopen(cs.name, "r"))) - fatal(errno, "error opening %s", cs.name); + disorder_fatal(errno, "error opening %s", cs.name); cs.line = 0; while(!inputline(cs.name, fp, &buffer, '\n')) { ++cs.line; @@ -94,17 +94,17 @@ static void option__readfile(const char *name) { if(!n) continue; if((i = TABLE_FIND(options, name, vec[0])) == -1) { - error(0, "%s:%d: unknown option '%s'", cs.name, cs.line, vec[0]); + disorder_error(0, "%s:%d: unknown option '%s'", cs.name, cs.line, vec[0]); continue; } ++vec; --n; if(n < options[i].minargs) { - error(0, "%s:%d: too few arguments to '%s'", cs.name, cs.line, vec[-1]); + disorder_error(0, "%s:%d: too few arguments to '%s'", cs.name, cs.line, vec[-1]); continue; } if(n > options[i].maxargs) { - error(0, "%s:%d: too many arguments to '%s'", cs.name, cs.line, vec[-1]); + disorder_error(0, "%s:%d: too many arguments to '%s'", cs.name, cs.line, vec[-1]); continue; } options[i].handler(n, vec); diff --git a/clients/authorize.c b/clients/authorize.c index 93fe3f4..652db04 100644 --- a/clients/authorize.c +++ b/clients/authorize.c @@ -56,7 +56,7 @@ int authorize(disorder_client *client, const char *user, const char *rights) { if(!(pw = getpwnam(user))) /* If it's a NIS world then /etc/passwd may be a lie, but it emphasizes * that it's talking about the login user, not the DisOrder user */ - fatal(0, "no such user as %s in /etc/passwd", user); + disorder_fatal(0, "no such user as %s in /etc/passwd", user); /* Choose a random password */ gcry_randomize(pwbin, sizeof pwbin, GCRY_STRONG_RANDOM); @@ -68,46 +68,46 @@ int authorize(disorder_client *client, const char *user, const char *rights) { /* Become the target user */ if(setegid(pw->pw_gid) < 0) - fatal(errno, "setegid %lu", (unsigned long)pw->pw_gid); + disorder_fatal(errno, "setegid %lu", (unsigned long)pw->pw_gid); if(seteuid(pw->pw_uid) < 0) - fatal(errno, "seteuid %lu", (unsigned long)pw->pw_uid); + disorder_fatal(errno, "seteuid %lu", (unsigned long)pw->pw_uid); /* Make sure the configuration directory exists*/ byte_xasprintf(&configdir, "%s/.disorder", pw->pw_dir); if(mkdir(configdir, 02700) < 0) { if(errno != EEXIST) - fatal(errno, "creating %s", configdir); + disorder_fatal(errno, "creating %s", configdir); } /* Make sure the configuration file does not exist */ byte_xasprintf(&configpath, "%s/passwd", configdir); if(lstat(configpath, &sb) == 0) - fatal(0, "%s already exists", configpath); + disorder_fatal(0, "%s already exists", configpath); if(errno != ENOENT) - fatal(errno, " checking %s", configpath); + disorder_fatal(errno, " checking %s", configpath); byte_xasprintf(&configpathtmp, "%s.new", configpath); /* Create config file with mode 600 */ if((fd = open(configpathtmp, O_WRONLY|O_CREAT, 0600)) < 0) - fatal(errno, "error creating %s", configpathtmp); + disorder_fatal(errno, "error creating %s", configpathtmp); /* Write password */ if(!(fp = fdopen(fd, "w"))) - fatal(errno, "error calling fdopen"); + disorder_fatal(errno, "error calling fdopen"); if(fprintf(fp, "password %s\n", pwhex) < 0 || fclose(fp) < 0) - fatal(errno, "error writing to %s", configpathtmp); + disorder_fatal(errno, "error writing to %s", configpathtmp); /* Rename config file into place */ if(rename(configpathtmp, configpath) < 0) - fatal(errno, "error renaming %s to %s", configpathtmp, configpath); + disorder_fatal(errno, "error renaming %s to %s", configpathtmp, configpath); /* Put our identity back */ if(seteuid(old_uid) < 0) - fatal(errno, "seteuid %lu", (unsigned long)old_uid); + disorder_fatal(errno, "seteuid %lu", (unsigned long)old_uid); if(setegid(old_gid) < 0) - fatal(errno, "setegid %lu", (unsigned long)old_gid); + disorder_fatal(errno, "setegid %lu", (unsigned long)old_gid); return 0; } diff --git a/clients/disorder.c b/clients/disorder.c index 48bef78..1d55b8d 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -162,7 +162,8 @@ static void cf_shutdown(char attribute((unused)) **argv) { static void cf_reconfigure(char attribute((unused)) **argv) { /* Re-check configuration for server */ - if(config_read(1, NULL)) fatal(0, "cannot read configuration"); + if(config_read(1, NULL)) + disorder_fatal(0, "cannot read configuration"); if(disorder_reconfigure(getclient())) exit(EXIT_FAILURE); } @@ -328,9 +329,9 @@ static void cf_move(char **argv) { int e; if((e = xstrtol(&n, argv[1], 0, 10))) - fatal(e, "cannot convert '%s'", argv[1]); + disorder_fatal(e, "cannot convert '%s'", argv[1]); if(n > INT_MAX || n < INT_MIN) - fatal(e, "%ld out of range", n); + disorder_fatal(e, "%ld out of range", n); if(disorder_move(getclient(), argv[0], (int)n)) exit(EXIT_FAILURE); } @@ -487,11 +488,11 @@ static void cf_setup_guest(char **argv) { case 'h': help_setup_guest(); case 'r': online_registration = 1; break; case 'R': online_registration = 0; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(online_registration && !config->mail_sender) - fatal(0, "you MUST set mail_sender if you want online registration"); + disorder_fatal(0, "you MUST set mail_sender if you want online registration"); if(disorder_adduser(getclient(), "guest", "", online_registration ? "read,register" : "read")) exit(EXIT_FAILURE); @@ -638,7 +639,7 @@ static void cf_playlist_set(char **argv) { if(argv[1]) { // Read track list from file if(!(input = fopen(argv[1], "r"))) - fatal(errno, "opening %s", argv[1]); + disorder_fatal(errno, "opening %s", argv[1]); tag = argv[1]; } else { // Read track list from standard input @@ -652,7 +653,7 @@ static void cf_playlist_set(char **argv) { vector_append(v, l); } if(ferror(input)) - fatal(errno, "reading %s", tag); + disorder_fatal(errno, "reading %s", tag); if(input != stdin) fclose(input); if(disorder_playlist_lock(getclient(), argv[0]) @@ -818,7 +819,7 @@ static void wait_for_root(void) { const char *password; while(!trackdb_readable()) { - info("waiting for trackdb..."); + disorder_info("waiting for trackdb..."); sleep(1); } trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE); @@ -828,7 +829,7 @@ static void wait_for_root(void) { trackdb_close(); if(password) break; - info("waiting for root user to be created..."); + disorder_info("waiting for root user to be created..."); sleep(1); } trackdb_deinit(NULL); @@ -844,8 +845,8 @@ int main(int argc, char **argv) { /* garbage-collect PCRE's memory */ pcre_malloc = xmalloc; pcre_free = xfree; - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); - if(!setlocale(LC_TIME, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); + if(!setlocale(LC_TIME, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "+hVc:dHlNu:p:W", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -858,10 +859,10 @@ int main(int argc, char **argv) { case 'u': user = optarg; break; case 'p': password = optarg; break; case 'W': wfr = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); if(user) { config->username = user; config->password = 0; @@ -882,9 +883,9 @@ int main(int argc, char **argv) { /* accumulate command args */ while(n < argc) { if((i = TABLE_FIND(commands, name, argv[n])) < 0) - fatal(0, "unknown command '%s'", argv[n]); + disorder_fatal(0, "unknown command '%s'", argv[n]); if(n + commands[i].min >= argc) - fatal(0, "missing arguments to '%s'", argv[n]); + disorder_fatal(0, "missing arguments to '%s'", argv[n]); vector_init(&args); /* Include the command name in the args, but at element -1, for * the benefit of subcommand getopt calls */ @@ -901,7 +902,7 @@ int main(int argc, char **argv) { n += j; } if(client && disorder_close(client)) exit(EXIT_FAILURE); - if(fclose(stdout) < 0) fatal(errno, "error closing stdout"); + if(fclose(stdout) < 0) disorder_fatal(errno, "error closing stdout"); return status; } diff --git a/clients/disorderfm.c b/clients/disorderfm.c index 241b701..ed31dd0 100644 --- a/clients/disorderfm.c +++ b/clients/disorderfm.c @@ -139,21 +139,22 @@ static int copy(const char *from, const char *to) { struct stat sb; if((fdin = open(from, O_RDONLY)) < 0) - fatal(errno, "error opening %s", from); + disorder_fatal(errno, "error opening %s", from); if((fdout = open(to, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) - fatal(errno, "error opening %s", to); + disorder_fatal(errno, "error opening %s", to); while((n = read(fdin, buffer, sizeof buffer)) > 0) { if(write(fdout, buffer, n) < 0) - fatal(errno, "error writing to %s", to); + disorder_fatal(errno, "error writing to %s", to); } - if(n < 0) fatal(errno, "error reading %s", from); + if(n < 0) + disorder_fatal(errno, "error reading %s", from); if(fstat(fdin, &sb) < 0) - fatal(errno, "error stating %s", from); + disorder_fatal(errno, "error stating %s", from); if(fchown(fdout, sb.st_uid, sb.st_gid) < 0) - fatal(errno, "error chowning %s", from); + disorder_fatal(errno, "error chowning %s", from); if(fchmod(fdout, sb.st_mode & 07777) < 0) - fatal(errno, "error chmoding %s", from); - if(close(fdout) < 0) fatal(errno, "error closing %s", to); + disorder_fatal(errno, "error chmoding %s", from); + if(close(fdout) < 0) disorder_fatal(errno, "error closing %s", to); xclose(fdin); return 0; } @@ -288,25 +289,25 @@ static void visit(const char *path, const char *destpath) { * directory. In that case we'd better not descend into it when we encounter * it in the source. */ if(!strcmp(fullsourcepath, destination)) { - info("%s matches destination directory, not recursing", errsourcepath); + disorder_info("%s matches destination directory, not recursing", errsourcepath); return; } /* Find out what kind of file we're dealing with */ if(stat(fullsourcepath, &sb) < 0) { - error(errno, "cannot stat %s", errsourcepath ); + disorder_error(errno, "cannot stat %s", errsourcepath ); ++errors; return; } if(S_ISREG(sb.st_mode)) { if(copier != nocopy) if(unlink(fulldestpath) < 0 && errno != ENOENT) { - error(errno, "cannot remove %s", errdestpath); + disorder_error(errno, "cannot remove %s", errdestpath); ++errors; return; } if(copier(fullsourcepath, fulldestpath) < 0) { - error(errno, "cannot link %s to %s", errsourcepath, errdestpath); + disorder_error(errno, "cannot link %s to %s", errsourcepath, errdestpath); ++errors; return; } @@ -322,22 +323,22 @@ static void visit(const char *path, const char *destpath) { /* Created new directory. Adjust permissions and ownership to match the * old one. */ if(chown(fulldestpath, sb.st_uid, sb.st_gid) < 0) { - error(errno, "cannot chown %s", errdestpath); + disorder_error(errno, "cannot chown %s", errdestpath); ++errors; } if(chmod(fulldestpath, sb.st_mode & 07777) < 0) { - error(errno, "cannot chmod %s", errdestpath); + disorder_error(errno, "cannot chmod %s", errdestpath); ++errors; } } } else if(errno != EEXIST) { - error(errno, "cannot mkdir %s", errdestpath); + disorder_error(errno, "cannot mkdir %s", errdestpath); ++errors; return; } /* We read the directory and visit all the files in it in any old order. */ if(!(dp = opendir(fullsourcepath))) { - error(errno, "cannot open directory %s", errsourcepath); + disorder_error(errno, "cannot open directory %s", errsourcepath); ++errors; return; } @@ -354,11 +355,12 @@ static void visit(const char *path, const char *destpath) { } visit(childpath, childdestpath); } - if(errno) fatal(errno, "error reading directory %s", errsourcepath); + if(errno) + disorder_fatal(errno, "error reading directory %s", errsourcepath); closedir(dp); } else { /* We don't handle special files, but we'd better warn the user. */ - info("ignoring %s", errsourcepath); + disorder_info("ignoring %s", errsourcepath); } } @@ -367,7 +369,8 @@ int main(int argc, char **argv) { struct pattern *p; mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) + disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVdf:t:i:e:ET:u:wlscn", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -393,17 +396,19 @@ int main(int argc, char **argv) { case 's': copier = symlink; break; case 'c': copier = copy; break; case 'n': copier = nocopy; dirmaker = nomkdir; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } - if(optind == argc) fatal(0, "missing SOURCE and DESTINATION arguments"); - else if(optind + 1 == argc) fatal(0, "missing DESTINATION argument"); - else if(optind + 2 != argc) fatal(0, "redundant extra arguments"); - if(extracttags) fatal(0, "--extract-tags is not implemented yet"); /* TODO */ + if(optind == argc) + disorder_fatal(0, "missing SOURCE and DESTINATION arguments"); + else if(optind + 1 == argc) disorder_fatal(0, "missing DESTINATION argument"); + else if(optind + 2 != argc) disorder_fatal(0, "redundant extra arguments"); + if(extracttags) + disorder_fatal(0, "--extract-tags is not implemented yet"); /* TODO */ if(tagencoding && !extracttags) - fatal(0, "--tag-encoding without --extra-tags does not make sense"); + disorder_fatal(0, "--tag-encoding without --extra-tags does not make sense"); if(untagged && !extracttags) - fatal(0, "--untagged without --extra-tags does not make sense"); + disorder_fatal(0, "--untagged without --extra-tags does not make sense"); source = argv[optind]; destination = argv[optind + 1]; nativeencoding = nl_langinfo(CODESET); diff --git a/clients/playrtp.c b/clients/playrtp.c index 7eed9eb..2ab6790 100644 --- a/clients/playrtp.c +++ b/clients/playrtp.c @@ -247,10 +247,10 @@ static void *control_thread(void attribute((unused)) *arg) { strcpy(sa.sun_path, control_socket); sfd = xsocket(PF_UNIX, SOCK_STREAM, 0); if(bind(sfd, (const struct sockaddr *)&sa, sizeof sa) < 0) - fatal(errno, "error binding to %s", control_socket); + disorder_fatal(errno, "error binding to %s", control_socket); if(listen(sfd, 128) < 0) - fatal(errno, "error calling listen on %s", control_socket); - info("listening on %s", control_socket); + disorder_fatal(errno, "error calling listen on %s", control_socket); + disorder_info("listening on %s", control_socket); for(;;) { salen = sizeof sa; cfd = accept(sfd, (struct sockaddr *)&sa, &salen); @@ -260,17 +260,17 @@ static void *control_thread(void attribute((unused)) *arg) { case EAGAIN: break; default: - fatal(errno, "error calling accept on %s", control_socket); + disorder_fatal(errno, "error calling accept on %s", control_socket); } } if(!(fp = fdopen(cfd, "r+"))) { - error(errno, "error calling fdopen for %s connection", control_socket); + disorder_error(errno, "error calling fdopen for %s connection", control_socket); close(cfd); continue; } if(!inputline(control_socket, fp, &line, '\n')) { if(!strcmp(line, "stop")) { - info("stopped via %s", control_socket); + disorder_info("stopped via %s", control_socket); exit(0); /* terminate immediately */ } if(!strcmp(line, "query")) @@ -278,7 +278,7 @@ static void *control_thread(void attribute((unused)) *arg) { xfree(line); } if(fclose(fp) < 0) - error(errno, "error closing %s connection", control_socket); + disorder_error(errno, "error closing %s connection", control_socket); } } @@ -371,19 +371,19 @@ static void *listen_thread(void attribute((unused)) *arg) { case EINTR: continue; default: - fatal(errno, "error reading from socket"); + disorder_fatal(errno, "error reading from socket"); } } /* Ignore too-short packets */ if((size_t)n <= sizeof (struct rtp_header)) { - info("ignored a short packet"); + disorder_info("ignored a short packet"); continue; } timestamp = htonl(header.timestamp); seq = htons(header.seq); /* Ignore packets in the past */ if(active && lt(timestamp, next_timestamp)) { - info("dropping old packet, timestamp=%"PRIx32" < %"PRIx32, + disorder_info("dropping old packet, timestamp=%"PRIx32" < %"PRIx32, timestamp, next_timestamp); continue; } @@ -402,8 +402,7 @@ static void *listen_thread(void attribute((unused)) *arg) { break; /* TODO support other RFC3551 media types (when the speaker does) */ default: - fatal(0, "unsupported RTP payload type %d", - header.mpt & 0x7F); + disorder_fatal(0, "unsupported RTP payload type %d", header.mpt & 0x7F); } /* See if packet is silent */ const uint16_t *s = p->samples_raw; @@ -449,7 +448,7 @@ void playrtp_fill_buffer(void) { //fprintf(stderr, "%8u/%u (%u) DROPPING\n", nsamples, maxbuffer, minbuffer); drop_first_packet(); } - info("Buffering..."); + disorder_info("Buffering..."); /* Wait until there's at least minbuffer samples available */ while(nsamples < minbuffer) { //fprintf(stderr, "%8u/%u (%u) FILLING\n", nsamples, maxbuffer, minbuffer); @@ -604,8 +603,8 @@ static size_t playrtp_callback(void *buffer, * basis. */ if(nsamples > minbuffer && silent) { - info("dropping %zu samples (%"PRIu32" > %"PRIu32")", - samples, nsamples, minbuffer); + disorder_info("dropping %zu samples (%"PRIu32" > %"PRIu32")", + samples, nsamples, minbuffer); samples = 0; } /* Junk obsolete packets */ @@ -648,7 +647,7 @@ int main(int argc, char **argv) { * timestamps in the logs */ logdate = 1; mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); backend = uaudio_apis[0]; while((n = getopt_long(argc, argv, "hVdD:m:x:L:R:aocC:re:P:M", options, 0)) >= 0) { switch(n) { @@ -675,10 +674,10 @@ int main(int argc, char **argv) { case 'e': backend = &uaudio_command; uaudio_set("command", optarg); break; case 'P': uaudio_set("pause-mode", optarg); break; case 'M': monitor = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); if(!maxbuffer) maxbuffer = 2 * minbuffer; argc -= optind; @@ -701,7 +700,7 @@ int main(int argc, char **argv) { sl.s = argv; break; default: - fatal(0, "usage: disorder-playrtp [OPTIONS] [[ADDRESS] PORT]"); + disorder_fatal(0, "usage: disorder-playrtp [OPTIONS] [[ADDRESS] PORT]"); } /* Look up address and port */ if(!(res = get_address(&sl, &prefs, &sockname))) @@ -710,7 +709,7 @@ int main(int argc, char **argv) { if((rtpfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) - fatal(errno, "error creating socket"); + disorder_fatal(errno, "error creating socket"); /* Allow multiple listeners */ xsetsockopt(rtpfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); is_multicast = multicast(res->ai_addr); @@ -728,11 +727,13 @@ int main(int argc, char **argv) { mgroup.in6.sin6_port = 0; break; default: - fatal(0, "unsupported family %d", (int)res->ai_addr->sa_family); + disorder_fatal(0, "unsupported address family %d", + (int)res->ai_addr->sa_family); } /* Bind to to the multicast group address */ if(bind(rtpfd, res->ai_addr, res->ai_addrlen) < 0) - fatal(errno, "error binding socket to %s", format_sockaddr(res->ai_addr)); + disorder_fatal(errno, "error binding socket to %s", + format_sockaddr(res->ai_addr)); /* Add multicast group membership */ switch(mgroup.sa.sa_family) { case PF_INET: @@ -740,21 +741,21 @@ int main(int argc, char **argv) { mreq.imr_interface.s_addr = 0; /* use primary interface */ if(setsockopt(rtpfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof mreq) < 0) - fatal(errno, "error calling setsockopt IP_ADD_MEMBERSHIP"); + disorder_fatal(errno, "error calling setsockopt IP_ADD_MEMBERSHIP"); break; case PF_INET6: mreq6.ipv6mr_multiaddr = mgroup.in6.sin6_addr; memset(&mreq6.ipv6mr_interface, 0, sizeof mreq6.ipv6mr_interface); if(setsockopt(rtpfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof mreq6) < 0) - fatal(errno, "error calling setsockopt IPV6_JOIN_GROUP"); + disorder_fatal(errno, "error calling setsockopt IPV6_JOIN_GROUP"); break; default: - fatal(0, "unsupported address family %d", res->ai_family); + disorder_fatal(0, "unsupported address family %d", res->ai_family); } /* Report what we did */ - info("listening on %s multicast group %s", - format_sockaddr(res->ai_addr), format_sockaddr(&mgroup.sa)); + disorder_info("listening on %s multicast group %s", + format_sockaddr(res->ai_addr), format_sockaddr(&mgroup.sa)); } else { /* Bind to 0/port */ switch(res->ai_addr->sa_family) { @@ -771,35 +772,36 @@ int main(int argc, char **argv) { break; } default: - fatal(0, "unsupported family %d", (int)res->ai_addr->sa_family); + disorder_fatal(0, "unsupported family %d", (int)res->ai_addr->sa_family); } if(bind(rtpfd, res->ai_addr, res->ai_addrlen) < 0) - fatal(errno, "error binding socket to %s", format_sockaddr(res->ai_addr)); + disorder_fatal(errno, "error binding socket to %s", + format_sockaddr(res->ai_addr)); /* Report what we did */ - info("listening on %s", format_sockaddr(res->ai_addr)); + disorder_info("listening on %s", format_sockaddr(res->ai_addr)); } len = sizeof rcvbuf; if(getsockopt(rtpfd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &len) < 0) - fatal(errno, "error calling getsockopt SO_RCVBUF"); + disorder_fatal(errno, "error calling getsockopt SO_RCVBUF"); if(target_rcvbuf > rcvbuf) { if(setsockopt(rtpfd, SOL_SOCKET, SO_RCVBUF, &target_rcvbuf, sizeof target_rcvbuf) < 0) - error(errno, "error calling setsockopt SO_RCVBUF %d", - target_rcvbuf); + disorder_error(errno, "error calling setsockopt SO_RCVBUF %d", + target_rcvbuf); /* We try to carry on anyway */ else - info("changed socket receive buffer from %d to %d", - rcvbuf, target_rcvbuf); + disorder_info("changed socket receive buffer from %d to %d", + rcvbuf, target_rcvbuf); } else - info("default socket receive buffer %d", rcvbuf); + disorder_info("default socket receive buffer %d", rcvbuf); //info("minbuffer %u maxbuffer %u", minbuffer, maxbuffer); if(logfp) - info("WARNING: -L option can impact performance"); + disorder_info("WARNING: -L option can impact performance"); if(control_socket) { pthread_t tid; if((err = pthread_create(&tid, 0, control_thread, 0))) - fatal(err, "pthread_create control_thread"); + disorder_fatal(err, "pthread_create control_thread"); } if(dumpfile) { int fd; @@ -807,20 +809,20 @@ int main(int argc, char **argv) { size_t written; if((fd = open(dumpfile, O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) - fatal(errno, "opening %s", dumpfile); + disorder_fatal(errno, "opening %s", dumpfile); /* Fill with 0s to a suitable size */ memset(buffer, 0, sizeof buffer); for(written = 0; written < dump_size * sizeof(int16_t); written += sizeof buffer) { if(write(fd, buffer, sizeof buffer) < 0) - fatal(errno, "clearing %s", dumpfile); + disorder_fatal(errno, "clearing %s", dumpfile); } /* Map the buffer into memory for convenience */ dump_buffer = mmap(0, dump_size * sizeof(int16_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if(dump_buffer == (void *)-1) - fatal(errno, "mapping %s", dumpfile); - info("dumping to %s", dumpfile); + disorder_fatal(errno, "mapping %s", dumpfile); + disorder_info("dumping to %s", dumpfile); } /* Set up output. Currently we only support L16 so there's no harm setting * the format before we know what it is! */ @@ -829,17 +831,17 @@ int main(int argc, char **argv) { backend->start(playrtp_callback, NULL); /* We receive and convert audio data in a background thread */ if((err = pthread_create(<id, 0, listen_thread, 0))) - fatal(err, "pthread_create listen_thread"); + disorder_fatal(err, "pthread_create listen_thread"); /* We have a second thread to add received packets to the queue */ if((err = pthread_create(<id, 0, queue_thread, 0))) - fatal(err, "pthread_create queue_thread"); + disorder_fatal(err, "pthread_create queue_thread"); pthread_mutex_lock(&lock); time_t lastlog = 0; for(;;) { /* Wait for the buffer to fill up a bit */ playrtp_fill_buffer(); /* Start playing now */ - info("Playing..."); + disorder_info("Playing..."); next_timestamp = pheap_first(&packets)->timestamp; active = 1; pthread_mutex_unlock(&lock); @@ -863,11 +865,11 @@ int main(int argc, char **argv) { if(now >= lastlog + 60) { int offset = nsamples - minbuffer; double offtime = (double)offset / (uaudio_rate * uaudio_channels); - info("%+d samples off (%d.%02ds, %d bytes)", - offset, - (int)fabs(offtime) * (offtime < 0 ? -1 : 1), - (int)(fabs(offtime) * 100) % 100, - offset * uaudio_bits / CHAR_BIT); + disorder_info("%+d samples off (%d.%02ds, %d bytes)", + offset, + (int)fabs(offtime) * (offtime < 0 ? -1 : 1), + (int)(fabs(offtime) * 100) % 100, + offset * uaudio_bits / CHAR_BIT); lastlog = now; } } diff --git a/clients/rtpmon.c b/clients/rtpmon.c index e64b08e..32974e8 100644 --- a/clients/rtpmon.c +++ b/clients/rtpmon.c @@ -129,7 +129,7 @@ static void frames(const struct timeval *when, size_t n) { rate((ringtail - RINGSIZE / 2) % RINGSIZE, (ringtail - 1) % RINGSIZE)) < 0 || fflush(stdout) < 0) - fatal(errno, "stdout"); + disorder_fatal(errno, "stdout"); } } @@ -159,13 +159,13 @@ int main(int argc, char **argv) { mem_init(); if(!setlocale(LC_CTYPE, "")) - fatal(errno, "error calling setlocale"); + disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVb:", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version("rtpmon"); case 'b': bpf = atoi(optarg); break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } argc -= optind; @@ -178,7 +178,7 @@ int main(int argc, char **argv) { sl.s = argv; break; default: - fatal(0, "usage: rtpmon [OPTIONS] [ADDRESS] PORT"); + disorder_fatal(0, "usage: rtpmon [OPTIONS] [ADDRESS] PORT"); } if(!(res = get_address(&sl, &prefs, &sockname))) exit(1); @@ -186,7 +186,7 @@ int main(int argc, char **argv) { if((rtpfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) - fatal(errno, "error creating socket"); + disorder_fatal(errno, "error creating socket"); /* Allow multiple listeners */ xsetsockopt(rtpfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); is_multicast = multicast(res->ai_addr); @@ -204,11 +204,12 @@ int main(int argc, char **argv) { mgroup.in6.sin6_port = 0; break; default: - fatal(0, "unsupported family %d", (int)res->ai_addr->sa_family); + disorder_fatal(0, "unsupported family %d", (int)res->ai_addr->sa_family); } /* Bind to to the multicast group address */ if(bind(rtpfd, res->ai_addr, res->ai_addrlen) < 0) - fatal(errno, "error binding socket to %s", format_sockaddr(res->ai_addr)); + disorder_fatal(errno, "error binding socket to %s", + format_sockaddr(res->ai_addr)); /* Add multicast group membership */ switch(mgroup.sa.sa_family) { case PF_INET: @@ -216,21 +217,21 @@ int main(int argc, char **argv) { mreq.imr_interface.s_addr = 0; /* use primary interface */ if(setsockopt(rtpfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof mreq) < 0) - fatal(errno, "error calling setsockopt IP_ADD_MEMBERSHIP"); + disorder_fatal(errno, "error calling setsockopt IP_ADD_MEMBERSHIP"); break; case PF_INET6: mreq6.ipv6mr_multiaddr = mgroup.in6.sin6_addr; memset(&mreq6.ipv6mr_interface, 0, sizeof mreq6.ipv6mr_interface); if(setsockopt(rtpfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof mreq6) < 0) - fatal(errno, "error calling setsockopt IPV6_JOIN_GROUP"); + disorder_fatal(errno, "error calling setsockopt IPV6_JOIN_GROUP"); break; default: - fatal(0, "unsupported address family %d", res->ai_family); + disorder_fatal(0, "unsupported address family %d", res->ai_family); } /* Report what we did */ - info("listening on %s multicast group %s", - format_sockaddr(res->ai_addr), format_sockaddr(&mgroup.sa)); + disorder_info("listening on %s multicast group %s", + format_sockaddr(res->ai_addr), format_sockaddr(&mgroup.sa)); } else { /* Bind to 0/port */ switch(res->ai_addr->sa_family) { @@ -239,8 +240,8 @@ int main(int argc, char **argv) { memset(&in->sin_addr, 0, sizeof (struct in_addr)); if(bind(rtpfd, res->ai_addr, res->ai_addrlen) < 0) - fatal(errno, "error binding socket to 0.0.0.0 port %d", - ntohs(in->sin_port)); + disorder_fatal(errno, "error binding socket to 0.0.0.0 port %d", + ntohs(in->sin_port)); break; } case AF_INET6: { @@ -250,12 +251,13 @@ int main(int argc, char **argv) { break; } default: - fatal(0, "unsupported family %d", (int)res->ai_addr->sa_family); + disorder_fatal(0, "unsupported family %d", (int)res->ai_addr->sa_family); } if(bind(rtpfd, res->ai_addr, res->ai_addrlen) < 0) - fatal(errno, "error binding socket to %s", format_sockaddr(res->ai_addr)); + disorder_fatal(errno, "error binding socket to %s", + format_sockaddr(res->ai_addr)); /* Report what we did */ - info("listening on %s", format_sockaddr(res->ai_addr)); + disorder_info("listening on %s", format_sockaddr(res->ai_addr)); } for(;;) { struct rtp_header header; @@ -274,11 +276,11 @@ int main(int argc, char **argv) { case EINTR: continue; default: - fatal(errno, "error reading from socket"); + disorder_fatal(errno, "error reading from socket"); } } if((size_t)n <= sizeof (struct rtp_header)) { - info("ignored a short packet"); + disorder_info("ignored a short packet"); continue; } frames(&when, (n - sizeof header) / bpf); diff --git a/disobedience/disobedience.c b/disobedience/disobedience.c index 7fad2eb..edffbb5 100644 --- a/disobedience/disobedience.c +++ b/disobedience/disobedience.c @@ -437,7 +437,7 @@ int main(int argc, char **argv) { /* garbage-collect PCRE's memory */ pcre_malloc = xmalloc; pcre_free = xfree; - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); gtkok = gtk_init_check(&argc, &argv); while((n = getopt_long(argc, argv, "hVc:dtHC", options, 0)) >= 0) { switch(n) { @@ -446,11 +446,11 @@ int main(int argc, char **argv) { case 'c': configfile = optarg; break; case 'd': debugging = 1; break; case 't': goesupto = 11; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(!gtkok) - fatal(0, "failed to initialize GTK+"); + disorder_fatal(0, "failed to initialize GTK+"); /* gcrypt initialization */ if(!gcry_check_version(NULL)) disorder_fatal(0, "gcry_check_version failed"); @@ -462,7 +462,7 @@ int main(int argc, char **argv) { /* create the event loop */ D(("create main loop")); mainloop = g_main_loop_new(0, 0); - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); /* we'll need mixer support */ backend = uaudio_apis[0]; if(backend->configure) diff --git a/disobedience/help.c b/disobedience/help.c index 9408654..8ec405c 100644 --- a/disobedience/help.c +++ b/disobedience/help.c @@ -34,7 +34,7 @@ void popup_help(void) { exitfn = _exit; if(!xfork()) { execlp(browser, browser, path, (char *)0); - fatal(errno, "error executing %s", browser); + disorder_fatal(errno, "error executing %s", browser); } _exit(0); } diff --git a/disobedience/misc.c b/disobedience/misc.c index c807a27..c26cb54 100644 --- a/disobedience/misc.c +++ b/disobedience/misc.c @@ -108,14 +108,14 @@ GdkPixbuf *find_image(const char *name) { if((n = TABLE_FIND(images, name, name)) >= 0) { /* Use the built-in copy */ if(!(pb = gdk_pixbuf_new_from_inline(-1, images[n].data, FALSE, &err))) { - error(0, "%s", err->message); + disorder_error(0, "%s", err->message); return 0; } } else { /* See if there's a copy on disk */ byte_xasprintf(&path, "%s/static/%s", pkgdatadir, name); if(!(pb = gdk_pixbuf_new_from_file(path, &err))) { - error(0, "%s", err->message); + disorder_error(0, "%s", err->message); return 0; } } diff --git a/disobedience/rtp.c b/disobedience/rtp.c index f5f91f0..cbedb18 100644 --- a/disobedience/rtp.c +++ b/disobedience/rtp.c @@ -107,30 +107,30 @@ void start_rtp(void) { /* double-fork so we don't have to wait() later */ if(!(pid = xfork())) { if(setsid() < 0) - fatal(errno, "error calling setsid"); + disorder_fatal(errno, "error calling setsid"); if(!(pid = xfork())) { /* grandchild */ exitfn = _exit; /* log errors and output somewhere reasonably sane. rtp_running() * will have made sure the directory exists. */ if((fd = open(rtp_log, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) - fatal(errno, "creating %s", rtp_log); + disorder_fatal(errno, "creating %s", rtp_log); if(dup2(fd, 1) < 0 || dup2(fd, 2) < 0) - fatal(errno, "dup2"); + disorder_fatal(errno, "dup2"); if(close(fd) < 0) - fatal(errno, "close"); + disorder_fatal(errno, "close"); /* We don't want to hang onto whatever stdin was */ if((fd = open("/dev/null", O_RDONLY)) < 0) - fatal(errno, "opening /dev/null"); + disorder_fatal(errno, "opening /dev/null"); if(dup2(fd, 0) < 0) - fatal(errno, "dup2"); + disorder_fatal(errno, "dup2"); if(close(fd) < 0) - fatal(errno, "close"); + disorder_fatal(errno, "close"); /* execute the player */ execlp("disorder-playrtp", "disorder-playrtp", "--socket", rtp_socket, (char *)0); - fatal(errno, "disorder-playrtp"); + disorder_fatal(errno, "disorder-playrtp"); } else { /* child */ _exit(0); diff --git a/disobedience/settings.c b/disobedience/settings.c index 71b953d..2c4ffeb 100644 --- a/disobedience/settings.c +++ b/disobedience/settings.c @@ -219,25 +219,25 @@ void load_settings(void) { if(!strcmp(vec[0], "color")) { GdkColor *color; if(nvec != 7) { - error(0, "%s: malformed '%s' command", path, vec[0]); + disorder_error(0, "%s: malformed '%s' command", path, vec[0]); continue; } for(n = 0; n < NSTYLES && strcmp(styles[n].name, vec[1]); ++n) ; if(n >= NSTYLES) { - error(0, "%s: unknown style '%s'", path, vec[1]); + disorder_error(0, "%s: unknown style '%s'", path, vec[1]); continue; } for(m = 0; m < NSTATES && strcmp(states[m], vec[2]); ++m) ; if(m >= NSTATES) { - error(0, "%s: unknown state '%s'", path, vec[2]); + disorder_error(0, "%s: unknown state '%s'", path, vec[2]); continue; } for(c = 0; c < NCOLORS && strcmp(colors[c].name, vec[3]); ++c) ; if(c >= NCOLORS) { - error(0, "%s: unknown color '%s'", path, vec[3]); + disorder_error(0, "%s: unknown color '%s'", path, vec[3]); continue; } color = (GdkColor *)((char *)styles[n].style + colors[c].offset) + m; @@ -246,13 +246,13 @@ void load_settings(void) { color->blue = strtoul(vec[6], 0, 0); } else if(!strcmp(vec[0], "browser")) { if(nvec != 2) { - error(0, "%s: malformed '%s' command", path, vec[0]); + disorder_error(0, "%s: malformed '%s' command", path, vec[0]); continue; } browser = vec[1]; } else /* mention errors but otherwise ignore them */ - error(0, "%s: unknown command '%s'", path, vec[0]); + disorder_error(0, "%s: unknown command '%s'", path, vec[0]); } if(ferror(fp)) { fpopup_msg(GTK_MESSAGE_ERROR, "error reading %s: %s", diff --git a/lib/addr.c b/lib/addr.c index ecbab22..052466c 100644 --- a/lib/addr.c +++ b/lib/addr.c @@ -63,23 +63,24 @@ struct addrinfo *get_address(const struct stringlist *a, case 1: byte_xasprintf(&name, "host * service %s", a->s[0]); if((rc = getaddrinfo(0, a->s[0], pref, &res))) { - error(0, "getaddrinfo %s: %s", a->s[0], gai_strerror(rc)); + disorder_error(0, "getaddrinfo %s: %s", a->s[0], gai_strerror(rc)); return 0; } break; case 2: byte_xasprintf(&name, "host %s service %s", a->s[0], a->s[1]); if((rc = getaddrinfo(a->s[0], a->s[1], pref, &res))) { - error(0, "getaddrinfo %s %s: %s", a->s[0], a->s[1], gai_strerror(rc)); + disorder_error(0, "getaddrinfo %s %s: %s", + a->s[0], a->s[1], gai_strerror(rc)); return 0; } break; default: - error(0, "invalid network address specification (n=%d)", a->n); + disorder_error(0, "invalid network address specification (n=%d)", a->n); return 0; } if(!res || (pref && res->ai_socktype != pref->ai_socktype)) { - error(0, "getaddrinfo didn't give us a suitable socket address"); + disorder_error(0, "getaddrinfo didn't give us a suitable socket address"); if(res) freeaddrinfo(res); return 0; @@ -126,7 +127,7 @@ int sockaddrcmp(const struct sockaddr *a, return memcmp(&in6a->sin6_addr, &in6b->sin6_addr, sizeof (struct in6_addr)); default: - fatal(0, "unsupported protocol family %d", a->sa_family); + disorder_fatal(0, "unsupported protocol family %d", a->sa_family); } } @@ -334,9 +335,9 @@ struct addrinfo *netaddress_resolve(const struct netaddress *na, snprintf(service, sizeof service, "%d", na->port); rc = getaddrinfo(na->address, service, hints, &res); if(rc) { - error(0, "getaddrinfo %s %d: %s", - na->address ? na->address : "*", - na->port, gai_strerror(rc)); + disorder_error(0, "getaddrinfo %s %d: %s", + na->address ? na->address : "*", + na->port, gai_strerror(rc)); return NULL; } return res; diff --git a/lib/asprintf.c b/lib/asprintf.c index 5400339..da37319 100644 --- a/lib/asprintf.c +++ b/lib/asprintf.c @@ -99,7 +99,7 @@ int byte_xvasprintf(char **ptrp, int n; if((n = byte_vasprintf(ptrp, fmt, ap)) < 0) - fatal(errno, "error calling byte_vasprintf"); + disorder_fatal(errno, "error calling byte_vasprintf"); return n; } diff --git a/lib/authhash.c b/lib/authhash.c index d5da9c5..8cc96f9 100644 --- a/lib/authhash.c +++ b/lib/authhash.c @@ -85,7 +85,7 @@ const char *authhash(const void *challenge, size_t nchallenge, gcry_error_t e; if((e = gcry_md_open(&h, id, 0))) { - error(0, "gcry_md_open: %s", gcry_strerror(e)); + disorder_error(0, "gcry_md_open: %s", gcry_strerror(e)); return 0; } } diff --git a/lib/cgi.c b/lib/cgi.c index 42d599f..15b556c 100644 --- a/lib/cgi.c +++ b/lib/cgi.c @@ -43,7 +43,7 @@ static struct kvp *cgi__init_get(void) { if((q = getenv("QUERY_STRING"))) return kvp_urldecode(q, strlen(q)); - error(0, "QUERY_STRING not set, assuming empty"); + disorder_error(0, "QUERY_STRING not set, assuming empty"); return NULL; } @@ -55,26 +55,26 @@ static void cgi__input(char **ptrp, size_t *np) { int r; if(!(cl = getenv("CONTENT_LENGTH"))) - fatal(0, "CONTENT_LENGTH not set"); + disorder_fatal(0, "CONTENT_LENGTH not set"); n = atol(cl); /* We check for overflow and also limit the input to 16MB. Lower * would probably do. */ if(!(n+1) || n > 16 * 1024 * 1024) - fatal(0, "input is much too large"); + disorder_fatal(0, "input is much too large"); q = xmalloc_noptr(n + 1); while(m < n) { r = read(0, q + m, n - m); if(r > 0) m += r; else if(r == 0) - fatal(0, "unexpected end of file reading request body"); + disorder_fatal(0, "unexpected end of file reading request body"); else switch(errno) { case EINTR: break; - default: fatal(errno, "error reading request body"); + default: disorder_fatal(errno, "error reading request body"); } } if(memchr(q, 0, n)) - fatal(0, "null character in request body"); + disorder_fatal(0, "null character in request body"); q[n + 1] = 0; *ptrp = q; if(np) @@ -92,12 +92,12 @@ static int cgi__field_callback(const char *name, const char *value, &disposition, &pname, &pvalue)) - fatal(0, "error parsing Content-Disposition field"); + disorder_fatal(0, "error parsing Content-Disposition field"); if(!strcmp(disposition, "form-data") && pname && !strcmp(pname, "name")) { if(*namep) - fatal(0, "duplicate Content-Disposition field"); + disorder_fatal(0, "duplicate Content-Disposition field"); *namep = pvalue; } } @@ -109,11 +109,11 @@ static int cgi__part_callback(const char *s, void *u) { char *name = 0; struct kvp *k, **head = u; - + if(!(s = mime_parse(s, cgi__field_callback, &name))) - fatal(0, "error parsing part header"); + disorder_fatal(0, "error parsing part header"); if(!name) - fatal(0, "no name found"); + disorder_fatal(0, "no name found"); k = xmalloc(sizeof *k); k->next = *head; k->name = name; @@ -129,7 +129,7 @@ static struct kvp *cgi__init_multipart(const char *boundary) { cgi__input(&q, 0); if(mime_multipart(q, cgi__part_callback, boundary, &head)) - fatal(0, "invalid multipart object"); + disorder_fatal(0, "invalid multipart object"); return head; } @@ -143,17 +143,17 @@ static struct kvp *cgi__init_post(void) { if(!(ct = getenv("CONTENT_TYPE"))) ct = "application/x-www-form-urlencoded"; if(mime_content_type(ct, &type, &k)) - fatal(0, "invalid content type '%s'", ct); + disorder_fatal(0, "invalid content type '%s'", ct); if(!strcmp(type, "application/x-www-form-urlencoded")) { cgi__input(&q, &n); return kvp_urldecode(q, n); } if(!strcmp(type, "multipart/form-data")) { if(!(boundary = kvp_get(k, "boundary"))) - fatal(0, "no boundary parameter found"); + disorder_fatal(0, "no boundary parameter found"); return cgi__init_multipart(boundary); } - fatal(0, "unrecognized content type '%s'", type); + disorder_fatal(0, "unrecognized content type '%s'", type); } /** @brief Initialize CGI arguments @@ -171,18 +171,18 @@ void cgi_init(void) { cgi_args = hash_new(sizeof (char *)); if(!(p = getenv("REQUEST_METHOD"))) - error(0, "REQUEST_METHOD not set, assuming GET"); + disorder_error(0, "REQUEST_METHOD not set, assuming GET"); if(!p || !strcmp(p, "GET")) k = cgi__init_get(); else if(!strcmp(p, "POST")) k = cgi__init_post(); else - fatal(0, "unknown request method %s", p); + disorder_fatal(0, "unknown request method %s", p); /* Validate the arguments and put them in a hash */ for(; k; k = k->next) { if(!utf8_valid(k->name, strlen(k->name)) || !utf8_valid(k->value, strlen(k->value))) - error(0, "invalid UTF-8 sequence in cgi argument %s", k->name); + disorder_error(0, "invalid UTF-8 sequence in cgi argument %s", k->name); else hash_add(cgi_args, k->name, &k->value, HASH_INSERT_OR_REPLACE); /* We just drop bogus arguments. */ diff --git a/lib/charset.c b/lib/charset.c index 0e29269..fdc6d61 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -45,7 +45,7 @@ static void *convert(const char *from, const char *to, size_t bufsize = 0, sl, dl; if((i = iconv_open(to, from)) == (iconv_t)-1) - fatal(errno, "error calling iconv_open"); + disorder_fatal(errno, "error calling iconv_open"); do { bufsize = bufsize ? 2 * bufsize : 32; buf = xrealloc_noptr(buf, bufsize); @@ -59,7 +59,7 @@ static void *convert(const char *from, const char *to, } while(len == (size_t)-1 && errno == E2BIG); iconv_close(i); if(len == (size_t)-1) { - error(errno, "error converting from %s to %s", from, to); + disorder_error(errno, "error converting from %s to %s", from, to); return 0; } return buf; diff --git a/lib/client-common.c b/lib/client-common.c index aa43124..c55da89 100644 --- a/lib/client-common.c +++ b/lib/client-common.c @@ -55,7 +55,7 @@ socklen_t find_server(struct config *c, } else { name = config_get_file2(c, "socket"); if(strlen(name) >= sizeof su.sun_path) { - error(errno, "socket path is too long"); + disorder_error(errno, "socket path is too long"); return -1; } memset(&su, 0, sizeof su); diff --git a/lib/client.c b/lib/client.c index a0502eb..67f8a53 100644 --- a/lib/client.c +++ b/lib/client.c @@ -107,7 +107,7 @@ static int response(disorder_client *c, char **rp) { return (r[0] * 10 + r[1]) * 10 + r[2] - 111 * '0'; } else { c->last = "invalid reply format"; - error(0, "invalid reply format from %s", c->ident); + disorder_error(0, "invalid reply format from %s", c->ident); return -1; } } @@ -144,7 +144,7 @@ static int check_response(disorder_client *c, char **rp) { return 0; } else { if(c->verbose) - error(0, "from %s: %s", c->ident, utf82mb(r)); + disorder_error(0, "from %s: %s", c->ident, utf82mb(r)); return rc; } } @@ -185,7 +185,7 @@ static int disorder_simple_v(disorder_client *c, if(!c->fpout) { c->last = "not connected"; - error(0, "not connected to server"); + disorder_error(0, "not connected to server"); return -1; } if(cmd) { @@ -222,7 +222,7 @@ static int disorder_simple_v(disorder_client *c, return check_response(c, rp); write_error: byte_xasprintf((char **)&c->last, "write error: %s", strerror(errno)); - error(errno, "error writing to %s", c->ident); + disorder_error(errno, "error writing to %s", c->ident); return -1; } @@ -294,7 +294,7 @@ static int dequote(int rc, char **rp) { *rp = *rr; return 0; } - error(0, "invalid reply: %s", *rp); + disorder_error(0, "invalid reply: %s", *rp); } return rc; } @@ -330,28 +330,28 @@ int disorder_connect_generic(struct config *conf, c->fpin = c->fpout = 0; if((fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) { byte_xasprintf((char **)&c->last, "socket: %s", strerror(errno)); - error(errno, "error calling socket"); + disorder_error(errno, "error calling socket"); return -1; } if(connect(fd, sa, salen) < 0) { byte_xasprintf((char **)&c->last, "connect: %s", strerror(errno)); - error(errno, "error calling connect"); + disorder_error(errno, "error calling connect"); goto error; } if((fd2 = dup(fd)) < 0) { byte_xasprintf((char **)&c->last, "dup: %s", strerror(errno)); - error(errno, "error calling dup"); + disorder_error(errno, "error calling dup"); goto error; } if(!(c->fpin = fdopen(fd, "rb"))) { byte_xasprintf((char **)&c->last, "fdopen: %s", strerror(errno)); - error(errno, "error calling fdopen"); + disorder_error(errno, "error calling fdopen"); goto error; } fd = -1; if(!(c->fpout = fdopen(fd2, "wb"))) { byte_xasprintf((char **)&c->last, "fdopen: %s", strerror(errno)); - error(errno, "error calling fdopen"); + disorder_error(errno, "error calling fdopen"); goto error; } fd2 = -1; @@ -361,13 +361,13 @@ int disorder_connect_generic(struct config *conf, goto error; if(nrvec != 3) { c->last = "cannot parse server greeting"; - error(0, "cannot parse server greeting %s", r); + disorder_error(0, "cannot parse server greeting %s", r); goto error; } protocol = *rvec++; if(strcmp(protocol, "2")) { c->last = "unknown protocol version"; - error(0, "unknown protocol version: %s", protocol); + disorder_error(0, "unknown protocol version: %s", protocol); goto error; } algorithm = *rvec++; @@ -380,7 +380,7 @@ int disorder_connect_generic(struct config *conf, return 0; /* success */ if(!username) { c->last = "cookie failed and no username"; - error(0, "cookie did not work and no username available"); + disorder_error(0, "cookie did not work and no username available"); goto error; } } @@ -437,7 +437,7 @@ int disorder_connect(disorder_client *c) { if(!(username = config->username)) { c->last = "no username"; - error(0, "no username configured"); + disorder_error(0, "no username configured"); return -1; } password = config->password; @@ -451,7 +451,7 @@ int disorder_connect(disorder_client *c) { if(!password) { /* Oh well */ c->last = "no password"; - error(0, "no password configured for user '%s'", username); + disorder_error(0, "no password configured for user '%s'", username); return -1; } return disorder_connect_generic(config, @@ -492,7 +492,7 @@ int disorder_close(disorder_client *c) { if(c->fpin) { if(fclose(c->fpin) < 0) { byte_xasprintf((char **)&c->last, "fclose: %s", strerror(errno)); - error(errno, "error calling fclose"); + disorder_error(errno, "error calling fclose"); ret = -1; } c->fpin = 0; @@ -500,7 +500,7 @@ int disorder_close(disorder_client *c) { if(c->fpout) { if(fclose(c->fpout) < 0) { byte_xasprintf((char **)&c->last, "fclose: %s", strerror(errno)); - error(errno, "error calling fclose"); + disorder_error(errno, "error calling fclose"); ret = -1; } c->fpout = 0; @@ -601,7 +601,7 @@ int disorder_version(disorder_client *c, char **rp) { static void client_error(const char *msg, void attribute((unused)) *u) { - error(0, "error parsing reply: %s", msg); + disorder_error(0, "error parsing reply: %s", msg); } /** @brief Get currently playing track @@ -651,10 +651,10 @@ static int disorder_somequeue(disorder_client *c, } if(ferror(c->fpin)) { byte_xasprintf((char **)&c->last, "input error: %s", strerror(errno)); - error(errno, "error reading %s", c->ident); + disorder_error(errno, "error reading %s", c->ident); } else { c->last = "input error: unexpxected EOF"; - error(0, "error reading %s: unexpected EOF", c->ident); + disorder_error(0, "error reading %s: unexpected EOF", c->ident); } return -1; } @@ -706,10 +706,10 @@ static int readlist(disorder_client *c, char ***vecp, int *nvecp) { } if(ferror(c->fpin)) { byte_xasprintf((char **)&c->last, "input error: %s", strerror(errno)); - error(errno, "error reading %s", c->ident); + disorder_error(errno, "error reading %s", c->ident); } else { c->last = "input error: unexpxected EOF"; - error(0, "error reading %s: unexpected EOF", c->ident); + disorder_error(0, "error reading %s: unexpected EOF", c->ident); } return -1; } @@ -826,7 +826,7 @@ int disorder_get(disorder_client *c, static void pref_error_handler(const char *msg, void attribute((unused)) *u) { - error(0, "error handling 'prefs' reply: %s", msg); + disorder_error(0, "error handling 'prefs' reply: %s", msg); } /** @brief Get all preferences for a trcak @@ -869,7 +869,7 @@ static int boolean(const char *cmd, const char *value, if(!strcmp(value, "yes")) *flagp = 1; else if(!strcmp(value, "no")) *flagp = 0; else { - error(0, "malformed response to '%s'", cmd); + disorder_error(0, "malformed response to '%s'", cmd); return -1; } return 0; @@ -1005,7 +1005,7 @@ int disorder_get_volume(disorder_client *c, int *left, int *right) { return rc; if(sscanf(r, "%d %d", left, right) != 2) { c->last = "malformed volume response"; - error(0, "error parsing response to 'volume': '%s'", r); + disorder_error(0, "error parsing response to 'volume': '%s'", r); return -1; } return 0; @@ -1158,7 +1158,7 @@ int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) { vec = split(r, &n, SPLIT_QUOTES, 0, 0); if(n != 2) { c->last = "malformed RTP address"; - error(0, "malformed rtp-address reply"); + disorder_error(0, "malformed rtp-address reply"); return -1; } *addressp = vec[0]; @@ -1307,11 +1307,11 @@ int disorder_schedule_get(disorder_client *c, const char *id, return rc; while(*lines) { if(!(bits = split(*lines++, &nbits, SPLIT_QUOTES, 0, 0))) { - error(0, "invalid schedule-get reply: cannot split line"); + disorder_error(0, "invalid schedule-get reply: cannot split line"); return -1; } if(nbits != 2) { - error(0, "invalid schedule-get reply: wrong number of fields"); + disorder_error(0, "invalid schedule-get reply: wrong number of fields"); return -1; } kvp_set(actiondatap, bits[0], bits[1]); @@ -1354,7 +1354,7 @@ int disorder_schedule_add(disorder_client *c, action, key, value, (char *)0); } else - fatal(0, "unknown action '%s'", action); + disorder_fatal(0, "unknown action '%s'", action); va_end(ap); return rc; } diff --git a/lib/configuration.c b/lib/configuration.c index e1cb830..443d60b 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -142,12 +142,12 @@ static int set_signal(const struct config_state *cs, int n; if(nvec != 1) { - error(0, "%s:%d: '%s' requires one argument", + disorder_error(0, "%s:%d: '%s' requires one argument", cs->path, cs->line, whoami->name); return -1; } if((n = find_signal(vec[0])) == -1) { - error(0, "%s:%d: unknown signal '%s'", + disorder_error(0, "%s:%d: unknown signal '%s'", cs->path, cs->line, vec[0]); return -1; } @@ -178,23 +178,23 @@ static int set_collections(const struct config_state *cs, root = vec[2]; break; case 0: - error(0, "%s:%d: '%s' requires at least one argument", - cs->path, cs->line, whoami->name); + disorder_error(0, "%s:%d: '%s' requires at least one argument", + cs->path, cs->line, whoami->name); return -1; default: - error(0, "%s:%d: '%s' requires at most three arguments", - cs->path, cs->line, whoami->name); + disorder_error(0, "%s:%d: '%s' requires at most three arguments", + cs->path, cs->line, whoami->name); return -1; } /* Sanity check root */ if(root[0] != '/') { - error(0, "%s:%d: collection root must start with '/'", - cs->path, cs->line); + disorder_error(0, "%s:%d: collection root must start with '/'", + cs->path, cs->line); return -1; } if(root[1] && root[strlen(root)-1] == '/') { - error(0, "%s:%d: collection root must not end with '/'", - cs->path, cs->line); + disorder_error(0, "%s:%d: collection root must not end with '/'", + cs->path, cs->line); return -1; } /* Defaults */ @@ -217,15 +217,15 @@ static int set_boolean(const struct config_state *cs, int state; if(nvec != 1) { - error(0, "%s:%d: '%s' takes only one argument", - cs->path, cs->line, whoami->name); + disorder_error(0, "%s:%d: '%s' takes only one argument", + cs->path, cs->line, whoami->name); return -1; } if(!strcmp(vec[0], "yes")) state = 1; else if(!strcmp(vec[0], "no")) state = 0; else { - error(0, "%s:%d: argument to '%s' must be 'yes' or 'no'", - cs->path, cs->line, whoami->name); + disorder_error(0, "%s:%d: argument to '%s' must be 'yes' or 'no'", + cs->path, cs->line, whoami->name); return -1; } VALUE(cs->config, int) = state; @@ -236,8 +236,8 @@ static int set_string(const struct config_state *cs, const struct conf *whoami, int nvec, char **vec) { if(nvec != 1) { - error(0, "%s:%d: '%s' takes only one argument", - cs->path, cs->line, whoami->name); + disorder_error(0, "%s:%d: '%s' takes only one argument", + cs->path, cs->line, whoami->name); return -1; } VALUE(cs->config, char *) = xstrdup(vec[0]); @@ -266,16 +266,16 @@ static int set_integer(const struct config_state *cs, char *e; if(nvec != 1) { - error(0, "%s:%d: '%s' takes only one argument", - cs->path, cs->line, whoami->name); + disorder_error(0, "%s:%d: '%s' takes only one argument", + cs->path, cs->line, whoami->name); return -1; } if(xstrtol(ADDRESS(cs->config, long), vec[0], &e, 0)) { - error(errno, "%s:%d: converting integer", cs->path, cs->line); + disorder_error(errno, "%s:%d: converting integer", cs->path, cs->line); return -1; } if(*e) { - error(0, "%s:%d: invalid integer syntax", cs->path, cs->line); + disorder_error(0, "%s:%d: invalid integer syntax", cs->path, cs->line); return -1; } return 0; @@ -339,8 +339,8 @@ static int set_restrict(const struct config_state *cs, for(n = 0; n < nvec; ++n) { if((i = TABLE_FIND(restrictions, name, vec[n])) < 0) { - error(0, "%s:%d: invalid restriction '%s'", - cs->path, cs->line, vec[n]); + disorder_error(0, "%s:%d: invalid restriction '%s'", + cs->path, cs->line, vec[n]); return -1; } r |= restrictions[i].bit; @@ -356,15 +356,17 @@ static int parse_sample_format(const struct config_state *cs, long t; if(nvec != 1) { - error(0, "%s:%d: wrong number of arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: wrong number of arguments", cs->path, cs->line); return -1; } if(xstrtol(&t, p, &p, 0)) { - error(errno, "%s:%d: converting bits-per-sample", cs->path, cs->line); + disorder_error(errno, "%s:%d: converting bits-per-sample", + cs->path, cs->line); return -1; } if(t != 8 && t != 16) { - error(0, "%s:%d: bad bite-per-sample (%ld)", cs->path, cs->line, t); + disorder_error(0, "%s:%d: bad bite-per-sample (%ld)", + cs->path, cs->line, t); return -1; } if(format) format->bits = t; @@ -375,37 +377,38 @@ static int parse_sample_format(const struct config_state *cs, } if(format) format->endian = t; if(*p != '/') { - error(errno, "%s:%d: expected `/' after bits-per-sample", + disorder_error(errno, "%s:%d: expected `/' after bits-per-sample", cs->path, cs->line); return -1; } p++; if(xstrtol(&t, p, &p, 0)) { - error(errno, "%s:%d: converting sample-rate", cs->path, cs->line); + disorder_error(errno, "%s:%d: converting sample-rate", cs->path, cs->line); return -1; } if(t < 1 || t > INT_MAX) { - error(0, "%s:%d: silly sample-rate (%ld)", cs->path, cs->line, t); + disorder_error(0, "%s:%d: silly sample-rate (%ld)", cs->path, cs->line, t); return -1; } if(format) format->rate = t; if(*p != '/') { - error(0, "%s:%d: expected `/' after sample-rate", - cs->path, cs->line); + disorder_error(0, "%s:%d: expected `/' after sample-rate", + cs->path, cs->line); return -1; } p++; if(xstrtol(&t, p, &p, 0)) { - error(errno, "%s:%d: converting channels", cs->path, cs->line); + disorder_error(errno, "%s:%d: converting channels", cs->path, cs->line); return -1; } if(t < 1 || t > 8) { - error(0, "%s:%d: silly number (%ld) of channels", cs->path, cs->line, t); + disorder_error(0, "%s:%d: silly number (%ld) of channels", + cs->path, cs->line, t); return -1; } if(format) format->channels = t; if(*p) { - error(0, "%s:%d: junk after channels", cs->path, cs->line); + disorder_error(0, "%s:%d: junk after channels", cs->path, cs->line); return -1; } return 0; @@ -428,11 +431,13 @@ static int set_namepart(const struct config_state *cs, pcre *re; if(nvec < 3) { - error(0, "%s:%d: namepart needs at least 3 arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: namepart needs at least 3 arguments", + cs->path, cs->line); return -1; } if(nvec > 5) { - error(0, "%s:%d: namepart needs at most 5 arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: namepart needs at most 5 arguments", + cs->path, cs->line); return -1; } reflags = nvec >= 5 ? regsub_flags(vec[4]) : 0; @@ -440,8 +445,8 @@ static int set_namepart(const struct config_state *cs, PCRE_UTF8 |regsub_compile_options(reflags), &errstr, &erroffset, 0))) { - error(0, "%s:%d: error compiling regexp /%s/: %s (offset %d)", - cs->path, cs->line, vec[1], errstr, erroffset); + disorder_error(0, "%s:%d: compiling regexp /%s/: %s (offset %d)", + cs->path, cs->line, vec[1], errstr, erroffset); return -1; } npl->s = xrealloc(npl->s, (npl->n + 1) * sizeof (struct namepart)); @@ -474,11 +479,13 @@ static int set_transform(const struct config_state *cs, int erroffset; if(nvec < 3) { - error(0, "%s:%d: transform needs at least 3 arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: transform needs at least 3 arguments", + cs->path, cs->line); return -1; } if(nvec > 5) { - error(0, "%s:%d: transform needs at most 5 arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: transform needs at most 5 arguments", + cs->path, cs->line); return -1; } reflags = (nvec >= 5 ? regsub_flags(vec[4]) : 0); @@ -486,8 +493,8 @@ static int set_transform(const struct config_state *cs, PCRE_UTF8 |regsub_compile_options(reflags), &errstr, &erroffset, 0))) { - error(0, "%s:%d: error compiling regexp /%s/: %s (offset %d)", - cs->path, cs->line, vec[1], errstr, erroffset); + disorder_error(0, "%s:%d: compiling regexp /%s/: %s (offset %d)", + cs->path, cs->line, vec[1], errstr, erroffset); return -1; } tl->t = xrealloc(tl->t, (tl->n + 1) * sizeof (struct namepart)); @@ -504,13 +511,13 @@ static int set_rights(const struct config_state *cs, const struct conf *whoami, int nvec, char **vec) { if(nvec != 1) { - error(0, "%s:%d: '%s' requires one argument", - cs->path, cs->line, whoami->name); + disorder_error(0, "%s:%d: '%s' requires one argument", + cs->path, cs->line, whoami->name); return -1; } if(parse_rights(vec[0], 0, 1)) { - error(0, "%s:%d: invalid rights string '%s'", - cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: invalid rights string '%s'", + cs->path, cs->line, vec[0]); return -1; } *ADDRESS(cs->config, char *) = vec[0]; @@ -523,7 +530,7 @@ static int set_netaddress(const struct config_state *cs, struct netaddress *na = ADDRESS(cs->config, struct netaddress); if(netaddress_parse(na, nvec, vec)) { - error(0, "%s:%d: invalid network address", cs->path, cs->line); + disorder_error(0, "%s:%d: invalid network address", cs->path, cs->line); return -1; } return 0; @@ -648,21 +655,22 @@ static const struct conftype * If @p test returns 0 then the file is not a @p what and an error * is reported and -1 is returned. */ -#define VALIDATE_FILE(test, what) do { \ - struct stat sb; \ - int n; \ - \ - for(n = 0; n < nvec; ++n) { \ - if(stat(vec[n], &sb) < 0) { \ - error(errno, "%s:%d: %s", cs->path, cs->line, vec[n]); \ - return -1; \ - } \ - if(!test(sb.st_mode)) { \ - error(0, "%s:%d: %s is not a %s", \ - cs->path, cs->line, vec[n], what); \ - return -1; \ - } \ - } \ +#define VALIDATE_FILE(test, what) do { \ + struct stat sb; \ + int n; \ + \ + for(n = 0; n < nvec; ++n) { \ + if(stat(vec[n], &sb) < 0) { \ + disorder_error(errno, "%s:%d: %s", \ + cs->path, cs->line, vec[n]); \ + return -1; \ + } \ + if(!test(sb.st_mode)) { \ + disorder_error(0, "%s:%d: %s is not a %s", \ + cs->path, cs->line, vec[n], what); \ + return -1; \ + } \ + } \ } while(0) /** @brief Validate an absolute path @@ -677,8 +685,8 @@ static int validate_isabspath(const struct config_state *cs, for(n = 0; n < nvec; ++n) if(vec[n][0] != '/') { - error(errno, "%s:%d: %s: not an absolute path", - cs->path, cs->line, vec[n]); + disorder_error(errno, "%s:%d: %s: not an absolute path", + cs->path, cs->line, vec[n]); return -1; } return 0; @@ -718,8 +726,8 @@ static int validate_player(const struct config_state *cs, int nvec, char attribute((unused)) **vec) { if(nvec < 2) { - error(0, "%s:%d: should be at least 'player PATTERN MODULE'", - cs->path, cs->line); + disorder_error(0, "%s:%d: should be at least 'player PATTERN MODULE'", + cs->path, cs->line); return -1; } return 0; @@ -735,8 +743,8 @@ static int validate_tracklength(const struct config_state *cs, int nvec, char attribute((unused)) **vec) { if(nvec < 2) { - error(0, "%s:%d: should be at least 'tracklength PATTERN MODULE'", - cs->path, cs->line); + disorder_error(0, "%s:%d: should be at least 'tracklength PATTERN MODULE'", + cs->path, cs->line); return -1; } return 0; @@ -754,7 +762,7 @@ static int validate_allow(const struct config_state *cs, int nvec, char attribute((unused)) **vec) { if(nvec != 2) { - error(0, "%s:%d: must be 'allow NAME PASS'", cs->path, cs->line); + disorder_error(0, "%s:%d: must be 'allow NAME PASS'", cs->path, cs->line); return -1; } return 0; @@ -771,19 +779,19 @@ static int validate_non_negative(const struct config_state *cs, long n; if(nvec < 1) { - error(0, "%s:%d: missing argument", cs->path, cs->line); + disorder_error(0, "%s:%d: missing argument", cs->path, cs->line); return -1; } if(nvec > 1) { - error(0, "%s:%d: too many arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: too many arguments", cs->path, cs->line); return -1; } if(xstrtol(&n, vec[0], 0, 0)) { - error(0, "%s:%d: %s", cs->path, cs->line, strerror(errno)); + disorder_error(0, "%s:%d: %s", cs->path, cs->line, strerror(errno)); return -1; } if(n < 0) { - error(0, "%s:%d: must not be negative", cs->path, cs->line); + disorder_error(0, "%s:%d: must not be negative", cs->path, cs->line); return -1; } return 0; @@ -800,19 +808,19 @@ static int validate_positive(const struct config_state *cs, long n; if(nvec < 1) { - error(0, "%s:%d: missing argument", cs->path, cs->line); + disorder_error(0, "%s:%d: missing argument", cs->path, cs->line); return -1; } if(nvec > 1) { - error(0, "%s:%d: too many arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: too many arguments", cs->path, cs->line); return -1; } if(xstrtol(&n, vec[0], 0, 0)) { - error(0, "%s:%d: %s", cs->path, cs->line, strerror(errno)); + disorder_error(0, "%s:%d: %s", cs->path, cs->line, strerror(errno)); return -1; } if(n <= 0) { - error(0, "%s:%d: must be positive", cs->path, cs->line); + disorder_error(0, "%s:%d: must be positive", cs->path, cs->line); return -1; } return 0; @@ -830,7 +838,7 @@ static int validate_isauser(const struct config_state *cs, struct passwd *pw; if(!(pw = getpwnam(vec[0]))) { - error(0, "%s:%d: no such user as '%s'", cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: no such user as '%s'", cs->path, cs->line, vec[0]); return -1; } return 0; @@ -880,7 +888,7 @@ static int validate_url(const struct config_state attribute((unused)) *cs, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789")); if(s[n] != ':') { - error(0, "%s:%d: invalid url '%s'", cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: invalid url '%s'", cs->path, cs->line, vec[0]); return -1; } if(!strncmp(s, "http:", 5) @@ -888,7 +896,7 @@ static int validate_url(const struct config_state attribute((unused)) *cs, s += n + 1; /* we only do a rather cursory check */ if(strncmp(s, "//", 2)) { - error(0, "%s:%d: invalid url '%s'", cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: invalid url '%s'", cs->path, cs->line, vec[0]); return -1; } } @@ -908,11 +916,11 @@ static int validate_alias(const struct config_state *cs, int in_brackets = 0, c; if(nvec < 1) { - error(0, "%s:%d: missing argument", cs->path, cs->line); + disorder_error(0, "%s:%d: missing argument", cs->path, cs->line); return -1; } if(nvec > 1) { - error(0, "%s:%d: too many arguments", cs->path, cs->line); + disorder_error(0, "%s:%d: too many arguments", cs->path, cs->line); return -1; } s = vec[0]; @@ -921,8 +929,8 @@ static int validate_alias(const struct config_state *cs, if(c == '}') in_brackets = 0; else if(!isalnum(c)) { - error(0, "%s:%d: invalid part name in alias expansion in '%s'", - cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: invalid part name in alias expansion in '%s'", + cs->path, cs->line, vec[0]); return -1; } } else { @@ -932,12 +940,12 @@ static int validate_alias(const struct config_state *cs, ++s; } else if(c == '\\') { if(!(c = (unsigned char)*s++)) { - error(0, "%s:%d: unterminated escape in alias expansion in '%s'", - cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: unterminated escape in alias expansion in '%s'", + cs->path, cs->line, vec[0]); return -1; } else if(c != '\\' && c != '{') { - error(0, "%s:%d: invalid escape in alias expansion in '%s'", - cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: invalid escape in alias expansion in '%s'", + cs->path, cs->line, vec[0]); return -1; } } @@ -945,8 +953,9 @@ static int validate_alias(const struct config_state *cs, ++s; } if(in_brackets) { - error(0, "%s:%d: unterminated part name in alias expansion in '%s'", - cs->path, cs->line, vec[0]); + disorder_error(0, + "%s:%d: unterminated part name in alias expansion in '%s'", + cs->path, cs->line, vec[0]); return -1; } return 0; @@ -962,11 +971,11 @@ static int validate_algo(const struct config_state attribute((unused)) *cs, int nvec, char **vec) { if(nvec != 1) { - error(0, "%s:%d: invalid algorithm specification", cs->path, cs->line); + disorder_error(0, "%s:%d: invalid algorithm specification", cs->path, cs->line); return -1; } if(!valid_authhash(vec[0])) { - error(0, "%s:%d: unsuported algorithm '%s'", cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: unsuported algorithm '%s'", cs->path, cs->line, vec[0]); return -1; } return 0; @@ -983,18 +992,18 @@ static int validate_backend(const struct config_state attribute((unused)) *cs, char **vec) { int n; if(nvec != 1) { - error(0, "%s:%d: invalid sound API specification", cs->path, cs->line); + disorder_error(0, "%s:%d: invalid sound API specification", cs->path, cs->line); return -1; } if(!strcmp(vec[0], "network")) { - error(0, "'api network' is deprecated; use 'api rtp'"); + disorder_error(0, "'api network' is deprecated; use 'api rtp'"); return 0; } if(config_uaudio_apis) { for(n = 0; config_uaudio_apis[n]; ++n) if(!strcmp(vec[0], config_uaudio_apis[n]->name)) return 0; - error(0, "%s:%d: unrecognized sound API '%s'", cs->path, cs->line, vec[0]); + disorder_error(0, "%s:%d: unrecognized sound API '%s'", cs->path, cs->line, vec[0]); return -1; } /* In non-server processes we have no idea what's valid */ @@ -1012,7 +1021,7 @@ static int validate_pausemode(const struct config_state attribute((unused)) *cs, char **vec) { if(nvec == 1 && (!strcmp(vec[0], "silence") || !strcmp(vec[0], "suspend"))) return 0; - error(0, "%s:%d: invalid pause mode", cs->path, cs->line); + disorder_error(0, "%s:%d: invalid pause mode", cs->path, cs->line); return -1; } @@ -1031,11 +1040,11 @@ static int validate_destaddr(const struct config_state attribute((unused)) *cs, struct netaddress na[1]; if(netaddress_parse(na, nvec, vec)) { - error(0, "%s:%d: invalid network address", cs->path, cs->line); + disorder_error(0, "%s:%d: invalid network address", cs->path, cs->line); return -1; } if(!na->address) { - error(0, "%s:%d: destination address required", cs->path, cs->line); + disorder_error(0, "%s:%d: destination address required", cs->path, cs->line); return -1; } return 0; @@ -1138,7 +1147,7 @@ static int config_set(const struct config_state *cs, D(("config_set %s", vec[0])); if(!(which = find(vec[0]))) { - error(0, "%s:%d: unknown configuration key '%s'", + disorder_error(0, "%s:%d: unknown configuration key '%s'", cs->path, cs->line, vec[0]); return -1; } @@ -1175,7 +1184,7 @@ static int config_set_args(const struct config_state *cs, static void config_error(const char *msg, void *u) { const struct config_state *cs = u; - error(0, "%s:%d: %s", cs->path, cs->line, msg); + disorder_error(0, "%s:%d: %s", cs->path, cs->line, msg); } /** @brief Include a file by name @@ -1194,13 +1203,13 @@ static int config_include(struct config *c, const char *path) { cs.config = c; D(("%s: reading configuration", path)); if(!(fp = fopen(path, "r"))) { - error(errno, "error opening %s", path); + disorder_error(errno, "error opening %s", path); return -1; } while(!inputline(path, fp, &inputbuffer, '\n')) { ++cs.line; if(!(buffer = mb2utf8(inputbuffer))) { - error(errno, "%s:%d: cannot convert to UTF-8", cs.path, cs.line); + disorder_error(errno, "%s:%d: cannot convert to UTF-8", cs.path, cs.line); ret = -1; xfree(inputbuffer); continue; @@ -1216,7 +1225,7 @@ static int config_include(struct config *c, const char *path) { /* 'include' is special-cased */ if(!strcmp(vec[0], "include")) { if(n != 2) { - error(0, "%s:%d: must be 'include PATH'", cs.path, cs.line); + disorder_error(0, "%s:%d: must be 'include PATH'", cs.path, cs.line); ret = -1; } else config_include(c, vec[1]); @@ -1228,7 +1237,7 @@ static int config_include(struct config *c, const char *path) { xfree(buffer); } if(ferror(fp)) { - error(errno, "error reading %s", path); + disorder_error(errno, "error reading %s", path); ret = -1; } fclose(fp); @@ -1324,7 +1333,7 @@ static struct config *config_default(void) { c->history = 60; c->home = xstrdup(pkgstatedir); if(!(pw = getpwuid(getuid()))) - fatal(0, "cannot determine our username"); + disorder_fatal(0, "cannot determine our username"); logname = pw->pw_name; c->username = xstrdup(logname); c->refresh = 15; @@ -1477,9 +1486,9 @@ static void config_postdefaults(struct config *c, c->api = xstrdup("rtp"); if(server) { if(!strcmp(c->api, "command") && !c->speaker_command) - fatal(0, "'api command' but speaker_command is not set"); + disorder_fatal(0, "'api command' but speaker_command is not set"); if((!strcmp(c->api, "rtp")) && c->broadcast.af == -1) - fatal(0, "'api rtp' but broadcast is not set"); + disorder_fatal(0, "'api rtp' but broadcast is not set"); } /* Override sample format */ if(!strcmp(c->api, "rtp")) { @@ -1544,7 +1553,7 @@ int config_read(int server, /* if there's a per-user system config file for this user, read it */ if(config_per_user) { if(!(pw = getpwuid(getuid()))) - fatal(0, "cannot determine our username"); + disorder_fatal(0, "cannot determine our username"); if((privconf = config_usersysconf(pw)) && access(privconf, F_OK) == 0 && config_include(c, privconf)) @@ -1562,35 +1571,35 @@ int config_read(int server, if(oldconfig) { int failed = 0; if(strcmp(c->home, oldconfig->home)) { - error(0, "'home' cannot be changed without a restart"); + disorder_error(0, "'home' cannot be changed without a restart"); failed = 1; } if(strcmp(c->alias, oldconfig->alias)) { - error(0, "'alias' cannot be changed without a restart"); + disorder_error(0, "'alias' cannot be changed without a restart"); failed = 1; } if(strcmp(c->user, oldconfig->user)) { - error(0, "'user' cannot be changed without a restart"); + disorder_error(0, "'user' cannot be changed without a restart"); failed = 1; } if(c->nice_speaker != oldconfig->nice_speaker) { - error(0, "'nice_speaker' cannot be changed without a restart"); + disorder_error(0, "'nice_speaker' cannot be changed without a restart"); /* ...but we accept the new config anyway */ } if(c->nice_server != oldconfig->nice_server) { - error(0, "'nice_server' cannot be changed without a restart"); + disorder_error(0, "'nice_server' cannot be changed without a restart"); /* ...but we accept the new config anyway */ } if(namepartlist_compare(&c->namepart, &oldconfig->namepart)) { - error(0, "'namepart' settings cannot be changed without a restart"); + disorder_error(0, "'namepart' settings cannot be changed without a restart"); failed = 1; } if(stringlist_compare(&c->stopword, &oldconfig->stopword)) { - error(0, "'stopword' settings cannot be changed without a restart"); + disorder_error(0, "'stopword' settings cannot be changed without a restart"); failed = 1; } if(failed) { - error(0, "not installing incompatible new configuration"); + disorder_error(0, "not installing incompatible new configuration"); return -1; } } @@ -1598,17 +1607,17 @@ int config_read(int server, config_free(config); /* warn about obsolete directives */ if(c->restrictions) - error(0, "'restrict' will be removed in a future version"); + disorder_error(0, "'restrict' will be removed in a future version"); if(c->allow.n) - error(0, "'allow' will be removed in a future version"); + disorder_error(0, "'allow' will be removed in a future version"); if(c->trust.n) - error(0, "'trust' will be removed in a future version"); + disorder_error(0, "'trust' will be removed in a future version"); if(!c->lock) - error(0, "'lock' will be removed in a future version"); + disorder_error(0, "'lock' will be removed in a future version"); if(c->gap) - error(0, "'gap' will be removed in a future version"); + disorder_error(0, "'gap' will be removed in a future version"); if(c->prefsync) - error(0, "'prefsync' will be removed in a future version"); + disorder_error(0, "'prefsync' will be removed in a future version"); config = c; return 0; } @@ -1627,7 +1636,7 @@ char *config_userconf(const char *home, const struct passwd *pw) { char *s; if(!home && !pw && !(pw = getpwuid(getuid()))) - fatal(0, "cannot determine our username"); + disorder_fatal(0, "cannot determine our username"); byte_xasprintf(&s, "%s/.disorder/passwd", home ? home : pw->pw_dir); return s; } diff --git a/lib/cookies.c b/lib/cookies.c index e32fc0c..0efe8d0 100644 --- a/lib/cookies.c +++ b/lib/cookies.c @@ -99,11 +99,11 @@ static char *sign(const uint8_t *key, char *sig64; if((e = gcry_md_open(&h, ALGO, GCRY_MD_FLAG_HMAC))) { - error(0, "gcry_md_open: %s", gcry_strerror(e)); + disorder_error(0, "gcry_md_open: %s", gcry_strerror(e)); return 0; } if((e = gcry_md_setkey(h, key, HASHSIZE))) { - error(0, "gcry_md_setkey: %s", gcry_strerror(e)); + disorder_error(0, "gcry_md_setkey: %s", gcry_strerror(e)); gcry_md_close(h); return 0; } @@ -125,13 +125,13 @@ char *make_cookie(const char *user) { /* dollar signs aren't allowed in usernames */ if(strchr(user, '$')) { - error(0, "make_cookie for username with dollar sign"); + disorder_error(0, "make_cookie for username with dollar sign"); return 0; } /* look up the password */ password = trackdb_get_password(user); if(!password) { - error(0, "make_cookie for nonexistent user"); + disorder_error(0, "make_cookie for nonexistent user"); return 0; } /* make sure we have a valid signing key */ @@ -165,24 +165,24 @@ char *verify_cookie(const char *cookie, rights_type *rights) { /* check the revocation list */ if(revoked && hash_find(revoked, cookie)) { - error(0, "attempt to log in with revoked cookie"); + disorder_error(0, "attempt to log in with revoked cookie"); return 0; } /* parse the cookie */ errno = 0; t = strtoimax(cookie, &c1, 16); if(errno) { - error(errno, "error parsing cookie timestamp"); + disorder_error(errno, "error parsing cookie timestamp"); return 0; } if(*c1 != '$') { - error(0, "invalid cookie timestamp"); + disorder_error(0, "invalid cookie timestamp"); return 0; } /* There'd better be two dollar signs */ c2 = strchr(c1 + 1, '$'); if(c2 == 0) { - error(0, "invalid cookie syntax"); + disorder_error(0, "invalid cookie syntax"); return 0; } /* Extract the username */ @@ -190,13 +190,13 @@ char *verify_cookie(const char *cookie, rights_type *rights) { /* check expiry */ xtime(&now); if(now >= t) { - error(0, "cookie has expired"); + disorder_error(0, "cookie has expired"); return 0; } /* look up the password */ k = trackdb_getuserinfo(user); if(!k) { - error(0, "verify_cookie for nonexistent user"); + disorder_error(0, "verify_cookie for nonexistent user"); return 0; } password = kvp_get(k, "password"); @@ -218,7 +218,7 @@ char *verify_cookie(const char *cookie, rights_type *rights) { if(!strcmp(sig, c2 + 1)) return user; /* that didn't match either */ - error(0, "cookie signature does not match"); + disorder_error(0, "cookie signature does not match"); return 0; } diff --git a/lib/coreaudio.c b/lib/coreaudio.c index 8540faa..aafab86 100644 --- a/lib/coreaudio.c +++ b/lib/coreaudio.c @@ -96,7 +96,7 @@ static int coreaudio_find_device(AudioObjectPropertySelector selector, '?', FALSE, output, sizeof output, &used); output[used] = 0; - info("device %u %s: %s", n, description, (char *)output); + disorder_info("device %u %s: %s", n, description, (char *)output); #endif if(CFStringCompare(dev, name, kCFCompareCaseInsensitive|kCFCompareNonliteral) diff --git a/lib/dateparse.c b/lib/dateparse.c index be96e8f..a620f81 100644 --- a/lib/dateparse.c +++ b/lib/dateparse.c @@ -62,11 +62,11 @@ time_t dateparse(const char *s) { case 0: return mktime(&t); case 7: - fatal(0, "date string '%s' not in a recognized format", s); + disorder_fatal(0, "date string '%s' not in a recognized format", s); case 8: - fatal(0, "date string '%s' not representable", s); + disorder_fatal(0, "date string '%s' not representable", s); default: - fatal(0, "date string '%s' produced unexpected error %d", s, rc); + disorder_fatal(0, "date string '%s' produced unexpected error %d", s, rc); } } diff --git a/lib/eclient.c b/lib/eclient.c index ba743ec..5eda674 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -741,7 +741,7 @@ static void process_line(disorder_eclient *c, char *line) { && line[1] >= '0' && line[1] <= '9' && line[2] >= '0' && line[2] <= '9' && line[3] == ' ')) - fatal(0, "invalid response from server: %s", line); + disorder_fatal(0, "invalid response from server: %s", line); c->rc = (line[0] * 10 + line[1]) * 10 + line[2] - 111 * '0'; c->line = line; switch(c->rc % 10) { diff --git a/lib/event.c b/lib/event.c index b63d0f6..64f1bdb 100644 --- a/lib/event.c +++ b/lib/event.c @@ -243,7 +243,7 @@ int ev_run(ev_source *ev) { } while(n < 0 && errno == EINTR); xsigprocmask(SIG_BLOCK, &ev->sigmask, 0); if(n < 0) { - error(errno, "error calling select"); + disorder_error(errno, "error calling select"); if(errno == EBADF) { /* If there's a bad FD in the mix then check them all and log what we * find, to ease debugging */ @@ -253,13 +253,13 @@ int ev_run(ev_source *ev) { if(FD_ISSET(fd, &ev->mode[mode].enabled) && fstat(fd, &sb) < 0) - error(errno, "mode %s fstat %d (%s)", - modenames[mode], fd, ev->mode[mode].fds[n].what); + disorder_error(errno, "mode %s fstat %d (%s)", + modenames[mode], fd, ev->mode[mode].fds[n].what); } for(n = 0; n <= maxfd; ++n) if(FD_ISSET(n, &ev->mode[mode].enabled) && fstat(n, &sb) < 0) - error(errno, "mode %s fstat %d", modenames[mode], n); + disorder_error(errno, "mode %s fstat %d", modenames[mode], n); } } return -1; @@ -539,7 +539,7 @@ static int signal_read(ev_source *ev, return ret; assert(n != 0); if(n < 0 && (errno != EINTR && errno != EAGAIN)) { - error(errno, "error reading from signal pipe %d", ev->sigpipe[0]); + disorder_error(errno, "error reading from signal pipe %d", ev->sigpipe[0]); return -1; } return 0; @@ -680,8 +680,8 @@ static int sigchld_callback(ev_source *ev, * want the disorder server to bomb out because of it. So we just log * the problem and ignore it. */ - error(errno, "error calling wait4 for PID %lu (broken ptrace?)", - (unsigned long)ev->children[n].pid); + disorder_error(errno, "error calling wait4 for PID %lu (broken ptrace?)", + (unsigned long)ev->children[n].pid); if(errno != ECHILD) return -1; } @@ -764,8 +764,8 @@ void ev_child_killall(ev_source *ev) { for(n = 0; n < ev->nchildren; ++n) { if(kill(ev->children[n].pid, SIGTERM) < 0) { - error(errno, "sending SIGTERM to pid %lu", - (unsigned long)ev->children[n].pid); + disorder_error(errno, "sending SIGTERM to pid %lu", + (unsigned long)ev->children[n].pid); ev->children[n].pid = -1; } } @@ -776,7 +776,8 @@ void ev_child_killall(ev_source *ev) { rc = waitpid(ev->children[n].pid, &w, 0); } while(rc < 0 && errno == EINTR); if(rc < 0) { - error(errno, "waiting for pid %lu", (unsigned long)ev->children[n].pid); + disorder_error(errno, "waiting for pid %lu", + (unsigned long)ev->children[n].pid); continue; } } @@ -818,22 +819,22 @@ static int listen_callback(ev_source *ev, int fd, void *u) { break; #ifdef ECONNABORTED case ECONNABORTED: - error(errno, "error calling accept"); + disorder_error(errno, "error calling accept"); break; #endif #ifdef EPROTO case EPROTO: /* XXX on some systems EPROTO should be fatal, but we don't know if * we're running on one of them */ - error(errno, "error calling accept"); + disorder_error(errno, "error calling accept"); break; #endif default: - fatal(errno, "error calling accept"); + disorder_fatal(errno, "error calling accept"); break; } if(errno != EINTR && errno != EAGAIN) - error(errno, "error calling accept"); + disorder_error(errno, "error calling accept"); return 0; } @@ -1017,8 +1018,8 @@ static int writer_timebound_exceeded(ev_source *ev, if(!w->abandoned) { w->abandoned = 1; - error(0, "abandoning writer '%s' because no writes within %ds", - w->what, w->timebound); + disorder_error(0, "abandoning writer '%s' because no writes within %ds", + w->what, w->timebound); w->error = ETIMEDOUT; } return writer_shutdown(ev, now, u); @@ -1090,15 +1091,15 @@ static int ev_writer_write(struct sink *sk, const void *s, int n) { if(!n) return 0; /* avoid silliness */ if(w->fd == -1) - error(0, "ev_writer_write on %s after shutdown", w->what); + disorder_error(0, "ev_writer_write on %s after shutdown", w->what); if(w->spacebound && w->b.end - w->b.start + n > w->spacebound) { /* The new buffer contents will exceed the space bound. We assume that the * remote client has gone away and TCP hasn't noticed yet, or that it's got * hopelessly stuck. */ if(!w->abandoned) { w->abandoned = 1; - error(0, "abandoning writer '%s' because buffer has reached %td bytes", - w->what, w->b.end - w->b.start); + disorder_error(0, "abandoning writer '%s' because buffer has reached %td bytes", + w->what, w->b.end - w->b.start); ev_fd_disable(w->ev, ev_write, w->fd); w->error = EPIPE; return ev_timeout(w->ev, 0, 0, writer_shutdown, w); @@ -1207,7 +1208,7 @@ int ev_writer_space_bound(ev_writer *w, */ struct sink *ev_writer_sink(ev_writer *w) { if(!w) - fatal(0, "ev_write_sink called with null writer"); + disorder_fatal(0, "ev_write_sink called with null writer"); return &w->s; } diff --git a/lib/hex.c b/lib/hex.c index 4ae9d67..efd14b1 100644 --- a/lib/hex.c +++ b/lib/hex.c @@ -75,7 +75,8 @@ int unhexdigitq(int c) { int unhexdigit(int c) { int d; - if((d = unhexdigitq(c)) < 0) error(0, "invalid hex digit"); + if((d = unhexdigitq(c)) < 0) + disorder_error(0, "invalid hex digit"); return d; } @@ -96,7 +97,7 @@ uint8_t *unhex(const char *s, size_t *np) { int d1, d2; if((l = strlen(s)) & 1) { - error(0, "hex string has odd length"); + disorder_error(0, "hex string has odd length"); return 0; } p = buf = xmalloc_noptr(l / 2); diff --git a/lib/hostname.c b/lib/hostname.c index 292b3ad..b7318e1 100644 --- a/lib/hostname.c +++ b/lib/hostname.c @@ -40,9 +40,9 @@ const char *local_hostname(void) { struct hostent *he; if(uname(&u) < 0) - fatal(errno, "error calling uname"); + disorder_fatal(errno, "error calling uname"); if(!(he = gethostbyname(u.nodename))) - fatal(0, "cannot resolve '%s'", u.nodename); + disorder_fatal(0, "cannot resolve '%s'", u.nodename); hostname = xstrdup(he->h_name); } return hostname; diff --git a/lib/ifreq.c b/lib/ifreq.c index 46326ad..370546d 100644 --- a/lib/ifreq.c +++ b/lib/ifreq.c @@ -44,7 +44,7 @@ int sockaddr_equal(const struct sockaddr *a, const struct sockaddr *b) { &((const struct sockaddr_in6 *)b)->sin6_addr, sizeof (struct in6_addr)); default: - fatal(0, "unknown address family %d", a->sa_family); + disorder_fatal(0, "unknown address family %d", a->sa_family); } } diff --git a/lib/inputline.c b/lib/inputline.c index 5894546..b9a7df8 100644 --- a/lib/inputline.c +++ b/lib/inputline.c @@ -60,11 +60,11 @@ int inputline(const char *tag, FILE *fp, char **lp, int newline) { } } if(ferror(fp)) { - error(errno, "error reading %s", tag); + disorder_error(errno, "error reading %s", tag); return -1; } else if(feof(fp)) { if(d.nvec != 0) - error(0, "error reading %s: unexpected EOF", tag); + disorder_error(0, "error reading %s: unexpected EOF", tag); return -1; } dynstr_terminate(&d); diff --git a/lib/log.c b/lib/log.c index 00ec7cd..82ba377 100644 --- a/lib/log.c +++ b/lib/log.c @@ -17,17 +17,18 @@ */ /** @file lib/log.c @brief Errors and logging * - * All messages are initially emitted by one of the four functions below. - * debug() is generally invoked via D() so that mostly you just do a test - * rather than a complete subroutine call. + * All messages are initially emitted by one of the four functions + * below. disorder_debug() is generally invoked via D() so that + * mostly you just do a test rather than a complete subroutine call. * * Messages are dispatched via @ref log_default. This defaults to @ref * log_stderr. daemonize() will turn off @ref log_stderr and use @ref * log_syslog instead. * - * fatal() will call exitfn() with a nonzero status. The default value is - * exit(), but it should be set to _exit() anywhere but the 'main line' of the - * program, to guarantee that exit() gets called at most once. + * disorder_fatal() will call exitfn() with a nonzero status. The + * default value is exit(), but it should be set to _exit() anywhere + * but the 'main line' of the program, to guarantee that exit() gets + * called at most once. */ #define NO_MEMORY_ALLOCATION diff --git a/lib/log.h b/lib/log.h index ecabd30..f1f55d2 100644 --- a/lib/log.h +++ b/lib/log.h @@ -41,18 +41,6 @@ void disorder_debug(const char *msg, ...) /* report a message of the given class. @errno_value@ if present an * non-zero is included. @fatal@ terminates the process. */ -/** @brief Backward-compatibility alias for disorder_fatal() */ -#define fatal disorder_fatal - -/** @brief Backward-compatibility alias for disorder_error() */ -#define error disorder_error - -/** @brief Backward-compatibility alias for disorder_info() */ -#define info disorder_info - -/** @brief Backward-compatibility alias for disorder_debug() */ -#define debug disorder_debug - extern int debugging; /* set when debugging enabled */ @@ -78,7 +66,7 @@ extern int logdate; if(debugging) { \ debug_filename=__FILE__; \ debug_lineno=__LINE__; \ - debug x; \ + disorder_debug x; \ } \ } while(0) diff --git a/lib/logfd.c b/lib/logfd.c index 015321a..7175108 100644 --- a/lib/logfd.c +++ b/lib/logfd.c @@ -43,12 +43,12 @@ static int logfd_readable(ev_source attribute((unused)) *ev, while((nl = memchr(ptr, '\n', bytes))) { len = nl - (char *)ptr; ev_reader_consume(reader, len + 1); - info("%s: %.*s", tag, len, (char *)ptr); + disorder_info("%s: %.*s", tag, len, (char *)ptr); ptr = nl + 1; bytes -= len + 1; } if(eof && bytes) { - info("%s: %.*s", tag, (int)bytes, (char *)ptr); + disorder_info("%s: %.*s", tag, (int)bytes, (char *)ptr); ev_reader_consume(reader, bytes); } return 0; @@ -60,7 +60,7 @@ static int logfd_error(ev_source attribute((unused)) *ev, void *u) { const char *tag = u; - error(errno_value, "error reading log pipe from %s", tag); + disorder_error(errno_value, "error reading log pipe from %s", tag); return 0; } @@ -74,7 +74,7 @@ static int logfd_error(ev_source attribute((unused)) *ev, * it in the parent). * * Any lines written to this fd (i.e. by the subprocess) will be logged via - * info(), with @p tag included. + * disorder_info(), with @p tag included. */ int logfd(ev_source *ev, const char *tag) { int p[2]; @@ -84,7 +84,7 @@ int logfd(ev_source *ev, const char *tag) { nonblock(p[0]); if(!ev_reader_new(ev, p[0], logfd_readable, logfd_error, (void *)tag, "logfd")) - fatal(errno, "error calling ev_reader_new"); + disorder_fatal(errno, "error calling ev_reader_new"); return p[1]; } diff --git a/lib/macros-builtin.c b/lib/macros-builtin.c index f314bd9..0c80232 100644 --- a/lib/macros-builtin.c +++ b/lib/macros-builtin.c @@ -79,7 +79,7 @@ char *mx_find(const char *name, int report) { if(name[0] == '/') { if(access(name, O_RDONLY) < 0) { if(report) - error(errno, "cannot read %s", name); + disorder_error(errno, "cannot read %s", name); return 0; } path = xstrdup(name); @@ -92,7 +92,7 @@ char *mx_find(const char *name, int report) { } if(n >= include_path.nvec) { if(report) - error(0, "cannot find '%s' in search path", name); + disorder_error(0, "cannot find '%s' in search path", name); return 0; } } @@ -137,11 +137,11 @@ static int exp_include(int attribute((unused)) nargs, /* Read the raw file. As with mx_expand_file() we insist that the file is a * regular file. */ if((fd = open(path, O_RDONLY)) < 0) - fatal(errno, "error opening %s", path); + disorder_fatal(errno, "error opening %s", path); if(fstat(fd, &sb) < 0) - fatal(errno, "error statting %s", path); + disorder_fatal(errno, "error statting %s", path); if(!S_ISREG(sb.st_mode)) - fatal(0, "%s: not a regular file", path); + disorder_fatal(0, "%s: not a regular file", path); while((n = read(fd, buffer, sizeof buffer)) > 0) { if(sink_write(output, buffer, n) < 0) { xclose(fd); @@ -149,7 +149,7 @@ static int exp_include(int attribute((unused)) nargs, } } if(n < 0) - fatal(errno, "error reading %s", path); + disorder_fatal(errno, "error reading %s", path); xclose(fd); return 0; } @@ -180,7 +180,7 @@ static int exp_shell(int attribute((unused)) nargs, xdup2(p[1], 1); xclose(p[1]); execlp("sh", "sh", "-c", args[0], (char *)0); - fatal(errno, "error executing sh"); + disorder_fatal(errno, "error executing sh"); } xclose(p[1]); while((n = read(p[0], buffer, sizeof buffer))) { @@ -188,7 +188,7 @@ static int exp_shell(int attribute((unused)) nargs, if(errno == EINTR) continue; else - fatal(errno, "error reading from pipe"); + disorder_fatal(errno, "error reading from pipe"); } if(output->write(output, buffer, n) < 0) return -1; @@ -197,9 +197,9 @@ static int exp_shell(int attribute((unused)) nargs, while((n = waitpid(pid, &w, 0)) < 0 && errno == EINTR) ; if(n < 0) - fatal(errno, "error calling waitpid"); + disorder_fatal(errno, "error calling waitpid"); if(w) - error(0, "shell command '%s' %s", args[0], wstat(w)); + disorder_error(0, "shell command '%s' %s", args[0], wstat(w)); return 0; } diff --git a/lib/macros.c b/lib/macros.c index d194ef5..e11c264 100644 --- a/lib/macros.c +++ b/lib/macros.c @@ -197,11 +197,11 @@ const struct mx_node *mx_parse(const char *filename, * and the name. */ dynstr_init(d); if(input == end) - fatal(0, "%s:%d: invalid expansion syntax (truncated)", - filename, e->line); + disorder_fatal(0, "%s:%d: invalid expansion syntax (truncated)", + filename, e->line); if(!isalnum((unsigned char)*input)) - fatal(0, "%s:%d: invalid expansion syntax (unexpected %#x)", - filename, e->line, (unsigned char)*input); + disorder_fatal(0, "%s:%d: invalid expansion syntax (unexpected %#x)", + filename, e->line, (unsigned char)*input); while(input < end && (isalnum((unsigned char)*input) || *input == '-')) dynstr_append(d, *input++); dynstr_terminate(d); @@ -240,9 +240,9 @@ const struct mx_node *mx_parse(const char *filename, } if(input >= end) { /* We ran out of input without encountering a balanced cbracket */ - fatal(0, "%s:%d: unterminated expansion argument '%.*s'", - filename, argument_start_line, - (int)(input - argument_start), argument_start); + disorder_fatal(0, "%s:%d: unterminated expansion argument '%.*s'", + filename, argument_start_line, + (int)(input - argument_start), argument_start); } /* Consistency check */ assert(*input == cbracket); @@ -390,8 +390,8 @@ int mx_register_macro(const char *name, /* This locates the error to the definition, which may be a line or two * beyond the @define command itself. The backtrace generated by * mx_expand() may help more. */ - error(0, "%s:%d: duplicate definition of '%s'", - definition->filename, definition->line, name); + disorder_error(0, "%s:%d: duplicate definition of '%s'", + definition->filename, definition->line, name); #endif return -2; } @@ -432,17 +432,17 @@ int mx_expand(const struct mx_node *m, case MX_EXPANSION: rc = 0; if(!(e = hash_find(expansions, m->name))) { - error(0, "%s:%d: unknown expansion name '%s'", - m->filename, m->line, m->name); + disorder_error(0, "%s:%d: unknown expansion name '%s'", + m->filename, m->line, m->name); if(sink_printf(output, "[['%s' unknown]]", m->name) < 0) return -1; } else if(m->nargs < e->min) { - error(0, "%s:%d: expansion '%s' requires %d args, only %d given", - m->filename, m->line, m->name, e->min, m->nargs); + disorder_error(0, "%s:%d: expansion '%s' requires %d args, only %d given", + m->filename, m->line, m->name, e->min, m->nargs); if(sink_printf(output, "[['%s' too few args]]", m->name) < 0) return -1; } else if(m->nargs > e->max) { - error(0, "%s:%d: expansion '%s' takes at most %d args, but %d given", + disorder_error(0, "%s:%d: expansion '%s' takes at most %d args, but %d given", m->filename, m->line, m->name, e->max, m->nargs); if(sink_printf(output, "[['%s' too many args]]", m->name) < 0) return -1; @@ -488,8 +488,8 @@ int mx_expand(const struct mx_node *m, if(rc) { /* For non-IO errors we generate some backtrace */ if(rc != -1) - error(0, " ...in @%s at %s:%d", - m->name, m->filename, m->line); + disorder_error(0, " ...in @%s at %s:%d", + m->name, m->filename, m->line); return rc; } break; @@ -523,7 +523,7 @@ int mx_expandstr(const struct mx_node *m, } else *sp = 0; if(rc && rc != -1 && what) - error(0, " ...in %s at %s:%d", what, m->filename, m->line); + disorder_error(0, " ...in %s at %s:%d", what, m->filename, m->line); return rc; } @@ -545,11 +545,11 @@ int mx_expand_file(const char *path, const struct mx_node *m; if((fd = open(path, O_RDONLY)) < 0) - fatal(errno, "error opening %s", path); + disorder_fatal(errno, "error opening %s", path); if(fstat(fd, &sb) < 0) - fatal(errno, "error statting %s", path); + disorder_fatal(errno, "error statting %s", path); if(!S_ISREG(sb.st_mode)) - fatal(0, "%s: not a regular file", path); + disorder_fatal(0, "%s: not a regular file", path); sofar = 0; b = xmalloc_noptr(sb.st_size); while(sofar < sb.st_size) { @@ -557,16 +557,16 @@ int mx_expand_file(const char *path, if(n > 0) sofar += n; else if(n == 0) - fatal(0, "unexpected EOF reading %s", path); + disorder_fatal(0, "unexpected EOF reading %s", path); else if(errno != EINTR) - fatal(errno, "error reading %s", path); + disorder_fatal(errno, "error reading %s", path); } xclose(fd); m = mx_parse(path, 1, b, b + sb.st_size); rc = mx_expand(m, output, u); if(rc && rc != -1) /* Mention inclusion in backtrace */ - error(0, " ...in inclusion of file '%s'", path); + disorder_error(0, " ...in inclusion of file '%s'", path); return rc; } diff --git a/lib/mem.c b/lib/mem.c index 89570ab..7f14fd9 100644 --- a/lib/mem.c +++ b/lib/mem.c @@ -88,7 +88,7 @@ void *xmalloc(size_t n) { void *ptr; if(!(ptr = do_malloc(n)) && n) - fatal(errno, "error allocating memory"); + disorder_fatal(errno, "error allocating memory"); return ptr; } @@ -102,7 +102,7 @@ void *xmalloc(size_t n) { */ void *xrealloc(void *ptr, size_t n) { if(!(ptr = do_realloc(ptr, n)) && n) - fatal(errno, "error allocating memory"); + disorder_fatal(errno, "error allocating memory"); return ptr; } @@ -116,7 +116,7 @@ void *xrealloc(void *ptr, size_t n) { */ void *xcalloc(size_t count, size_t size) { if(count > SIZE_MAX / size) - fatal(0, "excessively large calloc"); + disorder_fatal(0, "excessively large calloc"); return xmalloc(count * size); } @@ -132,7 +132,7 @@ void *xmalloc_noptr(size_t n) { void *ptr; if(!(ptr = do_malloc_atomic(n)) && n) - fatal(errno, "error allocating memory"); + disorder_fatal(errno, "error allocating memory"); return ptr; } @@ -146,7 +146,7 @@ void *xmalloc_noptr(size_t n) { */ void *xcalloc_noptr(size_t count, size_t size) { if(count > SIZE_MAX / size) - fatal(0, "excessively large calloc"); + disorder_fatal(0, "excessively large calloc"); return xmalloc_noptr(count * size); } @@ -163,7 +163,7 @@ void *xrealloc_noptr(void *ptr, size_t n) { if(ptr == 0) return xmalloc_noptr(n); if(!(ptr = do_realloc(ptr, n)) && n) - fatal(errno, "error allocating memory"); + disorder_fatal(errno, "error allocating memory"); return ptr; } @@ -177,7 +177,7 @@ char *xstrdup(const char *s) { char *t; if(!(t = do_malloc_atomic(strlen(s) + 1))) - fatal(errno, "error allocating memory"); + disorder_fatal(errno, "error allocating memory"); return strcpy(t, s); } @@ -193,7 +193,7 @@ char *xstrndup(const char *s, size_t n) { char *t; if(!(t = do_malloc_atomic(n + 1))) - fatal(errno, "error allocating memory"); + disorder_fatal(errno, "error allocating memory"); memcpy(t, s, n); t[n] = 0; return t; diff --git a/lib/mem.h b/lib/mem.h index 46412eb..8a8f245 100644 --- a/lib/mem.h +++ b/lib/mem.h @@ -35,7 +35,7 @@ void *xmalloc(size_t); void *xrealloc(void *, size_t); void *xcalloc(size_t count, size_t size); /* As malloc/realloc/calloc, but - * 1) succeed or call fatal + * 1) succeed or call disorder_fatal * 2) always clear (the unused part of) the new allocation * 3) are garbage-collected */ @@ -46,7 +46,7 @@ void *xcalloc_noptr(size_t count, size_t size); char *xstrdup(const char *); char *xstrndup(const char *, size_t); /* As malloc/realloc/strdup, but - * 1) succeed or call fatal + * 1) succeed or call disorder_fatal * 2) are garbage-collected * 3) allocated space must not contain any pointers * diff --git a/lib/mime.c b/lib/mime.c index 6bff61d..9cc54d6 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -328,7 +328,7 @@ const char *mime_parse(const char *s, return mime_qp(s); if(!strcmp(cte, "7bit") || !strcmp(cte, "8bit")) return s; - error(0, "unknown content-transfer-encoding '%s'", cte); + disorder_error(0, "unknown content-transfer-encoding '%s'", cte); return 0; } return s; @@ -376,7 +376,7 @@ int mime_multipart(const char *s, /* We must start with a boundary string */ if(!isboundary(s, boundary, bl)) { - error(0, "mime_multipart: first line is not the boundary string"); + disorder_error(0, "mime_multipart: first line is not the boundary string"); return -1; } /* Keep going until we hit a final boundary */ @@ -385,7 +385,7 @@ int mime_multipart(const char *s, start = s; while(!isboundary(s, boundary, bl)) { if(!(e = strstr(s, "\r\n"))) { - error(0, "mime_multipart: line does not end CRLF"); + disorder_error(0, "mime_multipart: line does not end CRLF"); return -1; } s = e + 2; @@ -566,17 +566,17 @@ int parse_cookie(const char *s, continue; } if(!(s = parsetoken(s, &n, cookie_separator))) { - error(0, "parse_cookie: cannot parse attribute name"); + disorder_error(0, "parse_cookie: cannot parse attribute name"); return -1; - } + } s = skipwhite(s, 0); if(*s++ != '=') { - error(0, "parse_cookie: did not find expected '='"); + disorder_error(0, "parse_cookie: did not find expected '='"); return -1; } s = skipwhite(s, 0); if(!(s = mime_parse_word(s, &v, cookie_value_separator))) { - error(0, "parse_cookie: cannot parse value for '%s'", n); + disorder_error(0, "parse_cookie: cannot parse value for '%s'", n); return -1; } if(n[0] == '$') { @@ -587,14 +587,14 @@ int parse_cookie(const char *s, if(cd->ncookies > 0 && cd->cookies[cd->ncookies-1].path == 0) cd->cookies[cd->ncookies-1].path = v; else { - error(0, "redundant $Path in Cookie: header"); + disorder_error(0, "redundant $Path in Cookie: header"); return -1; } } else if(!strcmp(n, "$Domain")) { if(cd->ncookies > 0 && cd->cookies[cd->ncookies-1].domain == 0) cd->cookies[cd->ncookies-1].domain = v; else { - error(0, "redundant $Domain in Cookie: header"); + disorder_error(0, "redundant $Domain in Cookie: header"); return -1; } } @@ -610,7 +610,7 @@ int parse_cookie(const char *s, } s = skipwhite(s, 0); if(*s && (*s != ',' && *s != ';')) { - error(0, "missing separator in Cookie: header"); + disorder_error(0, "missing separator in Cookie: header"); return -1; } } diff --git a/lib/queue.c b/lib/queue.c index db28687..69a7986 100644 --- a/lib/queue.c +++ b/lib/queue.c @@ -89,9 +89,9 @@ static const char *marshall_long(const struct queue_entry *q, size_t offset) { n = byte_snprintf(buffer, sizeof buffer, "%ld", VALUE(q, offset, long)); if(n < 0) - fatal(errno, "error converting int"); + disorder_fatal(errno, "error converting int"); else if((size_t)n >= sizeof buffer) - fatal(0, "long converted to decimal is too long"); + disorder_fatal(0, "long converted to decimal is too long"); return xstrdup(buffer); } @@ -128,9 +128,9 @@ static const char *marshall_time_t(const struct queue_entry *q, size_t offset) { n = byte_snprintf(buffer, sizeof buffer, "%"PRIdMAX, (intmax_t)VALUE(q, offset, time_t)); if(n < 0) - fatal(errno, "error converting time"); + disorder_fatal(errno, "error converting time"); else if((size_t)n >= sizeof buffer) - fatal(0, "time converted to decimal is too long"); + disorder_fatal(0, "time converted to decimal is too long"); return xstrdup(buffer); } diff --git a/lib/random.c b/lib/random.c index d6be3d9..e9933a2 100644 --- a/lib/random.c +++ b/lib/random.c @@ -47,12 +47,12 @@ static void random__rekey(void) { if(random_fd < 0) { if((random_fd = open("/dev/urandom", O_RDONLY)) < 0) - fatal(errno, "opening /dev/urandom"); + disorder_fatal(errno, "opening /dev/urandom"); } if((n = read(random_fd, key, sizeof key)) < 0) - fatal(errno, "reading from /dev/urandom"); + disorder_fatal(errno, "reading from /dev/urandom"); if((size_t)n < sizeof key) - fatal(0, "reading from /dev/urandom: short read"); + disorder_fatal(0, "reading from /dev/urandom: short read"); arcfour_setkey(random_ctx, key, sizeof key); random_count = 8 * 1024 * 1024; } diff --git a/lib/regsub.c b/lib/regsub.c index cde61cf..1b7cad4 100644 --- a/lib/regsub.c +++ b/lib/regsub.c @@ -143,7 +143,7 @@ const char *regsub(const pcre *re, const char *subject, const char *replace, break; } if(rc <= 0 && rc != PCRE_ERROR_NOMATCH) { - error(0, "pcre_exec returned %d, subject '%s'", rc, subject); + disorder_error(0, "pcre_exec returned %d, subject '%s'", rc, subject); return 0; } if((flags & REGSUB_MUST_MATCH) && matches == 0) diff --git a/lib/rights.c b/lib/rights.c index 05a3342..75a3d8e 100644 --- a/lib/rights.c +++ b/lib/rights.c @@ -85,7 +85,7 @@ int parse_rights(const char *s, rights_type *rp, int report) { if(!*s) { /* You can't have no rights */ if(report) - error(0, "empty rights string"); + disorder_error(0, "empty rights string"); return -1; } while(*s) { @@ -102,7 +102,7 @@ int parse_rights(const char *s, rights_type *rp, int report) { break; if(n >= NRIGHTS) { if(report) - error(0, "unknown user right '%.*s'", (int)l, s); + disorder_error(0, "unknown user right '%.*s'", (int)l, s); return -1; } r |= rights_names[n].bit; diff --git a/lib/sendmail.c b/lib/sendmail.c index a01b9d3..524f68d 100644 --- a/lib/sendmail.c +++ b/lib/sendmail.c @@ -57,20 +57,20 @@ static int getresponse(const char *tag, FILE *in) { && line[2] >= '0' && line[2] <= '9') { const int rc = 10 * (10 * line[0] + line[1]) + line[2] - 111 * '0'; if(rc >= 400 && rc <= 599) - error(0, "%s: %s", tag, line); + disorder_error(0, "%s: %s", tag, line); if(line[3] != '-') { return rc; } /* else go round for further response lines */ } else { - error(0, "%s: malformed response: %s", tag, line); + disorder_error(0, "%s: malformed response: %s", tag, line); return -1; } } if(ferror(in)) - error(errno, "%s: read error", tag); + disorder_error(errno, "%s: read error", tag); else - error(0, "%s: server closed connection", tag); + disorder_error(0, "%s: server closed connection", tag); return -1; } @@ -93,7 +93,7 @@ static int sendcommand(const char *tag, FILE *out, const char *fmt, ...) { rc = fflush(out); if(rc >= 0) return 0; - error(errno, "%s: write error", tag); + disorder_error(errno, "%s: write error", tag); return -1; } @@ -159,7 +159,7 @@ static int sendmailfp(const char *tag, FILE *in, FILE *out, || fprintf(out, "Date: %s\r\n", date) < 0 || fprintf(out, "\r\n") < 0) { write_error: - error(errno, "%s: write error", tag); + disorder_error(errno, "%s: write error", tag); return -1; } for(ptr = body; *ptr; ++ptr) { @@ -237,7 +237,7 @@ int sendmail(const char *sender, xdup2(outpipe[1], 1); execlp(config->sendmail, config->sendmail, "-bs", (char *)0); - fatal(errno, "executing %s", config->sendmail); + disorder_fatal(errno, "executing %s", config->sendmail); } xclose(inpipe[0]); xclose(outpipe[1]); @@ -253,17 +253,17 @@ int sendmail(const char *sender, return -1; fdin = xsocket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if(connect(fdin, ai->ai_addr, ai->ai_addrlen) < 0) { - error(errno, "error connecting to %s", tag); + disorder_error(errno, "error connecting to %s", tag); xclose(fdin); return -1; } if((fdout = dup(fdin)) < 0) - fatal(errno, "error calling dup2"); + disorder_fatal(errno, "error calling dup2"); } if(!(in = fdopen(fdin, "rb"))) - fatal(errno, "error calling fdopen"); + disorder_fatal(errno, "error calling fdopen"); if(!(out = fdopen(fdout, "wb"))) - fatal(errno, "error calling fdopen"); + disorder_fatal(errno, "error calling fdopen"); rc = sendmailfp(tag, in, out, sender, pubsender, recipient, subject, encoding, content_type, body); fclose(in); @@ -274,9 +274,9 @@ int sendmail(const char *sender, while(waitpid(pid, &w, 0) < 0 && errno == EINTR) ; if(w < 0) - fatal(errno, "error calling waitpid"); + disorder_fatal(errno, "error calling waitpid"); if(w) - info("warning: %s -bs: %s", config->sendmail, wstat(w)); + disorder_info("warning: %s -bs: %s", config->sendmail, wstat(w)); /* Not fatal - we determine success/failure from the SMTP conversation. * Some MTAs exit nonzero if you don't QUIT, which is just stupidly * picky. */ @@ -311,7 +311,7 @@ pid_t sendmail_subprocess(const char *sender, _exit(0); } if(pid < 0) - error(errno, "error calling fork"); + disorder_error(errno, "error calling fork"); return pid; } diff --git a/lib/sink.c b/lib/sink.c index 9450fea..7a74640 100644 --- a/lib/sink.c +++ b/lib/sink.c @@ -77,7 +77,7 @@ static int sink_stdio_write(struct sink *s, const void *buffer, int nbytes) { int n = fwrite(buffer, 1, nbytes, S(s)->fp); if(n < nbytes) { if(S(s)->name) - fatal(errno, "error writing to %s", S(s)->name); + disorder_fatal(errno, "error writing to %s", S(s)->name); else return -1; } diff --git a/lib/speaker-protocol.c b/lib/speaker-protocol.c index 487c495..4928091 100644 --- a/lib/speaker-protocol.c +++ b/lib/speaker-protocol.c @@ -40,7 +40,7 @@ void speaker_send(int fd, const struct speaker_message *sm) { ret = write(fd, sm, sizeof *sm); } while(ret < 0 && errno == EINTR); if(ret < 0) - fatal(errno, "write"); + disorder_fatal(errno, "write"); } /** @brief Receive a speaker message @@ -55,7 +55,8 @@ int speaker_recv(int fd, struct speaker_message *sm) { ret = read(fd, sm, sizeof *sm); } while(ret < 0 && errno == EINTR); if(ret < 0) { - if(errno != EAGAIN) fatal(errno, "recvmsg"); + if(errno != EAGAIN) + disorder_fatal(errno, "recvmsg"); return -1; } return ret; diff --git a/lib/syscalls.c b/lib/syscalls.c index b175666..e13922e 100644 --- a/lib/syscalls.c +++ b/lib/syscalls.c @@ -34,20 +34,21 @@ int mustnotbeminus1(const char *what, int ret) { if(ret == -1) - fatal(errno, "error calling %s", what); + disorder_fatal(errno, "error calling %s", what); return ret; } pid_t xfork(void) { pid_t pid; - if((pid = fork()) < 0) fatal(errno, "error calling fork"); + if((pid = fork()) < 0) + disorder_fatal(errno, "error calling fork"); return pid; } void xclose_guts(const char *path, int line, int fd) { if(close(fd) < 0) - fatal(errno, "%s:%d: close %d", path, line, fd); + disorder_fatal(errno, "%s:%d: close %d", path, line, fd); } void xdup2(int fd1, int fd2) { @@ -140,7 +141,8 @@ int xnice(int inc) { * be -1 */ errno = 0; ret = nice(inc); - if(errno) fatal(errno, "error calling nice"); + if(errno) + disorder_fatal(errno, "error calling nice"); return ret; } diff --git a/lib/trackdb-playlists.c b/lib/trackdb-playlists.c index f9f8252..fd33393 100644 --- a/lib/trackdb-playlists.c +++ b/lib/trackdb-playlists.c @@ -160,7 +160,7 @@ int trackdb_playlist_get(const char *name, int e; if(playlist_parse_name(name, 0, 0)) { - error(0, "invalid playlist name '%s'", name); + disorder_error(0, "invalid playlist name '%s'", name); return EINVAL; } WITH_TRANSACTION(trackdb_playlist_get_tid(name, who, @@ -186,7 +186,7 @@ static int trackdb_playlist_get_tid(const char *name, return e; /* Get sharability */ if(!(s = kvp_get(k, "sharing"))) { - error(0, "playlist '%s' has no 'sharing' key", name); + disorder_error(0, "playlist '%s' has no 'sharing' key", name); s = "private"; } /* Check the read is allowed */ @@ -197,12 +197,12 @@ static int trackdb_playlist_get_tid(const char *name, *sharep = xstrdup(s); /* Get track count */ if(!(s = kvp_get(k, "count"))) { - error(0, "playlist '%s' has no 'count' key", name); + disorder_error(0, "playlist '%s' has no 'count' key", name); s = "0"; } ntracks = atoi(s); if(ntracks < 0) { - error(0, "playlist '%s' has negative count", name); + disorder_error(0, "playlist '%s' has negative count", name); ntracks = 0; } /* Return track count */ @@ -216,7 +216,7 @@ static int trackdb_playlist_get_tid(const char *name, for(int n = 0; n < ntracks; ++n) { snprintf(b, sizeof b, "%d", n); if(!(s = kvp_get(k, b))) { - error(0, "playlist '%s' lacks track %d", name, n); + disorder_error(0, "playlist '%s' lacks track %d", name, n); s = "unknown"; } tracks[n] = xstrdup(s); @@ -260,7 +260,7 @@ int trackdb_playlist_set(const char *name, char *owner; if(playlist_parse_name(name, &owner, 0)) { - error(0, "invalid playlist name '%s'", name); + disorder_error(0, "invalid playlist name '%s'", name); return EINVAL; } /* Check valid share types */ @@ -269,13 +269,13 @@ int trackdb_playlist_set(const char *name, /* Playlists with an owner must be public or private */ if(strcmp(share, "public") && strcmp(share, "private")) { - error(0, "playlist '%s' must be public or private", name); + disorder_error(0, "playlist '%s' must be public or private", name); return EINVAL; } } else { /* Playlists with no owner must be shared */ if(strcmp(share, "shared")) { - error(0, "playlist '%s' must be shared", name); + disorder_error(0, "playlist '%s' must be shared", name); return EINVAL; } } @@ -318,7 +318,7 @@ static int trackdb_playlist_set_tid(const char *name, } /* Check that the modification is allowed */ if(!(s = kvp_get(k, "sharing"))) { - error(0, "playlist '%s' has no 'sharing' key", name); + disorder_error(0, "playlist '%s' has no 'sharing' key", name); s = "private"; } if(!playlist_may_write(name, who, s)) @@ -335,7 +335,7 @@ static int trackdb_playlist_set_tid(const char *name, /* Sanity check track count */ if(ntracks < 0 || ntracks > config->playlist_max) { - error(0, "invalid track count %d", ntracks); + disorder_error(0, "invalid track count %d", ntracks); return EINVAL; } /* Set the tracks */ @@ -398,11 +398,11 @@ static int trackdb_playlist_list_tid(const char *who, /* Extract owner; malformed names are skipped */ if(playlist_parse_name(name, &owner, 0)) { - error(0, "invalid playlist name '%s' found in database", name); + disorder_error(0, "invalid playlist name '%s' found in database", name); continue; } if(!share) { - error(0, "playlist '%s' has no 'sharing' key", name); + disorder_error(0, "playlist '%s' has no 'sharing' key", name); continue; } /* Always list public and shared playlists @@ -422,7 +422,7 @@ static int trackdb_playlist_list_tid(const char *who, case DB_LOCK_DEADLOCK: return e; default: - fatal(0, "c->c_get: %s", db_strerror(e)); + disorder_fatal(0, "c->c_get: %s", db_strerror(e)); } vector_terminate(v); if(playlistsp) @@ -449,7 +449,7 @@ int trackdb_playlist_delete(const char *name, char *owner; if(playlist_parse_name(name, &owner, 0)) { - error(0, "invalid playlist name '%s'", name); + disorder_error(0, "invalid playlist name '%s'", name); return EINVAL; } /* We've checked as much as we can for now, now go and attempt the change */ @@ -470,7 +470,7 @@ static int trackdb_playlist_delete_tid(const char *name, return e; /* Check that modification is allowed */ if(!(s = kvp_get(k, "sharing"))) { - error(0, "playlist '%s' has no 'sharing' key", name); + disorder_error(0, "playlist '%s' has no 'sharing' key", name); s = "private"; } if(!playlist_may_write(name, who, s)) diff --git a/lib/trackdb.c b/lib/trackdb.c index 85d38dd..d2ebe07 100644 --- a/lib/trackdb.c +++ b/lib/trackdb.c @@ -246,7 +246,7 @@ void trackdb_init(int flags) { ++initialized; if(home) { if(strcmp(home, config->home)) - fatal(0, "cannot change db home without server restart"); + disorder_fatal(0, "cannot change db home without server restart"); home = config->home; } @@ -264,14 +264,14 @@ void trackdb_init(int flags) { * The socket, not being a regular file, is excepted. */ if(!(dp = opendir(config->home))) - fatal(errno, "error reading %s", config->home); + disorder_fatal(errno, "error reading %s", config->home); while((de = readdir(dp))) { byte_xasprintf(&p, "%s/%s", config->home, de->d_name); if(lstat(p, &st) == 0 && S_ISREG(st.st_mode) && (st.st_mode & 077)) { if(chmod(p, st.st_mode & 07700) < 0) - fatal(errno, "cannot chmod %s", p); + disorder_fatal(errno, "cannot chmod %s", p); } xfree(p); } @@ -279,15 +279,15 @@ void trackdb_init(int flags) { } /* create environment */ - if((err = db_env_create(&trackdb_env, 0))) fatal(0, "db_env_create: %s", - db_strerror(err)); + if((err = db_env_create(&trackdb_env, 0))) + disorder_fatal(0, "db_env_create: %s", db_strerror(err)); if((err = trackdb_env->set_alloc(trackdb_env, xmalloc_noptr, xrealloc_noptr, xfree))) - fatal(0, "trackdb_env->set_alloc: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->set_alloc: %s", db_strerror(err)); if((err = trackdb_env->set_lk_max_locks(trackdb_env, 10000))) - fatal(0, "trackdb_env->set_lk_max_locks: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->set_lk_max_locks: %s", db_strerror(err)); if((err = trackdb_env->set_lk_max_objects(trackdb_env, 10000))) - fatal(0, "trackdb_env->set_lk_max_objects: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->set_lk_max_objects: %s", db_strerror(err)); if((err = trackdb_env->open(trackdb_env, config->home, DB_INIT_LOG |DB_INIT_LOCK @@ -296,7 +296,8 @@ void trackdb_init(int flags) { |DB_CREATE |recover_type[recover], 0600))) - fatal(0, "trackdb_env->open %s: %s", config->home, db_strerror(err)); + disorder_fatal(0, "trackdb_env->open %s: %s", + config->home, db_strerror(err)); trackdb_env->set_errpfx(trackdb_env, "DB"); trackdb_env->set_errfile(trackdb_env, stderr); trackdb_env->set_verbose(trackdb_env, DB_VERB_DEADLOCK, 1); @@ -313,8 +314,8 @@ static int reap_db_deadlock(ev_source attribute((unused)) *ev, void attribute((unused)) *u) { db_deadlock_pid = -1; if(initialized) - fatal(0, "deadlock manager unexpectedly terminated: %s", - wstat(status)); + disorder_fatal(0, "deadlock manager unexpectedly terminated: %s", + wstat(status)); else D(("deadlock manager terminated: %s", wstat(status))); return 0; @@ -361,12 +362,12 @@ static pid_t subprogram(ev_source *ev, int outputfd, const char *prog, } /* ensure we don't leak privilege anywhere */ if(setuid(geteuid()) < 0) - fatal(errno, "error calling setuid"); + disorder_fatal(errno, "error calling setuid"); /* If we were negatively niced, undo it. We don't bother checking for * error, it's not that important. */ setpriority(PRIO_PROCESS, 0, 0); execvp(prog, (char **)args); - fatal(errno, "error invoking %s", prog); + disorder_fatal(errno, "error invoking %s", prog); } return pid; } @@ -399,7 +400,7 @@ static void terminate_and_wait(ev_source *ev, if(pid == -1) return; if(kill(pid, SIGTERM) < 0) - fatal(errno, "error killing %s", what); + disorder_fatal(errno, "error killing %s", what); /* wait for the rescanner to finish */ while(waitpid(pid, &err, 0) == -1 && errno == EINTR) ; @@ -419,7 +420,7 @@ void trackdb_deinit(ev_source *ev) { /* close the environment */ if((err = trackdb_env->close(trackdb_env, 0))) - fatal(0, "trackdb_env->close: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->close: %s", db_strerror(err)); terminate_and_wait(ev, rescan_pid, "disorder-rescan"); rescan_pid = -1; @@ -460,22 +461,22 @@ static DB *open_db(const char *path, D(("open %s", path)); path = config_get_file(path); if((err = db_create(&db, trackdb_env, 0))) - fatal(0, "db_create %s: %s", path, db_strerror(err)); + disorder_fatal(0, "db_create %s: %s", path, db_strerror(err)); if(dbflags) if((err = db->set_flags(db, dbflags))) - fatal(0, "db->set_flags %s: %s", path, db_strerror(err)); + disorder_fatal(0, "db->set_flags %s: %s", path, db_strerror(err)); if(dbtype == DB_BTREE) if((err = db->set_bt_compare(db, compare))) - fatal(0, "db->set_bt_compare %s: %s", path, db_strerror(err)); + disorder_fatal(0, "db->set_bt_compare %s: %s", path, db_strerror(err)); if((err = db->open(db, 0, path, 0, dbtype, openflags | DB_AUTO_COMMIT, mode))) { if((openflags & DB_CREATE) || errno != ENOENT) { if((err2 = db->close(db, 0))) - error(0, "db->close: %s", db_strerror(err2)); + disorder_error(0, "db->close: %s", db_strerror(err2)); trackdb_close(); trackdb_env->close(trackdb_env,0); trackdb_env = 0; - fatal(0, "db->open %s: %s", path, db_strerror(err)); + disorder_fatal(0, "db->open %s: %s", path, db_strerror(err)); } db->close(db, 0); db = 0; @@ -511,32 +512,32 @@ void trackdb_open(int flags) { s = trackdb_get_global("_dbversion"); /* Close the database again, we'll open it property below */ if((err = trackdb_globaldb->close(trackdb_globaldb, 0))) - fatal(0, "error closing global.db: %s", db_strerror(err)); + disorder_fatal(0, "error closing global.db: %s", db_strerror(err)); trackdb_globaldb = 0; /* Convert version string to an integer */ oldversion = s ? atol(s) : 1; if(oldversion > config->dbversion) { /* Database is from the future; we never allow this. */ - fatal(0, "this version of DisOrder is too old for database version %ld", - oldversion); + disorder_fatal(0, "this version of DisOrder is too old for database version %ld", + oldversion); } if(oldversion < config->dbversion) { /* Database version is out of date */ switch(flags & TRACKDB_UPGRADE_MASK) { case TRACKDB_NO_UPGRADE: /* This database needs upgrading but this is not permitted */ - fatal(0, "database needs upgrading from %ld to %ld", - oldversion, config->dbversion); + disorder_fatal(0, "database needs upgrading from %ld to %ld", + oldversion, config->dbversion); case TRACKDB_CAN_UPGRADE: /* This database needs upgrading */ - info("invoking disorder-dbupgrade to upgrade from %ld to %ld", + disorder_info("invoking disorder-dbupgrade to upgrade from %ld to %ld", oldversion, config->dbversion); pid = subprogram(0, -1, "disorder-dbupgrade", (char *)0); while(waitpid(pid, &err, 0) == -1 && errno == EINTR) ; if(err) - fatal(0, "disorder-dbupgrade %s", wstat(err)); - info("disorder-dbupgrade succeeded"); + disorder_fatal(0, "disorder-dbupgrade %s", wstat(err)); + disorder_info("disorder-dbupgrade succeeded"); break; case TRACKDB_OPEN_FOR_UPGRADE: break; @@ -546,13 +547,13 @@ void trackdb_open(int flags) { } if(oldversion == config->dbversion && (flags & TRACKDB_OPEN_FOR_UPGRADE)) { /* This doesn't make any sense */ - fatal(0, "database is already at current version"); + disorder_fatal(0, "database is already at current version"); } trackdb_existing_database = 1; } else { if(flags & TRACKDB_OPEN_FOR_UPGRADE) { /* Cannot upgrade a new database */ - fatal(0, "cannot upgrade a database that does not exist"); + disorder_fatal(0, "cannot upgrade a database that does not exist"); } /* This is a brand new database */ trackdb_existing_database = 0; @@ -560,7 +561,7 @@ void trackdb_open(int flags) { /* open the databases */ if(!(trackdb_usersdb = open_db("users.db", 0, DB_HASH, dbflags, 0600))) - fatal(0, "cannot open users.db"); + disorder_fatal(0, "cannot open users.db"); trackdb_tracksdb = open_db("tracks.db", DB_RECNUM, DB_BTREE, dbflags, 0666); trackdb_searchdb = open_db("search.db", @@ -591,10 +592,10 @@ void trackdb_close(void) { /* sanity checks */ assert(opened == 1); --opened; -#define CLOSE(N, V) do { \ - if(V && (err = V->close(V, 0))) \ - fatal(0, "error closing %s: %s", N, db_strerror(err)); \ - V = 0; \ +#define CLOSE(N, V) do { \ + if(V && (err = V->close(V, 0))) \ + disorder_fatal(0, "error closing %s: %s", N, db_strerror(err)); \ + V = 0; \ } while(0) CLOSE("tracks.db", trackdb_tracksdb); CLOSE("search.db", trackdb_searchdb); @@ -635,10 +636,10 @@ int trackdb_getdata(DB *db, *kp = 0; return err; case DB_LOCK_DEADLOCK: - error(0, "error querying database: %s", db_strerror(err)); + disorder_error(0, "error querying database: %s", db_strerror(err)); return err; default: - fatal(0, "error querying database: %s", db_strerror(err)); + disorder_fatal(0, "error querying database: %s", db_strerror(err)); } } @@ -664,10 +665,10 @@ int trackdb_putdata(DB *db, case DB_KEYEXIST: return err; case DB_LOCK_DEADLOCK: - error(0, "error updating database: %s", db_strerror(err)); + disorder_error(0, "error updating database: %s", db_strerror(err)); return err; default: - fatal(0, "error updating database: %s", db_strerror(err)); + disorder_fatal(0, "error updating database: %s", db_strerror(err)); } } @@ -688,10 +689,10 @@ int trackdb_delkey(DB *db, case DB_NOTFOUND: return 0; case DB_LOCK_DEADLOCK: - error(0, "error updating database: %s", db_strerror(err)); + disorder_error(0, "error updating database: %s", db_strerror(err)); return err; default: - fatal(0, "error updating database: %s", db_strerror(err)); + disorder_fatal(0, "error updating database: %s", db_strerror(err)); } } @@ -706,7 +707,7 @@ DBC *trackdb_opencursor(DB *db, DB_TXN *tid) { switch(err = db->cursor(db, tid, &c, 0)) { case 0: break; - default: fatal(0, "error creating cursor: %s", db_strerror(err)); + default: disorder_fatal(0, "error creating cursor: %s", db_strerror(err)); } return c; } @@ -723,10 +724,10 @@ int trackdb_closecursor(DBC *c) { case 0: return err; case DB_LOCK_DEADLOCK: - error(0, "error closing cursor: %s", db_strerror(err)); + disorder_error(0, "error closing cursor: %s", db_strerror(err)); return err; default: - fatal(0, "error closing cursor: %s", db_strerror(err)); + disorder_fatal(0, "error closing cursor: %s", db_strerror(err)); } } @@ -759,19 +760,19 @@ int trackdb_delkeydata(DB *db, err = 0; break; case DB_LOCK_DEADLOCK: - error(0, "error updating database: %s", db_strerror(err)); + disorder_error(0, "error updating database: %s", db_strerror(err)); break; default: - fatal(0, "c->c_del: %s", db_strerror(err)); + disorder_fatal(0, "c->c_del: %s", db_strerror(err)); } break; case DB_NOTFOUND: break; case DB_LOCK_DEADLOCK: - error(0, "error updating database: %s", db_strerror(err)); + disorder_error(0, "error updating database: %s", db_strerror(err)); break; default: - fatal(0, "c->c_get: %s", db_strerror(err)); + disorder_fatal(0, "c->c_get: %s", db_strerror(err)); } if(trackdb_closecursor(c)) err = DB_LOCK_DEADLOCK; return err; @@ -785,7 +786,7 @@ DB_TXN *trackdb_begin_transaction(void) { int err; if((err = trackdb_env->txn_begin(trackdb_env, 0, &tid, 0))) - fatal(0, "trackdb_env->txn_begin: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->txn_begin: %s", db_strerror(err)); return tid; } @@ -799,7 +800,7 @@ void trackdb_abort_transaction(DB_TXN *tid) { if(tid) if((err = tid->abort(tid))) - fatal(0, "tid->abort: %s", db_strerror(err)); + disorder_fatal(0, "tid->abort: %s", db_strerror(err)); } /** @brief Commit transaction @@ -809,7 +810,7 @@ void trackdb_commit_transaction(DB_TXN *tid) { int err; if((err = tid->commit(tid, 0))) - fatal(0, "tid->commit: %s", db_strerror(err)); + disorder_fatal(0, "tid->commit: %s", db_strerror(err)); } /* search/tags shared code ***************************************************/ @@ -872,10 +873,10 @@ static int register_word(DB *db, const char *what, case DB_KEYEXIST: return 0; case DB_LOCK_DEADLOCK: - error(0, "error updating %s.db: %s", what, db_strerror(err)); + disorder_error(0, "error updating %s.db: %s", what, db_strerror(err)); return err; default: - fatal(0, "error updating %s.db: %s", what, db_strerror(err)); + disorder_fatal(0, "error updating %s.db: %s", what, db_strerror(err)); } } @@ -1214,7 +1215,8 @@ static int gettrackdata(const char *track, if((err = trackdb_getdata(trackdb_tracksdb, track, &t, tid))) goto done; if((actual = kvp_get(t, "_alias_for"))) { if(flags & GTD_NOALIAS) { - error(0, "alias passed to gettrackdata where real path required"); + disorder_error(0, + "alias passed to gettrackdata where real path required"); abort(); } if((err = trackdb_getdata(trackdb_tracksdb, actual, &t, tid))) goto done; @@ -1326,7 +1328,8 @@ int trackdb_notice_tid(const char *track, make_key(&data, track), 0)) { case 0: break; case DB_LOCK_DEADLOCK: return err; - default: fatal(0, "error updating noticed.db: %s", db_strerror(err)); + default: + disorder_fatal(0, "error updating noticed.db: %s", db_strerror(err)); } } return ret; @@ -1448,10 +1451,10 @@ static int get_stats(struct vector *v, case 0: break; case DB_LOCK_DEADLOCK: - error(0, "error querying database: %s", db_strerror(err)); + disorder_error(0, "error querying database: %s", db_strerror(err)); return err; default: - fatal(0, "error querying database: %s", db_strerror(err)); + disorder_fatal(0, "error querying database: %s", db_strerror(err)); } for(n = 0; n < nsi; ++n) { byte_xasprintf(&str, "%s=%"PRIuMAX, si[n].name, @@ -1533,10 +1536,10 @@ static int search_league(struct vector *v, int count, DB_TXN *tid) { err = 0; break; case DB_LOCK_DEADLOCK: - error(0, "error querying search database: %s", db_strerror(err)); + disorder_error(0, "error querying search database: %s", db_strerror(err)); break; default: - fatal(0, "error querying search database: %s", db_strerror(err)); + disorder_fatal(0, "error querying search database: %s", db_strerror(err)); } if(trackdb_closecursor(cursor)) err = DB_LOCK_DEADLOCK; if(err) return err; @@ -1637,7 +1640,7 @@ static int stats_finished(ev_source attribute((unused)) *ev, d->exited = 1; if(status) - error(0, "disorder-stats %s", wstat(status)); + disorder_error(0, "disorder-stats %s", wstat(status)); stats_complete(d); char *k; byte_xasprintf(&k, "%lu", (unsigned long)pid); @@ -1681,7 +1684,7 @@ static int stats_error(ev_source attribute((unused)) *ev, void *u) { struct stats_details *const d = u; - error(errno_value, "error reading from pipe to disorder-stats"); + disorder_error(errno_value, "error reading from pipe to disorder-stats"); d->closed = 1; stats_complete(d); return 0; @@ -1711,7 +1714,7 @@ void trackdb_stats_subprocess(ev_source *ev, ev_child(ev, pid, 0, stats_finished, d); if(!ev_reader_new(ev, p[0], stats_read, stats_error, d, "disorder-stats reader")) - fatal(0, "ev_reader_new for disorder-stats reader failed"); + disorder_fatal(0, "ev_reader_new for disorder-stats reader failed"); /* Remember the PID */ if(!stats_pids) stats_pids = hash_new(1); @@ -1993,7 +1996,7 @@ int trackdb_listkeys(DB *db, struct vector *v, DB_TXN *tid) { case DB_LOCK_DEADLOCK: return e; default: - fatal(0, "c->c_get: %s", db_strerror(e)); + disorder_fatal(0, "c->c_get: %s", db_strerror(e)); } if((e = trackdb_closecursor(c))) return e; @@ -2054,7 +2057,7 @@ static int choose_exited(ev_source *ev, const struct rusage attribute((unused)) *rusage, void attribute((unused)) *u) { if(status) - error(0, "disorder-choose %s", wstat(status)); + disorder_error(0, "disorder-choose %s", wstat(status)); choose_status = status; choose_finished(ev, CHOOSE_RUNNING); return 0; @@ -2091,7 +2094,7 @@ static int choose_readable(ev_source *ev, static int choose_read_error(ev_source *ev, int errno_value, void attribute((unused)) *u) { - error(errno_value, "error reading disorder-choose pipe"); + disorder_error(errno_value, "error reading disorder-choose pipe"); choose_finished(ev, CHOOSE_READING); return 0; } @@ -2125,7 +2128,7 @@ int trackdb_request_random(ev_source *ev, choose_complete = 0; if(!ev_reader_new(ev, p[0], choose_readable, choose_read_error, 0, "disorder-choose reader")) /* owns p[0] */ - fatal(0, "ev_reader_new for disorder-choose reader failed"); + disorder_fatal(0, "ev_reader_new for disorder-choose reader failed"); ev_child(ev, choose_pid, 0, choose_exited, 0); /* owns the subprocess */ return 0; } @@ -2244,7 +2247,7 @@ static int track_matches(size_t dl, const char *track, size_t tl, case PCRE_ERROR_NOMATCH: return 0; default: if(rc < 0) { - error(0, "pcre_exec returned %d, subject '%s'", rc, track); + disorder_error(0, "pcre_exec returned %d, subject '%s'", rc, track); return 0; } return 1; @@ -2340,10 +2343,10 @@ static int do_list(struct vector *v, const char *dir, err = 0; break; case DB_LOCK_DEADLOCK: - error(0, "error querying database: %s", db_strerror(err)); + disorder_error(0, "error querying database: %s", db_strerror(err)); break; default: - fatal(0, "error querying database: %s", db_strerror(err)); + disorder_fatal(0, "error querying database: %s", db_strerror(err)); } deadlocked: if(trackdb_closecursor(cursor)) err = DB_LOCK_DEADLOCK; @@ -2480,10 +2483,12 @@ char **trackdb_search(char **wordlist, int nwordlist, int *ntracks) { err = 0; break; case DB_LOCK_DEADLOCK: - error(0, "error querying %s database: %s", dbname, db_strerror(err)); + disorder_error(0, "error querying %s database: %s", + dbname, db_strerror(err)); break; default: - fatal(0, "error querying %s database: %s", dbname, db_strerror(err)); + disorder_fatal(0, "error querying %s database: %s", + dbname, db_strerror(err)); } if(trackdb_closecursor(cursor)) err = DB_LOCK_DEADLOCK; cursor = 0; @@ -2493,7 +2498,8 @@ char **trackdb_search(char **wordlist, int nwordlist, int *ntracks) { if((err = gettrackdata(v.vec[n], 0, &p, 0, 0, tid) == DB_LOCK_DEADLOCK)) goto fail; else if(err) { - error(0, "track %s unexpected error: %s", v.vec[n], db_strerror(err)); + disorder_error(0, "track %s unexpected error: %s", + v.vec[n], db_strerror(err)); continue; } twords = track_to_words(v.vec[n], p); @@ -2520,7 +2526,7 @@ char **trackdb_search(char **wordlist, int nwordlist, int *ntracks) { trackdb_closecursor(cursor); cursor = 0; trackdb_abort_transaction(tid); - info("retrying search"); + disorder_info("retrying search"); } trackdb_commit_transaction(tid); vector_terminate(&u); @@ -2591,11 +2597,11 @@ int trackdb_scan(const char *root, prefs = 0; break; case DB_LOCK_DEADLOCK: - error(0, "getting prefs: %s", db_strerror(err)); + disorder_error(0, "getting prefs: %s", db_strerror(err)); trackdb_closecursor(cursor); return err; default: - fatal(0, "getting prefs: %s", db_strerror(err)); + disorder_fatal(0, "getting prefs: %s", db_strerror(err)); } /* Advance to the next track before the callback so that the callback * may safely delete the track */ @@ -2617,10 +2623,10 @@ int trackdb_scan(const char *root, case DB_NOTFOUND: return 0; case DB_LOCK_DEADLOCK: - error(0, "c->c_get: %s", db_strerror(err)); + disorder_error(0, "c->c_get: %s", db_strerror(err)); return err; default: - fatal(0, "c->c_get: %s", db_strerror(err)); + disorder_fatal(0, "c->c_get: %s", db_strerror(err)); } } @@ -2656,7 +2662,7 @@ static int reap_rescan(ev_source attribute((unused)) *ev, void attribute((unused)) *u) { if(pid == rescan_pid) rescan_pid = -1; if(status) - error(0, RESCAN": %s", wstat(status)); + disorder_error(0, RESCAN": %s", wstat(status)); else D((RESCAN" terminated: %s", wstat(status))); /* Our cache of file lookups is out of date now */ @@ -2686,7 +2692,7 @@ void trackdb_rescan(ev_source *ev, int recheck, if(rescan_pid != -1) { trackdb_add_rescanned(rescanned, ru); - error(0, "rescan already underway"); + disorder_error(0, "rescan already underway"); return; } rescan_pid = subprogram(ev, -1, RESCAN, @@ -2710,7 +2716,7 @@ void trackdb_rescan(ev_source *ev, int recheck, int trackdb_rescan_cancel(void) { if(rescan_pid == -1) return 0; if(kill(rescan_pid, SIGTERM) < 0) - fatal(errno, "error killing rescanner"); + disorder_fatal(errno, "error killing rescanner"); rescan_pid = -1; return 1; } @@ -2744,16 +2750,16 @@ void trackdb_set_global(const char *name, /* log important state changes */ if(!strcmp(name, "playing")) { state = !value || !strcmp(value, "yes"); - info("playing %s by %s", - state ? "enabled" : "disabled", - who ? who : "-"); + disorder_info("playing %s by %s", + state ? "enabled" : "disabled", + who ? who : "-"); eventlog("state", state ? "enable_play" : "disable_play", (char *)0); } if(!strcmp(name, "random-play")) { state = !value || !strcmp(value, "yes"); - info("random play %s by %s", - state ? "enabled" : "disabled", - who ? who : "-"); + disorder_info("random play %s by %s", + state ? "enabled" : "disabled", + who ? who : "-"); eventlog("state", state ? "enable_random" : "disable_random", (char *)0); } } @@ -2783,7 +2789,7 @@ int trackdb_set_global_tid(const char *name, err = trackdb_globaldb->del(trackdb_globaldb, tid, &k, 0); if(err == DB_LOCK_DEADLOCK) return err; if(err) - fatal(0, "error updating database: %s", db_strerror(err)); + disorder_fatal(0, "error updating database: %s", db_strerror(err)); return 0; } @@ -2832,7 +2838,7 @@ int trackdb_get_global_tid(const char *name, case DB_LOCK_DEADLOCK: return err; default: - fatal(0, "error reading database: %s", db_strerror(err)); + disorder_fatal(0, "error reading database: %s", db_strerror(err)); } } @@ -2900,7 +2906,7 @@ static char **trackdb_new_tid(int *ntracksp, trackdb_closecursor(c); return 0; default: - fatal(0, "error reading noticed.db: %s", db_strerror(err)); + disorder_fatal(0, "error reading noticed.db: %s", db_strerror(err)); } if((err = trackdb_closecursor(c))) return 0; /* deadlock */ @@ -2946,8 +2952,8 @@ static int trackdb_expire_noticed_tid(time_t earliest, DB_TXN *tid) { break; if((err = c->c_del(c, 0))) { if(err != DB_LOCK_DEADLOCK) - fatal(0, "error deleting expired noticed.db entry: %s", - db_strerror(err)); + disorder_fatal(0, "error deleting expired noticed.db entry: %s", + db_strerror(err)); break; } ++count; @@ -2955,15 +2961,15 @@ static int trackdb_expire_noticed_tid(time_t earliest, DB_TXN *tid) { if(err == DB_NOTFOUND) err = 0; if(err && err != DB_LOCK_DEADLOCK) - fatal(0, "error expiring noticed.db: %s", db_strerror(err)); + disorder_fatal(0, "error expiring noticed.db: %s", db_strerror(err)); ret = err; if((err = trackdb_closecursor(c))) { if(err != DB_LOCK_DEADLOCK) - fatal(0, "error closing cursor: %s", db_strerror(err)); + disorder_fatal(0, "error closing cursor: %s", db_strerror(err)); ret = err; } if(!ret && count) - info("expired %d tracks from noticed.db", count); + disorder_info("expired %d tracks from noticed.db", count); return ret; } @@ -2981,9 +2987,9 @@ void trackdb_gc(void) { config->checkpoint_kbyte, config->checkpoint_min, 0))) - fatal(0, "trackdb_env->txn_checkpoint: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->txn_checkpoint: %s", db_strerror(err)); if((err = trackdb_env->log_archive(trackdb_env, &logfiles, DB_ARCH_REMOVE))) - fatal(0, "trackdb_env->log_archive: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->log_archive: %s", db_strerror(err)); /* This makes catastrophic recovery impossible. However, the user can still * preserve the important data by using disorder-dump to snapshot their * prefs, and later to restore it. This is likely to have much small @@ -3055,11 +3061,11 @@ static int create_user(const char *user, /* sanity check user */ if(!valid_username(user)) { - error(0, "invalid username '%s'", user); + disorder_error(0, "invalid username '%s'", user); return -1; } if(parse_rights(rights, 0, 1)) { - error(0, "invalid rights string"); + disorder_error(0, "invalid rights string"); return -1; } /* data for this user */ @@ -3089,7 +3095,7 @@ static int one_old_user(const char *user, const char *password, /* www-data doesn't get added */ if(!strcmp(user, "www-data")) { - info("not adding www-data to user database"); + disorder_info("not adding www-data to user database"); return 0; } /* pick rights */ @@ -3120,10 +3126,11 @@ static int trackdb_old_users_tid(DB_TXN *tid) { switch(one_old_user(config->allow.s[n].s[0], config->allow.s[n].s[1], tid)) { case 0: - info("created user %s from 'allow' directive", config->allow.s[n].s[0]); + disorder_info("created user %s from 'allow' directive", + config->allow.s[n].s[0]); break; case DB_KEYEXIST: - error(0, "user %s already exists, delete 'allow' directive", + disorder_error(0, "user %s already exists, delete 'allow' directive", config->allow.s[n].s[0]); /* This won't ever become fatal - eventually 'allow' will be * disabled. */ @@ -3157,7 +3164,7 @@ void trackdb_create_root(void) { 0/*email*/, 0/*confirmation*/, tid, DB_NOOVERWRITE)); if(e == 0) - info("created root user"); + disorder_info("created root user"); } /** @brief Find a user's password from the database @@ -3198,14 +3205,15 @@ int trackdb_adduser(const char *user, WITH_TRANSACTION(create_user(user, password, rights, email, confirmation, tid, DB_NOOVERWRITE)); if(e) { - error(0, "cannot create user '%s' because they already exist", user); + disorder_error(0, "cannot create user '%s' because they already exist", + user); return -1; } else { if(email) - info("created user '%s' with rights '%s' and email address '%s'", - user, rights, email); + disorder_info("created user '%s' with rights '%s' and email address '%s'", + user, rights, email); else - info("created user '%s' with rights '%s'", user, rights); + disorder_info("created user '%s' with rights '%s'", user, rights); eventlog("user_add", user, (char *)0); return 0; } @@ -3220,10 +3228,11 @@ int trackdb_deluser(const char *user) { WITH_TRANSACTION(trackdb_delkey(trackdb_usersdb, user, tid)); if(e) { - error(0, "cannot delete user '%s' because they do not exist", user); + disorder_error(0, "cannot delete user '%s' because they do not exist", + user); return -1; } - info("deleted user '%s'", user); + disorder_info("deleted user '%s'", user); eventlog("user_delete", user, (char *)0); return 0; } @@ -3277,32 +3286,33 @@ int trackdb_edituserinfo(const char *user, if(!strcmp(key, "rights")) { if(!value) { - error(0, "cannot remove 'rights' key from user '%s'", user); + disorder_error(0, "cannot remove 'rights' key from user '%s'", user); return -1; } if(parse_rights(value, 0, 1)) { - error(0, "invalid rights string"); + disorder_error(0, "invalid rights string"); return -1; } } else if(!strcmp(key, "email")) { if(*value) { if(!email_valid(value)) { - error(0, "invalid email address '%s' for user '%s'", value, user); + disorder_error(0, "invalid email address '%s' for user '%s'", + value, user); return -1; } } else value = 0; /* no email -> remove key */ } else if(!strcmp(key, "created")) { - error(0, "cannot change creation date for user '%s'", user); + disorder_error(0, "cannot change creation date for user '%s'", user); return -1; } else if(strcmp(key, "password") && !strcmp(key, "confirmation")) { - error(0, "unknown user info key '%s' for user '%s'", key, user); + disorder_error(0, "unknown user info key '%s' for user '%s'", key, user); return -1; } WITH_TRANSACTION(trackdb_edituserinfo_tid(user, key, value, tid)); if(e) { - error(0, "unknown user '%s'", user); + disorder_error(0, "unknown user '%s'", user); return -1; } else { eventlog("user_edit", user, key, (char *)0); @@ -3340,18 +3350,18 @@ static int trackdb_confirm_tid(const char *user, const char *confirmation, if((e = trackdb_getdata(trackdb_usersdb, user, &k, tid))) return e; if(!(stored_confirmation = kvp_get(k, "confirmation"))) { - error(0, "already confirmed user '%s'", user); + disorder_error(0, "already confirmed user '%s'", user); /* DB claims -30,800 to -30,999 so -1 should be a safe bet */ return -1; } if(!(rights = kvp_get(k, "rights"))) { - error(0, "no rights for unconfirmed user '%s'", user); + disorder_error(0, "no rights for unconfirmed user '%s'", user); return -1; } if(parse_rights(rights, rightsp, 1)) return -1; if(strcmp(confirmation, stored_confirmation)) { - error(0, "wrong confirmation string for user '%s'", user); + disorder_error(0, "wrong confirmation string for user '%s'", user); return -1; } /* 'sall good */ @@ -3372,11 +3382,11 @@ int trackdb_confirm(const char *user, const char *confirmation, WITH_TRANSACTION(trackdb_confirm_tid(user, confirmation, rightsp, tid)); switch(e) { case 0: - info("registration confirmed for user '%s'", user); + disorder_info("registration confirmed for user '%s'", user); eventlog("user_confirm", user, (char *)0); return 0; case DB_NOTFOUND: - error(0, "confirmation for nonexistent user '%s'", user); + disorder_error(0, "confirmation for nonexistent user '%s'", user); return -1; default: /* already reported */ return -1; diff --git a/lib/trackname.c b/lib/trackname.c index fa40c3b..4e2e06e 100644 --- a/lib/trackname.c +++ b/lib/trackname.c @@ -51,7 +51,7 @@ const char *find_track_root(const char *track) { const struct collection *c = find_track_collection(track); if(c) return c->root; - error(0, "found track in no collection '%s'", track); + disorder_error(0, "found track in no collection '%s'", track); return 0; } diff --git a/lib/uaudio-alsa.c b/lib/uaudio-alsa.c index 3cec315..ff85c08 100644 --- a/lib/uaudio-alsa.c +++ b/lib/uaudio-alsa.c @@ -89,7 +89,7 @@ static size_t alsa_play(void *buffer, size_t samples, unsigned flags) { case -EAGAIN: return 0; default: - fatal(0, "error calling snd_pcm_writei: %d", (int)rc); + disorder_fatal(0, "error calling snd_pcm_writei: %d", (int)rc); } } return rc * uaudio_channels; @@ -104,14 +104,14 @@ static void alsa_open(void) { device, SND_PCM_STREAM_PLAYBACK, 0))) - fatal(0, "error from snd_pcm_open: %d", err); + disorder_fatal(0, "error from snd_pcm_open: %d", err); snd_pcm_hw_params_t *hwparams; snd_pcm_hw_params_alloca(&hwparams); if((err = snd_pcm_hw_params_any(alsa_pcm, hwparams)) < 0) - fatal(0, "error from snd_pcm_hw_params_any: %d", err); + disorder_fatal(0, "error from snd_pcm_hw_params_any: %d", err); if((err = snd_pcm_hw_params_set_access(alsa_pcm, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) - fatal(0, "error from snd_pcm_hw_params_set_access: %d", err); + disorder_fatal(0, "error from snd_pcm_hw_params_set_access: %d", err); int sample_format; if(uaudio_bits == 16) sample_format = uaudio_signed ? SND_PCM_FORMAT_S16 : SND_PCM_FORMAT_U16; @@ -119,28 +119,28 @@ static void alsa_open(void) { sample_format = uaudio_signed ? SND_PCM_FORMAT_S8 : SND_PCM_FORMAT_U8; if((err = snd_pcm_hw_params_set_format(alsa_pcm, hwparams, sample_format)) < 0) - fatal(0, "error from snd_pcm_hw_params_set_format (%d): %d", + disorder_fatal(0, "error from snd_pcm_hw_params_set_format (%d): %d", sample_format, err); unsigned rate = uaudio_rate; if((err = snd_pcm_hw_params_set_rate_near(alsa_pcm, hwparams, &rate, 0)) < 0) - fatal(0, "error from snd_pcm_hw_params_set_rate_near (%d): %d", + disorder_fatal(0, "error from snd_pcm_hw_params_set_rate_near (%d): %d", rate, err); if((err = snd_pcm_hw_params_set_channels(alsa_pcm, hwparams, uaudio_channels)) < 0) - fatal(0, "error from snd_pcm_hw_params_set_channels (%d): %d", + disorder_fatal(0, "error from snd_pcm_hw_params_set_channels (%d): %d", uaudio_channels, err); if((err = snd_pcm_hw_params(alsa_pcm, hwparams)) < 0) - fatal(0, "error calling snd_pcm_hw_params: %d", err); + disorder_fatal(0, "error calling snd_pcm_hw_params: %d", err); } static void alsa_start(uaudio_callback *callback, void *userdata) { if(uaudio_channels != 1 && uaudio_channels != 2) - fatal(0, "asked for %d channels but only support 1 or 2", + disorder_fatal(0, "asked for %d channels but only support 1 or 2", uaudio_channels); if(uaudio_bits != 8 && uaudio_bits != 16) - fatal(0, "asked for %d bits/channel but only support 8 or 16", + disorder_fatal(0, "asked for %d bits/channel but only support 8 or 16", uaudio_bits); alsa_open(); uaudio_thread_start(callback, userdata, alsa_play, @@ -174,23 +174,24 @@ static void alsa_open_mixer(void) { snd_mixer_selem_id_alloca(&id); if((err = snd_mixer_open(&alsa_mixer_handle, 0))) - fatal(0, "snd_mixer_open: %s", snd_strerror(err)); + disorder_fatal(0, "snd_mixer_open: %s", snd_strerror(err)); if((err = snd_mixer_attach(alsa_mixer_handle, device))) - fatal(0, "snd_mixer_attach %s: %s", device, snd_strerror(err)); + disorder_fatal(0, "snd_mixer_attach %s: %s", device, snd_strerror(err)); if((err = snd_mixer_selem_register(alsa_mixer_handle, 0/*options*/, 0/*classp*/))) - fatal(0, "snd_mixer_selem_register %s: %s", + disorder_fatal(0, "snd_mixer_selem_register %s: %s", device, snd_strerror(err)); if((err = snd_mixer_load(alsa_mixer_handle))) - fatal(0, "snd_mixer_load %s: %s", device, snd_strerror(err)); + disorder_fatal(0, "snd_mixer_load %s: %s", device, snd_strerror(err)); snd_mixer_selem_id_set_name(id, channel); snd_mixer_selem_id_set_index(id, atoi(mixer)); if(!(alsa_mixer_elem = snd_mixer_find_selem(alsa_mixer_handle, id))) - fatal(0, "device '%s' mixer control '%s,%s' does not exist", - device, channel, mixer); + disorder_fatal(0, "device '%s' mixer control '%s,%s' does not exist", + device, channel, mixer); if(!snd_mixer_selem_has_playback_volume(alsa_mixer_elem)) - fatal(0, "device '%s' mixer control '%s,%s' has no playback volume", - device, channel, mixer); + disorder_fatal(0, + "device '%s' mixer control '%s,%s' has no playback volume", + device, channel, mixer); if(snd_mixer_selem_is_playback_mono(alsa_mixer_elem)) { alsa_mixer_left = alsa_mixer_right = SND_MIXER_SCHN_MONO; } else { @@ -201,8 +202,8 @@ static void alsa_open_mixer(void) { alsa_mixer_left) || !snd_mixer_selem_has_playback_channel(alsa_mixer_elem, alsa_mixer_right)) - fatal(0, "device '%s' mixer control '%s,%s' lacks required playback channels", - device, channel, mixer); + disorder_fatal(0, "device '%s' mixer control '%s,%s' lacks required playback channels", + device, channel, mixer); snd_mixer_selem_get_playback_volume_range(alsa_mixer_elem, &alsa_mixer_min, &alsa_mixer_max); @@ -222,7 +223,8 @@ static void alsa_get_volume(int *left, int *right) { alsa_mixer_left, &l)) || (err = snd_mixer_selem_get_playback_volume(alsa_mixer_elem, alsa_mixer_right, &r))) - fatal(0, "snd_mixer_selem_get_playback_volume: %s", snd_strerror(err)); + disorder_fatal(0, "snd_mixer_selem_get_playback_volume: %s", + snd_strerror(err)); *left = to_percent(l); *right = to_percent(r); } @@ -237,21 +239,24 @@ static void alsa_set_volume(int *left, int *right) { if((err = snd_mixer_selem_set_playback_volume (alsa_mixer_elem, alsa_mixer_left, from_percent(*left > *right ? *left : *right)))) - fatal(0, "snd_mixer_selem_set_playback_volume: %s", snd_strerror(err)); + disorder_fatal(0, "snd_mixer_selem_set_playback_volume: %s", + snd_strerror(err)); } else { /* Stereo output */ if((err = snd_mixer_selem_set_playback_volume (alsa_mixer_elem, alsa_mixer_left, from_percent(*left))) || (err = snd_mixer_selem_set_playback_volume (alsa_mixer_elem, alsa_mixer_right, from_percent(*right)))) - fatal(0, "snd_mixer_selem_set_playback_volume: %s", snd_strerror(err)); + disorder_fatal(0, "snd_mixer_selem_set_playback_volume: %s", + snd_strerror(err)); } /* Read it back to see what we ended up at */ if((err = snd_mixer_selem_get_playback_volume(alsa_mixer_elem, alsa_mixer_left, &l)) || (err = snd_mixer_selem_get_playback_volume(alsa_mixer_elem, alsa_mixer_right, &r))) - fatal(0, "snd_mixer_selem_get_playback_volume: %s", snd_strerror(err)); + disorder_fatal(0, "snd_mixer_selem_get_playback_volume: %s", + snd_strerror(err)); *left = to_percent(l); *right = to_percent(r); } diff --git a/lib/uaudio-apis.c b/lib/uaudio-apis.c index 1006fd9..568ae36 100644 --- a/lib/uaudio-apis.c +++ b/lib/uaudio-apis.c @@ -55,7 +55,7 @@ const struct uaudio *uaudio_find(const char *name) { return uaudio_apis[n]; if(!strcmp(name, "network")) return &uaudio_rtp; - fatal(0, "cannot find audio API '%s'", name); + disorder_fatal(0, "cannot find audio API '%s'", name); } /* diff --git a/lib/uaudio-command.c b/lib/uaudio-command.c index 57e8762..1c29c16 100644 --- a/lib/uaudio-command.c +++ b/lib/uaudio-command.c @@ -61,10 +61,10 @@ static void command_wait(void) { while((rc = waitpid(command_pid, &w, 0) < 0 && errno == EINTR)) ; if(rc < 0) - fatal(errno, "waitpid"); + disorder_fatal(errno, "waitpid"); if(w) { ws = wstat(w); - error(0, "command subprocess %s", ws); + disorder_error(0, "command subprocess %s", ws); xfree(ws); } } @@ -75,7 +75,7 @@ static void command_open(void) { const char *command; if(!(command = uaudio_get("command", NULL))) - fatal(0, "'command' not set"); + disorder_fatal(0, "'command' not set"); xpipe(pfd); command_pid = xfork(); if(!command_pid) { @@ -88,7 +88,7 @@ static void command_open(void) { * format. The original intended model is that you adapt DisOrder to the * command you run but it'd be nice to support the opposite. */ execl("/bin/sh", "sh", "-c", command, (char *)0); - fatal(errno, "error executing /bin/sh"); + disorder_fatal(errno, "error executing /bin/sh"); } close(pfd[0]); command_fd = pfd[1]; @@ -108,12 +108,12 @@ static size_t command_play(void *buffer, size_t nsamples, unsigned flags) { case EINTR: return 0; /* will retry */ case EPIPE: - error(0, "audio command subprocess terminated"); + disorder_error(0, "audio command subprocess terminated"); command_wait(); command_open(); return 0; /* will retry */ default: - fatal(errno, "error writing to audio command subprocess"); + disorder_fatal(errno, "error writing to audio command subprocess"); } } /* TODO what if we write a partial sample? Actually reasonably unlikely but @@ -134,7 +134,7 @@ static void command_start(uaudio_callback *callback, else if(!strcmp(pausemode, "suspend")) command_suspend_on_pause = 1; else - fatal(0, "unknown pause mode '%s'", pausemode); + disorder_fatal(0, "unknown pause mode '%s'", pausemode); command_open(); uaudio_schedule_init(); uaudio_thread_start(callback, diff --git a/lib/uaudio-oss.c b/lib/uaudio-oss.c index d0c9062..4429846 100644 --- a/lib/uaudio-oss.c +++ b/lib/uaudio-oss.c @@ -78,20 +78,20 @@ static void oss_open(void) { } #endif if((oss_fd = open(device, O_WRONLY, 0)) < 0) - fatal(errno, "error opening %s", device); + disorder_fatal(errno, "error opening %s", device); #if !EMPEG_HOST int stereo = (uaudio_channels == 2), format; if(ioctl(oss_fd, SNDCTL_DSP_STEREO, &stereo) < 0) - fatal(errno, "error calling ioctl SNDCTL_DSP_STEREO %d", stereo); + disorder_fatal(errno, "error calling ioctl SNDCTL_DSP_STEREO %d", stereo); if(uaudio_bits == 16) format = uaudio_signed ? AFMT_S16_NE : AFMT_U16_NE; else format = uaudio_signed ? AFMT_S8 : AFMT_U8; if(ioctl(oss_fd, SNDCTL_DSP_SETFMT, &format) < 0) - fatal(errno, "error calling ioctl SNDCTL_DSP_SETFMT %#x", format); + disorder_fatal(errno, "error calling ioctl SNDCTL_DSP_SETFMT %#x", format); int rate = uaudio_rate; if(ioctl(oss_fd, SNDCTL_DSP_SPEED, &rate) < 0) - fatal(errno, "error calling ioctl SNDCTL_DSP_SPEED %d", rate); + disorder_fatal(errno, "error calling ioctl SNDCTL_DSP_SPEED %d", rate); if(rate != uaudio_rate) error(0, "asked for %dHz, got %dHz", uaudio_rate, rate); #endif @@ -127,17 +127,17 @@ static size_t oss_play(void *buffer, size_t samples, unsigned flags) { const size_t bytes = samples * uaudio_sample_size; int rc = write(oss_fd, buffer, bytes); if(rc < 0) - fatal(errno, "error writing to sound device"); + disorder_fatal(errno, "error writing to sound device"); return rc / uaudio_sample_size; } static void oss_start(uaudio_callback *callback, void *userdata) { if(uaudio_channels != 1 && uaudio_channels != 2) - fatal(0, "asked for %d channels but only support 1 or 2", + disorder_fatal(0, "asked for %d channels but only support 1 or 2", uaudio_channels); if(uaudio_bits != 8 && uaudio_bits != 16) - fatal(0, "asked for %d bits/channel but only support 8 or 16", + disorder_fatal(0, "asked for %d bits/channel but only support 8 or 16", uaudio_bits); #if EMPEG_HOST /* Very specific buffer size requirements here apparently */ @@ -178,11 +178,11 @@ static void oss_open_mixer(void) { const char *mixer = uaudio_get("mixer-device", "/dev/mixer"); /* TODO infer mixer-device from device */ if((oss_mixer_fd = open(mixer, O_RDWR, 0)) < 0) - fatal(errno, "error opening %s", mixer); + disorder_fatal(errno, "error opening %s", mixer); const char *channel = uaudio_get("mixer-channel", "pcm"); oss_mixer_channel = oss_mixer_find_channel(channel); if(oss_mixer_channel < 0) - fatal(0, "no such channel as '%s'", channel); + disorder_fatal(0, "no such channel as '%s'", channel); } static void oss_close_mixer(void) { @@ -195,7 +195,7 @@ static void oss_get_volume(int *left, int *right) { *left = *right = 0; if(ioctl(oss_mixer_fd, SOUND_MIXER_READ(oss_mixer_channel), &r) < 0) - error(errno, "error getting volume"); + disorder_error(errno, "error getting volume"); else { *left = r & 0xff; *right = (r >> 8) & 0xff; @@ -205,9 +205,9 @@ static void oss_get_volume(int *left, int *right) { static void oss_set_volume(int *left, int *right) { int r = (*left & 0xff) + (*right & 0xff) * 256; if(ioctl(oss_mixer_fd, SOUND_MIXER_WRITE(oss_mixer_channel), &r) == -1) - error(errno, "error setting volume"); + disorder_error(errno, "error setting volume"); else if(ioctl(oss_mixer_fd, SOUND_MIXER_READ(oss_mixer_channel), &r) < 0) - error(errno, "error getting volume"); + disorder_error(errno, "error getting volume"); else { *left = r & 0xff; *right = (r >> 8) & 0xff; diff --git a/lib/uaudio-rtp.c b/lib/uaudio-rtp.c index e1768a8..c8e2ef2 100644 --- a/lib/uaudio-rtp.c +++ b/lib/uaudio-rtp.c @@ -97,7 +97,7 @@ static void rtp_get_netconfig(const char *af, na->af = -1; else if(netaddress_parse(na, 3, vec)) - fatal(0, "invalid RTP address"); + disorder_fatal(0, "invalid RTP address"); } static void rtp_set_netconfig(const char *af, @@ -174,10 +174,10 @@ static size_t rtp_play(void *buffer, size_t nsamples, unsigned flags) { written_bytes = writev(rtp_fd, vec, 2); } while(written_bytes < 0 && errno == EINTR); if(written_bytes < 0) { - error(errno, "error transmitting audio data"); + disorder_error(errno, "error transmitting audio data"); ++rtp_errors; if(rtp_errors == 10) - fatal(0, "too many audio tranmission errors"); + disorder_fatal(0, "too many audio tranmission errors"); return 0; } else rtp_errors /= 2; /* gradual decay */ @@ -219,7 +219,7 @@ static void rtp_open(void) { if((rtp_fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) - fatal(errno, "error creating broadcast socket"); + disorder_fatal(errno, "error creating broadcast socket"); if(multicast(res->ai_addr)) { /* Enable multicast options */ const int ttl = atoi(uaudio_get("multicast-ttl", "1")); @@ -228,31 +228,31 @@ static void rtp_open(void) { case PF_INET: { if(setsockopt(rtp_fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof ttl) < 0) - fatal(errno, "error setting IP_MULTICAST_TTL on multicast socket"); + disorder_fatal(errno, "error setting IP_MULTICAST_TTL on multicast socket"); if(setsockopt(rtp_fd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof loop) < 0) - fatal(errno, "error setting IP_MULTICAST_LOOP on multicast socket"); + disorder_fatal(errno, "error setting IP_MULTICAST_LOOP on multicast socket"); break; } case PF_INET6: { if(setsockopt(rtp_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof ttl) < 0) - fatal(errno, "error setting IPV6_MULTICAST_HOPS on multicast socket"); + disorder_fatal(errno, "error setting IPV6_MULTICAST_HOPS on multicast socket"); if(setsockopt(rtp_fd, IPPROTO_IP, IPV6_MULTICAST_LOOP, &loop, sizeof loop) < 0) - fatal(errno, "error setting IPV6_MULTICAST_LOOP on multicast socket"); + disorder_fatal(errno, "error setting IPV6_MULTICAST_LOOP on multicast socket"); break; } default: - fatal(0, "unsupported address family %d", res->ai_family); + disorder_fatal(0, "unsupported address family %d", res->ai_family); } - info("multicasting on %s TTL=%d loop=%s", - format_sockaddr(res->ai_addr), ttl, loop ? "yes" : "no"); + disorder_info("multicasting on %s TTL=%d loop=%s", + format_sockaddr(res->ai_addr), ttl, loop ? "yes" : "no"); } else { struct ifaddrs *ifs; if(getifaddrs(&ifs) < 0) - fatal(errno, "error calling getifaddrs"); + disorder_fatal(errno, "error calling getifaddrs"); while(ifs) { /* (At least on Darwin) IFF_BROADCAST might be set but ifa_broadaddr * still a null pointer. It turns out that there's a subsequent entry @@ -265,35 +265,34 @@ static void rtp_open(void) { } if(ifs) { if(setsockopt(rtp_fd, SOL_SOCKET, SO_BROADCAST, &one, sizeof one) < 0) - fatal(errno, "error setting SO_BROADCAST on broadcast socket"); - info("broadcasting on %s (%s)", + disorder_fatal(errno, "error setting SO_BROADCAST on broadcast socket"); + disorder_info("broadcasting on %s (%s)", format_sockaddr(res->ai_addr), ifs->ifa_name); } else - info("unicasting on %s", format_sockaddr(res->ai_addr)); + disorder_info("unicasting on %s", format_sockaddr(res->ai_addr)); } /* Enlarge the socket buffer */ len = sizeof sndbuf; if(getsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, &len) < 0) - fatal(errno, "error getting SO_SNDBUF"); + disorder_fatal(errno, "error getting SO_SNDBUF"); if(target_sndbuf > sndbuf) { if(setsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF, &target_sndbuf, sizeof target_sndbuf) < 0) - error(errno, "error setting SO_SNDBUF to %d", target_sndbuf); + disorder_error(errno, "error setting SO_SNDBUF to %d", target_sndbuf); else - info("changed socket send buffer size from %d to %d", + disorder_info("changed socket send buffer size from %d to %d", sndbuf, target_sndbuf); } else - info("default socket send buffer is %d", - sndbuf); + disorder_info("default socket send buffer is %d", sndbuf); /* We might well want to set additional broadcast- or multicast-related * options here */ if(sres && bind(rtp_fd, sres->ai_addr, sres->ai_addrlen) < 0) - fatal(errno, "error binding broadcast socket to %s", - format_sockaddr(sres->ai_addr)); + disorder_fatal(errno, "error binding broadcast socket to %s", + format_sockaddr(sres->ai_addr)); if(connect(rtp_fd, res->ai_addr, res->ai_addrlen) < 0) - fatal(errno, "error connecting broadcast socket to %s", - format_sockaddr(res->ai_addr)); + disorder_fatal(errno, "error connecting broadcast socket to %s", + format_sockaddr(res->ai_addr)); } static void rtp_start(uaudio_callback *callback, @@ -308,8 +307,8 @@ static void rtp_start(uaudio_callback *callback, && uaudio_rate == 44100) rtp_payload = 11; else - fatal(0, "asked for %d/%d/%d 16/44100/1 and 16/44100/2", - uaudio_bits, uaudio_rate, uaudio_channels); + disorder_fatal(0, "asked for %d/%d/%d 16/44100/1 and 16/44100/2", + uaudio_bits, uaudio_rate, uaudio_channels); /* Various fields are required to have random initial values by RFC3550. The * packet contents are highly public so there's no point asking for very * strong randomness. */ diff --git a/lib/uaudio-thread.c b/lib/uaudio-thread.c index f04b84b..e42980c 100644 --- a/lib/uaudio-thread.c +++ b/lib/uaudio-thread.c @@ -245,12 +245,12 @@ void uaudio_thread_start(uaudio_callback *callback, NULL, uaudio_collect_thread_fn, NULL))) - fatal(e, "pthread_create"); + disorder_fatal(e, "pthread_create"); if((e = pthread_create(&uaudio_play_thread, NULL, uaudio_play_thread_fn, NULL))) - fatal(e, "pthread_create"); + disorder_fatal(e, "pthread_create"); } /** @brief Shut down background threads for audio processing */ diff --git a/lib/url.c b/lib/url.c index e1740ac..7ee1f45 100644 --- a/lib/url.c +++ b/lib/url.c @@ -47,7 +47,7 @@ char *infer_url(int include_path_info) { /* Figure out the server. 'MUST' be set and we don't cope if it * is not. */ if(!(server = getenv("SERVER_NAME"))) - fatal(0, "SERVER_NAME is not set"); + disorder_fatal(0, "SERVER_NAME is not set"); server = xstrdup(server); /* Figure out the port. 'MUST' be set but we cope if it is not. */ @@ -67,7 +67,7 @@ char *infer_url(int include_path_info) { } else { /* RFC3875 s4.1.13 */ if(!(script = getenv("SCRIPT_NAME"))) - fatal(0, "SCRIPT_NAME is not set"); + disorder_fatal(0, "SCRIPT_NAME is not set"); /* SCRIPT_NAME may be "" */ if(!*script) script = "/"; @@ -78,7 +78,7 @@ char *infer_url(int include_path_info) { script, urlencodestring(path_info)); } if(script[0] != '/') - fatal(0, "SCRIPT_NAME does not start with a '/'"); + disorder_fatal(0, "SCRIPT_NAME does not start with a '/'"); script = xstrdup(script); if(port == 80) diff --git a/lib/user.c b/lib/user.c index 488caf9..100da16 100644 --- a/lib/user.c +++ b/lib/user.c @@ -42,21 +42,30 @@ void become_mortal(void) { if(config->user) { if(!(pw = getpwnam(config->user))) - fatal(0, "cannot find user %s", config->user); + disorder_fatal(0, "cannot find user %s", config->user); if(pw->pw_uid != getuid()) { if(initgroups(config->user, pw->pw_gid)) - fatal(errno, "error calling initgroups"); - if(setgid(pw->pw_gid) < 0) fatal(errno, "error calling setgid"); - if(setuid(pw->pw_uid) < 0) fatal(errno, "error calling setgid"); - info("changed to user %s (uid %lu)", config->user, (unsigned long)getuid()); + disorder_fatal(errno, "error calling initgroups"); + if(setgid(pw->pw_gid) < 0) + disorder_fatal(errno, "error calling setgid"); + if(setuid(pw->pw_uid) < 0) + disorder_fatal(errno, "error calling setgid"); + disorder_info("changed to user %s (uid %lu)", + config->user, (unsigned long)getuid()); } /* sanity checks */ - if(getuid() != pw->pw_uid) fatal(0, "wrong real uid"); - if(geteuid() != pw->pw_uid) fatal(0, "wrong effective uid"); - if(getgid() != pw->pw_gid) fatal(0, "wrong real gid"); - if(getegid() != pw->pw_gid) fatal(0, "wrong effective gid"); - if(setuid(0) != -1) fatal(0, "setuid(0) unexpectedly succeeded"); - if(seteuid(0) != -1) fatal(0, "seteuid(0) unexpectedly succeeded"); + if(getuid() != pw->pw_uid) + disorder_fatal(0, "wrong real uid"); + if(geteuid() != pw->pw_uid) + disorder_fatal(0, "wrong effective uid"); + if(getgid() != pw->pw_gid) + disorder_fatal(0, "wrong real gid"); + if(getegid() != pw->pw_gid) + disorder_fatal(0, "wrong effective gid"); + if(setuid(0) != -1) + disorder_fatal(0, "setuid(0) unexpectedly succeeded"); + if(seteuid(0) != -1) + disorder_fatal(0, "seteuid(0) unexpectedly succeeded"); } } @@ -84,13 +93,13 @@ void make_home(void) { } /* create the directory itself */ if(mkdir(config->home, 02755) < 0) - fatal(errno, "error creating %s", config->home); + disorder_fatal(errno, "error creating %s", config->home); /* make sure it has the right ownership */ if(config->user) { if(!(pw = getpwnam(config->user))) - fatal(0, "cannot find user %s", config->user); + disorder_fatal(0, "cannot find user %s", config->user); if(chown(config->home, pw->pw_uid, pw->pw_gid) < 0) - fatal(errno, "error chowning %s", config->home); + disorder_fatal(errno, "error chowning %s", config->home); } } } diff --git a/libtests/t-cgi.c b/libtests/t-cgi.c index 109a38a..f621495 100644 --- a/libtests/t-cgi.c +++ b/libtests/t-cgi.c @@ -26,7 +26,7 @@ static void input_from(const char *s) { || fputs("wibble wibble\r\nspong", fp) < 0 /* ensure CONTENT_LENGTH * honored */ || fflush(fp) < 0) - fatal(errno, "writing to temporary file"); + disorder_fatal(errno, "writing to temporary file"); rewind(fp); xdup2(fileno(fp), 0); lseek(0, 0/*offset*/, SEEK_SET); diff --git a/libtests/t-unicode.c b/libtests/t-unicode.c index de04e47..1505844 100644 --- a/libtests/t-unicode.c +++ b/libtests/t-unicode.c @@ -32,11 +32,11 @@ static FILE *open_unicode_test(const char *path) { snprintf(buffer, sizeof buffer, "wget http://www.unicode.org/Public/5.1.0/ucd/%s", path); if((w = system(buffer))) - fatal(0, "%s: %s", buffer, wstat(w)); + disorder_fatal(0, "%s: %s", buffer, wstat(w)); if(chmod(base, 0444) < 0) - fatal(errno, "chmod %s", base); + disorder_fatal(errno, "chmod %s", base); if(!(fp = fopen(base, "r"))) - fatal(errno, "%s", base); + disorder_fatal(errno, "%s", base); } return fp; } @@ -79,7 +79,7 @@ static void breaktest(const char *path, buffer[bn++] = strtoul(lp, &lp, 16); continue; } - fatal(0, "%s:%d: evil line: %s", path, lineno, l); + disorder_fatal(0, "%s:%d: evil line: %s", path, lineno, l); } for(n = 0; n <= bn; ++n) { if(breakfn(buffer, bn, n) != break_allowed[n]) { diff --git a/libtests/test.c b/libtests/test.c index 73bfdd2..354106b 100644 --- a/libtests/test.c +++ b/libtests/test.c @@ -102,7 +102,8 @@ uint32_t *ucs4parse(const char *s) { while(*s) { errno = 0; dynstr_ucs4_append(&d, strtoul(s, &e, 0)); - if(errno) fatal(errno, "strtoul (%s)", s); + if(errno) + disorder_fatal(errno, "strtoul (%s)", s); s = e; } dynstr_ucs4_terminate(&d); diff --git a/server/background.c b/server/background.c index 4b8a49b..4901047 100644 --- a/server/background.c +++ b/server/background.c @@ -50,7 +50,7 @@ int play_background(ev_source *ev, * modules use this so it's not well tested, unfortunately. */ if(q->type & DISORDER_PLAYER_PREFORK) if(!(q->data = play_prefork(q->pl, q->track))) { - error(0, "prefork function for %s failed", q->track); + disorder_error(0, "prefork function for %s failed", q->track); return START_HARDFAIL; } /* Capture the player/decoder's stderr and feed it into our logs. @@ -80,7 +80,7 @@ int play_background(ev_source *ev, ++optv; --optc; } else { - error(0, "unknown option %s", optv[0]); + disorder_error(0, "unknown option %s", optv[0]); return START_HARDFAIL; } } @@ -105,7 +105,7 @@ int play_background(ev_source *ev, _exit(child(q, params, bgdata)); case -1: /* Back in disorderd (child could not be created) */ - error(errno, "error calling fork"); + disorder_error(errno, "error calling fork"); if(q->type & DISORDER_PLAYER_PREFORK) play_cleanup(q->pl, q->data); /* else would leak */ if(lfd != -1) diff --git a/server/choose.c b/server/choose.c index 7347fb1..405a95d 100644 --- a/server/choose.c +++ b/server/choose.c @@ -97,7 +97,7 @@ static unsigned long compute_weight(const char *track, /* Reject tracks not in any collection (race between edit config and * rescan) */ if(!find_track_root(track)) { - info("found track not in any collection: %s", track); + disorder_info("found track not in any collection: %s", track); return 0; } @@ -264,7 +264,7 @@ int main(int argc, char **argv) { set_progname(argv); mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -274,14 +274,14 @@ int main(int argc, char **argv) { case 'D': debugging = 0; break; case 'S': logsyslog = 0; break; case 's': logsyslog = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(logsyslog) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); /* Find out current queue/recent list */ queue_read(); recent_read(); @@ -290,10 +290,10 @@ int main(int argc, char **argv) { trackdb_open(TRACKDB_NO_UPGRADE|TRACKDB_READ_ONLY); global_tid = trackdb_begin_transaction(); if((err = trackdb_get_global_tid("required-tags", global_tid, &tags))) - fatal(0, "error getting required-tags: %s", db_strerror(err)); + disorder_fatal(0, "error getting required-tags: %s", db_strerror(err)); required_tags = parsetags(tags); if((err = trackdb_get_global_tid("prohibited-tags", global_tid, &tags))) - fatal(0, "error getting prohibited-tags: %s", db_strerror(err)); + disorder_fatal(0, "error getting prohibited-tags: %s", db_strerror(err)); prohibited_tags = parsetags(tags); if(trackdb_scan(0, collect_tracks_callback, 0, global_tid)) { global_tid->abort(global_tid); @@ -304,9 +304,9 @@ int main(int argc, char **argv) { trackdb_deinit(NULL); D(("ntracks=%ld total_weight=%lld", ntracks, total_weight)); if(!total_weight) - fatal(0, "no tracks match random choice criteria"); + disorder_fatal(0, "no tracks match random choice criteria"); if(!winning) - fatal(0, "internal: failed to pick a track"); + disorder_fatal(0, "internal: failed to pick a track"); /* Pick a track */ xprintf("%s", winning); xfclose(stdout); diff --git a/server/daemonize.c b/server/daemonize.c index c86154b..960b4ad 100644 --- a/server/daemonize.c +++ b/server/daemonize.c @@ -41,7 +41,7 @@ void daemonize(const char *tag, int fac, const char *pidfile) { * /dev/null) */ do { if((dn = open("/dev/null", O_RDWR, 0)) < 0) - fatal(errno, "error opening /dev/null"); + disorder_fatal(errno, "error opening /dev/null"); } while(dn < 3); pid = xfork(); if(pid) { @@ -50,14 +50,16 @@ void daemonize(const char *tag, int fac, const char *pidfile) { exitfn = _exit; while((r = waitpid(pid, &w, 0)) == -1 && errno == EINTR) ; - if(r < 0) fatal(errno, "error calling waitpid"); - if(w) error(0, "subprocess exited with wait status %#x", (unsigned)w); + if(r < 0) disorder_fatal(errno, "error calling waitpid"); + if(w) + disorder_error(0, "subprocess exited with wait status %#x", (unsigned)w); _exit(0); } /* First child process. This will be the session leader, and will * be transient. */ D(("first child pid=%lu", (unsigned long)getpid())); - if(setsid() < 0) fatal(errno, "error calling setsid"); + if(setsid() < 0) + disorder_fatal(errno, "error calling setsid"); /* we'll log to syslog */ openlog(tag, LOG_PID, fac); log_default = &log_syslog; @@ -75,7 +77,7 @@ void daemonize(const char *tag, int fac, const char *pidfile) { if(!(fp = fopen(pidfile, "w")) || fprintf(fp, "%lu\n", (unsigned long)getpid()) < 0 || fclose(fp) < 0) - fatal(errno, "error creating %s", pidfile); + disorder_fatal(errno, "error creating %s", pidfile); } } diff --git a/server/dbparams.c b/server/dbparams.c index 60ba4a8..4ebd248 100644 --- a/server/dbparams.c +++ b/server/dbparams.c @@ -51,11 +51,11 @@ void dbparams_check(void) { for(;;) { DB_TXN *tid; if(oldparams) - info("database parameter string changed from %s to %s - removing old data", + disorder_info("database parameter string changed from %s to %s - removing old data", oldparams, newparams); else { - info("new database parameter string %s - removing old data", - newparams); + disorder_info("new database parameter string %s - removing old data", + newparams); /* This is a slightly annoying case; the global pref wasn't present. In * practice this is almost certainly either an upgrade (with no change to * any relevant parameters) or a new installation (with no tracks). @@ -75,14 +75,14 @@ void dbparams_check(void) { switch(err) { case 0: trackdb_commit_transaction(tid); - info("removed old data OK, will regenerate on rescan"); + disorder_info("removed old data OK, will regenerate on rescan"); return; case DB_LOCK_DEADLOCK: /* Deadlocked, try again */ trackdb_abort_transaction(tid); break; default: - fatal(0, "error updating database: %s", db_strerror(err)); + disorder_fatal(0, "error updating database: %s", db_strerror(err)); } } } @@ -94,7 +94,7 @@ static int dbparams_cleanup(DB_TXN *tid) { /* We'll regenerate search.db based on the new set of stopwords */ if((err = trackdb_searchdb->truncate(trackdb_searchdb, tid, &count, 0))) { - error(err, "truncating search.db: %s", db_strerror(err)); + disorder_error(err, "truncating search.db: %s", db_strerror(err)); return err; } /* We'll regenerate aliases based on the new alias/namepart settings, so @@ -107,25 +107,25 @@ static int dbparams_cleanup(DB_TXN *tid) { cursor = trackdb_opencursor(trackdb_tracksdb, tid); if((err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d), DB_FIRST)) == DB_LOCK_DEADLOCK) { - error(0, "cursor->c_get: %s", db_strerror(err)); + disorder_error(0, "cursor->c_get: %s", db_strerror(err)); goto done; } while(err == 0) { struct kvp *data = kvp_urldecode(d.data, d.size); if(kvp_get(data, "_alias_for")) { if((err = cursor->c_del(cursor, 0))) { - error(0, "cursor->c_del: %s", db_strerror(err)); + disorder_error(0, "cursor->c_del: %s", db_strerror(err)); goto done; } } err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d), DB_NEXT); } if(err == DB_LOCK_DEADLOCK) { - error(0, "cursor operation: %s", db_strerror(err)); + disorder_error(0, "cursor operation: %s", db_strerror(err)); goto done; } if(err != DB_NOTFOUND) - fatal(0, "cursor->c_get: %s", db_strerror(err)); + disorder_fatal(0, "cursor->c_get: %s", db_strerror(err)); err = 0; done: if(trackdb_closecursor(cursor) && !err) err = DB_LOCK_DEADLOCK; @@ -151,7 +151,7 @@ static char *compute_dbparams(void) { gcrypt_hash_handle h; if((e = gcry_md_open(&h, GCRY_MD_SHA256, 0))) - fatal(0, "gcry_md_open: %s", gcry_strerror(e)); + disorder_fatal(0, "gcry_md_open: %s", gcry_strerror(e)); h_write_string(h, "alias"); h_write_string(h, config->alias); for(int n = 0; n < config->stopword.n; ++n) { diff --git a/server/dbupgrade.c b/server/dbupgrade.c index 09dd789..18e6aa1 100644 --- a/server/dbupgrade.c +++ b/server/dbupgrade.c @@ -92,24 +92,24 @@ static int scan_core(const char *name, DB *db, break; ++count; if(count % 1000 == 0) - info("scanning %s, %ld so far", name, count); + disorder_info("scanning %s, %ld so far", name, count); } if(err && err != DB_NOTFOUND && err != DB_LOCK_DEADLOCK) - fatal(0, "%s: error scanning database: %s", name, db_strerror(err)); + disorder_fatal(0, "%s: error scanning database: %s", name, db_strerror(err)); r = (err == DB_LOCK_DEADLOCK ? err : 0); if((err = c->c_close(c))) - fatal(0, "%s: error closing cursor: %s", name, db_strerror(err)); - info("%s: %ld entries scanned", name, count); + disorder_fatal(0, "%s: error closing cursor: %s", name, db_strerror(err)); + disorder_info("%s: %ld entries scanned", name, count); if(values_normalized || values_already_ok) - info("%s: %ld values converted, %ld already ok", name, - values_normalized, values_already_ok); + disorder_info("%s: %ld values converted, %ld already ok", name, + values_normalized, values_already_ok); if(keys_normalized || keys_already_ok) - info("%s: %ld keys converted, %ld already OK", name, - keys_normalized, keys_already_ok); + disorder_info("%s: %ld keys converted, %ld already OK", name, + keys_normalized, keys_already_ok); if(aliases_removed) - info("%s: %ld aliases removed", name, aliases_removed); + disorder_info("%s: %ld aliases removed", name, aliases_removed); if(renoticed) - info("%s: %ld tracks re-noticed", name, renoticed); + disorder_info("%s: %ld tracks re-noticed", name, renoticed); return r; } @@ -121,13 +121,13 @@ static int scan_core(const char *name, DB *db, static void scandb(const char *name, DB *db, int (*callback)(const char *name, DB *db, DBC *c, DBT *k, DBT *d)) { - info("scanning %s", name); + disorder_info("scanning %s", name); for(;;) { global_tid = trackdb_begin_transaction(); if(scan_core(name, db, callback)) { trackdb_abort_transaction(global_tid); global_tid = 0; - error(0, "detected deadlock, restarting scan"); + disorder_error(0, "detected deadlock, restarting scan"); continue; } else { trackdb_commit_transaction(global_tid); @@ -146,7 +146,7 @@ static void truncate_database(const char *name, DB *db) { err = db->truncate(db, 0, &count, DB_AUTO_COMMIT); } while(err == DB_LOCK_DEADLOCK); if(err) - fatal(0, "error truncating %s: %s", name, db_strerror(err)); + disorder_fatal(0, "error truncating %s: %s", name, db_strerror(err)); } /* scan callbacks */ @@ -162,22 +162,22 @@ static int normalize_keys(const char *name, DB *db, DBC *c, if(!knfc) { switch(badkey) { case BADKEY_WARN: - error(0, "%s: invalid key: %.*s", name, - (int)k->size, (const char *)k->data); + disorder_error(0, "%s: invalid key: %.*s", name, + (int)k->size, (const char *)k->data); break; case BADKEY_DELETE: - error(0, "%s: deleting invalid key: %.*s", name, - (int)k->size, (const char *)k->data); + disorder_error(0, "%s: deleting invalid key: %.*s", name, + (int)k->size, (const char *)k->data); if((err = c->c_del(c, 0))) { if(err != DB_LOCK_DEADLOCK) - fatal(0, "%s: error removing denormalized key: %s", - name, db_strerror(err)); + disorder_fatal(0, "%s: error removing denormalized key: %s", + name, db_strerror(err)); return err; } break; case BADKEY_FAIL: - fatal(0, "%s: invalid key: %.*s", name, - (int)k->size, (const char *)k->data); + disorder_fatal(0, "%s: invalid key: %.*s", name, + (int)k->size, (const char *)k->data); } return 0; } @@ -189,15 +189,16 @@ static int normalize_keys(const char *name, DB *db, DBC *c, /* To rename the key we must delete the old one and insert a new one */ if((err = c->c_del(c, 0))) { if(err != DB_LOCK_DEADLOCK) - fatal(0, "%s: error removing denormalized key: %s", - name, db_strerror(err)); + disorder_fatal(0, "%s: error removing denormalized key: %s", + name, db_strerror(err)); return err; } k->size = nknfc; k->data = knfc; if((err = db->put(db, global_tid, k, d, DB_NOOVERWRITE))) { if(err != DB_LOCK_DEADLOCK) - fatal(0, "%s: error storing normalized key: %s", name, db_strerror(err)); + disorder_fatal(0, "%s: error storing normalized key: %s", + name, db_strerror(err)); return err; } ++keys_normalized; @@ -214,8 +215,8 @@ static int normalize_values(const char *name, DB *db, /* Find the normalized form of the value */ dnfc = utf8_compose_canon(d->data, d->size, &ndnfc); if(!dnfc) - fatal(0, "%s: cannot convert data to NFC: %.*s", name, - (int)d->size, (const char *)d->data); + disorder_fatal(0, "%s: cannot convert data to NFC: %.*s", name, + (int)d->size, (const char *)d->data); /* If the key is already in NFC then do nothing */ if(ndnfc == d->size && !memcmp(d->data, dnfc, ndnfc)) { ++values_already_ok; @@ -225,7 +226,8 @@ static int normalize_values(const char *name, DB *db, d->data = dnfc; if((err = db->put(db, global_tid, k, d, 0))) { if(err != DB_LOCK_DEADLOCK) - fatal(0, "%s: error storing normalized data: %s", name, db_strerror(err)); + disorder_fatal(0, "%s: error storing normalized data: %s", + name, db_strerror(err)); return err; } ++values_normalized; @@ -245,8 +247,8 @@ static int renotice(const char *name, DB attribute((unused)) *db, * in the scan. */ if(kvp_get(t, "_alias_for")) return 0; - fatal(0, "%s: no '_path' for %.*s", name, - (int)k->size, (const char *)k->data); + disorder_fatal(0, "%s: no '_path' for %.*s", name, + (int)k->size, (const char *)k->data); } switch(err = trackdb_notice_tid(track, path, global_tid)) { case 0: @@ -255,8 +257,8 @@ static int renotice(const char *name, DB attribute((unused)) *db, case DB_LOCK_DEADLOCK: return err; default: - fatal(0, "%s: unexpected return from trackdb_notice_tid: %s", - name, db_strerror(err)); + disorder_fatal(0, "%s: unexpected return from trackdb_notice_tid: %s", + name, db_strerror(err)); } } @@ -269,14 +271,14 @@ static int remove_aliases_normalize_keys(const char *name, DB *db, DBC *c, /* This is an alias. We remove all the alias entries. */ if((err = c->c_del(c, 0))) { if(err != DB_LOCK_DEADLOCK) - fatal(0, "%s: error removing alias: %s", name, db_strerror(err)); + disorder_fatal(0, "%s: error removing alias: %s", name, db_strerror(err)); return err; } ++aliases_removed; return 0; } else if(!kvp_get(t, "_path")) - error(0, "%s: %.*s has neither _alias_for nor _path", name, - (int)k->size, (const char *)k->data); + disorder_error(0, "%s: %.*s has neither _alias_for nor _path", name, + (int)k->size, (const char *)k->data); return normalize_keys(name, db, c, k, d); } @@ -288,16 +290,16 @@ static int remove_aliases_normalize_keys(const char *name, DB *db, DBC *c, static void upgrade(void) { char buf[32]; - info("upgrading database to dbversion %ld", config->dbversion); + disorder_info("upgrading database to dbversion %ld", config->dbversion); /* Normalize keys and values as required. We will also remove aliases as * they will be regenerated when we re-noticed the tracks. */ - info("renormalizing keys"); + disorder_info("renormalizing keys"); scandb("tracks.db", trackdb_tracksdb, remove_aliases_normalize_keys); scandb("prefs.db", trackdb_prefsdb, normalize_keys); scandb("global.db", trackdb_globaldb, normalize_keys); scandb("noticed.db", trackdb_noticeddb, normalize_values); /* search.db and tags.db we will rebuild */ - info("regenerating search database and aliases"); + disorder_info("regenerating search database and aliases"); truncate_database("search.db", trackdb_searchdb); truncate_database("tags.db", trackdb_tagsdb); /* Regenerate the search database and aliases */ @@ -305,7 +307,7 @@ static void upgrade(void) { /* Finally update the database version */ snprintf(buf, sizeof buf, "%ld", config->dbversion); trackdb_set_global("_dbversion", buf, 0); - info("completed database upgrade"); + disorder_info("completed database upgrade"); } int main(int argc, char **argv) { @@ -313,7 +315,7 @@ int main(int argc, char **argv) { set_progname(argv); mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dDSsxX", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -325,7 +327,7 @@ int main(int argc, char **argv) { case 's': logsyslog = 1; break; case 'x': badkey = BADKEY_DELETE; break; case 'X': badkey = BADKEY_FAIL; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } /* If stderr is a TTY then log there, otherwise to syslog. */ @@ -333,7 +335,7 @@ int main(int argc, char **argv) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); /* Open the database */ trackdb_init(TRACKDB_NO_RECOVER); trackdb_open(TRACKDB_OPEN_FOR_UPGRADE); diff --git a/server/deadlock.c b/server/deadlock.c index d90a123..72a82d4 100644 --- a/server/deadlock.c +++ b/server/deadlock.c @@ -54,7 +54,7 @@ int main(int argc, char **argv) { int n, err, aborted, logsyslog = !isatty(2); set_progname(argv); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -64,28 +64,28 @@ int main(int argc, char **argv) { case 'D': debugging = 0; break; case 'S': logsyslog = 0; break; case 's': logsyslog = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(logsyslog) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); - info("started"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); + disorder_info("started"); trackdb_init(TRACKDB_NO_RECOVER); while(getppid() != 1) { if((err = trackdb_env->lock_detect(trackdb_env, 0, DB_LOCK_DEFAULT, &aborted))) - fatal(0, "trackdb_env->lock_detect: %s", db_strerror(err)); + disorder_fatal(0, "trackdb_env->lock_detect: %s", db_strerror(err)); if(aborted) D(("aborted %d lock requests", aborted)); sleep(1); } /* if our parent goes away, it's time to stop */ - info("stopped (parent terminated)"); + disorder_info("stopped (parent terminated)"); return 0; } diff --git a/server/decode.c b/server/decode.c index 0c8893c..11a0592 100644 --- a/server/decode.c +++ b/server/decode.c @@ -63,14 +63,14 @@ static int input_count; /** @brief Write an 8-bit word */ static inline void output_8(int n) { if(putc(n, outputfp) < 0) - fatal(errno, "decoding %s: output error", path); + disorder_fatal(errno, "decoding %s: output error", path); } /** @brief Write a 16-bit word in bigendian format */ static inline void output_16(uint16_t n) { if(putc(n >> 8, outputfp) < 0 || putc(n, outputfp) < 0) - fatal(errno, "decoding %s: output error", path); + disorder_fatal(errno, "decoding %s: output error", path); } /** @brief Write a 24-bit word in bigendian format */ @@ -78,7 +78,7 @@ static inline void output_24(uint32_t n) { if(putc(n >> 16, outputfp) < 0 || putc(n >> 8, outputfp) < 0 || putc(n, outputfp) < 0) - fatal(errno, "decoding %s: output error", path); + disorder_fatal(errno, "decoding %s: output error", path); } /** @brief Write a 32-bit word in bigendian format */ @@ -87,7 +87,7 @@ static inline void output_32(uint32_t n) { || putc(n >> 16, outputfp) < 0 || putc(n >> 8, outputfp) < 0 || putc(n, outputfp) < 0) - fatal(errno, "decoding %s: output error", path); + disorder_fatal(errno, "decoding %s: output error", path); } /** @brief Write a block header @@ -98,7 +98,7 @@ static inline void output_32(uint32_t n) { * @param endian @ref ENDIAN_BIG or @ref ENDIAN_LITTLE * * Checks that the sample format is a supported one (so other calls do not have - * to) and calls fatal() on error. + * to) and calls disorder_fatal() on error. */ static void output_header(int rate, int channels, @@ -108,18 +108,20 @@ static void output_header(int rate, struct stream_header header; if(bits <= 0 || bits % 8 || bits > 64) - fatal(0, "decoding %s: unsupported sample size %d bits", path, bits); + disorder_fatal(0, "decoding %s: unsupported sample size %d bits", + path, bits); if(channels <= 0 || channels > 2) - fatal(0, "decoding %s: unsupported channel count %d", path, channels); + disorder_fatal(0, "decoding %s: unsupported channel count %d", + path, channels); if(rate <= 0) - fatal(0, "decoding %s: nonsensical sample rate %dHz", path, rate); + disorder_fatal(0, "decoding %s: nonsensical sample rate %dHz", path, rate); header.rate = rate; header.bits = bits; header.channels = channels; header.endian = endian; header.nbytes = nbytes; if(fwrite(&header, sizeof header, 1, outputfp) < 1) - fatal(errno, "decoding %s: writing format header", path); + disorder_fatal(errno, "decoding %s: writing format header", path); } /** @brief Dithering state @@ -239,7 +241,7 @@ static enum mad_flow mp3_input(void attribute((unused)) *data, /* Read new data */ n = read(inputfd, input_buffer + remain, (sizeof input_buffer) - remain); if(n < 0) - fatal(errno, "reading from %s", path); + disorder_fatal(errno, "reading from %s", path); /* Compute total number of bytes available */ input_count = remain + n; if(input_count) @@ -256,8 +258,8 @@ static enum mad_flow mp3_error(void attribute((unused)) *data, struct mad_frame attribute((unused)) *frame) { if(0) /* Just generates pointless verbosity l-( */ - error(0, "decoding %s: %s (%#04x)", - path, mad_stream_errorstr(stream), stream->error); + disorder_error(0, "decoding %s: %s (%#04x)", + path, mad_stream_errorstr(stream), stream->error); return MAD_FLOW_CONTINUE; } @@ -266,7 +268,7 @@ static void decode_mp3(void) { struct mad_decoder mad[1]; if((inputfd = open(path, O_RDONLY)) < 0) - fatal(errno, "opening %s", path); + disorder_fatal(errno, "opening %s", path); mad_decoder_init(mad, 0/*data*/, mp3_input, 0/*header*/, 0/*filter*/, mp3_output, mp3_error, 0/*message*/); if(mad_decoder_run(mad, MAD_DECODER_MODE_SYNC)) @@ -284,22 +286,22 @@ static void decode_ogg(void) { vorbis_info *vi; if(!(fp = fopen(path, "rb"))) - fatal(errno, "cannot open %s", path); + disorder_fatal(errno, "cannot open %s", path); /* There doesn't seem to be any standard function for mapping the error codes * to strings l-( */ if((err = ov_open(fp, vf, 0/*initial*/, 0/*ibytes*/))) - fatal(0, "ov_fopen %s: %d", path, err); + disorder_fatal(0, "ov_fopen %s: %d", path, err); if(!(vi = ov_info(vf, 0/*link*/))) - fatal(0, "ov_info %s: failed", path); + disorder_fatal(0, "ov_info %s: failed", path); while((n = ov_read(vf, input_buffer, sizeof input_buffer, 1/*bigendianp*/, 2/*bytes/word*/, 1/*signed*/, &bitstream))) { if(n < 0) - fatal(0, "ov_read %s: %ld", path, n); + disorder_fatal(0, "ov_read %s: %ld", path, n); if(bitstream > 0) - fatal(0, "only single-bitstream ogg files are supported"); + disorder_fatal(0, "only single-bitstream ogg files are supported"); output_header(vi->rate, vi->channels, 16/*bits*/, n, ENDIAN_BIG); if(fwrite(input_buffer, 1, n, outputfp) < (size_t)n) - fatal(errno, "decoding %s: writing sample data", path); + disorder_fatal(errno, "decoding %s: writing sample data", path); } } @@ -309,7 +311,7 @@ static int wav_write(struct wavfile attribute((unused)) *f, size_t nbytes, void attribute((unused)) *u) { if(fwrite(data, 1, nbytes, outputfp) < nbytes) - fatal(errno, "decoding %s: writing sample data", path); + disorder_fatal(errno, "decoding %s: writing sample data", path); return 0; } @@ -319,10 +321,10 @@ static void decode_wav(void) { int err; if((err = wav_init(f, path))) - fatal(err, "opening %s", path); + disorder_fatal(err, "opening %s", path); output_header(f->rate, f->channels, f->bits, f->datasize, ENDIAN_LITTLE); if((err = wav_data(f, wav_write, 0))) - fatal(err, "error decoding %s", path); + disorder_fatal(err, "error decoding %s", path); } /** @brief Metadata callback for FLAC decoder @@ -338,8 +340,8 @@ static void flac_metadata(const FLAC__FileDecoder attribute((unused)) *decoder, static void flac_error(const FLAC__FileDecoder attribute((unused)) *decoder, FLAC__StreamDecoderErrorStatus status, void attribute((unused)) *client_data) { - fatal(0, "error decoding %s: %s", path, - FLAC__StreamDecoderErrorStatusString[status]); + disorder_fatal(0, "error decoding %s: %s", path, + FLAC__StreamDecoderErrorStatusString[status]); } /** @brief Write callback for FLAC decoder */ @@ -377,26 +379,26 @@ static void decode_flac(void) { FLAC__FileDecoderState fs; if(!(fd = FLAC__file_decoder_new())) - fatal(0, "FLAC__file_decoder_new failed"); + disorder_fatal(0, "FLAC__file_decoder_new failed"); if(!(FLAC__file_decoder_set_filename(fd, path))) - fatal(0, "FLAC__file_set_filename failed"); + disorder_fatal(0, "FLAC__file_set_filename failed"); FLAC__file_decoder_set_metadata_callback(fd, flac_metadata); FLAC__file_decoder_set_error_callback(fd, flac_error); FLAC__file_decoder_set_write_callback(fd, flac_write); if((fs = FLAC__file_decoder_init(fd))) - fatal(0, "FLAC__file_decoder_init: %s", FLAC__FileDecoderStateString[fs]); + disorder_fatal(0, "FLAC__file_decoder_init: %s", FLAC__FileDecoderStateString[fs]); FLAC__file_decoder_process_until_end_of_file(fd); #else FLAC__StreamDecoder *sd = FLAC__stream_decoder_new(); FLAC__StreamDecoderInitStatus is; if (!sd) - fatal(0, "FLAC__stream_decoder_new failed"); + disorder_fatal(0, "FLAC__stream_decoder_new failed"); if((is = FLAC__stream_decoder_init_file(sd, path, flac_write, flac_metadata, flac_error, 0))) - fatal(0, "FLAC__stream_decoder_init_file %s: %s", - path, FLAC__StreamDecoderInitStatusString[is]); + disorder_fatal(0, "FLAC__stream_decoder_init_file %s: %s", + path, FLAC__StreamDecoderInitStatusString[is]); FLAC__stream_decoder_process_until_end_of_stream(sd); FLAC__stream_decoder_finish(sd); @@ -442,21 +444,21 @@ int main(int argc, char **argv) { const char *e; set_progname(argv); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "calling setlocale"); while((n = getopt_long(argc, argv, "hV", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version("disorder-decode"); - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(optind >= argc) - fatal(0, "missing filename"); + disorder_fatal(0, "missing filename"); if(optind + 1 < argc) - fatal(0, "excess arguments"); + disorder_fatal(0, "excess arguments"); if((e = getenv("DISORDER_RAW_FD"))) { if(!(outputfp = fdopen(atoi(e), "wb"))) - fatal(errno, "fdopen"); + disorder_fatal(errno, "fdopen"); } else outputfp = stdout; path = argv[optind]; @@ -466,7 +468,7 @@ int main(int argc, char **argv) { ++n) ; if(!decoders[n].pattern) - fatal(0, "cannot determine file type for %s", path); + disorder_fatal(0, "cannot determine file type for %s", path); decoders[n].decode(); xfclose(outputfp); return 0; diff --git a/server/disorderd.c b/server/disorderd.c index ab88190..14b459f 100644 --- a/server/disorderd.c +++ b/server/disorderd.c @@ -57,7 +57,7 @@ static void help(void) { static int handle_sighup(ev_source attribute((unused)) *ev_, int attribute((unused)) sig, void attribute((unused)) *u) { - info("received SIGHUP"); + disorder_info("received SIGHUP"); reconfigure(ev, RECONFIGURE_RELOADING); return 0; } @@ -67,14 +67,14 @@ static int handle_sighup(ev_source attribute((unused)) *ev_, static int handle_sigint(ev_source attribute((unused)) *ev_, int attribute((unused)) sig, void attribute((unused)) *u) { - info("received SIGINT"); + disorder_info("received SIGINT"); quit(ev); } static int handle_sigterm(ev_source attribute((unused)) *ev_, int attribute((unused)) sig, void attribute((unused)) *u) { - info("received SIGTERM"); + disorder_info("received SIGTERM"); quit(ev); } @@ -159,7 +159,7 @@ static void fix_path(void) { /* static or libgc collects it! */ if(!path) - error(0, "PATH is not set at all!"); + disorder_error(0, "PATH is not set at all!"); if(*finkbindir && strcmp(finkbindir, "/")) /* We appear to be a finkized mac; include fink on the path in case the @@ -169,7 +169,7 @@ static void fix_path(void) { else byte_xasprintf(&newpath, "PATH=%s:%s:%s", path, bindir, sbindir); putenv(newpath); - info("%s", newpath); + disorder_info("%s", newpath); } int main(int argc, char **argv) { @@ -179,7 +179,8 @@ int main(int argc, char **argv) { set_progname(argv); mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) + disorder_fatal(errno, "error calling setlocale"); /* garbage-collect PCRE's memory */ pcre_malloc = xmalloc; pcre_free = xfree; @@ -193,7 +194,7 @@ int main(int argc, char **argv) { case 'P': pidfile = optarg; break; case 's': logsyslog = 1; break; case 'w': wideopen = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } /* go into background if necessary */ @@ -205,7 +206,7 @@ int main(int argc, char **argv) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - info("process ID %lu", (unsigned long)getpid()); + disorder_info("process ID %lu", (unsigned long)getpid()); fix_path(); srand(xtime(0)); /* don't start the same every time */ /* gcrypt initialization */ @@ -216,22 +217,22 @@ int main(int argc, char **argv) { /* make sure we can't have more than FD_SETSIZE files open (event.c does * check but this provides an additional line of defence) */ if(getrlimit(RLIMIT_NOFILE, rl) < 0) - fatal(errno, "getrlimit RLIMIT_NOFILE"); + disorder_fatal(errno, "getrlimit RLIMIT_NOFILE"); if(rl->rlim_cur > FD_SETSIZE) { rl->rlim_cur = FD_SETSIZE; if(setrlimit(RLIMIT_NOFILE, rl) < 0) - fatal(errno, "setrlimit to reduce RLIMIT_NOFILE to %lu", - (unsigned long)rl->rlim_cur); - info("set RLIM_NOFILE to %lu", (unsigned long)rl->rlim_cur); + disorder_fatal(errno, "setrlimit to reduce RLIMIT_NOFILE to %lu", + (unsigned long)rl->rlim_cur); + disorder_info("set RLIM_NOFILE to %lu", (unsigned long)rl->rlim_cur); } else - info("RLIM_NOFILE is %lu", (unsigned long)rl->rlim_cur); + disorder_info("RLIM_NOFILE is %lu", (unsigned long)rl->rlim_cur); /* create event loop */ ev = ev_new(); - if(ev_child_setup(ev)) fatal(0, "ev_child_setup failed"); + if(ev_child_setup(ev)) disorder_fatal(0, "ev_child_setup failed"); /* read config */ config_uaudio_apis = uaudio_apis; if(config_read(1, NULL)) - fatal(0, "cannot read configuration"); + disorder_fatal(0, "cannot read configuration"); /* make sure the home directory exists and has suitable permissions */ make_home(); /* Start the speaker process (as root! - so it can choose its nice value) */ @@ -242,7 +243,8 @@ int main(int argc, char **argv) { /* change user */ become_mortal(); /* make sure we're not root, whatever the config says */ - if(getuid() == 0 || geteuid() == 0) fatal(0, "do not run as root"); + if(getuid() == 0 || geteuid() == 0) + disorder_fatal(0, "do not run as root"); /* open a lockfile - we only want one copy of the server to run at once. */ if(1) { const char *lockfile; @@ -251,20 +253,20 @@ int main(int argc, char **argv) { lockfile = config_get_file("lock"); if((lockfd = open(lockfile, O_RDWR|O_CREAT, 0600)) < 0) - fatal(errno, "error opening %s", lockfile); + disorder_fatal(errno, "error opening %s", lockfile); cloexec(lockfd); memset(&lock, 0, sizeof lock); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; if(fcntl(lockfd, F_SETLK, &lock) < 0) - fatal(errno, "error locking %s", lockfile); + disorder_fatal(errno, "error locking %s", lockfile); } /* initialize database environment */ trackdb_init(TRACKDB_NORMAL_RECOVER|TRACKDB_MAY_CREATE); trackdb_master(ev); /* install new config; don't create socket */ if(reconfigure(ev, RECONFIGURE_FIRST)) - fatal(0, "failed to read configuration"); + disorder_fatal(0, "failed to read configuration"); /* Open the database */ trackdb_open(TRACKDB_CAN_UPGRADE); /* load the queue and recently-played list */ @@ -281,10 +283,13 @@ int main(int argc, char **argv) { /* check for change to database parameters */ dbparams_check(); /* re-read config if we receive a SIGHUP */ - if(ev_signal(ev, SIGHUP, handle_sighup, 0)) fatal(0, "ev_signal failed"); + if(ev_signal(ev, SIGHUP, handle_sighup, 0)) + disorder_fatal(0, "ev_signal failed"); /* exit on SIGINT/SIGTERM */ - if(ev_signal(ev, SIGINT, handle_sigint, 0)) fatal(0, "ev_signal failed"); - if(ev_signal(ev, SIGTERM, handle_sigterm, 0)) fatal(0, "ev_signal failed"); + if(ev_signal(ev, SIGINT, handle_sigint, 0)) + disorder_fatal(0, "ev_signal failed"); + if(ev_signal(ev, SIGTERM, handle_sigterm, 0)) + disorder_fatal(0, "ev_signal failed"); /* ignore SIGPIPE */ signal(SIGPIPE, SIG_IGN); /* Rescan immediately and then daily */ @@ -300,7 +305,7 @@ int main(int argc, char **argv) { /* enter the event loop */ n = ev_run(ev); /* if we exit the event loop, something must have gone wrong */ - fatal(errno, "ev_run returned %d", n); + disorder_fatal(errno, "ev_run returned %d", n); } /* diff --git a/server/dump.c b/server/dump.c index 3a38352..cdc3a44 100644 --- a/server/dump.c +++ b/server/dump.c @@ -82,7 +82,7 @@ static int dump_one(struct sink *s, || sink_writec(s, '\n') < 0 || urlencode(s, d.data, d.size) || sink_writec(s, '\n') < 0) - fatal(errno, "error writing to %s", tag); + disorder_fatal(errno, "error writing to %s", tag); err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d), DB_NEXT); } @@ -95,7 +95,7 @@ static int dump_one(struct sink *s, case 0: assert(!"cannot happen"); default: - fatal(0, "error reading %s: %s", dbname, db_strerror(err)); + disorder_fatal(0, "error reading %s: %s", dbname, db_strerror(err)); } } @@ -121,13 +121,13 @@ static void do_dump(FILE *fp, const char *tag) { for(;;) { tid = trackdb_begin_transaction(); if(fseek(fp, 0, SEEK_SET) < 0) - fatal(errno, "error calling fseek"); + disorder_fatal(errno, "error calling fseek"); if(fflush(fp) < 0) - fatal(errno, "error calling fflush"); + disorder_fatal(errno, "error calling fflush"); if(ftruncate(fileno(fp), 0) < 0) - fatal(errno, "error calling ftruncate"); + disorder_fatal(errno, "error calling ftruncate"); if(fprintf(fp, "V0") < 0) - fatal(errno, "error writing to %s", tag); + disorder_fatal(errno, "error writing to %s", tag); for(size_t n = 0; n < NDBTABLE; ++n) if(dump_one(s, tag, dbtable[n].letter, dbtable[n].dbname, *dbtable[n].db, @@ -135,16 +135,16 @@ static void do_dump(FILE *fp, const char *tag) { goto fail; if(fputs("E\n", fp) < 0) - fatal(errno, "error writing to %s", tag); + disorder_fatal(errno, "error writing to %s", tag); break; fail: - info("aborting transaction and retrying dump"); + disorder_info("aborting transaction and retrying dump"); trackdb_abort_transaction(tid); } trackdb_commit_transaction(tid); - if(fflush(fp) < 0) fatal(errno, "error writing to %s", tag); + if(fflush(fp) < 0) disorder_fatal(errno, "error writing to %s", tag); /* caller might not be paranoid so we are paranoid on their behalf */ - if(fsync(fileno(fp)) < 0) fatal(errno, "error syncing %s", tag); + if(fsync(fileno(fp)) < 0) disorder_fatal(errno, "error syncing %s", tag); } /* delete all aliases prefs, return 0 or DB_LOCK_DEADLOCK */ @@ -155,11 +155,11 @@ static int remove_aliases(DB_TXN *tid, int remove_pathless) { struct kvp *data; int alias, pathless; - info("removing aliases"); + disorder_info("removing aliases"); cursor = trackdb_opencursor(trackdb_tracksdb, tid); if((err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d), DB_FIRST)) == DB_LOCK_DEADLOCK) { - error(0, "cursor->c_get: %s", db_strerror(err)); + disorder_error(0, "cursor->c_get: %s", db_strerror(err)); goto done; } while(err == 0) { @@ -167,24 +167,25 @@ static int remove_aliases(DB_TXN *tid, int remove_pathless) { alias = !!kvp_get(data, "_alias_for"); pathless = !kvp_get(data, "_path"); if(pathless && !remove_pathless) - info("no _path for %s", utf82mb(xstrndup(k.data, k.size))); + disorder_info("no _path for %s", utf82mb(xstrndup(k.data, k.size))); if(alias || (remove_pathless && pathless)) { switch(err = cursor->c_del(cursor, 0)) { case 0: break; case DB_LOCK_DEADLOCK: - error(0, "cursor->c_get: %s", db_strerror(err)); + disorder_error(0, "cursor->c_get: %s", db_strerror(err)); goto done; default: - fatal(0, "cursor->c_del: %s", db_strerror(err)); + disorder_fatal(0, "cursor->c_del: %s", db_strerror(err)); } } err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d), DB_NEXT); } if(err == DB_LOCK_DEADLOCK) { - error(0, "cursor operation: %s", db_strerror(err)); + disorder_error(0, "cursor operation: %s", db_strerror(err)); goto done; } - if(err != DB_NOTFOUND) fatal(0, "cursor->c_get: %s", db_strerror(err)); + if(err != DB_NOTFOUND) + disorder_fatal(0, "cursor->c_get: %s", db_strerror(err)); err = 0; done: if(trackdb_closecursor(cursor) && !err) err = DB_LOCK_DEADLOCK; @@ -199,10 +200,10 @@ static int truncdb(DB_TXN *tid, DB *db) { switch(err = db->truncate(db, tid, &count, 0)) { case 0: break; case DB_LOCK_DEADLOCK: - error(0, "db->truncate: %s", db_strerror(err)); + disorder_error(0, "db->truncate: %s", db_strerror(err)); break; default: - fatal(0, "db->truncate: %s", db_strerror(err)); + disorder_fatal(0, "db->truncate: %s", db_strerror(err)); } return err; } @@ -215,7 +216,7 @@ static int undump_dbt(FILE *fp, const char *tag, DBT *dbt) { if(inputline(tag, fp, &s, '\n')) return -1; dynstr_init(&d); if(urldecode(sink_dynstr(&d), s, strlen(s))) - fatal(0, "invalid URL-encoded data in %s", tag); + disorder_fatal(0, "invalid URL-encoded data in %s", tag); dbt->data = d.vec; dbt->size = d.nvec; return 0; @@ -225,9 +226,9 @@ static int undump_dbt(FILE *fp, const char *tag, DBT *dbt) { static int undump_from_fp(DB_TXN *tid, FILE *fp, const char *tag) { int err, c; - info("undumping"); + disorder_info("undumping"); if(fseek(fp, 0, SEEK_SET) < 0) - fatal(errno, "error calling fseek on %s", tag); + disorder_fatal(errno, "error calling fseek on %s", tag); if((err = truncdb(tid, trackdb_prefsdb))) return err; if((err = truncdb(tid, trackdb_globaldb))) return err; if((err = truncdb(tid, trackdb_searchdb))) return err; @@ -249,10 +250,10 @@ static int undump_from_fp(DB_TXN *tid, FILE *fp, const char *tag) { case 0: break; case DB_LOCK_DEADLOCK: - error(0, "error updating %s: %s", dbname, db_strerror(err)); + disorder_error(0, "error updating %s: %s", dbname, db_strerror(err)); return err; default: - fatal(0, "error updating %s: %s", dbname, db_strerror(err)); + disorder_fatal(0, "error updating %s: %s", dbname, db_strerror(err)); } goto next; } @@ -262,7 +263,7 @@ static int undump_from_fp(DB_TXN *tid, FILE *fp, const char *tag) { case 'V': c = getc(fp); if(c != '0') - fatal(0, "unknown version '%c'", c); + disorder_fatal(0, "unknown version '%c'", c); break; case 'E': return 0; @@ -270,17 +271,17 @@ static int undump_from_fp(DB_TXN *tid, FILE *fp, const char *tag) { break; default: if(c >= 32 && c <= 126) - fatal(0, "unexpected character '%c'", c); + disorder_fatal(0, "unexpected character '%c'", c); else - fatal(0, "unexpected character 0x%02X", c); + disorder_fatal(0, "unexpected character 0x%02X", c); } next: c = getc(fp); } if(ferror(fp)) - fatal(errno, "error reading %s", tag); + disorder_fatal(errno, "error reading %s", tag); else - fatal(0, "unexpected EOF reading %s", tag); + disorder_fatal(0, "unexpected EOF reading %s", tag); return 0; } @@ -293,7 +294,7 @@ static int recompute_aliases(DB_TXN *tid) { struct kvp *data; const char *path, *track; - info("recomputing aliases"); + disorder_info("recomputing aliases"); cursor = trackdb_opencursor(trackdb_tracksdb, tid); if((err = cursor->c_get(cursor, prepare_data(&k), prepare_data(&d), DB_FIRST)) == DB_LOCK_DEADLOCK) goto done; @@ -302,7 +303,7 @@ static int recompute_aliases(DB_TXN *tid) { track = xstrndup(k.data, k.size); if(!kvp_get(data, "_alias_for")) { if(!(path = kvp_get(data, "_path"))) - error(0, "%s is not an alias but has no path", utf82mb(track)); + disorder_error(0, "%s is not an alias but has no path", utf82mb(track)); else if((err = trackdb_notice_tid(track, path, tid)) == DB_LOCK_DEADLOCK) goto done; @@ -319,7 +320,7 @@ static int recompute_aliases(DB_TXN *tid) { case DB_LOCK_DEADLOCK: break; default: - fatal(0, "cursor->c_get: %s", db_strerror(err)); + disorder_fatal(0, "cursor->c_get: %s", db_strerror(err)); } done: if(trackdb_closecursor(cursor) && !err) err = DB_LOCK_DEADLOCK; @@ -337,10 +338,10 @@ static void do_undump(FILE *fp, const char *tag, int remove_pathless) { || recompute_aliases(tid)) goto fail; break; fail: - info("aborting transaction and retrying undump"); + disorder_info("aborting transaction and retrying undump"); trackdb_abort_transaction(tid); } - info("committing undump"); + disorder_info("committing undump"); trackdb_commit_transaction(tid); } @@ -354,10 +355,10 @@ static void do_recompute(int remove_pathless) { || recompute_aliases(tid)) goto fail; break; fail: - info("aborting transaction and retrying recomputation"); + disorder_info("aborting transaction and retrying recomputation"); trackdb_abort_transaction(tid); } - info("committing recomputed aliases"); + disorder_info("committing recomputed aliases"); trackdb_commit_transaction(tid); } @@ -381,23 +382,24 @@ int main(int argc, char **argv) { case 'R': recover = TRACKDB_FATAL_RECOVER; case 'a': recompute = 1; break; case 'P': remove_pathless = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(dump + undump + recompute != 1) - fatal(0, "choose exactly one of --dump, --undump or --recompute-aliases"); + disorder_fatal(0, "choose exactly one of --dump, --undump or --recompute-aliases"); if(recompute) { if(optind != argc) - fatal(0, "--recompute-aliases does not take a filename"); + disorder_fatal(0, "--recompute-aliases does not take a filename"); path = 0; } else { if(optind >= argc) - fatal(0, "missing dump file name"); + disorder_fatal(0, "missing dump file name"); if(optind + 1 < argc) - fatal(0, "specify only a dump file name"); + disorder_fatal(0, "specify only a dump file name"); path = argv[optind]; } - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(config_read(0, NULL)) + disorder_fatal(0, "cannot read configuration"); trackdb_init(recover|TRACKDB_MAY_CREATE); trackdb_open(TRACKDB_NO_UPGRADE); if(dump) { @@ -405,18 +407,20 @@ int main(int argc, char **argv) { * sure the permissions are tight from the start. */ byte_xasprintf(&tmp, "%s.%lx.tmp", path, (unsigned long)getpid()); if((fd = open(tmp, O_CREAT|O_TRUNC|O_WRONLY, 0600)) < 0) - fatal(errno, "error opening %s", tmp); + disorder_fatal(errno, "error opening %s", tmp); if(!(fp = fdopen(fd, "w"))) - fatal(errno, "fdopen on %s", tmp); + disorder_fatal(errno, "fdopen on %s", tmp); do_dump(fp, tmp); - if(fclose(fp) < 0) fatal(errno, "error closing %s", tmp); + if(fclose(fp) < 0) disorder_fatal(errno, "error closing %s", tmp); if(rename(tmp, path) < 0) - fatal(errno, "error renaming %s to %s", tmp, path); + disorder_fatal(errno, "error renaming %s to %s", tmp, path); } else if(undump) { /* the databases or logfiles might end up with wrong permissions * if new ones are created */ - if(getuid() == 0) info("you might need to chown database files"); - if(!(fp = fopen(path, "r"))) fatal(errno, "error opening %s", path); + if(getuid() == 0) + disorder_info("you might need to chown database files"); + if(!(fp = fopen(path, "r"))) + disorder_fatal(errno, "error opening %s", path); do_undump(fp, path, remove_pathless); xfclose(fp); } else if(recompute) { diff --git a/server/normalize.c b/server/normalize.c index 717f3cc..52df3d7 100644 --- a/server/normalize.c +++ b/server/normalize.c @@ -69,16 +69,16 @@ static void copy(int infd, int outfd, size_t n) { if(errno == EINTR) continue; else - fatal(errno, "read error"); + disorder_fatal(errno, "read error"); } if(readden == 0) - fatal(0, "unexpected EOF"); + disorder_fatal(0, "unexpected EOF"); n -= readden; written = 0; while(written < readden) { const ssize_t w = write(outfd, buffer + written, readden - written); if(w < 0) - fatal(errno, "write error"); + disorder_fatal(errno, "write error"); written += w; } } @@ -102,7 +102,7 @@ static void soxargs(const char ***pp, char **qq, case 16: *(*pp)++ = "-w"; break; case 32: *(*pp)++ = "-l"; break; case 64: *(*pp)++ = "-d"; break; - default: fatal(0, "cannot handle sample size %d", header->bits); + default: disorder_fatal(0, "cannot handle sample size %d", header->bits); } break; case 1: @@ -113,11 +113,11 @@ static void soxargs(const char ***pp, char **qq, case ENDIAN_LITTLE: *(*pp)++ = "-L"; break; } if(header->bits % 8) - fatal(0, "cannot handle sample size %d", header->bits); + disorder_fatal(0, "cannot handle sample size %d", header->bits); *qq += sprintf((char *)(*(*pp)++ = *qq), "-%d", header->bits / 8) + 1; break; default: - fatal(0, "unknown sox_generation %ld", config->sox_generation); + disorder_fatal(0, "unknown sox_generation %ld", config->sox_generation); } } @@ -128,7 +128,7 @@ int main(int argc, char attribute((unused)) **argv) { set_progname(argv); if(!setlocale(LC_CTYPE, "")) - fatal(errno, "error calling setlocale"); + disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -138,11 +138,11 @@ int main(int argc, char attribute((unused)) **argv) { case 'D': debugging = 0; break; case 'S': logsyslog = 0; break; case 's': logsyslog = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(config_read(1, NULL)) - fatal(0, "cannot read configuration"); + disorder_fatal(0, "cannot read configuration"); if(logsyslog) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; @@ -155,10 +155,10 @@ int main(int argc, char attribute((unused)) **argv) { if(r < 0) { if(errno != EINTR) - fatal(errno, "error reading header"); + disorder_fatal(errno, "error reading header"); } else if(r == 0) { if(n) - fatal(0, "EOF reading header"); + disorder_fatal(0, "EOF reading header"); break; } else n += r; @@ -167,14 +167,14 @@ int main(int argc, char attribute((unused)) **argv) { break; /* Sanity check the header */ if(header.rate < 100 || header.rate > 1000000) - fatal(0, "implausible rate %"PRId32"Hz (%#"PRIx32")", - header.rate, header.rate); + disorder_fatal(0, "implausible rate %"PRId32"Hz (%#"PRIx32")", + header.rate, header.rate); if(header.channels < 1 || header.channels > 2) - fatal(0, "unsupported channel count %d", header.channels); + disorder_fatal(0, "unsupported channel count %d", header.channels); if(header.bits % 8 || !header.bits || header.bits > 64) - fatal(0, "unsupported sample size %d bits", header.bits); + disorder_fatal(0, "unsupported sample size %d bits", header.bits); if(header.endian != ENDIAN_BIG && header.endian != ENDIAN_LITTLE) - fatal(0, "unsupported byte order %x", header.bits); + disorder_fatal(0, "unsupported byte order %x", header.bits); /* Skip empty chunks regardless of their alleged format */ if(header.nbytes == 0) continue; @@ -184,9 +184,9 @@ int main(int argc, char attribute((unused)) **argv) { /* There's a running converter, stop it */ xclose(outfd); if(waitpid(pid, &n, 0) < 0) - fatal(errno, "error calling waitpid"); + disorder_fatal(errno, "error calling waitpid"); if(n) - fatal(0, "sox failed: %#x", n); + disorder_fatal(0, "sox failed: %#x", n); pid = -1; outfd = -1; } @@ -209,7 +209,7 @@ int main(int argc, char attribute((unused)) **argv) { xclose(p[0]); xclose(p[1]); execvp(av[0], (char **)av); - fatal(errno, "sox"); + disorder_fatal(errno, "sox"); } xclose(p[0]); outfd = p[1]; @@ -227,9 +227,9 @@ int main(int argc, char attribute((unused)) **argv) { if(pid != -1) { /* There's still a converter running */ if(waitpid(pid, &n, 0) < 0) - fatal(errno, "error calling waitpid"); + disorder_fatal(errno, "error calling waitpid"); if(n) - fatal(0, "sox failed: %#x", n); + disorder_fatal(0, "sox failed: %#x", n); } return 0; } diff --git a/server/play.c b/server/play.c index a9a505f..f93fd5a 100644 --- a/server/play.c +++ b/server/play.c @@ -59,8 +59,7 @@ static int speaker_terminated(ev_source attribute((unused)) *ev, int attribute((unused)) status, const struct rusage attribute((unused)) *rusage, void attribute((unused)) *u) { - fatal(0, "speaker subprocess %s", - wstat(status)); + disorder_fatal(0, "speaker subprocess %s", wstat(status)); } /** @brief Called when we get a message from the speaker process */ @@ -92,7 +91,7 @@ static int speaker_readable(ev_source *ev, int fd, playing->sofar = sm.data; break; default: - error(0, "unknown speaker message type %d", sm.type); + disorder_error(0, "unknown speaker message type %d", sm.type); } return 0; } @@ -104,7 +103,7 @@ void speaker_setup(ev_source *ev) { struct speaker_message sm; if(socketpair(PF_UNIX, SOCK_DGRAM, 0, sp) < 0) - fatal(errno, "error calling socketpair"); + disorder_fatal(errno, "error calling socketpair"); if(!(pid = xfork())) { exitfn = _exit; ev_signal_atfork(ev); @@ -124,7 +123,7 @@ void speaker_setup(ev_source *ev) { log_default == &log_syslog ? "--syslog" : "--no-syslog", (char *)0); #endif - fatal(errno, "error invoking %s", SPEAKER); + disorder_fatal(errno, "error invoking %s", SPEAKER); } ev_child(ev, pid, 0, speaker_terminated, 0); speaker_fd = sp[1]; @@ -134,7 +133,7 @@ void speaker_setup(ev_source *ev) { speaker_recv(speaker_fd, &sm); nonblock(speaker_fd); if(ev_fd(ev, ev_read, speaker_fd, speaker_readable, 0, "speaker read") < 0) - fatal(0, "error registering speaker socket fd"); + disorder_fatal(0, "error registering speaker socket fd"); } /** @brief Tell the speaker to reload its configuration */ @@ -233,7 +232,7 @@ static int player_finished(ev_source *ev, /* Regardless we always report and record the status and do cleanup for * prefork calls. */ if(status) - error(0, "player for %s %s", q->track, wstat(status)); + disorder_error(0, "player for %s %s", q->track, wstat(status)); if(q->type & DISORDER_PLAYER_PREFORK) play_cleanup(q->pl, q->data); q->wstat = status; @@ -327,7 +326,7 @@ static int start_child(struct queue_entry *q, if(*params->waitdevice) { n = ao_driver_id(params->waitdevice); if(n == -1) - fatal(0, "invalid libao driver: %s", params->waitdevice); + disorder_fatal(0, "invalid libao driver: %s", params->waitdevice); } else n = ao_default_driver_id(); /* Make up a format. */ @@ -404,7 +403,7 @@ static int prepare_child(struct queue_entry *q, /* np will be the pipe to disorder-normalize */ int np[2]; if(socketpair(PF_UNIX, SOCK_STREAM, 0, np) < 0) - fatal(errno, "error calling socketpair"); + disorder_fatal(errno, "error calling socketpair"); /* Beware of the Leopard! On OS X 10.5.x, the order of the shutdown * calls here DOES MATTER. If you do the SHUT_WR first then the SHUT_RD * fails with "Socket is not connected". I think this is a bug but @@ -430,15 +429,15 @@ static int prepare_child(struct queue_entry *q, "%s/speaker/socket", config->home); int sfd = xsocket(PF_UNIX, SOCK_STREAM, 0); if(connect(sfd, (const struct sockaddr *)&addr, sizeof addr) < 0) - fatal(errno, "connecting to %s", addr.sun_path); + disorder_fatal(errno, "connecting to %s", addr.sun_path); /* Send the ID, with a NATIVE-ENDIAN 32 bit length */ uint32_t l = strlen(q->id); if(write(sfd, &l, sizeof l) < 0 || write(sfd, q->id, l) < 0) - fatal(errno, "writing to %s", addr.sun_path); + disorder_fatal(errno, "writing to %s", addr.sun_path); /* Await the ack */ if (read(sfd, &l, 1) < 0) - fatal(errno, "reading ack from %s", addr.sun_path); + disorder_fatal(errno, "reading ack from %s", addr.sun_path); /* Plumbing */ xdup2(np[0], 0); xdup2(sfd, 1); @@ -451,7 +450,7 @@ static int prepare_child(struct queue_entry *q, log_default == &log_syslog ? "--syslog" : "--no-syslog", "--config", configfile, (char *)0); - fatal(errno, "executing disorder-normalize"); + disorder_fatal(errno, "executing disorder-normalize"); /* End of the great-grandchild of disorderd */ } /* Back in the grandchild of disorderd */ @@ -468,7 +467,7 @@ static int prepare_child(struct queue_entry *q, char buffer[64]; snprintf(buffer, sizeof buffer, "DISORDER_RAW_FD=%d", np[1]); if(putenv(buffer) < 0) - fatal(errno, "error calling putenv"); + disorder_fatal(errno, "error calling putenv"); /* Close all the FDs we don't need */ xclose(np[0]); /* Start the decoder itself */ @@ -744,11 +743,11 @@ int pause_playing(const char *who) { case DISORDER_PLAYER_STANDALONE: if(!(playing->type & DISORDER_PLAYER_PAUSES)) { default: - error(0, "cannot pause because player is not powerful enough"); + disorder_error(0, "cannot pause because player is not powerful enough"); return -1; } if(play_pause(playing->pl, &played, playing->data)) { - error(0, "player indicates it cannot pause"); + disorder_error(0, "player indicates it cannot pause"); return -1; } xtime(&playing->lastpaused); @@ -761,7 +760,8 @@ int pause_playing(const char *who) { speaker_send(speaker_fd, &sm); break; } - if(who) info("paused by %s", who); + if(who) + disorder_info("paused by %s", who); notify_pause(playing->track, who); paused = 1; if(playing->state == playing_started) @@ -793,7 +793,7 @@ void resume_playing(const char *who) { speaker_send(speaker_fd, &sm); break; } - if(who) info("resumed by %s", who); + if(who) disorder_info("resumed by %s", who); notify_resume(playing->track, who); if(playing->state == playing_paused) playing->state = playing_started; diff --git a/server/plugin.c b/server/plugin.c index 6695d5a..7afbde9 100644 --- a/server/plugin.c +++ b/server/plugin.c @@ -54,7 +54,7 @@ const struct plugin *open_plugin(const char *name, if(access(p, R_OK) == 0) { h = dlopen(p, RTLD_NOW); if(!h) { - error(0, "error opening %s: %s", p, dlerror()); + disorder_error(0, "error opening %s: %s", p, dlerror()); continue; } pl = xmalloc(sizeof *pl); @@ -65,7 +65,8 @@ const struct plugin *open_plugin(const char *name, return pl; } } - (flags & PLUGIN_FATAL ? fatal : error)(0, "cannot find plugin '%s'", name); + (flags & PLUGIN_FATAL ? disorder_fatal : disorder_error) + (0, "cannot find plugin '%s'", name); return 0; } @@ -75,8 +76,8 @@ function_t *get_plugin_function(const struct plugin *pl, f = (function_t *)dlsym(pl->dlhandle, symbol); if(!f) - fatal(0, "error looking up function '%s' in '%s': %s", - symbol, pl->name, dlerror()); + disorder_fatal(0, "error looking up function '%s' in '%s': %s", + symbol, pl->name, dlerror()); return f; } @@ -86,8 +87,8 @@ const void *get_plugin_object(const struct plugin *pl, o = dlsym(pl->dlhandle, symbol); if(!o) - fatal(0, "error looking up object '%s' in '%s': %s", - symbol, pl->name, dlerror()); + disorder_fatal(0, "error looking up object '%s' in '%s': %s", + symbol, pl->name, dlerror()); return o; } diff --git a/server/queue-ops.c b/server/queue-ops.c index f2b3457..e513d16 100644 --- a/server/queue-ops.c +++ b/server/queue-ops.c @@ -154,7 +154,7 @@ int queue_move(struct queue_entry *q, int delta, const char *who) { } if(moved) { - info("user %s moved %s", who, q->id); + disorder_info("user %s moved %s", who, q->id); notify_queue_move(q->track, who); sprintf(buffer, "%d", moved); eventlog("moved", who, (char *)0); @@ -182,7 +182,7 @@ void queue_moveafter(struct queue_entry *target, queue_insert_entry(target, q); target = q; /* Log the individual tracks */ - info("user %s moved %s", who, q->id); + disorder_info("user %s moved %s", who, q->id); notify_queue_move(q->track, who); } /* Report that the queue changed to the event log */ @@ -191,7 +191,7 @@ void queue_moveafter(struct queue_entry *target, void queue_remove(struct queue_entry *which, const char *who) { if(who) { - info("user %s removed %s", who, which->id); + disorder_info("user %s removed %s", who, which->id); notify_queue_move(which->track, who); } eventlog("removed", which->id, who, (const char *)0); diff --git a/server/rescan.c b/server/rescan.c index f3e93f1..bc99681 100644 --- a/server/rescan.c +++ b/server/rescan.c @@ -70,12 +70,12 @@ static int aborted(void) { /* Exit if our parent has gone away or we have been told to stop. */ static void checkabort(void) { if(getppid() == 1) { - info("parent has terminated"); + disorder_info("parent has terminated"); trackdb_abort_transaction(global_tid); exit(0); } if(signalled) { - info("received signal %d", signalled); + disorder_info("received signal %d", signalled); trackdb_abort_transaction(global_tid); exit(0); } @@ -90,7 +90,7 @@ static void rescan_collection(const struct collection *c) { long ntracks = 0, nnew = 0; checkabort(); - info("rescanning %s with %s", c->root, c->module); + disorder_info("rescanning %s with %s", c->root, c->module); /* plugin runs in a subprocess */ xpipe(p); if(!(pid = xfork())) { @@ -100,29 +100,29 @@ static void rescan_collection(const struct collection *c) { xclose(p[1]); scan(c->module, c->root); if(fflush(stdout) < 0) - fatal(errno, "error writing to scanner pipe"); + disorder_fatal(errno, "error writing to scanner pipe"); _exit(0); } xclose(p[1]); if(!(fp = fdopen(p[0], "r"))) - fatal(errno, "error calling fdopen"); + disorder_fatal(errno, "error calling fdopen"); /* read tracks from the plugin */ while(!inputline("rescanner", fp, &path, 0)) { checkabort(); /* actually we can cope relatively well within the server, but they'll go * wrong in track listings */ if(strchr(path, '\n')) { - error(0, "cannot cope with tracks with newlines in the name"); + disorder_error(0, "cannot cope with tracks with newlines in the name"); continue; } if(!(track = any2utf8(c->encoding, path))) { - error(0, "cannot convert track path to UTF-8: %s", path); + disorder_error(0, "cannot convert track path to UTF-8: %s", path); continue; } if(config->dbversion > 1) { /* We use NFC track names */ if(!(track = utf8_compose_canon(track, strlen(track), 0))) { - error(0, "cannot convert track path to NFC: %s", path); + disorder_error(0, "cannot convert track path to NFC: %s", path); continue; } } @@ -135,27 +135,27 @@ static void rescan_collection(const struct collection *c) { nnew += !!trackdb_notice(track, path); ++ntracks; if(ntracks % 100 == 0 && xtime(0) > last_report + 10) { - info("rescanning %s, %ld tracks so far", c->root, ntracks); + disorder_info("rescanning %s, %ld tracks so far", c->root, ntracks); xtime(&last_report); } } } /* tidy up */ if(ferror(fp)) { - error(errno, "error reading from scanner pipe"); + disorder_error(errno, "error reading from scanner pipe"); goto done; } xfclose(fp); fp = 0; while((r = waitpid(pid, &w, 0)) == -1 && errno == EINTR) ; - if(r < 0) fatal(errno, "error calling waitpid"); + if(r < 0) disorder_fatal(errno, "error calling waitpid"); pid = 0; if(w) { - error(0, "scanner subprocess: %s", wstat(w)); + disorder_error(0, "scanner subprocess: %s", wstat(w)); goto done; } - info("rescanned %s, %ld tracks, %ld new", c->root, ntracks, nnew); + disorder_info("rescanned %s, %ld tracks, %ld new", c->root, ntracks, nnew); done: if(fp) xfclose(fp); @@ -229,7 +229,7 @@ static int recheck_track_tid(struct recheck_state *cs, if(fnmatch(config->tracklength.s[n].s[0], t->track, 0) == 0) break; if(n >= config->tracklength.n) - error(0, "no tracklength plugin found for %s", t->track); + disorder_error(0, "no tracklength plugin found for %s", t->track); else { length = tracklength(config->tracklength.s[n].s[1], t->track, path); if(length > 0) { @@ -259,9 +259,9 @@ static void recheck_collection(const struct collection *c) { long nrc; if(c) - info("rechecking %s", c->root); + disorder_info("rechecking %s", c->root); else - info("rechecking all tracks"); + disorder_info("rechecking all tracks"); /* Doing the checking inside a transaction locks up the server for much too * long (because it spends lots of time thinking about each track). So we * pull the full track list into memory and work from that. @@ -271,7 +271,7 @@ static void recheck_collection(const struct collection *c) { */ for(;;) { checkabort(); - info("getting track list"); + disorder_info("getting track list"); global_tid = trackdb_begin_transaction(); memset(&cs, 0, sizeof cs); cs.c = c; @@ -288,9 +288,9 @@ static void recheck_collection(const struct collection *c) { sleep(10); checkabort(); if(c) - info("resuming recheck of %s", c->root); + disorder_info("resuming recheck of %s", c->root); else - info("resuming global recheck"); + disorder_info("resuming global recheck"); } trackdb_commit_transaction(global_tid); global_tid = 0; @@ -302,17 +302,17 @@ static void recheck_collection(const struct collection *c) { ++nrc; if(nrc % 100 == 0 && xtime(0) > last_report + 10) { if(c) - info("rechecking %s, %ld tracks so far", c->root, nrc); + disorder_info("rechecking %s, %ld tracks so far", c->root, nrc); else - info("rechecking all tracks, %ld tracks so far", nrc); + disorder_info("rechecking all tracks, %ld tracks so far", nrc); xtime(&last_report); } } if(c) - info("rechecked %s, %ld obsoleted, %ld lengths calculated", - c->root, cs.nobsolete, cs.nlength); + disorder_info("rechecked %s, %ld obsoleted, %ld lengths calculated", + c->root, cs.nobsolete, cs.nlength); else - info("rechecked all tracks, %ld no collection, %ld obsoleted, %ld lengths calculated", + disorder_info("rechecked all tracks, %ld no collection, %ld obsoleted, %ld lengths calculated", cs.nnocollection, cs.nobsolete, cs.nlength); } @@ -327,7 +327,7 @@ static void do_directory(const char *s, if(n < config->collection.n) fn(&config->collection.s[n]); else - error(0, "no collection has root '%s'", s); + disorder_error(0, "no collection has root '%s'", s); } /* rescan/recheck all collections */ @@ -361,7 +361,7 @@ int main(int argc, char **argv) { set_progname(argv); mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dDSsKC", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -373,21 +373,21 @@ int main(int argc, char **argv) { case 's': logsyslog = 1; break; case 'K': do_check = 1; break; case 'C': do_check = 0; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(logsyslog) { openlog(progname, LOG_PID, LOG_DAEMON); log_default = &log_syslog; } - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); xnice(config->nice_rescan); sa.sa_handler = signal_handler; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); xsigaction(SIGTERM, &sa, 0); xsigaction(SIGINT, &sa, 0); - info("started"); + disorder_info("started"); trackdb_init(TRACKDB_NO_RECOVER); trackdb_open(TRACKDB_NO_UPGRADE); if(optind == argc) { @@ -410,7 +410,7 @@ int main(int argc, char **argv) { } trackdb_close(); trackdb_deinit(NULL); - info("completed"); + disorder_info("completed"); return 0; } diff --git a/server/schedule.c b/server/schedule.c index f93c0f0..f1b20a1 100644 --- a/server/schedule.c +++ b/server/schedule.c @@ -114,7 +114,8 @@ static int schedule_parse(const DBT *k, /* Reject bogus keys */ if(!k->size || k->size > 128) { - error(0, "bogus schedule.db key (%lu bytes)", (unsigned long)k->size); + disorder_error(0, "bogus schedule.db key (%lu bytes)", + (unsigned long)k->size); return -1; } id = xstrndup(k->data, k->size); @@ -122,8 +123,8 @@ static int schedule_parse(const DBT *k, /* Reject items without the required fields */ for(n = 0; n < NREQUIRED; ++n) { if(!kvp_get(actiondata, schedule_required[n])) { - error(0, "scheduled event %s: missing required field '%s'", - id, schedule_required[n]); + disorder_error(0, "scheduled event %s: missing required field '%s'", + id, schedule_required[n]); return -1; } } @@ -146,10 +147,10 @@ static int cdel(DBC *cursor) { case 0: break; case DB_LOCK_DEADLOCK: - error(0, "error deleting from schedule.db: %s", db_strerror(err)); + disorder_error(0, "error deleting from schedule.db: %s", db_strerror(err)); break; default: - fatal(0, "error deleting from schedule.db: %s", db_strerror(err)); + disorder_fatal(0, "error deleting from schedule.db: %s", db_strerror(err)); } return err; } @@ -188,7 +189,7 @@ static int schedule_init_tid(ev_source *ev, if(priority && !strcmp(priority, "junk")) { /* Junk actions that are in the past are discarded during startup */ /* TODO recurring events should be handled differently here */ - info("junk event %s is in the past, discarding", id); + disorder_info("junk event %s is in the past, discarding", id); if(cdel(cursor)) goto deadlocked; /* Skip this time */ @@ -203,10 +204,10 @@ static int schedule_init_tid(ev_source *ev, err = 0; break; case DB_LOCK_DEADLOCK: - error(0, "error querying schedule.db: %s", db_strerror(err)); + disorder_error(0, "error querying schedule.db: %s", db_strerror(err)); break; default: - fatal(0, "error querying schedule.db: %s", db_strerror(err)); + disorder_fatal(0, "error querying schedule.db: %s", db_strerror(err)); } deadlocked: if(trackdb_closecursor(cursor)) @@ -247,12 +248,12 @@ static int schedule_add_tid(const char *id, case 0: break; case DB_LOCK_DEADLOCK: - error(0, "error updating schedule.db: %s", db_strerror(err)); + disorder_error(0, "error updating schedule.db: %s", db_strerror(err)); return err; case DB_KEYEXIST: return err; default: - fatal(0, "error updating schedule.db: %s", db_strerror(err)); + disorder_fatal(0, "error updating schedule.db: %s", db_strerror(err)); } return 0; } @@ -276,8 +277,8 @@ const char *schedule_add(ev_source *ev, /* Check that the required field are present */ for(n = 0; n < NREQUIRED; ++n) { if(!kvp_get(actiondata, schedule_required[n])) { - error(0, "new scheduled event is missing required field '%s'", - schedule_required[n]); + disorder_error(0, "new scheduled event is missing required field '%s'", + schedule_required[n]); return 0; } } @@ -288,7 +289,7 @@ const char *schedule_add(ev_source *ev, when.tv_usec = 0; /* Reject events in the past */ if(when.tv_sec <= xtime(0)) { - error(0, "new scheduled event is in the past"); + disorder_error(0, "new scheduled event is in the past"); return 0; } do { @@ -313,8 +314,8 @@ struct kvp *schedule_get(const char *id) { /* Check that the required field are present */ for(n = 0; n < NREQUIRED; ++n) { if(!kvp_get(actiondata, schedule_required[n])) { - error(0, "scheduled event %s is missing required field '%s'", - id, schedule_required[n]); + disorder_error(0, "scheduled event %s is missing required field '%s'", + id, schedule_required[n]); return 0; } } @@ -362,18 +363,18 @@ static void schedule_play(ev_source *ev, /* This stuff has rather a lot in common with c_play() */ if(!track) { - error(0, "scheduled event %s: no track field", id); + disorder_error(0, "scheduled event %s: no track field", id); return; } if(!trackdb_exists(track)) { - error(0, "scheduled event %s: no such track as %s", id, track); + disorder_error(0, "scheduled event %s: no such track as %s", id, track); return; } if(!(track = trackdb_resolve(track))) { - error(0, "scheduled event %s: cannot resolve track %s", id, track); + disorder_error(0, "scheduled event %s: cannot resolve track %s", id, track); return; } - info("scheduled event %s: %s play %s", id, who, track); + disorder_info("scheduled event %s: %s play %s", id, who, track); q = queue_add(track, who, WHERE_START, NULL, origin_scheduled); queue_write(); if(q == qhead.next && playing) @@ -389,18 +390,19 @@ static void schedule_set_global(ev_source attribute((unused)) *ev, const char *value = kvp_get(actiondata, "value"); if(!key) { - error(0, "scheduled event %s: no key field", id); + disorder_error(0, "scheduled event %s: no key field", id); return; } if(key[0] == '_') { - error(0, "scheduled event %s: cannot set internal global preferences (%s)", - id, key); + disorder_error(0, "scheduled event %s: cannot set internal global preferences (%s)", + id, key); return; } if(value) - info("scheduled event %s: %s set-global %s=%s", id, who, key, value); + disorder_info("scheduled event %s: %s set-global %s=%s", + id, who, key, value); else - info("scheduled event %s: %s set-global %s unset", id, who, key); + disorder_info("scheduled event %s: %s set-global %s unset", id, who, key); trackdb_set_global(key, value, who); } @@ -438,27 +440,28 @@ static int schedule_lookup(const char *id, /* Look up the action */ n = TABLE_FIND(schedule_actions, name, action); if(n < 0) { - error(0, "scheduled event %s: unrecognized action '%s'", id, action); + disorder_error(0, "scheduled event %s: unrecognized action '%s'", + id, action); return -1; } /* Find the user */ if(!(userinfo = trackdb_getuserinfo(who))) { - error(0, "scheduled event %s: user '%s' does not exist", id, who); + disorder_error(0, "scheduled event %s: user '%s' does not exist", id, who); return -1; } /* Check that they have suitable rights */ if(!(rights = kvp_get(userinfo, "rights"))) { - error(0, "scheduled event %s: user %s' has no rights???", id, who); + disorder_error(0, "scheduled event %s: user %s' has no rights???", id, who); return -1; } if(parse_rights(rights, &r, 1)) { - error(0, "scheduled event %s: user %s has invalid rights '%s'", - id, who, rights); + disorder_error(0, "scheduled event %s: user %s has invalid rights '%s'", + id, who, rights); return -1; } if(!(r & schedule_actions[n].right)) { - error(0, "scheduled event %s: user %s lacks rights for action %s", - id, who, action); + disorder_error(0, "scheduled event %s: user %s lacks rights for action %s", + id, who, action); return -1; } return n; diff --git a/server/server-queue.c b/server/server-queue.c index ab15474..25dae71 100644 --- a/server/server-queue.c +++ b/server/server-queue.c @@ -61,7 +61,7 @@ void queue_fix_sofar(struct queue_entry *q) { static void queue_read_error(const char *msg, void *u) { - fatal(0, "error parsing queue %s: %s", (const char *)u, msg); + disorder_fatal(0, "error parsing queue %s: %s", (const char *)u, msg); } static void queue_do_read(struct queue_entry *head, const char *path) { @@ -73,7 +73,7 @@ static void queue_do_read(struct queue_entry *head, const char *path) { if(!(fp = fopen(path, "r"))) { if(errno == ENOENT) return; /* no queue */ - fatal(errno, "error opening %s", path); + disorder_fatal(errno, "error opening %s", path); } head->next = head->prev = head; while(!inputline(path, fp, &buffer, '\n')) { @@ -105,10 +105,11 @@ static void queue_do_read(struct queue_entry *head, const char *path) { if(head == &qhead && (!q->track || !q->when)) - fatal(0, "incomplete queue entry in %s", path); + disorder_fatal(0, "incomplete queue entry in %s", path); queue_insert_entry(head->prev, q); } - if(ferror(fp)) fatal(errno, "error reading %s", path); + if(ferror(fp)) + disorder_fatal(errno, "error reading %s", path); fclose(fp); } @@ -135,15 +136,15 @@ static void queue_do_write(const struct queue_entry *head, const char *path) { struct queue_entry *q; byte_xasprintf(&tmp, "%s.new", path); - if(!(fp = fopen(tmp, "w"))) fatal(errno, "error opening %s", tmp); + if(!(fp = fopen(tmp, "w"))) disorder_fatal(errno, "error opening %s", tmp); /* Save version indicator */ if(fprintf(fp, "#1\n") < 0) - fatal(errno, "error writing %s", tmp); + disorder_fatal(errno, "error writing %s", tmp); for(q = head->next; q != head; q = q->next) if(fprintf(fp, "%s\n", queue_marshall(q)) < 0) - fatal(errno, "error writing %s", tmp); - if(fclose(fp) < 0) fatal(errno, "error closing %s", tmp); - if(rename(tmp, path) < 0) fatal(errno, "error replacing %s", path); + disorder_fatal(errno, "error writing %s", tmp); + if(fclose(fp) < 0) disorder_fatal(errno, "error closing %s", tmp); + if(rename(tmp, path) < 0) disorder_fatal(errno, "error replacing %s", path); } void queue_write(void) { diff --git a/server/server.c b/server/server.c index 6866764..858edbc 100644 --- a/server/server.c +++ b/server/server.c @@ -165,7 +165,7 @@ static int writer_error(ev_source attribute((unused)) *ev, D(("S%x writer completed", c->tag)); } else { if(errno_value != EPIPE) - error(errno_value, "S%x write error on socket", c->tag); + disorder_error(errno_value, "S%x write error on socket", c->tag); if(c->r) { D(("cancel reader")); ev_reader_cancel(c->r); @@ -189,7 +189,7 @@ static int reader_error(ev_source attribute((unused)) *ev, struct conn *c = u; D(("server reader_error S%x %d", c->tag, errno_value)); - error(errno_value, "S%x read error on socket", c->tag); + disorder_error(errno_value, "S%x read error on socket", c->tag); if(c->w) ev_writer_close(c->w); c->w = 0; @@ -277,7 +277,7 @@ static int c_playafter(struct conn *c, char **vec, sink_printf(ev_writer_sink(c->w), "550 No such ID\n"); return 1; } - info("added %s as %s after %s", track, q->id, afterme); + disorder_info("added %s as %s after %s", track, q->id, afterme); afterme = q->id; } queue_write(); @@ -287,7 +287,7 @@ static int c_playafter(struct conn *c, char **vec, * prepare the same track twice so there's no point. */ if(qhead.next != &qhead) { prepare(c->ev, qhead.next); - info("prepared %s", qhead.next->id); + disorder_info("prepared %s", qhead.next->id); } /* If the queue was empty but we are for some reason paused then * unpause. */ @@ -306,7 +306,7 @@ static int c_remove(struct conn *c, char **vec, return 1; } if(!right_removable(c->rights, c->who, q)) { - error(0, "%s attempted remove but lacks required rights", c->who); + disorder_error(0, "%s attempted remove but lacks required rights", c->who); sink_writes(ev_writer_sink(c->w), "510 Not authorized to remove that track\n"); return 1; @@ -335,7 +335,7 @@ static int c_scratch(struct conn *c, * playing track then you will get 550 if you weren't authorized to scratch * the currently playing track. */ if(!right_scratchable(c->rights, c->who, playing)) { - error(0, "%s attempted scratch but lacks required rights", c->who); + disorder_error(0, "%s attempted scratch but lacks required rights", c->who); sink_writes(ev_writer_sink(c->w), "510 Not authorized to scratch that track\n"); return 1; @@ -380,7 +380,7 @@ static int c_resume(struct conn *c, static int c_shutdown(struct conn *c, char attribute((unused)) **vec, int attribute((unused)) nvec) { - info("S%x shut down by %s", c->tag, c->who); + disorder_info("S%x shut down by %s", c->tag, c->who); sink_writes(ev_writer_sink(c->w), "250 shutting down\n"); ev_writer_flush(c->w); quit(c->ev); @@ -389,7 +389,7 @@ static int c_shutdown(struct conn *c, static int c_reconfigure(struct conn *c, char attribute((unused)) **vec, int attribute((unused)) nvec) { - info("S%x reconfigure by %s", c->tag, c->who); + disorder_info("S%x reconfigure by %s", c->tag, c->who); if(reconfigure(c->ev, 1)) sink_writes(ev_writer_sink(c->w), "550 error reading new config\n"); else @@ -457,9 +457,9 @@ static int c_rescan(struct conn *c, } } /* Report what was requested */ - info("S%x rescan by %s (%s %s)", c->tag, c->who, - flag_wait ? "wait" : "", - flag_fresh ? "fresh" : ""); + disorder_info("S%x rescan by %s (%s %s)", c->tag, c->who, + flag_wait ? "wait" : "", + flag_fresh ? "fresh" : ""); if(trackdb_rescan_underway()) { if(flag_fresh) { /* We want a fresh rescan but there is already one underway. Arrange a @@ -533,13 +533,14 @@ static const char *connection_host(struct conn *c) { /* get connection data */ l = sizeof u; if(getpeername(c->fd, &u.sa, &l) < 0) { - error(errno, "S%x error calling getpeername", c->tag); + disorder_error(errno, "S%x error calling getpeername", c->tag); return 0; } if(c->l->pf != PF_UNIX) { if((n = getnameinfo(&u.sa, l, host, sizeof host, 0, 0, NI_NUMERICHOST))) { - error(0, "S%x error calling getnameinfo: %s", c->tag, gai_strerror(n)); + disorder_error(0, "S%x error calling getnameinfo: %s", + c->tag, gai_strerror(n)); return 0; } return xstrdup(host); @@ -567,20 +568,21 @@ static int c_user(struct conn *c, k = trackdb_getuserinfo(vec[0]); /* reject nonexistent users */ if(!k) { - error(0, "S%x unknown user '%s' from %s", c->tag, vec[0], host); + disorder_error(0, "S%x unknown user '%s' from %s", c->tag, vec[0], host); sink_writes(ev_writer_sink(c->w), "530 authentication failed\n"); return 1; } /* reject unconfirmed users */ if(kvp_get(k, "confirmation")) { - error(0, "S%x unconfirmed user '%s' from %s", c->tag, vec[0], host); + disorder_error(0, "S%x unconfirmed user '%s' from %s", + c->tag, vec[0], host); sink_writes(ev_writer_sink(c->w), "530 authentication failed\n"); return 1; } password = kvp_get(k, "password"); if(!password) password = ""; if(parse_rights(kvp_get(k, "rights"), &rights, 1)) { - error(0, "error parsing rights for %s", vec[0]); + disorder_error(0, "error parsing rights for %s", vec[0]); sink_writes(ev_writer_sink(c->w), "530 authentication failed\n"); return 1; } @@ -592,14 +594,15 @@ static int c_user(struct conn *c, c->rights = rights; /* currently we only bother logging remote connections */ if(strcmp(host, "local")) - info("S%x %s connected from %s", c->tag, vec[0], host); + disorder_info("S%x %s connected from %s", c->tag, vec[0], host); else c->rights |= RIGHT__LOCAL; sink_writes(ev_writer_sink(c->w), "230 OK\n"); return 1; } /* oops, response was wrong */ - info("S%x authentication failure for %s from %s", c->tag, vec[0], host); + disorder_info("S%x authentication failure for %s from %s", + c->tag, vec[0], host); sink_writes(ev_writer_sink(c->w), "530 authentication failed\n"); return 1; } @@ -915,7 +918,8 @@ static int c_volume(struct conn *c, } rights = set ? RIGHT_VOLUME : RIGHT_READ; if(!(c->rights & rights)) { - error(0, "%s attempted to set volume but lacks required rights", c->who); + disorder_error(0, "%s attempted to set volume but lacks required rights", + c->who); sink_writes(ev_writer_sink(c->w), "510 Prohibited\n"); return 1; } @@ -1044,7 +1048,7 @@ static int c_move(struct conn *c, return 1; } if(!has_move_rights(c, &q, 1)) { - error(0, "%s attempted move but lacks required rights", c->who); + disorder_error(0, "%s attempted move but lacks required rights", c->who); sink_writes(ev_writer_sink(c->w), "510 Not authorized to move that track\n"); return 1; @@ -1079,7 +1083,8 @@ static int c_moveafter(struct conn *c, return 1; } if(!has_move_rights(c, qs, nvec)) { - error(0, "%s attempted moveafter but lacks required rights", c->who); + disorder_error(0, "%s attempted moveafter but lacks required rights", + c->who); sink_writes(ev_writer_sink(c->w), "510 Not authorized to move those tracks\n"); return 1; @@ -1237,7 +1242,7 @@ static int c_cookie(struct conn *c, c->cookie = vec[0]; c->rights = rights; if(strcmp(host, "local")) - info("S%x %s connected with cookie from %s", c->tag, user, host); + disorder_info("S%x %s connected with cookie from %s", c->tag, user, host); else c->rights |= RIGHT__LOCAL; /* Response contains username so client knows who they are acting as */ @@ -1274,7 +1279,7 @@ static int c_adduser(struct conn *c, const char *rights; if(!config->remote_userman && !(c->rights & RIGHT__LOCAL)) { - error(0, "S%x: remote adduser", c->tag); + disorder_error(0, "S%x: remote adduser", c->tag); sink_writes(ev_writer_sink(c->w), "550 Remote user management is disabled\n"); return 1; } @@ -1300,7 +1305,7 @@ static int c_deluser(struct conn *c, struct conn *d; if(!config->remote_userman && !(c->rights & RIGHT__LOCAL)) { - error(0, "S%x: remote deluser", c->tag); + disorder_error(0, "S%x: remote deluser", c->tag); sink_writes(ev_writer_sink(c->w), "550 Remote user management is disabled\n"); return 1; } @@ -1322,7 +1327,7 @@ static int c_edituser(struct conn *c, struct conn *d; if(!config->remote_userman && !(c->rights & RIGHT__LOCAL)) { - error(0, "S%x: remote edituser", c->tag); + disorder_error(0, "S%x: remote edituser", c->tag); sink_writes(ev_writer_sink(c->w), "550 Remote user management is disabled\n"); return 1; } @@ -1363,7 +1368,8 @@ static int c_edituser(struct conn *c, } sink_writes(ev_writer_sink(c->w), "250 OK\n"); } else { - error(0, "%s attempted edituser but lacks required rights", c->who); + disorder_error(0, "%s attempted edituser but lacks required rights", + c->who); sink_writes(ev_writer_sink(c->w), "510 Restricted to administrators\n"); } return 1; @@ -1380,7 +1386,7 @@ static int c_userinfo(struct conn *c, if(!config->remote_userman && !(c->rights & RIGHT__LOCAL) && strcmp(vec[1], "rights")) { - error(0, "S%x: remote userinfo %s %s", c->tag, vec[0], vec[1]); + disorder_error(0, "S%x: remote userinfo %s %s", c->tag, vec[0], vec[1]); sink_writes(ev_writer_sink(c->w), "550 Remote user management is disabled\n"); return 1; } @@ -1398,7 +1404,8 @@ static int c_userinfo(struct conn *c, else sink_writes(ev_writer_sink(c->w), "550 No such user\n"); } else { - error(0, "%s attempted userinfo but lacks required rights", c->who); + disorder_error(0, "%s attempted userinfo but lacks required rights", + c->who); sink_writes(ev_writer_sink(c->w), "510 Restricted to administrators\n"); } return 1; @@ -1423,7 +1430,7 @@ static int c_register(struct conn *c, * letters and digits, minimizing the chance of the URL being mispasted. */ gcry_randomize(nonce, sizeof nonce, GCRY_STRONG_RANDOM); if(basen(nonce, CONFIRM_SIZE, nonce_str, sizeof nonce_str, 62)) { - error(0, "buffer too small encoding confirmation string"); + disorder_error(0, "buffer too small encoding confirmation string"); sink_writes(ev_writer_sink(c->w), "550 Cannot create user\n"); } byte_xasprintf(&cs, "%s/%s", vec[0], nonce_str); @@ -1459,7 +1466,7 @@ static int c_confirm(struct conn *c, c->cookie = 0; c->rights = rights; if(strcmp(host, "local")) - info("S%x %s confirmed from %s", c->tag, user, host); + disorder_info("S%x %s confirmed from %s", c->tag, user, host); else c->rights |= RIGHT__LOCAL; /* Response contains username so client knows who they are acting as */ @@ -1479,7 +1486,7 @@ static int sent_reminder(ev_source attribute((unused)) *ev, if(!status) { sink_writes(ev_writer_sink(c->w), "250 OK\n"); } else { - error(0, "reminder subprocess %s", wstat(status)); + disorder_error(0, "reminder subprocess %s", wstat(status)); sink_writes(ev_writer_sink(c->w), "550 Cannot send a reminder email\n"); } /* Re-enable this connection */ @@ -1499,24 +1506,24 @@ static int c_reminder(struct conn *c, static hash *last_reminder; if(!config->mail_sender) { - error(0, "cannot send password reminders because mail_sender not set"); + disorder_error(0, "cannot send password reminders because mail_sender not set"); sink_writes(ev_writer_sink(c->w), "550 Cannot send a reminder email\n"); return 1; } if(!(k = trackdb_getuserinfo(vec[0]))) { - error(0, "reminder for user '%s' who does not exist", vec[0]); + disorder_error(0, "reminder for user '%s' who does not exist", vec[0]); sink_writes(ev_writer_sink(c->w), "550 Cannot send a reminder email\n"); return 1; } if(!(email = kvp_get(k, "email")) || !email_valid(email)) { - error(0, "user '%s' has no valid email address", vec[0]); + disorder_error(0, "user '%s' has no valid email address", vec[0]); sink_writes(ev_writer_sink(c->w), "550 Cannot send a reminder email\n"); return 1; } if(!(password = kvp_get(k, "password")) || !*password) { - error(0, "user '%s' has no password", vec[0]); + disorder_error(0, "user '%s' has no password", vec[0]); sink_writes(ev_writer_sink(c->w), "550 Cannot send a reminder email\n"); return 1; } @@ -1528,7 +1535,7 @@ static int c_reminder(struct conn *c, last = hash_find(last_reminder, vec[0]); xtime(&now); if(last && now < *last + config->reminder_interval) { - error(0, "sent a password reminder to '%s' too recently", vec[0]); + disorder_error(0, "sent a password reminder to '%s' too recently", vec[0]); sink_writes(ev_writer_sink(c->w), "550 Cannot send a reminder email\n"); return 1; } @@ -1541,7 +1548,7 @@ static int c_reminder(struct conn *c, "\n" " %s\n", password); if(!(text = mime_encode_text(text, &charset, &encoding))) - fatal(0, "cannot encode email"); + disorder_fatal(0, "cannot encode email"); byte_xasprintf((char **)&content_type, "text/plain;charset=%s", quote822(charset, 0)); pid = sendmail_subprocess("", config->mail_sender, email, @@ -1552,7 +1559,7 @@ static int c_reminder(struct conn *c, return 1; } hash_add(last_reminder, vec[0], &now, HASH_INSERT_OR_REPLACE); - info("sending a passsword reminder to user '%s'", vec[0]); + disorder_info("sending a passsword reminder to user '%s'", vec[0]); /* We can only continue when the subprocess finishes */ ev_child(c->ev, pid, 0, sent_reminder, c); return 0; @@ -1993,7 +2000,8 @@ static int command(struct conn *c, char *line) { else { if(commands[n].rights && !(c->rights & commands[n].rights)) { - error(0, "%s attempted %s but lacks required rights", c->who ? c->who : "NULL", + disorder_error(0, "%s attempted %s but lacks required rights", + c->who ? c->who : "NULL", commands[n].name); sink_writes(ev_writer_sink(c->w), "510 Prohibited\n"); return 1; @@ -2056,7 +2064,7 @@ static int reader_callback(ev_source attribute((unused)) *ev, } if(eof) { if(bytes) - error(0, "S%x unterminated line", c->tag); + disorder_error(0, "S%x unterminated line", c->tag); D(("normal reader close")); c->r = 0; if(c->w) { @@ -2087,7 +2095,7 @@ static int listen_callback(ev_source *ev, c->w = ev_writer_new(ev, fd, writer_error, c, "client writer"); if(!c->w) { - error(0, "ev_writer_new for file inbound connection (fd=%d) failed", + disorder_error(0, "ev_writer_new for file inbound connection (fd=%d) failed", fd); close(fd); return 0; @@ -2097,7 +2105,9 @@ static int listen_callback(ev_source *ev, if(!c->r) /* Main reason for failure is the FD is too big and that will already have * been handled */ - fatal(0, "ev_reader_new for file inbound connection (fd=%d) failed", fd); + disorder_fatal(0, + "ev_reader_new for file inbound connection (fd=%d) failed", + fd); ev_tie(c->r, c->w); c->fd = fd; c->reader = reader_callback; @@ -2124,7 +2134,7 @@ int server_start(ev_source *ev, int pf, fd = xsocket(pf, SOCK_STREAM, 0); xsetsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); if(bind(fd, sa, socklen) < 0) { - error(errno, "error binding to %s", name); + disorder_error(errno, "error binding to %s", name); return -1; } xlisten(fd, 128); @@ -2134,7 +2144,7 @@ int server_start(ev_source *ev, int pf, l->pf = pf; if(ev_listen(ev, fd, listen_callback, l, "server listener")) exit(EXIT_FAILURE); - info("listening on %s", name); + disorder_info("listening on %s", name); return fd; } diff --git a/server/speaker.c b/server/speaker.c index 892e33c..de5692b 100644 --- a/server/speaker.c +++ b/server/speaker.c @@ -318,7 +318,7 @@ static int speaker_fill(struct track *t) { pthread_mutex_lock(&lock); if(n < 0) { if(errno != EAGAIN) - fatal(errno, "error reading sample stream"); + disorder_fatal(errno, "error reading sample stream"); rc = 0; } else if(n == 0) { D(("fill %s: eof detected", t->id)); @@ -440,9 +440,10 @@ static size_t speaker_callback(void *buffer, memset(buffer, 0, max_bytes); provided_samples = max_samples; if(playing) - info("%zu samples silence, playing->used=%zu", provided_samples, playing->used); + disorder_info("%zu samples silence, playing->used=%zu", + provided_samples, playing->used); else - info("%zu samples silence, playing=NULL", provided_samples); + disorder_info("%zu samples silence, playing=NULL", provided_samples); } pthread_mutex_unlock(&lock); return provided_samples; @@ -495,7 +496,7 @@ static void mainloop(void) { pthread_mutex_lock(&lock); if(n < 0) { if(errno == EINTR) continue; - fatal(errno, "error calling poll"); + disorder_fatal(errno, "error calling poll"); } /* Perhaps a connection has arrived */ if(fds[listen_slot].revents & POLLIN) { @@ -507,22 +508,22 @@ static void mainloop(void) { if((fd = accept(listenfd, (struct sockaddr *)&addr, &addrlen)) >= 0) { blocking(fd); if(read(fd, &l, sizeof l) < 4) { - error(errno, "reading length from inbound connection"); + disorder_error(errno, "reading length from inbound connection"); xclose(fd); } else if(l >= sizeof id) { - error(0, "id length too long"); + disorder_error(0, "id length too long"); xclose(fd); } else if(read(fd, id, l) < (ssize_t)l) { - error(errno, "reading id from inbound connection"); + disorder_error(errno, "reading id from inbound connection"); xclose(fd); } else { id[l] = 0; D(("id %s fd %d", id, fd)); t = findtrack(id, 1/*create*/); if (write(fd, "", 1) < 0) /* write an ack */ - error(errno, "writing ack to inbound connection"); + disorder_error(errno, "writing ack to inbound connection"); if(t->fd != -1) { - error(0, "%s: already got a connection", id); + disorder_error(0, "%s: already got a connection", id); xclose(fd); } else { nonblock(fd); @@ -530,7 +531,7 @@ static void mainloop(void) { } } } else - error(errno, "accept"); + disorder_error(errno, "accept"); } /* Perhaps we have a command to process */ if(fds[stdin_slot].revents & POLLIN) { @@ -550,16 +551,17 @@ static void mainloop(void) { /* If finished isn't set then the server can't believe that this * track has finished */ if(!playing->finished) - fatal(0, "got SM_PLAY but already playing something"); + disorder_fatal(0, "got SM_PLAY but already playing something"); /* If pending_playing is set then the server must believe that that * is playing */ if(pending_playing) - fatal(0, "got SM_PLAY but have a pending playing track"); + disorder_fatal(0, "got SM_PLAY but have a pending playing track"); } t = findtrack(sm.id, 1); D(("SM_PLAY %s fd %d", t->id, t->fd)); if(t->fd == -1) - error(0, "cannot play track because no connection arrived"); + disorder_error(0, + "cannot play track because no connection arrived"); /* TODO as things stand we often report this error message but then * appear to proceed successfully. Understanding why requires a look * at play.c: we call prepare() which makes the connection in a child @@ -602,7 +604,7 @@ static void mainloop(void) { * log more because there's been a bug here recently than because * it's particularly interesting; the log message will be removed * if no further problems show up. */ - info("SM_CANCEL for nonplaying track %s", sm.id); + disorder_info("SM_CANCEL for nonplaying track %s", sm.id); sm.type = SM_STILLBORN; } strcpy(sm.id, t->id); @@ -611,7 +613,7 @@ static void mainloop(void) { /* Probably scratching the playing track well before it's got * going, but could indicate a bug, so we log this as an error. */ sm.type = SM_UNKNOWN; - error(0, "SM_CANCEL for unknown track %s", sm.id); + disorder_error(0, "SM_CANCEL for unknown track %s", sm.id); } speaker_send(1, &sm); force_report = 1; @@ -619,11 +621,11 @@ static void mainloop(void) { case SM_RELOAD: D(("SM_RELOAD")); if(config_read(1, NULL)) - error(0, "cannot read configuration"); - info("reloaded configuration"); + disorder_error(0, "cannot read configuration"); + disorder_info("reloaded configuration"); break; default: - error(0, "unknown message type %d", sm.type); + disorder_error(0, "unknown message type %d", sm.type); } } /* Read in any buffered data */ @@ -699,7 +701,7 @@ int main(int argc, char **argv) { struct rlimit rl[1]; set_progname(argv); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -709,7 +711,7 @@ int main(int argc, char **argv) { case 'D': debugging = 0; break; case 'S': logsyslog = 0; break; case 's': logsyslog = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if((d = getenv("DISORDER_DEBUG_SPEAKER"))) debugging = atoi(d); @@ -718,7 +720,7 @@ int main(int argc, char **argv) { log_default = &log_syslog; } config_uaudio_apis = uaudio_apis; - if(config_read(1, NULL)) fatal(0, "cannot read configuration"); + if(config_read(1, NULL)) disorder_fatal(0, "cannot read configuration"); /* ignore SIGPIPE */ signal(SIGPIPE, SIG_IGN); /* set nice value */ @@ -727,19 +729,19 @@ int main(int argc, char **argv) { become_mortal(); /* make sure we're not root, whatever the config says */ if(getuid() == 0 || geteuid() == 0) - fatal(0, "do not run as root"); + disorder_fatal(0, "do not run as root"); /* Make sure we can't have more than NFDS files open (it would bust our * poll() array) */ if(getrlimit(RLIMIT_NOFILE, rl) < 0) - fatal(errno, "getrlimit RLIMIT_NOFILE"); + disorder_fatal(errno, "getrlimit RLIMIT_NOFILE"); if(rl->rlim_cur > NFDS) { rl->rlim_cur = NFDS; if(setrlimit(RLIMIT_NOFILE, rl) < 0) - fatal(errno, "setrlimit to reduce RLIMIT_NOFILE to %lu", + disorder_fatal(errno, "setrlimit to reduce RLIMIT_NOFILE to %lu", (unsigned long)rl->rlim_cur); - info("set RLIM_NOFILE to %lu", (unsigned long)rl->rlim_cur); + disorder_info("set RLIM_NOFILE to %lu", (unsigned long)rl->rlim_cur); } else - info("RLIM_NOFILE is %lu", (unsigned long)rl->rlim_cur); + disorder_info("RLIM_NOFILE is %lu", (unsigned long)rl->rlim_cur); /* gcrypt initialization */ if(!gcry_check_version(NULL)) disorder_fatal(0, "gcry_check_version failed"); @@ -764,7 +766,7 @@ int main(int argc, char **argv) { byte_xasprintf(&dir, "%s/speaker", config->home); unlink(dir); /* might be a leftover socket */ if(mkdir(dir, 0700) < 0 && errno != EEXIST) - fatal(errno, "error creating %s", dir); + disorder_fatal(errno, "error creating %s", dir); /* set up the listen socket */ listenfd = xsocket(PF_UNIX, SOCK_STREAM, 0); memset(&addr, 0, sizeof addr); @@ -772,18 +774,18 @@ int main(int argc, char **argv) { snprintf(addr.sun_path, sizeof addr.sun_path, "%s/speaker/socket", config->home); if(unlink(addr.sun_path) < 0 && errno != ENOENT) - error(errno, "removing %s", addr.sun_path); + disorder_error(errno, "removing %s", addr.sun_path); xsetsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); if(bind(listenfd, (const struct sockaddr *)&addr, sizeof addr) < 0) - fatal(errno, "error binding socket to %s", addr.sun_path); + disorder_fatal(errno, "error binding socket to %s", addr.sun_path); xlisten(listenfd, 128); nonblock(listenfd); - info("listening on %s", addr.sun_path); + disorder_info("listening on %s", addr.sun_path); memset(&sm, 0, sizeof sm); sm.type = SM_READY; speaker_send(1, &sm); mainloop(); - info("stopped (parent terminated)"); + disorder_info("stopped (parent terminated)"); exit(0); } diff --git a/server/state.c b/server/state.c index 74f1566..b125417 100644 --- a/server/state.c +++ b/server/state.c @@ -46,7 +46,7 @@ const struct uaudio *api; /** @brief Quit DisOrder */ void quit(ev_source *ev) { - info("shutting down..."); + disorder_info("shutting down..."); quitting(ev); trackdb_close(); trackdb_deinit(ev); @@ -66,7 +66,7 @@ void quit(ev_source *ev) { * These are not shut down currently. */ ev_child_killall(ev); - info("exiting"); + disorder_info("exiting"); exit(0); } @@ -92,22 +92,22 @@ void reset_sockets(ev_source *ev) { /* stop the old one and remove it from the filesystem */ server_stop(ev, current_unix_fd); if(unlink(current_unix) < 0) - fatal(errno, "unlink %s", current_unix); + disorder_fatal(errno, "unlink %s", current_unix); } /* start the new one */ if(strlen(new_unix) >= sizeof sun.sun_path) - fatal(0, "socket path %s is too long", new_unix); + disorder_fatal(0, "socket path %s is too long", new_unix); memset(&sun, 0, sizeof sun); sun.sun_family = AF_UNIX; strcpy(sun.sun_path, new_unix); if(unlink(new_unix) < 0 && errno != ENOENT) - fatal(errno, "unlink %s", new_unix); + disorder_fatal(errno, "unlink %s", new_unix); if((current_unix_fd = server_start(ev, PF_UNIX, sizeof sun, (const struct sockaddr *)&sun, new_unix)) >= 0) { current_unix = new_unix; if(chmod(new_unix, 0777) < 0) - fatal(errno, "error calling chmod %s", new_unix); + disorder_fatal(errno, "error calling chmod %s", new_unix); } else current_unix = 0; } @@ -185,7 +185,7 @@ int reconfigure(ev_source *ev, unsigned flags) { else { /* Tell the speaker it needs to reload its config too. */ speaker_reload(); - info("%s: installed new configuration", configfile); + disorder_info("%s: installed new configuration", configfile); } } /* New audio API */ diff --git a/server/stats.c b/server/stats.c index ad35cb8..60e2e39 100644 --- a/server/stats.c +++ b/server/stats.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) { set_progname(argv); mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) { switch(n) { case 'h': help(); @@ -67,7 +67,7 @@ int main(int argc, char **argv) { case 'D': debugging = 0; break; case 'S': logsyslog = 0; break; case 's': logsyslog = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(logsyslog) { @@ -75,7 +75,7 @@ int main(int argc, char **argv) { log_default = &log_syslog; } if(config_read(0, NULL)) - fatal(0, "cannot read configuration"); + disorder_fatal(0, "cannot read configuration"); trackdb_init(TRACKDB_NO_RECOVER); trackdb_open(TRACKDB_NO_UPGRADE); stats = trackdb_stats(0); diff --git a/server/trackname.c b/server/trackname.c index b661e0c..096f97a 100644 --- a/server/trackname.c +++ b/server/trackname.c @@ -45,23 +45,24 @@ int main(int argc, char **argv) { int n; const char *s; - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) + disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVc:d", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version("trackname"); case 'c': configfile = optarg; break; case 'd': debugging = 1; break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } - if(argc - optind < 3) fatal(0, "not enough arguments"); - if(argc - optind > 3) fatal(0, "too many arguments"); - if(config_read(0, NULL)) fatal(0, "cannot read configuration"); + if(argc - optind < 3) disorder_fatal(0, "not enough arguments"); + if(argc - optind > 3) disorder_fatal(0, "too many arguments"); + if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration"); s = trackname_part(argv[optind], argv[optind+1], argv[optind+2]); - if(!s) fatal(0, "trackname_part returned NULL"); + if(!s) disorder_fatal(0, "trackname_part returned NULL"); xprintf("%s\n", nullcheck(utf82mb(s))); - if(fclose(stdout) < 0) fatal(errno, "error closing stdout"); + if(fclose(stdout) < 0) disorder_fatal(errno, "error closing stdout"); return 0; } diff --git a/tests/udplog.c b/tests/udplog.c index a27252c..81c0808 100644 --- a/tests/udplog.c +++ b/tests/udplog.c @@ -92,20 +92,20 @@ int main(int argc, char **argv) { set_progname(argv); mem_init(); - if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); + if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale"); while((n = getopt_long(argc, argv, "hVo:", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version(); case 'o': if(!freopen(optarg, "w", stdout)) - fatal(errno, "%s", optarg); + disorder_fatal(errno, "%s", optarg); break; - default: fatal(0, "invalid option"); + default: disorder_fatal(0, "invalid option"); } } if(optind + 2 != argc) - fatal(0, "missing arguments"); + disorder_fatal(0, "missing arguments"); a.n = 2; a.s = &argv[optind]; if(!(ai = get_address(&a, &pref, &name))) @@ -113,7 +113,7 @@ int main(int argc, char **argv) { fd = xsocket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); nonblock(fd); if(bind(fd, ai->ai_addr, ai->ai_addrlen) < 0) - fatal(errno, "error binding to %s", name); + disorder_fatal(errno, "error binding to %s", name); while(getppid() != 1) { /* Wait for something to happen. We don't just block forever in recvfrom() * as otherwise we'd never die if the parent terminated uncontrolledly. */ @@ -127,11 +127,11 @@ int main(int argc, char **argv) { if(n < 0) { if(errno == EINTR || errno == EAGAIN) continue; - fatal(errno, "%s: recvfrom", name); + disorder_fatal(errno, "%s: recvfrom", name); } if((err = getnameinfo(&sa.sa, len, h, sizeof h, s, sizeof s, NI_NUMERICHOST|NI_NUMERICSERV|NI_DGRAM))) - fatal(0, "getnameinfo: %s", gai_strerror(err)); + disorder_fatal(0, "getnameinfo: %s", gai_strerror(err)); xprintf("from host %s service %s: %d bytes\n", h, s, n); for(i = 0; i < n; i += 16) { for(j = i; j < n && j < i + 16; ++j) @@ -143,7 +143,7 @@ int main(int argc, char **argv) { xprintf("%c", buffer[j] < 128 && isprint(buffer[j]) ? buffer[j] : '.'); xprintf("\n"); if(fflush(stdout) < 0) - fatal(errno, "stdout"); + disorder_fatal(errno, "stdout"); } } return 0; -- [mdw]