-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketbox-inetd.c
More file actions
36 lines (36 loc) · 833 Bytes
/
Copy pathsocketbox-inetd.c
File metadata and controls
36 lines (36 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include "unix_scm_rights.h"
#include "libsocketbox.h"
int main(int argc, char **argv) {
skbox_set_validation_level(-1);
signal(SIGCHLD, SIG_IGN);
if (argc<3) {
fprintf(stderr, "Usage: %s [socket] [program] [arguments]\n", argv[0]);
return 1;
}
int socket_fd = skbox_new(argv[1]);
if (socket_fd == -1) {
perror("Failed to create socket");
return 1;
}
while (1) {
int s = skbox_receive_fd_from_socket_p(socket_fd, 1);
if (s == -1 && errno != EINTR) {
perror("Failed to receive from socket");
continue;
}
if (!fork()) {
if (setsid() < 0) _exit(1);
if (dup2(s, 1) < 0) _exit(1);
if (dup2(s, 0) < 0) _exit(1);
if (s > 1) close(s);
execvp(argv[2], &argv[2]);
_exit(127);
}
close(s);
}
}