aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2023-06-07 00:53:29 +0200
committerStefano Brivio <sbrivio@redhat.com>2023-06-07 00:53:29 +0200
commit7e9762ead3e1f11ebf5301ed55d213e825893a24 (patch)
treee1c083c3be8568ec31ad6b9f7ec39aa9c98db5e1
parente2698a0d3e0b20cf770dbb67cbe6c7643b62f056 (diff)
downloadseitan-7e9762ead3e1f11ebf5301ed55d213e825893a24.tar
seitan-7e9762ead3e1f11ebf5301ed55d213e825893a24.tar.gz
seitan-7e9762ead3e1f11ebf5301ed55d213e825893a24.tar.bz2
seitan-7e9762ead3e1f11ebf5301ed55d213e825893a24.tar.lz
seitan-7e9762ead3e1f11ebf5301ed55d213e825893a24.tar.xz
seitan-7e9762ead3e1f11ebf5301ed55d213e825893a24.tar.zst
seitan-7e9762ead3e1f11ebf5301ed55d213e825893a24.zip
seitan, main: Più umano più vero (more human more true)
...and terminate on EPOLLHUP. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--seitan.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/seitan.c b/seitan.c
index 630ff83..4005a9b 100644
--- a/seitan.c
+++ b/seitan.c
@@ -186,12 +186,11 @@ int main(int argc, char **argv)
struct seccomp_notif *req = (struct seccomp_notif *)req_b;
struct arguments arguments;
char path[PATH_MAX + 1];
- bool running = true;
+ int fd = -1, epollfd;
int pidfd, notifier;
struct gluten g;
- int fd, epollfd;
int notifierfd;
- int nevents, i;
+ int n, i;
arguments.pid = -1;
parse(argc, argv, &arguments);
@@ -227,23 +226,29 @@ int main(int argc, char **argv)
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, notifier, &ev) == -1)
die(" epoll_ctl: notifier");
- while (running) {
- nevents = epoll_wait(epollfd, events, EPOLL_EVENTS, -1);
- if (nevents < 0)
- die(" waiting for seccomp events");
- memset(req, 0, sizeof(*req));
- if (ioctl(notifier, SECCOMP_IOCTL_NOTIF_RECV, req) < 0)
- die(" recieving seccomp notification");
- for (i = 0; i < nevents; ++i) {
- if (events[i].events & EPOLLHUP) {
- /* The notifier fd was closed by the target */
- running = false;
- } else if (notifier == events[i].data.fd) {
- if (eval(&g, req, notifier) == -1 )
- err(" an error occured during the evaluation");
- }
+loop:
+ n = epoll_wait(epollfd, events, EPOLL_EVENTS, -1);
+ if (n < 0)
+ die("waiting for seccomp events: %s", strerror(errno));
+
+ for (i = 0; i < n; i++) {
+ if (events[i].events & EPOLLHUP) {
+ if (fd >= 0)
+ unlink(arguments.socket);
+ exit(EXIT_SUCCESS);
}
+
+ if (events[i].events & EPOLLERR)
+ die("error on notifier");
}
- if (strcmp(arguments.socket, "") > 0)
- unlink(arguments.socket);
+
+ if (ioctl(notifier, SECCOMP_IOCTL_NOTIF_RECV, req) < 0)
+ die("receiving seccomp notification: %s", strerror(errno));
+
+ if (eval(&g, req, notifier))
+ err("an error occured during the evaluation");
+
+ goto loop;
+
+ return 0;
}