dmesg
This commit is contained in:
parent
e7e0439e3a
commit
076ec8f540
@ -33,6 +33,7 @@ char *MakePath(const char *src, const char *output_dir) {
|
|||||||
|
|
||||||
void Compile(const char *src, const char *output_dir) {
|
void Compile(const char *src, const char *output_dir) {
|
||||||
char *path = MakePath(src, output_dir);
|
char *path = MakePath(src, output_dir);
|
||||||
|
printf("[CC] Building %s -> %s\n", src, path);
|
||||||
|
|
||||||
size_t len = strlen(CC) + strlen(CFLAGS) + strlen(src) + strlen(path) + 7;
|
size_t len = strlen(CC) + strlen(CFLAGS) + strlen(src) + strlen(path) + 7;
|
||||||
char *arg = malloc(len + 1);
|
char *arg = malloc(len + 1);
|
||||||
@ -50,21 +51,20 @@ void Compile(const char *src, const char *output_dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ListAndCompile(const char *dir, const char *output_dir) {
|
void ListAndCompile(const char *dir, const char *output_dir) {
|
||||||
chdir(dir);
|
printf("[CHDIR] %s\n", dir);
|
||||||
DIR *dp = opendir(".");
|
if (chdir(dir) < 0) {
|
||||||
if (dp == NULL) {
|
fprintf(stderr, "builder: %s: %s\n", dir, strerror(errno));
|
||||||
fprintf(stderr, "builder: %s\n", strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DIR *dp = opendir(".");
|
||||||
|
|
||||||
struct dirent *ep;
|
struct dirent *ep;
|
||||||
while ((ep = readdir(dp)) != NULL) {
|
while ((ep = readdir(dp)) != NULL) {
|
||||||
if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
|
if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
printf("[INFO] Building %s\n", ep->d_name);
|
|
||||||
Compile(ep->d_name, output_dir);
|
Compile(ep->d_name, output_dir);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
const char *objects[] = {
|
const char *objects[] = {
|
||||||
"console-tools",
|
"console-tools",
|
||||||
"coreutils",
|
"coreutils",
|
||||||
|
"loginutils",
|
||||||
|
"sysutils",
|
||||||
"networking",
|
"networking",
|
||||||
"procps",
|
"procps",
|
||||||
"shell"
|
"shell"
|
||||||
@ -14,5 +16,5 @@ const char *libs[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define CFLAGS "-Wall -Wextra -pedantic -Os -s -I ../libmu"
|
#define CFLAGS "-Wall -Wextra -pedantic -Os -s -I ../libmu"
|
||||||
#define CC "tcc"
|
#define CC "cc"
|
||||||
#endif
|
#endif
|
||||||
|
@ -77,12 +77,15 @@ int main(const int argc, const char **argv) {
|
|||||||
switch (argc - i) {
|
switch (argc - i) {
|
||||||
case 4:
|
case 4:
|
||||||
skip2 = parse_int(argv[i + 3]);
|
skip2 = parse_int(argv[i + 3]);
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
skip1 = parse_int(argv[i + 2]);
|
skip1 = parse_int(argv[i + 2]);
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
fp2 = file_open(argv[i + 1]);
|
fp2 = file_open(argv[i + 1]);
|
||||||
|
/* fallthrough */
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
fp1 = file_open(argv[i]);
|
fp1 = file_open(argv[i]);
|
||||||
|
0
obj/.gitignore
vendored
0
obj/.gitignore
vendored
65
sysutils/dmesg.c
Normal file
65
sysutils/dmesg.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/klog.h>
|
||||||
|
#define BUF_SIZE 8196
|
||||||
|
|
||||||
|
int main(const int argc, const char **argv) {
|
||||||
|
unsigned int s_size = 0;
|
||||||
|
unsigned int n_level = 0;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
if (argv[i][0] != '-')
|
||||||
|
break;
|
||||||
|
|
||||||
|
else if (!strncmp(argv[i], "-s=", 3))
|
||||||
|
s_size = atoi(argv[i] + 3);
|
||||||
|
|
||||||
|
else if (!strncmp(argv[i], "-n=", 3))
|
||||||
|
n_level = atoi(argv[i] + 3);
|
||||||
|
|
||||||
|
else if (!strcmp(argv[i], "--help")) {
|
||||||
|
printf("dmesg [-n=L Set console logging level] [-s=S Buffer Size]\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Setup */
|
||||||
|
if (n_level)
|
||||||
|
if (klogctl(8, NULL, (long)n_level) < 0) {
|
||||||
|
fprintf(stderr, "dmesg: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!s_size)
|
||||||
|
s_size = klogctl(10, NULL, 0);
|
||||||
|
|
||||||
|
/* Get kernel log */
|
||||||
|
char *buf = malloc(s_size + 1);
|
||||||
|
if (buf == NULL) {
|
||||||
|
fprintf(stderr, "dmesg: malloc failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int n = klogctl(3, buf, s_size);
|
||||||
|
if (n <= 0) {
|
||||||
|
free(buf);
|
||||||
|
if (n == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fprintf(stderr, "dmesg: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print */
|
||||||
|
write(STDOUT_FILENO, buf, n);
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user