aboutsummaryrefslogtreecommitdiff
path: root/src/jail.c
diff options
context:
space:
mode:
authorlns <matzeton@googlemail.com>2018-04-22 18:58:49 +0200
committerlns <matzeton@googlemail.com>2018-04-22 18:58:49 +0200
commit10023e21207d9cdd0c299efeca116a1bae6cad1c (patch)
tree62091f9c6f09979d39274795eeed197f7a5c8e94 /src/jail.c
parent3778cdb66b7a7fc3e6dd43be0bb0da0c5f3f0d7a (diff)
POTD skeleton #24.
Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'src/jail.c')
-rw-r--r--src/jail.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/jail.c b/src/jail.c
index 6e6c6ab..cf6dfc0 100644
--- a/src/jail.c
+++ b/src/jail.c
@@ -5,7 +5,9 @@
#include <assert.h>
#include "jail.h"
+#include "log.h"
+static int jail_daemonfn(jail_ctx *ctx);
static int jail_childfn(void *arg);
@@ -32,20 +34,45 @@ void jail_free(jail_ctx **ctx)
*ctx = NULL;
}
-int jail_fork(jail_ctx *ctx)
+int jail_daemonize(jail_ctx *ctx)
+{
+ assert(ctx);
+ ctx->jail_pid = fork();
+
+ switch (ctx->jail_pid) {
+ case -1:
+ W_STRERR("Jail daemonize");
+ return 1;
+ case 0:
+ N("%s", "Jail daemon mainloop");
+ jail_daemonfn(ctx);
+ break;
+ }
+ D2("Jail daemon pid: %d", ctx->jail_pid);
+
+ return 0;
+}
+
+static int jail_daemonfn(jail_ctx *ctx)
{
int clone_flags = CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|
CLONE_NEWNS|CLONE_NEWNET;
assert(ctx);
- ctx->jail_pid = clone(jail_childfn, ctx->stack_beg,
- SIGCHLD|clone_flags, ctx);
- return ctx->jail_pid < 0;
+ while (1) {
+ ctx->jail_pid = clone(jail_childfn, ctx->stack_beg,
+ SIGCHLD|clone_flags, ctx);
+ sleep(1);
+ printf("---\n");
+ }
+
+ exit(EXIT_SUCCESS);
}
static int jail_childfn(void *arg)
{
+ printf("----> CHILD FN <----\n");
FILE *log = fopen("./test.log", "wb");
fprintf(log, "---> CHILD FN <----\n");
sleep(200);