commit ee65a698571dab1326ccfb733437670af6b48e5b
parent fae441e25a1ac266742ba6446b37ae56c8e57076
Author: Jan Pobrislo <ccx@te2000.cz>
Date: Wed, 12 Nov 2025 21:35:01 +0000
pidns_run: Use skalibs function to create liveness pipe.
Diffstat:
1 file changed, 2 insertions(+), 34 deletions(-)
diff --git a/src/pidns_run.c b/src/pidns_run.c
@@ -1,4 +1,3 @@
-#include <fcntl.h>
#include <errno.h>
#include <sched.h> /* Definition of CLONE_* constants & unshare */
#include <unistd.h> /* fork(), getpid() */
@@ -13,45 +12,14 @@
#define PROG "pidns_run"
-void fd_cloexec(int fd) {
- int flags = fcntl(fd, F_GETFD);
- if(flags == -1) {
- strerr_dief1sys(111, "fcntl() getfd");
- }
- if(fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
- strerr_dief1sys(111, "fcntl() setfd");
- }
-}
-
-void fd_nonblock(int fd) {
- int flags = fcntl(fd, F_GETFL);
- if(flags == -1) {
- strerr_dief1sys(111, "fcntl() getfd");
- }
- if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
- strerr_dief1sys(111, "fcntl() setfd");
- }
-}
-
-void nonblock_cloexec(int fd) {
- fd_cloexec(fd);
- fd_nonblock(fd);
-}
-
int main(const int argc, const char **argv) {
int piperw[2];
#define parent_rfd piperw[0]
#define parent_wfd piperw[1]
- /* returns EINVAL for some reason
- if(pipe2(piperw, O_NONBLOCK | FD_CLOEXEC) != 0) {
- strerr_dief1sys(111, "pipe2()");
- }
- */
- if(pipe(piperw) != 0) {
+ /* Create pipe with (O_NONBLOCK | FD_CLOEXEC) */
+ if(pipenbcoe(piperw) != 0) {
strerr_dief1sys(111, "pipe()");
}
- nonblock_cloexec(parent_rfd);
- nonblock_cloexec(parent_wfd);
if(unshare(CLONE_NEWPID) != 0) {
strerr_dief1sys(111, "unshare()");
}