--- embedaddon/mpd/src/main.c 2013/07/22 08:44:29 1.1.1.2 +++ embedaddon/mpd/src/main.c 2016/11/01 09:56:12 1.1.1.3 @@ -26,6 +26,9 @@ #include "ccp_mppc.h" #endif +#ifdef USE_BACKTRACE +#include +#endif #include /* @@ -47,7 +50,7 @@ }; typedef struct option *Option; - static const char *UsageStr = "[options] [system]"; + static const char *UsageStr = "[options] [configuration]"; static struct option OptList[] = { { 0, 'b', "background", "", "Run as a background daemon" }, @@ -173,7 +176,7 @@ main(int ac, char *av[]) Context c; PhysType pt; - gPid=getpid(); + gPid = getpid(); /* enable libpdel typed_mem */ typed_mem_enable(); @@ -265,8 +268,8 @@ main(int ac, char *av[]) } /* Create signaling pipe */ - if ((ret = pipe(gSignalPipe)) != 0) { - Log(LG_ERR, ("Could not create signal pipe %d", ret)); + if (pipe(gSignalPipe) < 0) { + Perror("Could not create signal pipe"); exit(EX_UNAVAILABLE); } if (EventRegister(&gSignalEvent, EVENT_READ, gSignalPipe[0], @@ -320,15 +323,17 @@ static void ConfigRead(int type, void *arg) { Context c = (Context)arg; + int err; /* Read startup configuration section */ - ReadFile(gConfigFile, STARTUP_CONF, DoCommand, c); + err = ReadFile(gConfigFile, STARTUP_CONF, DoCommand, c); /* Read configuration as specified on the command line, or default */ - if (!gPeerSystem) - ReadFile(gConfigFile, DEFAULT_CONF, DoCommand, c); - else { - if (ReadFile(gConfigFile, gPeerSystem, DoCommand, c) < 0) { + if (!gPeerSystem) { + if (err != -2) + ReadFile(gConfigFile, DEFAULT_CONF, DoCommand, c); + } else { + if (err == -2 || ReadFile(gConfigFile, gPeerSystem, DoCommand, c) < 0) { Log(LG_ERR, ("can't read configuration for \"%s\"", gPeerSystem)); DoExit(EX_CONFIG); } @@ -469,10 +474,29 @@ FatalSignal(int sig) static struct pppTimer gDeathTimer; int k; int upLinkCount; +#ifdef USE_BACKTRACE + void *buffer[100]; + char **strings; + int n; +#endif /* If a SIGTERM or SIGINT, gracefully shutdown; otherwise shutdown now */ Log(LG_ERR, ("caught fatal signal %s", sys_signame[sig])); gShutdownInProgress=1; +#ifdef USE_BACKTRACE + if (sig != SIGTERM && sig != SIGINT) { + n = backtrace(buffer, 100); + strings = backtrace_symbols(buffer, n); + if (strings == NULL) { + Log(LG_ERR, ("No backtrace symbols found")); + } else { + for (k = 0; k < n; k++) { + Log(LG_ERR, ("%s", strings[k])); + } + free(strings); + } + } +#endif for (k = 0; k < gNumBundles; k++) { if ((b = gBundles[k])) { if (sig != SIGTERM && sig != SIGINT) @@ -688,7 +712,7 @@ Usage(int ex) opt = OptList + k; snprintf(buf, sizeof(buf), " -%c, --%-s %s", opt->sflag, opt->lflag, opt->usage); - fprintf(stderr, "%-40s%s\n", buf, opt->desc); + fprintf(stderr, "%-35s%s\n", buf, opt->desc); } exit(ex); }