Read this first. Everything else under Operating Yuneta assumes you already know what
main()does, who is the parent of who, and why a yuno survives akill -9of its agent.
A yuno is an autonomous machine. It is engineered to keep running with
or without an agent on the box. The agent is one more peer in the ecosystem
— a manager, not a parent. The mechanism that makes that autonomy concrete
lives in two files of kernel/c/root-linux/src/:
| File | Role |
|---|---|
entry_point.c | The int main() body every yuno calls. argp, gbmem, config, log, gobj_start_up, registration, then either daemon or foreground. |
ydaemon.c | The supervision kernel under --start. Double fork, watcher process, auto-relaunch on abnormal exit. |
Every standalone or citizen yuno’s main.c boils down to one call to
yuneta_entry_point() (optionally preceded by yuneta_setup() if it wants
to override defaults). See yunos/c/yuno_agent/src/main.c for the
canonical example.
1. The picture¶
The same picture in text:
┌─────────────────────────────────────────┐
init / sysv ──► │ grandparent: yuneta_agent --start │
│ fork() ── parent exits ──► │
│ ┌─────────────────────────────────────┤
│ │ watcher (session leader, watcher_pid)
│ │ waitpid() loop, ignores all signals except SIGCHLD
│ │ fork() ──► │
│ │ ┌─────────────────────────────────┤
│ │ │ yuno child (pid) │
│ │ │ gobj tree, yev_loop_run │
│ │ │ own signalfd handler (c_yuno.c)│
│ │ └─────────────────────────────────┘
└─────────────────────────────────────────┘Two implications worth keeping in your head:
Every yuno you see in
pshas a sibling watcher.pgrep yuneta_agenton a healthy box returns two pids: the watcher and the child.The watcher does not know what the agent is. It uses
waitpid()on one specific pid. If the child SEGVs, the watcher waits (2 s the first time, longer if it keeps failing: §4.3) and re-execs the same binary with the same args. The agent is informed indirectly (its channel to the yuno closes). It does not drive the restart.
2. yuneta_setup() — pluggable defaults (optional)¶
Call before yuneta_entry_point() if you want to override any of:
| Knob | Default | Where the default is set |
|---|---|---|
persistent_attrs | db_load/save/remove/list_persistent_attrs (dbsimple) | entry_point.c |
command_parser | internal command_parser() | entry_point.c |
stats_parser | internal stats_parser() | entry_point.c |
authz_checker | C_AUTHZ monoclass checker | entry_point.c |
authentication_parser | C_AUTHZ parser | entry_point.c |
MEM_MIN_BLOCK / MEM_MAX_BLOCK | 512 B / 16 MiB | entry_point.c |
MEM_SUPERBLOCK | 16 MiB | entry_point.c |
MEM_MAX_SYSTEM_MEMORY | 64 MiB | entry_point.c |
USE_OWN_SYSTEM_MEMORY | FALSE (use libc malloc under gbmem) | entry_point.c |
The memory tunables are passed straight to gbmem_setup() later. Yunos
that handle large messages (image proxies, mqtt brokers under load) bump
MEM_MAX_BLOCK and MEM_MAX_SYSTEM_MEMORY. See yuno_agent/src/main.c
for a representative call site.
3. yuneta_entry_point() — the choreography¶
entry_point.c. In execution order:
3.1 Identity sanity¶
APP_NAMEmust be ≤ 15 chars (Linuxcommfield limit). Test binaries starting withtest_are exempted (PREFIX_TEST_APP— flagged as a BUG in the source itself).The Unix user running the binary must be
yunetaor in groupyuneta, otherwiseprint_error(PEF_EXIT, …).
3.2 argp¶
| Flag | Effect |
|---|---|
-S, --start | Run as daemon (double-fork + watcher). Else foreground. |
-K, --stop | Call daemon_shutdown(process_name) and exit (see §4.5). |
--pid-file=FILE | With --start: write the WATCHER’s pid in FILE before returning (see §4.7). |
-f, --config-file=FILE | Merge external JSON on top of fixed/variable config. |
-p, --print-config | Print final merged config and exit. |
-P, --print-verbose-config | Print config with all defaults expanded and exit. |
-r, --print-role | Print {role,name,alias,version,date,description,tags,…} and exit. |
-v, --version | Print yuno version and exit. |
-V, --yuneta-version | Print yuneta runtime version and exit. |
-l, --verbose-log=N | Override handler_options of the stdout log handler. Not a trace switch — it only selects which fields each line prints. |
-g, --global-trace=LEVEL | Enable a global trace level before the first service starts. Repeatable and comma-separated. list prints the available levels. The only way to trace start up itself, since set-global-trace needs the agent channel that a failing yuno never opens. See DEBUGGING.md §4.1. |
3.3 Close-and-rewire stdio in daemon mode¶
With --start, the framework closes every fd in
[0, sysconf(_SC_OPEN_MAX)). Then it opens /dev/null to take fd 0, and
calls dup2 for fd 1 and fd 2. After this, no inherited fd survives.
check_open_fds() warns if anything stays open beyond 4.
3.4 Allocator switch — this is load-bearing¶
gbmem_get_allocators(&malloc, &realloc, &calloc, &free);
json_set_alloc_funcs(malloc_func, free_func); // jansson now uses gbmem
gbmem_setup(MEM_MAX_BLOCK, MEM_MAX_SYSTEM_MEMORY, USE_OWN_SYSTEM_MEMORY,
MEM_MIN_BLOCK, MEM_SUPERBLOCK);After this line, every json_* allocation goes through gbmem_* and is
tracked under CONFIG_DEBUG_TRACK_MEMORY.
Test-author trap: any json_pack() / set_expected_results() called
before yuneta_entry_point returns gets libc-tracked memory that
gbmem cannot free later → false leaks. Put that setup inside
register_yuno_and_more() (which runs at §3.10 below), never in main().
The canonical example is tests/c/c_task_authenticate/.
3.5 Logging boot¶
glog_init() registers the available log handler types (stdout, file,
udp). rotatory_start_up() arms the rotation timer. No handlers are
attached yet.
3.6 Merge the config¶
json_config() merges, in order:
fixed_config (compiled into the yuno) +
variable_config (compiled, intended to be overridden) +
--config-file=… contents +
[json blob passed as argp positional argument]view-config on a running yuno (ycommand command-yuno id=<id> service=__yuno__ command=view-config) returns this merged result, not
the on-disk file. Verify any claim about a running yuno’s config with
view-config, never from the external JSON alone.
3.7 Environment registration¶
Reads environment.{work_dir, domain_dir, xpermission, rpermission} from
the merged config and calls register_yuneta_environment(). This is what
later powers yuneta_realm_file(), yuneta_log_file() and the rest of
the path helpers.
3.8 gobj_start_up()¶
Initializes the gobj registry, persistent-attrs subsystem, the four
parsers (command/stats/authz/authentication) and the trace plumbing. From
here on, gobj_create*/gobj_log_*/gobj_subscribe_event are usable.
3.9 Log handlers — files and UDP¶
Reads environment.{daemon|console}_log_handlers depending on
__as_daemon__. For each entry:
handler_type: stdout→ attaches withhandler_options(overridable with-l).handler_type: file→ opens a rotatory at the path resolved byyuneta_log_file(), honouringbf_size,max_megas_rotatoryfile_size,min_free_disk_percentage.handler_type: udp(or legacy typoupd) →udpc_open()to the configuredurl. This is the logcenter feed.
3.10 Register gclasses¶
result += yunetas_register_c_core(); // runtime gclasses (c_tcp, c_timer, …)
if(result < 0) {
exit(-1); // a core gclass refused
}
int ret = register_yuno_and_more(); // the yuno's own gclasses + setup
if(ret < 0) {
exit(-1); // one of the yuno's refused (an ERROR first)
}A gclass of the yuno that gclass_create() refuses stops it there, as one of
the core does (7.27.0+): up to 7.26.9 the yuno ran, and its services failed
later with “gclass NOT FOUND”. So register_yuno_and_more() answers the sum
of what its register_c_*() answer.
register_yuno_and_more() runs after environment + gobj_start_up are
ready, but before any service or yuno gobj is created. This is the
canonical place to:
gobj_register_gclass(…)your own classes,enable traces from code,
in tests,
set_expected_results()(see §3.4).
3.11 Branch on daemon mode¶
if(__as_daemon__) {
daemon_run(process, process_name, work_dir, domain_dir, cleaning_fn);
return gobj_get_exit_code();
} else {
process(process_name, work_dir, domain_dir, cleaning_fn);
return result;
}The foreground path runs process() directly. The daemon path goes
through ydaemon.c. Both paths reach the same process() function.
4. ydaemon.c — the supervision kernel¶
ydaemon.c. The reason a yuno survives kill -9 yuneta_agent.
4.1 Double fork¶
continue_as_daemon(): fork() once. The parent calls
_exit(EXIT_SUCCESS). The child becomes session leader via setsid() and
records watcher_pid = getpid(). This is the watcher process.
relauncher(): fork() again. The watcher waitpid()s on
the grandchild, and the grandchild is the actual yuno. The grandchild
gets back the signals its starter gave (§4.2), inherits umask 0, chdirs to
work_dir, and calls process().
4.2 Watcher signal posture¶
// daemon_catch_signals(): once, before the first fork
sigaction(SIGPIPE, SIG_IGN, &given[...]); // what the starter gave is kept
sigaction(SIGTERM, SIG_IGN, ...);
sigaction(SIGALRM, SIG_IGN, ...);
sigaction(SIGINT, SIG_IGN, ...); // ctrl+c
sigaction(SIGUSR1, SIG_IGN, ...);
sigaction(SIGUSR2, SIG_IGN, ...);
sigaction(SIGHUP, SIG_IGN, ...);
sigaction(SIGQUIT, {on_watcher_sigquit, SA_RESTART}, ...); // notes the stop
sigprocmask(SIG_UNBLOCK, {SIGQUIT}, NULL);The watcher is deliberately deaf to everything except SIGCHLD (delivered
implicitly via waitpid), SIGKILL (uncatchable, terminates it) and
SIGQUIT, which does not end it: it notes the stop, and the child that ends
after it is not relaunched, whatever its end (SA_RESTART keeps the
waitpid() going). Up to 7.25.22 SIGQUIT was ignored too, and an agent that
crashed during its orderly stop was relaunched 2 s later.
Set before the first fork.
daemon_run()sets them in the process it starts in, so the watcher has them from its first instruction, and a stop that comes before the first child is forked launches nothing. Up to 7.29.3 they were set after each fork of a child: a SIGQUIT that came right after the first one found the default, ended the watcher, and left the child an orphan.SIGQUIT is unblocked. A yuno starts with its signals blocked (below), and otherwise the watcher hears its stop only when it looks for it.
The yuno’s signals are blocked from the first line of
yuneta_entry_point(). With--startthey stay blocked until the watcher sets its signals, so a SIGQUIT that comes before is pending, and then it is the stop: nothing is launched. Without--startthey are given back once the arguments are read (a foreground process keeps their defaults until itsC_YUNOblocks them). Up to 7.29.3 a yuno started by hand or by a systemd unit had nothing blocked there, and a SIGQUIT ended it with a core dump. One that the agent launched inherited the agent’s mask.SIGHUP is ignored, as SIGTERM. The stop is SIGQUIT and nothing else (
--stop, the units’ExecStop). The watcher has no terminal (setsid()), so a SIGHUP can only be a stray one, akill -HUPby name or a script that reloads by signal, and if the watcher takes it as a stop, such a signal ends the yuno for good. Up to 7.29.3 it ended the watcher, and the child ran on with nobody to relaunch it.Every child gets back what the starter gave. Right after its fork the child restores the dispositions of those signals and the mask that the watcher was started with: a relaunched child starts as the first one. Up to 7.29.3 the relaunched children inherited the watcher’s: SIGTERM, SIGINT, SIGALRM, SIGUSR1, SIGUSR2 and SIGPIPE ignored (
SigIgn: 0x7a02in/proc/<pid>/status), and SIGQUIT caught by the watcher’s handler. Once the yuno blocked them for its signalfd they reached it all the same: Linux queues a blocked signal even when it is ignored, sokill -10 <pid>(the trace cycle) worked on a relaunched yuno too. What was lost was a signal that came before the signalfd (ignored, or a SIGQUIT taken by the inherited handler), and the programs the yuno ran inherited the ignores (an ignored signal stays ignored acrossexec).The yuno’s signals are blocked from the fork to the signalfd. The watcher blocks SIGPIPE, SIGTERM, SIGALRM, SIGQUIT, SIGINT, SIGUSR1 and SIGUSR2 (the set of
C_YUNO’ssignalfd) around eachfork(), and the child keeps them blocked, on top of the starter’s mask, until its signalfd reads them. A signal that comes before is pending: the signalfd reads it when it is made. Up to 7.29.3 that held only for a yuno the agent launched (it inherited the agent’s mask, those signals blocked). For a yuno started with an empty mask (both agents’ systemd units, or by hand), a SIGQUIT before the signalfd ended the child with a core dump (LimitCORE=infinity) and the watcher relaunched it, and a SIGUSR1 ended it too. Since programs run by a yuno start with an empty mask (§6), a yuno the agent launches starts that way as well.A stop that comes while the watcher waits for a child reaches the child. The watcher looks at the stop with SIGQUIT blocked, so one that came before its look (pending) launches nothing. After the fork it notes the child’s pid, still with SIGQUIT blocked, and from then on its handler passes every SIGQUIT to that child (
kill(child, SIGQUIT)), where it waits for the signalfd. Whoever sent it does not always know the child:--stoplists the processes once, and a child forked after that is not in the list. Up to 7.29.3 the child ran on until--stop’s SIGKILL 10 s later. The watcher waits for the child’s end without reaping it (waitid()withWNOWAIT), forgets its pid, and only then reaps it: a SIGQUIT is never passed to a pid that can be another process by then. So a stop sent to the watcher AND to the child (--stop, theExecStopof the agents’ units, the agent’skill-yunoof a yuno it does not know running) reaches the child twice. A daemon takes the first one and no other (§6).
grep -E 'SigIgn|SigBlk' /proc/<yuno pid>/status # the same before and after a relaunch4.3 waitpid() decision matrix¶
Event reported by waitpid() | Watcher action |
|---|---|
WIFEXITED && exit_code == 0 | return 1 → exit (no relaunch) |
WIFEXITED && exit_code != 0 | return -1 → wait + relaunch |
WIFSIGNALED && signal == SIGKILL | return 1 → exit (no relaunch) |
WIFSIGNALED && signal != SIGKILL (SEGV…) | return -1 → wait + relaunch |
| anything else | return -1 → wait + relaunch |
The wait grows while the child keeps failing. The first relaunch comes
2 s after the end, so a yuno that crashed once is back at once. When the
relaunched child ends again less than 60 s after its start, the wait doubles:
2, 4, 8, 16, 32 s, then 60 s, and it stays at 60 s. A child that lived 60 s or
more sets it back to 2 s. A SIGQUIT (§4.2) cuts a wait short: the watcher
exits at once and does not relaunch. That holds whenever the SIGQUIT comes,
even just before the wait starts: the watcher blocks SIGQUIT, looks at the
stop, and waits in sigtimedwait(), which takes a SIGQUIT that is pending.
The wait was a sleep(), and a SIGQUIT that came after the child ended and
before the sleep() let the whole wait run: 2 s up to 7.29.3, and, once the
wait was able to grow to 60 s, past systemd’s TimeoutStopSec=30 or the 10 s of
--stop, and into a SIGKILL.
sigprocmask(SIG_BLOCK, {SIGQUIT}, &old);
while(!stop_requested && !test_msectimer(wait_timer)) {
if(sigtimedwait({SIGQUIT}, NULL, &left) == SIGQUIT) {
stop_requested = 1;
}
}
sigprocmask(SIG_SETMASK, &old, NULL); // a SIGQUIT still pending reaches the handlerEach time the wait grows, the watcher says it on stdout and syslog
(ERROR YUNETAS: <process> ended again within 60 s of its start (signal …, exit code …): relaunched in <N> s, pid <watcher>). At 60 s, it stops saying it.
For example, an agent whose audit directory cannot be made exits at each start:
its relaunches come at 2, 6, 14, 30, 62, 122 s, and then one a minute.
Why a cap of one minute and not more: the agent is the only way into a sealed node. Once the cause is gone (the disk freed, the directory fixed), it must be back soon without anybody restarting its unit. Why not stay at 2 s: a cause that does not go away (a full disk, a directory of the wrong owner) printed its error twice every 2 s, about 43,200 syslog lines a day each. And because the watcher stays alive, systemd’s own restart limit never applies to it. Up to 7.29.3 the wait was always 2 s, as it was before v7.
relaunch_times is bumped on every restart and logged by the new child, with
the wait it came after (relaunch_wait, in seconds):
MSGSET_SYSTEM "Daemon relaunched" process=… pid=… relaunch_times=… relaunch_wait=… signal_code=… exit_code=…That log line is the only indication a watcher resurrection happened.
If you see relaunch_times > 0 after a quiet day, something crashed.
4.4 What the agent does and does not do¶
Auto-restart on crash is the watcher’s job, not the agent’s.
The agent sees a closed channel (
EV_ON_CLOSE) when the yuno child dies — but the agent’s record-clear and the watcher’s relaunch run in parallel and are unrelated. By the time the agent reconciles, the watcher has already spawned a new yuno child with a new pid.If you
kill -9the agent itself, every yuno on the box keeps running. Each one still has its watcher. Restarting the agent re-discovers them viagetpgid(pid) >= 0checks plus the boot-timerun_enabled_yunos().
4.5 --stop / daemon_shutdown()¶
daemon_shutdown() scans /proc/*/comm for entries matching
process_name that were started as it. The name is the base name of argv[0] in
/proc/<pid>/cmdline, readable whoever owns the process. The SysV script of
the same name has its interpreter there, /bin/sh, and is not one of them.
An agent whose binary was renamed or replaced on disk still is one. A zombie of
the name is dead: it is not taken, and an EPERM on one is no failure. The
list has no fixed size, so look-alikes of the name, which anybody can start,
cannot crowd the real ones out of it. The function sends
SIGQUIT to every one of them -- the watchers first (a
process whose parent is not of the name), so none relaunches its child --,
gives them 10 s to be gone (looked at every 100 ms), then scans again and
kills with SIGKILL what is still there:
kill(watcher, SIGQUIT); // first: it will not relaunch
kill(child, SIGQUIT); // soft exit, let it delete pid file, flush logs
wait_until = start_msectimer(STOP_WAIT_MS); // 10 s for all of them
... // every 100 ms: gone, or a zombie?
search_process(name, ...); // again: what is left, relaunched or not
kill(pid, SIGKILL); // guarantee they goA process of the name that another user runs is not taken, unless --stop
runs as root (the owner of /proc/<pid> is compared with the effective
uid): anybody can start a look-alike of the name. In 7.30.18 it was taken,
its kill() failed with EPERM, and --stop exited 1. When such processes
are all there is of the name, --stop says so and exits 1:
$ yuneta_agent --stop # as a user that does not run the agent
--stop: yuneta_agent not stopped: 1 process(es) of the name run as another user (pid 1142, uid 1001), not mine to stop: run --stop as that user or as rootIn 7.30.19 it said nothing and exited 0: the operator took the agent for
stopped, and the --start after it launched a second agent beside the
running one.
With /proc mounted hidepid=1, the name of another user’s process cannot
be read (EPERM). When nothing of the name is the user’s own and such
processes exist, --stop cannot tell whether the daemon runs: it says so and
exits 1 (in 7.30.20 it said nothing and exited 0):
$ yuneta_agent --stop # as a user, /proc mounted hidepid=1
--stop: yuneta_agent: not known if it runs: the name of 250 process(es) of other users cannot be read (pid 1: /proc mounted with hidepid?): run --stop as rootWith hidepid=2 another user’s process is not listed at all, so that
cannot be known: --stop says nothing and exits 0. Run --stop as root, or
as the user that runs the daemon.
Every kill() is checked: one that fails is said on stdout (and syslog), not waited for,
and --stop exits 1. Up to 7.25.22 none was checked: an EPERM waited 10 s, printed “killed (SIGKILL)” and exited
0. And an agent that crashed during its stop was relaunched by its watcher,
the watcher was SIGKILLed at 10 s, and the new agent was left an orphan.
Up to 7.25.21 each process was killed 1 s after its own SIGQUIT, one after the other: the agent had one second for its orderly shutdown, and the watcher, deaf to SIGQUIT, always took its whole second.
The scan matches both processes of the pair, because the watcher and the child share the process name. Each one answers differently:
The child catches SIGQUIT through its signalfd and calls
set_yuno_must_die(), which setsgobj_set_exit_code(0)before the orderly shutdown. So it exits 0 — and per the matrix in §4.3 the watcher then returns 1 and exits by itself. A SIGQUIT does not leave a resurrecting yuno behind. The signalfd is read with one io_uring read, armed again after each signal. When that read ends with an error while the yuno runs (its fd closed under it, a read that cannot be done), the yuno says it and reads again, on a new signalfd when the old fd is no longer one:ERROR: {"function": "read_signals_again", "msg": "the read of the signals ended while the yuno runs: read again", "result": -32, "serrno": "Broken pipe", "fd": 4, "fd_is": "/dev/null", "failures": 1, ...}Up to 7.28.1 it was not armed again and nothing was said: the process was deaf to every signal from then on -- a SIGQUIT and a SIGALRM stayed pending for ever (
SigPnd/ShdPndin/proc/<pid>/status), and only a SIGKILL ended it. The agents of two nodes showed exactly that: the stop of their unit timed out into a SIGKILL (the pid file in §4.7), after a day or two of running. A read that ended is the likely cause, not a proven one -- what ended it was never seen. Ten failures in a row and it is no longer read, with a last ERROR that says the yuno is deaf. Test:tests/c/c_yuno_signal_read.The watcher notes SIGQUIT (§4.2) and stays in its
waitpid(): when the child ends, it exits instead of relaunching it, even if the child crashed in its shutdown.
The SIGKILL is therefore not what breaks a relaunch loop: it is the
guarantee for the case where 10 s were not enough: a child stuck in its
shutdown, and the watcher still sitting in waitpid(). SIGKILL is uncatchable
and takes both. --stop says so on stdout and syslog (“still alive after the wait:
killed (SIGKILL)”, or “started while the stop ran” for a process of the
name that was not in the first scan).
That exit code is the whole protocol. The restart path uses the other value:
timeout_restart sets gobj_set_exit_code(-1), and the non-zero exit is
precisely what asks the watcher to launch the yuno again.
4.6 get_watcher_pid()¶
Exported so c_yuno.c can include both pid and watcher_pid in the
yuno’s identity card. That is how the agent gets the yuno_pid and the
watcher_pid rows in its treedb (used by kill-yuno, see §7).
4.7 Under a systemd unit: --pid-file¶
The agents run under native units (yuneta_agent.service,
yuneta_agent22.service, shipped by the packages after 7.25.21). A unit of
Type=forking needs the pid of the process that STAYS, and here that is the
watcher, not the agent: --pid-file makes the process started with --start
write the watcher’s pid (the child of its fork) before it exits, which is the
moment systemd reads PIDFile=. The file is written aside and renamed, so it
is whole or absent. A failure to write it is printed and logged to syslog.
[Service]
Type=forking
User=yuneta
RuntimeDirectory=yuneta_agent
PIDFile=/run/yuneta_agent/yuneta_agent.pid
ExecStart=/yuneta/agent/yuneta_agent --config-file=/yuneta/agent/yuneta_agent.json --start --pid-file=/run/yuneta_agent/yuneta_agent.pid
ExecStop=-/bin/kill -QUIT $MAINPID
ExecStop=-/usr/bin/pkill -QUIT -P $MAINPID -x yuneta_agent
ExecStopPost=-/bin/sh -c 'cg=$$(systemctl show -p ControlGroup --value %n); for r in /sys/fs/cgroup /sys/fs/cgroup/unified /sys/fs/cgroup/systemd; do [ -n "$$cg" ] && [ -r "$$r$$cg/cgroup.procs" ] || continue; for p in $$(cat "$$r$$cg/cgroup.procs"); do if [ "$$(cat /proc/$$p/comm 2>/dev/null)" = "yuneta_agent" ]; then kill -KILL $$p && logger -t yuneta_agent "ExecStopPost: pid $$p left in %n after its stop: killed"; fi; done; exit 0; done; logger -t yuneta_agent "ExecStopPost: no cgroup.procs of %n found: nothing checked"; exit 0'
KillMode=process
SuccessExitStatus=SIGKILL
Restart=noWhat each line keeps from this chapter:
Restart=no. The watcher relaunches the agent (§4.3). A crash of the agent is seen by the watcher, not by systemd: the unit staysrunningwith the same main pid. If systemd also restarts it, a second agent starts and fights the first for its ports.ExecStopasks only THIS unit’s agent for its orderly shutdown: first its watcher ($MAINPID), which then does not relaunch it, then the agent (the child of$MAINPID). The watcher ends with it. Not--stop(§4.5), which ends every process of the name: systemd runsExecStopalso when the watcher ended on its own, and ifExecStopused--stop, a second agent that met the first one running and left takes the first one with it.SuccessExitStatus=SIGKILL. A hand-run--stopwhose agent is not gone in 10 s ends the watcher with SIGKILL. Without it, the unit readsfailed. (Up to 7.25.21 every--stopdid.)ExecStopPost. The watcher ignores SIGTERM, so afterTimeoutStopSecsystemd SIGKILLs it -- it only, withKillMode=process. WithoutExecStopPost, an agent hung in its shutdown, or relaunched by the watcher while the stop ran, stays in the cgroup, unsupervised, and meets the next start.ExecStopPostkills what is left of that agent in the unit’s own cgroup (the yunos there have other names), and says each kill in the journal. It asks systemd for the cgroup (ControlGroup) and reads it under the v2, hybrid or v1 mount. When none is found, it says so. Up to 7.25.22 it read a v2 path written by hand: a no-op, unsaid, on a v1 or hybrid host, and a kill with nothing in the journal. Such a stop endsfailed (timeout), which is what it was.The pid file of a killed agent. An agent killed with SIGKILL runs no
atexit(), so its own pid file (/yuneta/realms/agent/yuneta_agent.pid, not the unit’s) stays behind, and the next start reads it a few milliseconds later, when that pid is still a zombie nobody reaped. The agent tells the cases apart: a pid that is an agent (of any user: its cmdline is read even whenkill()answersEPERM) means “already running”, and it exits. A pid that is gone is removed in silence. A pid that is something else -- a zombie, with an empty cmdline, or another program -- is a WARNING, “pid file left by an agent that did not end in order”, and removed. A file without a pid is a WARNING too. Up to 7.28.0 the zombie was an ERROR, “cannot check pid” witherrno 0, and a file without a pid was read as pid 0 -- this very process -- and the agent exited as “already running”. Example, the WARNING after a stop that timed out:WARNING: {"process": "yuneta_agent^node1", "msg": "pid file left by an agent that did not end in order: its pid is not an agent now (killed and not yet reaped, or taken by another program), removed", "pid_in_file": 1142552, ...}The unit is the package’s. A node that builds from source does not install the packages, so it keeps the unit of the last package it had: a unit older than 7.26.0 asks only the agent to stop (
pkill), not its watcher, and itsExecStopPostreads a hand-written cgroup path and says nothing (two production nodes had one in 2026-10). Compare withsystemctl cat yuneta_agentand copypackages/templates/*.serviceby hand when it differs.KillMode=process. The yunos the agent launches are in the unit’s cgroup. A stop or a restart must not take them (they outlive their agent, §4.4). The journal says “Found left-over process” for them at the next start, which is that rule working.A SIGKILL of the agent alone is a stop, not a crash (§4.3): the watcher exits and the unit goes
inactive. To test the relaunch, crash it with another signal (kill -SEGV).
An agent started by hand with --start runs outside the unit, where systemd
does not see it: sudo /etc/init.d/yuneta_agent start stops it and starts the
units (main agent first, agent22 once it is up), or restart it with
systemctl restart yuneta_agent. Stopping needs no root: --stop run as
yuneta ends the agent, and its unit goes inactive.
5. process() — the inner loop¶
entry_point.c. What every yuno runs after the daemon
ceremony is complete.
Emit the startup banner (
MSGSET_STARTUP "Starting yuno") with the full realm + yuno identity. This is the first line in anylogs/<N>.log.gobj_create_yuno(__yuno_name__, C_YUNO, kw_yuno)→ the grandmother gobj of the runtime tree.For every entry in
config.services[]:gobj_service_factory(name, tree)instantiates the service subtree.run_services()→ start every service in declared order.yev_loop_run(yuno_event_loop(), -1)→ block here for the rest of the process’s life. Returns only whenset_yuno_must_die()flips the stop flag (§6).stop_services()→ graceful shutdown in reverse order.gobj_end()→ destroy yuno, free baseline allocations.json_decref(__jn_config__), optionalcleaning_fn().print_track_mem()— underCONFIG_DEBUG_TRACK_MEMORY, dumps any surviving blocks.gobj_end()must run before anyget_cur_system_memory()check, per the test rule inCLAUDE.md.rotatory_end()— last, so the report reaches the log file.
When process() returns, the daemon child reaches the bottom of
relauncher() and exits with gobj_get_exit_code() — which determines
whether the watcher exits cleanly (§4.3).
In the foreground (a test, a utility, a yuno run by hand), yuneta_entry_point()
returns -1 when that audit found blocks still busy, so the process ends with
an error. It catches what a get_cur_system_memory() check in main() after
yuneta_entry_point() cannot: a block held across the end and freed after it,
which the audit logs (“print_track_mem(): system memory not free”) and the
later check sees as gone. Without CONFIG_DEBUG_TRACK_MEMORY there is no audit,
and nothing changes:
int result = yuneta_entry_point(argc, argv, ..., register_yuno_and_more, cleaning);
if(get_cur_system_memory() != 0) { // still the check of what is never freed
result += -1;
}
return result < 0? -1 : 0;6. Signals inside the yuno child¶
c_yuno.c installs a signalfd() that watches SIGTERM,
SIGQUIT, SIGINT, SIGALRM, SIGUSR1, SIGUSR2, SIGPIPE. yev_loop pumps it.
The handler (c_yuno.c):
| Signal | First time | Second time |
|---|---|---|
| SIGQUIT / SIGINT / SIGALRM | set_yuno_must_die() → exit code 0 → yev_loop_run returns → clean shutdown → watcher does not relaunch | daemon: nothing more, the orderly stop goes on — foreground: _exit(0) immediately (still exit code 0) |
| SIGUSR1 | cycle global trace level (off → L0 → L1 → L2 → off) | same |
| SIGUSR2 | toggle deep tracing | same |
| SIGTERM | daemon (--start): ignored — foreground: same as SIGQUIT | daemon: ignored — foreground: _exit(0) |
| SIGPIPE | ignored | ignored |
The child is born with these signals blocked (§4.2), so one sent before the signalfd exists is read by it, not lost and not fatal.
Three consequences:
Sending SIGQUIT to a healthy yuno is the correct way to ask it to stop. The first SIGQUIT is a request. In the foreground the second is “I said now” (a second ctrl+c). A daemon takes the first one and no other: its stop is sent to the watcher, which passes it on (§4.2), and to the child as well, so a second SIGQUIT is the same stop arriving twice. Taken as an order, it was an
_exit()in the middle of the orderly stop (the end of the stop of the services,gobj_end(), the memory audit, the close of the logs): with the watcher that passes the stop,--stopcut 17 of 20 stops of a yuno in a check. A daemon hung in its stop is ended by a SIGKILL:--stop’s after 10 s, the unit’s afterTimeoutStopSec,kill-yuno force=1.A daemon ignores SIGTERM.
initcan send it on shutdown, and a straykillallmust not take a node’s yunos down. A daemon depends on the agent’skill-yuno(which sends SIGQUIT), or on the SIGQUIT + SIGKILL chain of the init script. The agent launches every managed yuno with--start, so they all get this posture.A foreground process honours SIGTERM, since 7.9.9. Without
--startthe process is a CLI utility, a test, or a yuno run by hand, and ignoring the signal thatkill(1)andtimeout(1)send breaks the Unix contract:timeoutnever escalates to SIGKILL on its own, sotimeout N ycommand …hung forever and left an immortal process behind. The switch isyuneta_is_daemon(), which reports whether--startwas given.
A program the yuno runs does not inherit any of this. The signals stay
blocked in the yuno for as long as it lives (the signalfd needs them so),
and a blocked or an ignored signal stays so across exec. So every way the
framework runs a program gives it an empty mask and every signal at its
default: run_process2() (how the agent launches a yuno),
run_command(), pty_sync_spawn(),
C_PTY’s command and launch_daemon(), and none of
them gives it an fd of the yuno but stdin, stdout and stderr (an fd without
O_CLOEXEC stays open across exec. Up to 7.29.3, the program kept every
one of them). The agent’s
startup_command and cert_sync_copy_cmd, logcenter’s
restart_yuneta_command and watchfs’s command run through
run_process2("/bin/sh", {"sh", "-c", …}), not system(): system() gives
the command the caller’s mask, and it sets SIGQUIT to SIG_IGN while it
waits, which throws away a stop that is pending. Up to 7.29.3 every program
a yuno ran had SigBlk: 0x7a06 (unless a dash cleared it), so a timeout
it ran was not able to stop its child with SIGTERM, and a ctrl+c did nothing in a
console.
grep -E 'SigIgn|SigBlk' /proc/<pid of a program a yuno runs>/status # both 07. How the agent kills a yuno (the watcher’s view)¶
c_agent.c::kill_yuno(). For each yuno node in the
treedb:
int signal2kill = gobj_read_integer_attr(gobj, "signal2kill"); // default SIGQUIT
kill(yuno_pid, signal2kill);
if(signal2kill == SIGKILL) {
kill(watcher_pid, signal2kill); // only on --force / set-quick-kill
}Two modes, toggled by the agent’s signal2kill attribute (SDATA default
3 = SIGQUIT, c_agent.c):
Graceful kill (
set-graceful-kill, default). SIGQUIT to the child → child’s signalfd handler runsset_yuno_must_die()→ clean exit code 0 → watcher exits on its own. The agent does not touch the watcher.Quick kill (
set-quick-kill, orkill-yuno force=1). SIGKILL to the child and to the watcher. A SIGKILL on the child alone is enough: the watcher exits on it (table above), it does not relaunch -- the watcher’s own SIGKILL is belt and braces. (This line said the opposite until 2026-10, against the code.)
That is why kill-yuno with default options can fail to make a wedged
yuno go away: the child has to cooperate with SIGQUIT. If a yuno hangs
its signalfd handler, set-quick-kill is the escape hatch.
8. Crash forensics (/var/crash/core.%e)¶
The .deb (see packages/deb/make-yuneta-agent-deb.sh) wires this up
end-to-end. Everything below is on every machine where the package is
installed. On a developer machine without the package, apply it by hand.
8.1 sysctl¶
/etc/sysctl.d/99-yuneta-core.conf:
net.core.somaxconn = 65535
kernel.core_uses_pid = 0
kernel.core_pattern = /var/crash/core.%e
fs.file-max = 4000000
fs.nr_open = 4000000core_uses_pid = 0and the%epattern means a yuno that crashes drops/var/crash/core.<role>(the exe basename) with no PID suffix. Successive crashes of the same role overwrite the previous file. This is deliberate: the last crash is the one that you want to examine, and other files fill the disk. If you need two cores, copy the first one out before you cause the next crash.
8.2 PAM limits¶
/etc/security/limits.d/99-yuneta-core.conf:
yuneta soft core unlimited
yuneta hard core unlimited
yuneta soft nofile unlimited
yuneta hard nofile unlimitedThe postinst appends session required pam_limits.so to
/etc/pam.d/common-session and common-session-noninteractive so these
limits apply to interactive shells and to su - invocations from the
init script.
8.3 SysV init limits¶
/etc/init.d/yuneta_agent calls _set_limits before
su - yuneta -c '/yuneta/agent/yuneta_agent --start …':
ulimit -c unlimited
ulimit -l unlimited # memlock, for the io_uring rings
ulimit -Hn 200000 ; ulimit -n 200000 # fallback 65535ulimit -l is here as well as in /etc/security/limits.d/, because
pam_limits does not reach every boot path that runs this script. An
io_uring ring is pinned memory, counted per user, so a node that starts
many yunos at once fails in yev_loop_create() with ENOMEM when the
memlock ceiling is the default one.
8.3.1 The init script does not start a web server itself¶
The script starts and stops the node’s web server through systemd:
WEBUNIT="yuneta-webserver.service"
systemctl start "$WEBUNIT" # start_web
systemctl stop "$WEBUNIT" # stop_websystemctl start on a unit that already runs does nothing, so it does not
matter whether systemd or this script gets there first at boot. The unit
also serves the web server the NODE chose, nginx or openresty.
An older version of the script ran /yuneta/bin/nginx/sbin/nginx directly.
That is a second web server, always plain nginx, that races the unit for
ports 80 and 443. On a node that serves with openresty it lost the race and
wrote [emerg] bind() … Address already in use at every boot. If it won the race,
it served the stock server_name localhost configuration for
every vhost of the node.
The script is generated by the packagers
(packages/{deb,rpm}/make-yuneta-agent-*.sh). The copy in
yunos/c/yuno_agent/service/ must stay identical to the .deb one: the
CMake install rule puts it in /yuneta/agent, which is where the postinst
reads it from, so a build on a source node replaces the packaged script
with it.
The owner of the cores is yuneta:yuneta. /var/crash itself is 0775 root:yuneta.
8.4 The post-mortem workflow¶
ls -lt /var/crash/ # find the freshest core.<role>
gdb /yuneta/agent/<role> /var/crash/core.<role>
(gdb) bt full
(gdb) info threadsCross-reference with the yuno’s logs:
ls -lt /yuneta/realms/<realm>/<yuno>/logs/
grep -a 'Daemon relaunched' /yuneta/realms/<realm>/<yuno>/logs/*.logThe Daemon relaunched line is what the watcher emits after each
restart. The signal_code/exit_code fields tell you whether it was a
crash (signal_code != 0) or a bad exit (exit_code != 0). Either way,
the core in /var/crash/ is from the previous incarnation.
A bad exit is not always a fault: read what the yuno wrote just before it.
Up to 7.27.3, an exit_code -1 some 2 s after the agent restarted the node
(deactivate-snap), preceded by “bind() FAILED ... Address already in
use” and “Exiting” from a C_TCP_S, is a port still held by the
instance just killed: its io_uring ring is torn down after the process is
gone, with the accept that holds the socket. The yunos that bind early (an
auth_bff, an emailsender) lost that race, and the watcher’s relaunch
won it. Since then C_TCP_S listens again for listen_retry_msec before it
exits (see the transport gclasses, Address in use at the start).
9. Pitfalls (concrete)¶
Anything
json_*beforegbmem_setupleaks. Do notjson_packinmain()beforeyuneta_entry_point(). Useregister_yuno_and_more. 2. Executable basename must equalyuno_role. The framework enforces this. Do notmva yuno binary to rename it. Useupdate-binary, so that the agent rewrites the launcher script too.test_prefix skips the 15-charAPP_NAMElimit. This is convenient for test binaries, and the source marks it as a BUG. Do not depend on it for production yunos.Two pids per yuno.
ps -ef | grep <role>returns the watcher and the child. The child is the one with the open log fds. The watcher shows inppidand has no open files of its own (ls -l /proc/<pid>/fd). 5.relaunch_times > 0is a crash signal. No alarm starts. AddDaemon relaunchedto the checklist of your log greps.The framework overwrites the cores. The pattern has no PID. If a yuno crashes in a loop, only the last core survives. If you want the history, run
cp /var/crash/core.<role> /var/crash/core.<role>.$(date +%s).gobj_endbelongs toprocess(). A customcleaning_fnruns aftergobj_endand afterjson_decrefof the config, and beforeprint_track_memandrotatory_end, so what it logs reaches the log file and what it frees is out of the leak report. At that time the gobj system is gone. Usecleaning_fnonly to free things that do not depend on it.
See also¶
The Typed-Graph Model — the conceptual frame that the technical chapters under Operating Yuneta sit inside. Useful if you want to step up one level before diving deeper.
YUNO_LIFECYCLE.md— what happens once a yuno is alive: the agent’s view,run-yuno,kill-yuno, the play/pause gate.DEBUGGING.md— traces, the dev panel, ievent end-to-end tracing.GOBJ.md— the gobj framework oncegobj_start_up()has run.kernel/c/root-linux/src/entry_point.c— 934 lines, the source.kernel/c/root-linux/src/ydaemon.c— 480 lines, the supervisor.packages/deb/make-yuneta-agent-deb.sh:324-358— the sysctl + limits block that enables core dumps.