View | Details | Raw Unified | Return to bug 43434
Collapse All | Expand All

(-)sbin/dmesg/dmesg.c (-2 / +38 lines)
Lines 66-77 Link Here
66
	{ NULL },
66
	{ NULL },
67
};
67
};
68
68
69
int getlastbootpos(char *buf, int len);
69
void usage(void) __dead2;
70
void usage(void) __dead2;
70
71
71
#define	KREAD(addr, var) \
72
#define	KREAD(addr, var) \
72
	kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
73
	kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
73
74
74
int
75
int
76
getlastbootpos(char *buf, int len)
77
{
78
	int i;
79
	char *ptr, *save;
80
81
	/* Skip NULL bytes */
82
	for(i = 0; (buf[i] == 0x0) && (i < len); i++);
83
84
	if (strlen(buf) == 0)
85
		return(-1);
86
87
	while((ptr = (char *) strstr((buf +i), BOOT_TAG)) != NULL) {
88
		save = (char *) ptr;
89
		i += strlen(BOOT_TAG); /* Force strstr() to catch
90
					* the next tag
91
					*/
92
	}
93
94
	return((int) ((int) (save + (strlen(BOOT_TAG))) - (int) buf));
95
}
96
97
int
75
main(int argc, char *argv[])
98
main(int argc, char *argv[])
76
{
99
{
77
	int ch, newl, skip;
100
	int ch, newl, skip;
Lines 84-93 Link Here
84
	int pri;
107
	int pri;
85
	size_t buflen;
108
	size_t buflen;
86
	int bufpos;
109
	int bufpos;
110
	int old = 0;
111
	int lastboot = 0;
87
112
88
	(void) setlocale(LC_CTYPE, "");
113
	(void) setlocale(LC_CTYPE, "");
89
	memf = nlistf = NULL;
114
	memf = nlistf = NULL;
90
	while ((ch = getopt(argc, argv, "aM:N:")) != -1)
115
	while ((ch = getopt(argc, argv, "aM:N:o")) != -1)
91
		switch(ch) {
116
		switch(ch) {
92
		case 'a':
117
		case 'a':
93
			all++;
118
			all++;
Lines 98-103 Link Here
98
		case 'N':
123
		case 'N':
99
			nlistf = optarg;
124
			nlistf = optarg;
100
			break;
125
			break;
126
		case 'o':
127
			old = 1;
128
			break;
101
		case '?':
129
		case '?':
102
		default:
130
		default:
103
			usage();
131
			usage();
Lines 151-161 Link Here
151
	 * we effectively start at the oldest data.
179
	 * we effectively start at the oldest data.
152
	 */
180
	 */
153
	p = bp + bufpos;
181
	p = bp + bufpos;
182
	if (!old) {
183
		lastboot = getlastbootpos(p, buflen);
184
		if (lastboot != -1)
185
			p = bp + lastboot;
186
	}
154
	ep = (bufpos == 0 ? bp + buflen : p);
187
	ep = (bufpos == 0 ? bp + buflen : p);
155
	newl = skip = 0;
188
	newl = skip = 0;
156
	do {
189
	do {
157
		if (p == bp + buflen)
190
		if (p == bp + buflen)
158
			p = bp;
191
			p = bp;
192
		/* Skipping boot tag */
193
		if (!memcmp(p, BOOT_TAG, strlen(BOOT_TAG)))
194
			p += strlen(BOOT_TAG);
159
		ch = *p;
195
		ch = *p;
160
		/* Skip "\n<.*>" syslog sequences. */
196
		/* Skip "\n<.*>" syslog sequences. */
161
		if (skip) {
197
		if (skip) {
Lines 193-198 Link Here
193
void
229
void
194
usage(void)
230
usage(void)
195
{
231
{
196
	(void)fprintf(stderr, "usage: dmesg [-a] [-M core] [-N system]\n");
232
	(void)fprintf(stderr, "usage: dmesg [-a] [-M core] [-N system] [-o]\n");
197
	exit(1);
233
	exit(1);
198
}
234
}
(-)sbin/dmesg/dmesg.8 (+3 lines)
Lines 43-48 Link Here
43
.Op Fl a
43
.Op Fl a
44
.Op Fl M Ar core
44
.Op Fl M Ar core
45
.Op Fl N Ar system
45
.Op Fl N Ar system
46
.Op Fl o
46
.Sh DESCRIPTION
47
.Sh DESCRIPTION
47
The
48
The
48
.Nm
49
.Nm
Lines 73-78 Link Here
73
.It Fl N
74
.It Fl N
74
Extract the name list from the specified system instead of the default,
75
Extract the name list from the specified system instead of the default,
75
which is the kernel image the system has booted from.
76
which is the kernel image the system has booted from.
77
.It Fl o
78
Display all boot messages, not only the last.
76
.El
79
.El
77
.Sh FILES
80
.Sh FILES
78
.Bl -tag -width ".Pa /var/run/dmesg.boot" -compact
81
.Bl -tag -width ".Pa /var/run/dmesg.boot" -compact
(-)sys/sys/msgbuf.h (+4 lines)
Lines 46-51 Link Here
46
	char * 		msg_ptr;		/* pointer to buffer */
46
	char * 		msg_ptr;		/* pointer to buffer */
47
};
47
};
48
48
49
#define	BOOT_TAG  "---<<BOOT>>---"	/* used by dmesg util to know where a
50
					 * boot message starts.
51
					 */
52
49
#ifdef _KERNEL
53
#ifdef _KERNEL
50
extern int	msgbuftrigger;
54
extern int	msgbuftrigger;
51
extern struct	msgbuf *msgbufp;
55
extern struct	msgbuf *msgbufp;
(-)sys/kern/subr_prf.c (+3 lines)
Lines 818-823 Link Here
818
		msgbufp->msg_size = (char *)msgbufp - cp;
818
		msgbufp->msg_size = (char *)msgbufp - cp;
819
	}
819
	}
820
	msgbufp->msg_ptr = cp;
820
	msgbufp->msg_ptr = cp;
821
	memcpy((void *) (msgbufp->msg_ptr + msgbufp->msg_bufx), BOOT_TAG,
822
            strlen(BOOT_TAG));
823
	msgbufp->msg_bufx += strlen(BOOT_TAG);
821
	if (msgbufmapped && oldp != msgbufp)
824
	if (msgbufmapped && oldp != msgbufp)
822
		msgbufcopy(oldp);
825
		msgbufcopy(oldp);
823
	msgbufmapped = 1;
826
	msgbufmapped = 1;

Return to bug 43434