summaryrefslogtreecommitdiff
path: root/Userland/dmesg.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-28 22:40:55 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-28 22:40:55 +0100
commit7455f5ea4200c5f90bcbc2c025c58a00938952c4 (patch)
tree74c4232ecea73688a726bcd009e2d4f1092c2260 /Userland/dmesg.cpp
parent442351a5f801e3c3feb967d60404457988da30e7 (diff)
downloadserenity-7455f5ea4200c5f90bcbc2c025c58a00938952c4.zip
Expose the kernel log buffer through /proc/dmesg.
Also add a /bin/dmesg program for convenience.
Diffstat (limited to 'Userland/dmesg.cpp')
-rw-r--r--Userland/dmesg.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/Userland/dmesg.cpp b/Userland/dmesg.cpp
new file mode 100644
index 0000000000..4f396a1b53
--- /dev/null
+++ b/Userland/dmesg.cpp
@@ -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;
+}