chore: organize code

add -Wextra by default
pipefd to communicate better with parent and forked process
rustify some stuff
add the desktop parser to the file read
This commit is contained in:
2025-08-27 22:02:14 +02:00
parent 056ec64bcb
commit 109c9bd0be
17 changed files with 185 additions and 113 deletions

View File

@@ -4,6 +4,7 @@
#include <stdlib.h>
#include "chvt.h"
#include "macros.h"
static char* vterms[] = {"/dev/tty", "/dev/tty0", "/dev/vc/0", "/dev/systty",
"/dev/console"};
@@ -24,15 +25,13 @@ int chvt_str(char* str) {
}
int chvt(int n) {
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
(void)fprintf(stderr, "activating vt %d\n", n);
// NOLINTNEXTLINE(readability-identifier-length)
char c = 0;
for (size_t i = 0; i < sizeof(vterms) / sizeof(vterms[0]); i++) {
for (size_t i = 0; i < LEN(vterms); i++) {
int fd = open(vterms[i], O_RDWR);
if (fd >= 0 && isatty(fd) && ioctl(fd, KDGKBTYPE, &c) == 0 && c < 3) {
if (ioctl(fd, VT_ACTIVATE, n) < 0 || ioctl(fd, VT_WAITACTIVE, n) < 0) {
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
(void)fprintf(stderr, "Couldn't activate vt %d\n", n);
return -1;
}