1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 25 unchanged lines hidden (view full) --- 34 The Regents of the University of California. All rights reserved.\n"; 35#endif /* not lint */ 36 37#ifndef lint 38static const char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93"; 39#endif /* not lint */ 40#endif 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/sbin/dmesg/dmesg.c 250430 2013-05-10 03:42:48Z eadler $"); |
43 44#include <sys/types.h> 45#include <sys/msgbuf.h> 46#include <sys/sysctl.h> 47 48#include <ctype.h> 49#include <err.h> 50#include <errno.h> 51#include <fcntl.h> 52#include <kvm.h> 53#include <limits.h> 54#include <locale.h> 55#include <nlist.h> 56#include <stdio.h> |
57#include <stdbool.h> |
58#include <stdlib.h> 59#include <string.h> 60#include <unistd.h> 61#include <vis.h> 62#include <sys/syslog.h> 63 64static struct nlist nl[] = { 65#define X_MSGBUF 0 --- 9 unchanged lines hidden (view full) --- 75int 76main(int argc, char *argv[]) 77{ 78 struct msgbuf *bufp, cur; 79 char *bp, *ep, *memf, *nextp, *nlistf, *p, *q, *visbp; 80 kvm_t *kd; 81 size_t buflen, bufpos; 82 long pri; |
83 int ch, clear; 84 bool all; |
85 |
86 all = false; 87 clear = false; |
88 (void) setlocale(LC_CTYPE, ""); 89 memf = nlistf = NULL; |
90 while ((ch = getopt(argc, argv, "acM:N:")) != -1) |
91 switch(ch) { 92 case 'a': |
93 all = true; |
94 break; |
95 case 'c': 96 clear = true; 97 break; |
98 case 'M': 99 memf = optarg; 100 break; 101 case 'N': 102 nlistf = optarg; 103 break; 104 case '?': 105 default: --- 85 unchanged lines hidden (view full) --- 191 continue; 192 p = q + 1; 193 } 194 } 195 196 (void)strvisx(visbp, p, nextp - p, 0); 197 (void)printf("%s", visbp); 198 } |
199 if (clear) 200 if (sysctlbyname("kern.msgbuf_clear", NULL, NULL, &clear, sizeof(int))) 201 err(1, "sysctl kern.msgbuf_clear"); 202 |
203 exit(0); 204} 205 206void 207usage(void) 208{ |
209 fprintf(stderr, "usage: dmesg [-ac] [-M core [-N system]]\n"); |
210 exit(1); 211} |