Skip to content

uloop improvements - #494

Open
nbd168 wants to merge 2 commits into
ucode-lang:masterfrom
nbd168:uloop
Open

nbd168 wants to merge 2 commits into
ucode-lang:masterfrom
nbd168:uloop

Conversation

@nbd168

@nbd168 nbd168 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor
  • allow passing a prepare function to uloop.process()
  • properly handle exit() in callbacks

@nbd168
nbd168 force-pushed the uloop branch 2 times, most recently from f34096b to bd05296 Compare October 17, 2026 18:04
Since the exception guard was added, uc_uloop_vm_call() hands every
exception of a callback to the guard handler, also the EXCEPTION_EXIT
that exit() raises. The guard receives an "Exit" exception and the loop
keeps running. When run() returns, the script ends with code 0 instead
of the code given to exit(), because the VM already reset its call
frames for the exit request.

End the loop and keep the exit request pending, as without a guard, so
that the script terminates with the requested code.

Fixes: aaf712e ("uloop: add guard() function")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
A program started by uloop.process() can need preparatory work in the
child before exec(), for example to redirect a file descriptor.

Accept a function instead of the executable path. The function runs in
the child after fork(), receives the argument vector and the
environment, and returns the complete argument vector to execute.
Changes to the environment object apply to the executed program.
exit() in the function sets the exit code of the child. If the function
throws an exception or does not return a non-empty array, the child
exits with code 255, the same as for a failed exec().

Release the event loop in the child before the function runs, like
uloop.task() does. The child otherwise shares the signal pipe of the
parent, so a signal sent to the child runs signal callbacks of the
parent, and SIGTERM does not end the child.

Flush the output of the parent before fork(), since a flush in the child
writes the inherited buffer a second time.

Signed-off-by: Felix Fietkau <nbd@nbd.name>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant