Big update: 6/N fix

This commit is contained in:
Your Name 2023-11-07 17:24:49 +03:00
parent 5582a0cc18
commit 98a7ba56c7

View File

@ -7,23 +7,23 @@
#include <sys/klog.h> #include <sys/klog.h>
#define BUF_SIZE 8196 #define BUF_SIZE 8196
int main(const int argc, const char **argv) { int main(int argc, char **argv) {
unsigned int s_size = 0; unsigned int s_size = 0;
unsigned int n_level = 0; unsigned int n_level = 0;
int i; int opt;
for (i = 1; i < argc; i++) { while ((opt = getopt(argc, argv, "s:n:")) != -1) {
if (argv[i][0] != '-') switch (opt) {
case 's':
s_size = atoi(optarg);
break; break;
else if (!strncmp(argv[i], "-s=", 3)) case 'n':
s_size = atoi(argv[i] + 3); n_level = atoi(optarg);
break;
else if (!strncmp(argv[i], "-n=", 3)) default:
n_level = atoi(argv[i] + 3); printf("dmesg\n\t[-n=L Set console logging level] [-s=S Buffer Size]\n");
else if (!strcmp(argv[i], "--help")) {
printf("dmesg [-n=L Set console logging level] [-s=S Buffer Size]\n");
return 0; return 0;
} }
} }
@ -38,6 +38,7 @@ int main(const int argc, const char **argv) {
if (!s_size) if (!s_size)
s_size = klogctl(10, NULL, 0); s_size = klogctl(10, NULL, 0);
/* Get kernel log */ /* Get kernel log */
char *buf = malloc(s_size + 1); char *buf = malloc(s_size + 1);
if (buf == NULL) { if (buf == NULL) {
@ -55,6 +56,7 @@ int main(const int argc, const char **argv) {
return 1; return 1;
} }
/* Print */ /* Print */
write(STDOUT_FILENO, buf, n); write(STDOUT_FILENO, buf, n);
putchar('\n'); putchar('\n');