taps: fix error messages

This commit is contained in:
Else Someone 2026-01-22 15:08:38 +02:00
parent 564913c123
commit 691a193bba
2 changed files with 16 additions and 8 deletions

View file

@ -10,7 +10,7 @@
#include <pwd.h>
#include <fnmatch.h>
#include <fcntl.h> /* open, O_NONBLOCK, &c */
#include <stdio.h> /* perror */
#include <error.h>
#include <errno.h>
#include <sys/ioctl.h>
@ -31,8 +31,7 @@
#define DO_OR_DIE(expr) DO_OR_DIE_X((expr) == 0)
#define DO_OR_DIE_X(expr) \
do if (!(expr)) { \
perror((#expr)); \
exit(EXIT_FAILURE); \
error(EXIT_FAILURE, errno, ("Failed assertion: " #expr)); \
} while(false)
struct allow_pattern {
@ -214,6 +213,7 @@ int main(int argc, char **argv) {
char **rest = argv + 1;
DO_OR_DIE_X(argc > 1);
if (strcmp(rest[0], "serve") == 0) {
cmdServe = true;
++rest;
@ -221,21 +221,26 @@ int main(int argc, char **argv) {
cmdGet = true;
++rest;
} else {
exit(EXIT_FAILURE);
error(EINVAL, EINVAL, "no subcommand \"%s\"", rest[0]);
}
const char *patternsRaw = secure_getenv("TAPS_ALLOW");
struct allow_patterns patterns = { 0 };
if (cmdServe && patternsRaw != NULL) { patterns = parsePatterns(patternsRaw); }
if (cmdServe && patternsRaw != NULL) {
patterns = parsePatterns(patternsRaw);
DO_OR_DIE_X(patterns.patterns != NULL);
}
const char *servePath = secure_getenv("TAPS_SOCK");
if (cmdServe && patterns.patterns != NULL) {
if (cmdServe) {
error(patterns.patterns == NULL, EINVAL, "TAPS_ALLOW");
acceptRequests(servePath, &patterns);
} else if (cmdGet) {
error(ENOSYS, ENOSYS, "get");
} else {
exit(EXIT_FAILURE); }
error(EINVAL, EINVAL, "subcommand args");
}
return 0;
}

View file

@ -6,5 +6,8 @@ mkShell.override { stdenv = stdenvNoCC; } {
virtiofsd
crosvm # virtio-gpu
npins
] ++ [
man-pages
linux-manual
];
}