--- embedaddon/mpd/src/main.c 2012/02/21 23:32:47 1.1.1.1 +++ embedaddon/mpd/src/main.c 2021/03/17 00:39:23 1.1.1.4 @@ -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" }, @@ -65,6 +68,10 @@ { 1, 's', "syslog-ident", "ident", "Identifier to use for syslog" }, #endif +#ifdef USE_PAM + { 1, 'm', "pam-service", "service", + "PAM service name" }, +#endif { 0, 'v', "version", "", "Show version information" }, { 0, 'h', "help", "", @@ -99,14 +106,14 @@ #ifdef PHYSTYPE_PPTP int gPPTPto = 10; - int gPPTPtunlimit = 100; + unsigned gPPTPtunlimit = 100; #endif #ifdef PHYSTYPE_L2TP int gL2TPto = 10; #if ((__FreeBSD_version > 603100 && __FreeBSD_version < 700000) || __FreeBSD_version >= 700055) - int gL2TPtunlimit = 100; + unsigned gL2TPtunlimit = 100; #else - int gL2TPtunlimit = 10; + unsigned gL2TPtunlimit = 10; #endif #endif int gChildren = 0; /* Current number of children links */ @@ -116,6 +123,10 @@ struct acl *acl_filters[ACL_FILTERS]; /* mpd's global internal bpf filters */ #endif +#ifdef USE_PAM + char gPamService[32]; +#endif + struct globalconf gGlobalConf; pthread_mutex_t gGiantMutex; @@ -163,9 +174,9 @@ main(int ac, char *av[]) int ret, k; char *args[MAX_ARGS]; Context c; - PhysType pt; + const struct phystype *pt; - gPid=getpid(); + gPid = getpid(); /* enable libpdel typed_mem */ typed_mem_enable(); @@ -202,6 +213,12 @@ main(int ac, char *av[]) RadsrvInit(&gRadsrv); #endif +#ifdef USE_PAM + if (!*gPamService) + strcpy(gPamService, "mpd"); +#endif + + /* Set up libnetgraph logging */ NgSetErrLog(NgFuncErr, NgFuncErrx); @@ -251,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], @@ -306,15 +323,18 @@ static void ConfigRead(int type, void *arg) { Context c = (Context)arg; + int err; + (void)type; /* 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); } @@ -355,7 +375,7 @@ DoExit(int code) Bund b; Rep r; Link l; - PhysType pt; + const struct phystype *pt; int k; gShutdownInProgress=1; @@ -429,6 +449,8 @@ SignalHandler(int type, void *arg) { u_char sig; + (void)type; + (void)arg; read(gSignalPipe[0], &sig, sizeof(sig)); switch(sig) { @@ -455,10 +477,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) @@ -590,6 +631,9 @@ OptApply(Option opt, int ac, char *av[]) #ifdef SYSLOG_FACILITY memset(gSysLogIdent, 0, sizeof(gSysLogIdent)); #endif +#ifdef USE_PAM + memset(gPamService, 0, sizeof(gPamService)); +#endif if (opt == NULL) Usage(EX_USAGE); @@ -619,6 +663,11 @@ OptApply(Option opt, int ac, char *av[]) strlcpy(gSysLogIdent, *av, sizeof(gSysLogIdent)); return(1); #endif +#ifdef USE_PAM + case 'm': + strlcpy(gPamService, *av, sizeof(gPamService)); + return(1); +#endif case 'v': fprintf(stderr, "Version %s\n", gVersion); exit(EX_NORMAL); @@ -666,7 +715,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); }