mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:57:47 +00:00
Expose the kernel log buffer through /proc/dmesg.
Also add a /bin/dmesg program for convenience.
This commit is contained in:
parent
442351a5f8
commit
7455f5ea42
8 changed files with 77 additions and 0 deletions
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -27,3 +27,4 @@ sysctl
|
|||
rm
|
||||
cp
|
||||
rmdir
|
||||
dmesg
|
||||
|
|
|
@ -24,6 +24,7 @@ OBJS = \
|
|||
sysctl.o \
|
||||
cp.o \
|
||||
rmdir.o \
|
||||
dmesg.o \
|
||||
rm.o
|
||||
|
||||
APPS = \
|
||||
|
@ -53,6 +54,7 @@ APPS = \
|
|||
sysctl \
|
||||
cp \
|
||||
rmdir \
|
||||
dmesg \
|
||||
rm
|
||||
|
||||
ARCH_FLAGS =
|
||||
|
@ -118,6 +120,9 @@ tst: tst.o
|
|||
mm: mm.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
dmesg: dmesg.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
kill: kill.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
|
|
31
Userland/dmesg.cpp
Normal file
31
Userland/dmesg.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
int fd = open("/proc/dmesg", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open /proc/dmesg");
|
||||
return 1;
|
||||
}
|
||||
for (;;) {
|
||||
char buffer[BUFSIZ];
|
||||
ssize_t nread = read(fd, buffer, sizeof(buffer));
|
||||
if (nread < 0) {
|
||||
perror("read");
|
||||
return 1;
|
||||
}
|
||||
if (nread == 0) {
|
||||
break;
|
||||
}
|
||||
ssize_t nwritten = write(1, buffer, nread);
|
||||
assert(nwritten == nread);
|
||||
}
|
||||
int rc = close(fd);
|
||||
assert(rc == 0);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue