1c39934eaSBrian Somers /*- 2c39934eaSBrian Somers * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org> 3c39934eaSBrian Somers * All rights reserved. 4c39934eaSBrian Somers * 5c39934eaSBrian Somers * Redistribution and use in source and binary forms, with or without 6c39934eaSBrian Somers * modification, are permitted provided that the following conditions 7c39934eaSBrian Somers * are met: 8c39934eaSBrian Somers * 1. Redistributions of source code must retain the above copyright 9c39934eaSBrian Somers * notice, this list of conditions and the following disclaimer. 10c39934eaSBrian Somers * 2. Redistributions in binary form must reproduce the above copyright 11c39934eaSBrian Somers * notice, this list of conditions and the following disclaimer in the 12c39934eaSBrian Somers * documentation and/or other materials provided with the distribution. 13c39934eaSBrian Somers * 14c39934eaSBrian Somers * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15c39934eaSBrian Somers * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16c39934eaSBrian Somers * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17c39934eaSBrian Somers * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18c39934eaSBrian Somers * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19c39934eaSBrian Somers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20c39934eaSBrian Somers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21c39934eaSBrian Somers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22c39934eaSBrian Somers * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23c39934eaSBrian Somers * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24c39934eaSBrian Somers * SUCH DAMAGE. 25c39934eaSBrian Somers * 2697d92980SPeter Wemm * $FreeBSD$ 2775240ed1SBrian Somers */ 2875240ed1SBrian Somers 292764b86aSBrian Somers #include <sys/types.h> 3075240ed1SBrian Somers 31ba16c840SBrian Somers #include <ctype.h> 3253c9f6c0SAtsushi Murai #include <stdarg.h> 3353c9f6c0SAtsushi Murai #include <stdio.h> 3470a91e4cSBrian Somers #include <string.h> 3575240ed1SBrian Somers #include <syslog.h> 3685b542cfSBrian Somers #include <termios.h> 3775240ed1SBrian Somers 38c9e11a11SBrian Somers #include "defs.h" 39b6e82f33SBrian Somers #include "command.h" 40927145beSBrian Somers #include "mbuf.h" 41927145beSBrian Somers #include "log.h" 4285b542cfSBrian Somers #include "descriptor.h" 4385b542cfSBrian Somers #include "prompt.h" 44af57ed9fSAtsushi Murai 45182c898aSBrian Somers static const char * const LogNames[] = { 46927145beSBrian Somers "Async", 4792b09558SBrian Somers "CBCP", 48cb611434SBrian Somers "CCP", 49927145beSBrian Somers "Chat", 50927145beSBrian Somers "Command", 51927145beSBrian Somers "Connect", 52927145beSBrian Somers "Debug", 53927145beSBrian Somers "HDLC", 545106c671SBrian Somers "ID0", 55cb611434SBrian Somers "IPCP", 56927145beSBrian Somers "LCP", 57927145beSBrian Somers "LQM", 58927145beSBrian Somers "Phase", 596815097bSBrian Somers "Physical", 606815097bSBrian Somers "Sync", 61927145beSBrian Somers "TCP/IP", 62b1ac9332SBrian Somers "Timer", 63927145beSBrian Somers "Tun", 64927145beSBrian Somers "Warning", 65927145beSBrian Somers "Error", 66927145beSBrian Somers "Alert" 67927145beSBrian Somers }; 68af57ed9fSAtsushi Murai 69927145beSBrian Somers #define MSK(n) (1<<((n)-1)) 70af57ed9fSAtsushi Murai 71d47dceb8SBrian Somers static u_long LogMask = MSK(LogPHASE); 72a1e8f937SBrian Somers static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN); 73927145beSBrian Somers static int LogTunno = -1; 740f2f3eb3SBrian Somers static struct prompt *promptlist; /* Where to log local stuff */ 75b4f63b0bSBrian Somers struct prompt *log_PromptContext; 760bdcbcbeSBrian Somers int log_PromptListChanged; 770f2f3eb3SBrian Somers 780f2f3eb3SBrian Somers struct prompt * 790f2f3eb3SBrian Somers log_PromptList() 800f2f3eb3SBrian Somers { 810f2f3eb3SBrian Somers return promptlist; 820f2f3eb3SBrian Somers } 83b6217683SBrian Somers 84b6217683SBrian Somers void 85b6217683SBrian Somers log_RegisterPrompt(struct prompt *prompt) 86b6217683SBrian Somers { 870f2f3eb3SBrian Somers prompt->next = promptlist; 880f2f3eb3SBrian Somers promptlist = prompt; 890f2f3eb3SBrian Somers prompt->active = 1; 900f2f3eb3SBrian Somers log_DiscardAllLocal(&prompt->logmask); 91b6217683SBrian Somers } 920f2f3eb3SBrian Somers 930f2f3eb3SBrian Somers void 940f2f3eb3SBrian Somers log_ActivatePrompt(struct prompt *prompt) 950f2f3eb3SBrian Somers { 960f2f3eb3SBrian Somers prompt->active = 1; 970f2f3eb3SBrian Somers LogMaskLocal |= prompt->logmask; 98b6217683SBrian Somers } 99b6217683SBrian Somers 10067568487SBrian Somers static void 10167568487SBrian Somers LogSetMaskLocal(void) 10267568487SBrian Somers { 10367568487SBrian Somers struct prompt *p; 10467568487SBrian Somers 10567568487SBrian Somers LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN); 1060f2f3eb3SBrian Somers for (p = promptlist; p; p = p->next) 10767568487SBrian Somers LogMaskLocal |= p->logmask; 10867568487SBrian Somers } 10967568487SBrian Somers 110b6217683SBrian Somers void 1110f2f3eb3SBrian Somers log_DeactivatePrompt(struct prompt *prompt) 1120f2f3eb3SBrian Somers { 1130f2f3eb3SBrian Somers if (prompt->active) { 1140f2f3eb3SBrian Somers prompt->active = 0; 1150f2f3eb3SBrian Somers LogSetMaskLocal(); 1160f2f3eb3SBrian Somers } 1170f2f3eb3SBrian Somers } 1180f2f3eb3SBrian Somers 1190f2f3eb3SBrian Somers void 120b6217683SBrian Somers log_UnRegisterPrompt(struct prompt *prompt) 121b6217683SBrian Somers { 122b6217683SBrian Somers if (prompt) { 123b6217683SBrian Somers struct prompt **p; 124b6217683SBrian Somers 1250f2f3eb3SBrian Somers for (p = &promptlist; *p; p = &(*p)->next) 126b6217683SBrian Somers if (*p == prompt) { 1270f2f3eb3SBrian Somers *p = prompt->next; 1280f2f3eb3SBrian Somers prompt->next = NULL; 129b6217683SBrian Somers break; 130b6217683SBrian Somers } 13167568487SBrian Somers LogSetMaskLocal(); 1320bdcbcbeSBrian Somers log_PromptListChanged++; 133b6217683SBrian Somers } 134b6217683SBrian Somers } 135af57ed9fSAtsushi Murai 1360f2f3eb3SBrian Somers void 1370f2f3eb3SBrian Somers log_DestroyPrompts(struct server *s) 1380f2f3eb3SBrian Somers { 139a39fd214SBrian Somers struct prompt *p, *pn, *pl; 1400f2f3eb3SBrian Somers 1410f2f3eb3SBrian Somers p = promptlist; 142a39fd214SBrian Somers pl = NULL; 1430f2f3eb3SBrian Somers while (p) { 1440f2f3eb3SBrian Somers pn = p->next; 145a39fd214SBrian Somers if (s && p->owner == s) { 146a39fd214SBrian Somers if (pl) 147a39fd214SBrian Somers pl->next = p->next; 148a39fd214SBrian Somers else 149a39fd214SBrian Somers promptlist = p->next; 1500f2f3eb3SBrian Somers p->next = NULL; 1510f2f3eb3SBrian Somers prompt_Destroy(p, 1); 152a39fd214SBrian Somers } else 153a39fd214SBrian Somers pl = p; 1540f2f3eb3SBrian Somers p = pn; 1550f2f3eb3SBrian Somers } 1560f2f3eb3SBrian Somers } 1570f2f3eb3SBrian Somers 1580f2f3eb3SBrian Somers void 1590f2f3eb3SBrian Somers log_DisplayPrompts() 1600f2f3eb3SBrian Somers { 1610f2f3eb3SBrian Somers struct prompt *p; 1620f2f3eb3SBrian Somers 1630f2f3eb3SBrian Somers for (p = promptlist; p; p = p->next) 1640f2f3eb3SBrian Somers prompt_Required(p); 1650f2f3eb3SBrian Somers } 1660f2f3eb3SBrian Somers 1670f2f3eb3SBrian Somers void 168bf1d3ff6SBrian Somers log_WritePrompts(struct datalink *dl, const char *fmt,...) 1690f2f3eb3SBrian Somers { 170bf1d3ff6SBrian Somers va_list ap; 1710f2f3eb3SBrian Somers struct prompt *p; 1720f2f3eb3SBrian Somers 173bf1d3ff6SBrian Somers va_start(ap, fmt); 1740f2f3eb3SBrian Somers for (p = promptlist; p; p = p->next) 1750f2f3eb3SBrian Somers if (prompt_IsTermMode(p, dl)) 176bf1d3ff6SBrian Somers prompt_vPrintf(p, fmt, ap); 177bf1d3ff6SBrian Somers va_end(ap); 1780f2f3eb3SBrian Somers } 1790f2f3eb3SBrian Somers 1800f2f3eb3SBrian Somers void 1810f2f3eb3SBrian Somers log_SetTtyCommandMode(struct datalink *dl) 1820f2f3eb3SBrian Somers { 1830f2f3eb3SBrian Somers struct prompt *p; 1840f2f3eb3SBrian Somers 1850f2f3eb3SBrian Somers for (p = promptlist; p; p = p->next) 1860f2f3eb3SBrian Somers if (prompt_IsTermMode(p, dl)) 1870f2f3eb3SBrian Somers prompt_TtyCommandMode(p); 1880f2f3eb3SBrian Somers } 1890f2f3eb3SBrian Somers 190927145beSBrian Somers static int 191927145beSBrian Somers syslogLevel(int lev) 192927145beSBrian Somers { 193927145beSBrian Somers switch (lev) { 1946f384573SBrian Somers case LogDEBUG: 1956f384573SBrian Somers case LogTIMER: 1966f384573SBrian Somers return LOG_DEBUG; 197944f7098SBrian Somers case LogWARN: 198944f7098SBrian Somers return LOG_WARNING; 199944f7098SBrian Somers case LogERROR: 200944f7098SBrian Somers return LOG_ERR; 201944f7098SBrian Somers case LogALERT: 202944f7098SBrian Somers return LOG_ALERT; 203927145beSBrian Somers } 204927145beSBrian Somers return lev >= LogMIN && lev <= LogMAX ? LOG_INFO : 0; 205927145beSBrian Somers } 206af57ed9fSAtsushi Murai 207927145beSBrian Somers const char * 208dd7e2610SBrian Somers log_Name(int id) 209927145beSBrian Somers { 210927145beSBrian Somers return id < LogMIN || id > LogMAX ? "Unknown" : LogNames[id - 1]; 211927145beSBrian Somers } 212af57ed9fSAtsushi Murai 213af57ed9fSAtsushi Murai void 214dd7e2610SBrian Somers log_Keep(int id) 215af57ed9fSAtsushi Murai { 216927145beSBrian Somers if (id >= LogMIN && id <= LogMAXCONF) 217927145beSBrian Somers LogMask |= MSK(id); 218af57ed9fSAtsushi Murai } 219927145beSBrian Somers 220927145beSBrian Somers void 221dd7e2610SBrian Somers log_KeepLocal(int id, u_long *mask) 222a1e8f937SBrian Somers { 223b6217683SBrian Somers if (id >= LogMIN && id <= LogMAXCONF) { 224a1e8f937SBrian Somers LogMaskLocal |= MSK(id); 225b6217683SBrian Somers *mask |= MSK(id); 226b6217683SBrian Somers } 227a1e8f937SBrian Somers } 228a1e8f937SBrian Somers 229a1e8f937SBrian Somers void 230dd7e2610SBrian Somers log_Discard(int id) 231927145beSBrian Somers { 232927145beSBrian Somers if (id >= LogMIN && id <= LogMAXCONF) 233927145beSBrian Somers LogMask &= ~MSK(id); 234927145beSBrian Somers } 235927145beSBrian Somers 236927145beSBrian Somers void 237dd7e2610SBrian Somers log_DiscardLocal(int id, u_long *mask) 238a1e8f937SBrian Somers { 239b6217683SBrian Somers if (id >= LogMIN && id <= LogMAXCONF) { 240b6217683SBrian Somers *mask &= ~MSK(id); 24167568487SBrian Somers LogSetMaskLocal(); 242b6217683SBrian Somers } 243a1e8f937SBrian Somers } 244a1e8f937SBrian Somers 245a1e8f937SBrian Somers void 246dd7e2610SBrian Somers log_DiscardAll() 247927145beSBrian Somers { 248927145beSBrian Somers LogMask = 0; 249af57ed9fSAtsushi Murai } 250af57ed9fSAtsushi Murai 251a1e8f937SBrian Somers void 252dd7e2610SBrian Somers log_DiscardAllLocal(u_long *mask) 253a1e8f937SBrian Somers { 25467568487SBrian Somers *mask = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN); 25567568487SBrian Somers LogSetMaskLocal(); 256a1e8f937SBrian Somers } 257a1e8f937SBrian Somers 258af57ed9fSAtsushi Murai int 259dd7e2610SBrian Somers log_IsKept(int id) 260af57ed9fSAtsushi Murai { 261a1e8f937SBrian Somers if (id < LogMIN || id > LogMAX) 262927145beSBrian Somers return 0; 263a1e8f937SBrian Somers if (id > LogMAXCONF) 264a1e8f937SBrian Somers return LOG_KEPT_LOCAL | LOG_KEPT_SYSLOG; 265a1e8f937SBrian Somers 266a1e8f937SBrian Somers return ((LogMaskLocal & MSK(id)) ? LOG_KEPT_LOCAL : 0) | 267a1e8f937SBrian Somers ((LogMask & MSK(id)) ? LOG_KEPT_SYSLOG : 0); 268af57ed9fSAtsushi Murai } 269af57ed9fSAtsushi Murai 270b6217683SBrian Somers int 271dd7e2610SBrian Somers log_IsKeptLocal(int id, u_long mask) 272b6217683SBrian Somers { 273b6217683SBrian Somers if (id < LogMIN || id > LogMAX) 274b6217683SBrian Somers return 0; 275b6217683SBrian Somers if (id > LogMAXCONF) 276b6217683SBrian Somers return LOG_KEPT_LOCAL | LOG_KEPT_SYSLOG; 277b6217683SBrian Somers 278b6217683SBrian Somers return ((mask & MSK(id)) ? LOG_KEPT_LOCAL : 0) | 279b6217683SBrian Somers ((LogMask & MSK(id)) ? LOG_KEPT_SYSLOG : 0); 280b6217683SBrian Somers } 281b6217683SBrian Somers 282af57ed9fSAtsushi Murai void 283dd7e2610SBrian Somers log_Open(const char *Name) 284af57ed9fSAtsushi Murai { 285927145beSBrian Somers openlog(Name, LOG_PID, LOG_DAEMON); 286af57ed9fSAtsushi Murai } 287af57ed9fSAtsushi Murai 288af57ed9fSAtsushi Murai void 289dd7e2610SBrian Somers log_SetTun(int tunno) 290af57ed9fSAtsushi Murai { 291927145beSBrian Somers LogTunno = tunno; 292af57ed9fSAtsushi Murai } 293af57ed9fSAtsushi Murai 294af57ed9fSAtsushi Murai void 295dd7e2610SBrian Somers log_Close() 296af57ed9fSAtsushi Murai { 297927145beSBrian Somers closelog(); 298927145beSBrian Somers LogTunno = -1; 2996ed9fb2fSBrian Somers } 300af57ed9fSAtsushi Murai 301af57ed9fSAtsushi Murai void 302dd7e2610SBrian Somers log_Printf(int lev, const char *fmt,...) 30353c9f6c0SAtsushi Murai { 30453c9f6c0SAtsushi Murai va_list ap; 305b6217683SBrian Somers struct prompt *prompt; 306944f7098SBrian Somers 307927145beSBrian Somers va_start(ap, fmt); 308dd7e2610SBrian Somers if (log_IsKept(lev)) { 309d93d3a9cSBrian Somers char nfmt[200]; 31053c9f6c0SAtsushi Murai 311b4f63b0bSBrian Somers if (promptlist && (log_IsKept(lev) & LOG_KEPT_LOCAL)) { 312dd7e2610SBrian Somers if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1) 3131384bd27SBrian Somers snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME, 314dd7e2610SBrian Somers LogTunno, log_Name(lev), fmt); 315927145beSBrian Somers else 316dd7e2610SBrian Somers snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt); 317b6217683SBrian Somers 318b4f63b0bSBrian Somers if (log_PromptContext && lev == LogWARN) 319b4f63b0bSBrian Somers /* Warnings just go to the current prompt */ 320b4f63b0bSBrian Somers prompt_vPrintf(log_PromptContext, nfmt, ap); 321b4f63b0bSBrian Somers else for (prompt = promptlist; prompt; prompt = prompt->next) 322b6217683SBrian Somers if (lev > LogMAXCONF || (prompt->logmask & MSK(lev))) 323b6217683SBrian Somers prompt_vPrintf(prompt, nfmt, ap); 324a1e8f937SBrian Somers } 325a1e8f937SBrian Somers 3260f2f3eb3SBrian Somers if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) && 327b4f63b0bSBrian Somers (lev != LogWARN || !log_PromptContext)) { 328dd7e2610SBrian Somers if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1) 3291384bd27SBrian Somers snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME, 330dd7e2610SBrian Somers LogTunno, log_Name(lev), fmt); 331a1e8f937SBrian Somers else 332dd7e2610SBrian Somers snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt); 333927145beSBrian Somers vsyslog(syslogLevel(lev), nfmt, ap); 334927145beSBrian Somers } 335a1e8f937SBrian Somers } 33653c9f6c0SAtsushi Murai va_end(ap); 33753c9f6c0SAtsushi Murai } 33853c9f6c0SAtsushi Murai 33953c9f6c0SAtsushi Murai void 340dd7e2610SBrian Somers log_DumpBp(int lev, const char *hdr, const struct mbuf *bp) 341af57ed9fSAtsushi Murai { 342dd7e2610SBrian Somers if (log_IsKept(lev)) { 343ba16c840SBrian Somers char buf[68]; 344ba16c840SBrian Somers char *b, *c; 3459773f8c0SBrian Somers const u_char *ptr; 346a9e8f807SBrian Somers int f; 347a9e8f807SBrian Somers 348a9e8f807SBrian Somers if (hdr && *hdr) 349dd7e2610SBrian Somers log_Printf(lev, "%s\n", hdr); 350a9e8f807SBrian Somers 351a9e8f807SBrian Somers b = buf; 352ba16c840SBrian Somers c = b + 50; 353a9e8f807SBrian Somers do { 35426af0ae9SBrian Somers f = bp->m_len; 3559773f8c0SBrian Somers ptr = CONST_MBUF_CTOP(bp); 356a9e8f807SBrian Somers while (f--) { 357ba16c840SBrian Somers sprintf(b, " %02x", (int) *ptr); 358ba16c840SBrian Somers *c++ = isprint(*ptr) ? *ptr : '.'; 359ba16c840SBrian Somers ptr++; 360a9e8f807SBrian Somers b += 3; 361ba16c840SBrian Somers if (b == buf + 48) { 362ba16c840SBrian Somers memset(b, ' ', 2); 3639cf01ccfSBrian Somers *c = '\0'; 3649cf01ccfSBrian Somers log_Printf(lev, "%s\n", buf); 365a9e8f807SBrian Somers b = buf; 366ba16c840SBrian Somers c = b + 50; 367a9e8f807SBrian Somers } 368a9e8f807SBrian Somers } 36926af0ae9SBrian Somers } while ((bp = bp->m_next) != NULL); 370a9e8f807SBrian Somers 371a1e8f937SBrian Somers if (b > buf) { 372ba16c840SBrian Somers memset(b, ' ', 50 - (b - buf)); 3739cf01ccfSBrian Somers *c = '\0'; 3749cf01ccfSBrian Somers log_Printf(lev, "%s\n", buf); 375a9e8f807SBrian Somers } 376af57ed9fSAtsushi Murai } 377a1e8f937SBrian Somers } 378af57ed9fSAtsushi Murai 379af57ed9fSAtsushi Murai void 380dd7e2610SBrian Somers log_DumpBuff(int lev, const char *hdr, const u_char *ptr, int n) 381af57ed9fSAtsushi Murai { 382dd7e2610SBrian Somers if (log_IsKept(lev)) { 383ba16c840SBrian Somers char buf[68]; 384ba16c840SBrian Somers char *b, *c; 385af57ed9fSAtsushi Murai 386927145beSBrian Somers if (hdr && *hdr) 387dd7e2610SBrian Somers log_Printf(lev, "%s\n", hdr); 388927145beSBrian Somers while (n > 0) { 389927145beSBrian Somers b = buf; 390ba16c840SBrian Somers c = b + 50; 391ba16c840SBrian Somers for (b = buf; b != buf + 48 && n--; b += 3, ptr++) { 392ba16c840SBrian Somers sprintf(b, " %02x", (int) *ptr); 393ba16c840SBrian Somers *c++ = isprint(*ptr) ? *ptr : '.'; 394ba16c840SBrian Somers } 395ba16c840SBrian Somers memset(b, ' ', 50 - (b - buf)); 3969cf01ccfSBrian Somers *c = '\0'; 3979cf01ccfSBrian Somers log_Printf(lev, "%s\n", buf); 398af57ed9fSAtsushi Murai } 399af57ed9fSAtsushi Murai } 400c6c740beSBrian Somers } 401b6217683SBrian Somers 402b6217683SBrian Somers int 403b6217683SBrian Somers log_ShowLevel(struct cmdargs const *arg) 404b6217683SBrian Somers { 405b6217683SBrian Somers int i; 406b6217683SBrian Somers 407b6217683SBrian Somers prompt_Printf(arg->prompt, "Log: "); 408b6217683SBrian Somers for (i = LogMIN; i <= LogMAX; i++) 409dd7e2610SBrian Somers if (log_IsKept(i) & LOG_KEPT_SYSLOG) 410dd7e2610SBrian Somers prompt_Printf(arg->prompt, " %s", log_Name(i)); 411b6217683SBrian Somers 412b6217683SBrian Somers prompt_Printf(arg->prompt, "\nLocal:"); 413b6217683SBrian Somers for (i = LogMIN; i <= LogMAX; i++) 414dd7e2610SBrian Somers if (log_IsKeptLocal(i, arg->prompt->logmask) & LOG_KEPT_LOCAL) 415dd7e2610SBrian Somers prompt_Printf(arg->prompt, " %s", log_Name(i)); 416b6217683SBrian Somers 417b6217683SBrian Somers prompt_Printf(arg->prompt, "\n"); 418b6217683SBrian Somers 419b6217683SBrian Somers return 0; 420b6217683SBrian Somers } 421b6217683SBrian Somers 422b6217683SBrian Somers int 423b6217683SBrian Somers log_SetLevel(struct cmdargs const *arg) 424b6217683SBrian Somers { 425b6217683SBrian Somers int i, res, argc, local; 426b6217683SBrian Somers char const *const *argv, *argp; 427b6217683SBrian Somers 42825092092SBrian Somers argc = arg->argc - arg->argn; 42925092092SBrian Somers argv = arg->argv + arg->argn; 430b6217683SBrian Somers res = 0; 431b6217683SBrian Somers 432b6217683SBrian Somers if (argc == 0 || strcasecmp(argv[0], "local")) 433b6217683SBrian Somers local = 0; 434b6217683SBrian Somers else { 435b6217683SBrian Somers if (arg->prompt == NULL) { 436dd7e2610SBrian Somers log_Printf(LogWARN, "set log local: Only available on the command line\n"); 437b6217683SBrian Somers return 1; 438b6217683SBrian Somers } 439b6217683SBrian Somers argc--; 440b6217683SBrian Somers argv++; 441b6217683SBrian Somers local = 1; 442b6217683SBrian Somers } 443b6217683SBrian Somers 444e43ebac1SBrian Somers if (argc == 0 || (argv[0][0] != '+' && argv[0][0] != '-')) { 445b6217683SBrian Somers if (local) 446dd7e2610SBrian Somers log_DiscardAllLocal(&arg->prompt->logmask); 447b6217683SBrian Somers else 448dd7e2610SBrian Somers log_DiscardAll(); 449e43ebac1SBrian Somers } 450b6217683SBrian Somers 451b6217683SBrian Somers while (argc--) { 452b6217683SBrian Somers argp = **argv == '+' || **argv == '-' ? *argv + 1 : *argv; 453b6217683SBrian Somers for (i = LogMIN; i <= LogMAX; i++) 454dd7e2610SBrian Somers if (strcasecmp(argp, log_Name(i)) == 0) { 455e43ebac1SBrian Somers if (**argv == '-') { 456b6217683SBrian Somers if (local) 457dd7e2610SBrian Somers log_DiscardLocal(i, &arg->prompt->logmask); 458b6217683SBrian Somers else 459dd7e2610SBrian Somers log_Discard(i); 460e43ebac1SBrian Somers } else if (local) 461dd7e2610SBrian Somers log_KeepLocal(i, &arg->prompt->logmask); 462b6217683SBrian Somers else 463dd7e2610SBrian Somers log_Keep(i); 464b6217683SBrian Somers break; 465b6217683SBrian Somers } 466b6217683SBrian Somers if (i > LogMAX) { 467dd7e2610SBrian Somers log_Printf(LogWARN, "%s: Invalid log value\n", argp); 468b6217683SBrian Somers res = -1; 469b6217683SBrian Somers } 470b6217683SBrian Somers argv++; 471b6217683SBrian Somers } 472b6217683SBrian Somers return res; 473b6217683SBrian Somers } 474b6217683SBrian Somers 475b6217683SBrian Somers int 476b6217683SBrian Somers log_ShowWho(struct cmdargs const *arg) 477b6217683SBrian Somers { 478b6217683SBrian Somers struct prompt *p; 479b6217683SBrian Somers 4800f2f3eb3SBrian Somers for (p = promptlist; p; p = p->next) { 481565e35e5SBrian Somers prompt_Printf(arg->prompt, "%s (%s)", p->src.type, p->src.from); 482f91ad6b0SBrian Somers if (p == arg->prompt) 483f91ad6b0SBrian Somers prompt_Printf(arg->prompt, " *"); 484f91ad6b0SBrian Somers if (!p->active) 485f91ad6b0SBrian Somers prompt_Printf(arg->prompt, " ^Z"); 486f91ad6b0SBrian Somers prompt_Printf(arg->prompt, "\n"); 487f91ad6b0SBrian Somers } 488b6217683SBrian Somers 489b6217683SBrian Somers return 0; 490b6217683SBrian Somers } 491