- Component: reboot-manager
- Binary: rebootnow
- Version: 1.0
- Date: 2026-02-27
- Scope: module-level and function-level behavior of reboot-manager implementation
rebootnow/
├── include/
│ ├── rebootnow.h
│ └── rbus_interface.h
└── src/
├── main.c
├── cyclic_reboot.c
├── system_cleanup.c
├── rbus_interface.c
└── utils.c
int handle_cyclic_reboot(const char *source, const char *rebootReason, const char *customReason, const char *otherReason);void timestamp_update(char *buf, size_t sz);int write_rebootinfo_log(const char *path, const char *line);void cleanup_services(void);int pidfile_write_and_guard(void);void cleanup_pidfile(void);void t2CountNotify(const char *marker, int val);void t2ValNotify(const char *marker, const char *val);
bool rbus_init(void);void rbus_cleanup(void);bool rbus_get_string_param(const char* param_name, char* value_buf, size_t buf_size);bool rbus_get_bool_param(const char* param_name, bool* value);bool rbus_get_int_param(const char* param_name, int* value);bool rbus_set_bool_param(const char* param_name, bool value);bool rbus_set_int_param(const char* param_name, int value);
- Parse CLI arguments (
-s,-c,-r,-o,-h). - Initialize logging, optional telemetry, RBUS session, and PID guard.
- Classify reboot reason from source list tables.
- Persist current reboot details into text and JSON files.
- Call cyclic reboot handler to decide defer vs immediate reboot.
- Trigger pre-reboot cleanup and reboot sequence with fallback.
usage(FILE *out): prints command usage.check_string_value(...): substring match against trigger source arrays.emit_t2_for_source(...): emits mapped T2 marker based on source and crash flag.signal_cleanup_handler(...): signal handler to cleanup PID file.update_reboot_log(...): safe append into fixed-size message buffer usingvsnprintf.
- Truncates
/opt/logs/rebootInfo.logwithfopen(..., "w"). - Writes key lines to rebootInfo log:
RebootReasonRebootInitiatedByRebootTimeCustomReasonOtherReason
- Writes JSON to:
/opt/secure/reboot/reboot.info/opt/secure/reboot/previousreboot.info
- Appends
PreviousRebootInfo:<...>to/opt/secure/reboot/parodusreboot.info.
- Creates reboot trigger flag file
/opt/secure/reboot/rebootNow. - Calls
cleanup_services(). - Attempts
rebootviafork + execlp. - Waits 90s; if still running, attempts
systemctl reboot. - Terminates child and issues force fallback
reboot -f.
- Read RFC controls for reboot-stop detection and pause duration.
- Compare current reboot context with previous reboot info.
- Detect repeated reboot loops within reboot window.
- Maintain and persist reboot counter.
- Enter reboot-stop mode and schedule deferred reboot if threshold is reached.
file_exists(path)read_rebootcounter(path, out)/write_rebootcounter(path, value)touch_file(path)read_proc_uptime_secs()extract_json_value(buf, key, out, outsz)read_previous_reboot_info(...)compute_cron_time(add_minutes, out, outsz)
- Read
RebootStop.DetectionandRebootStop.Duration. - If last reboot was by rebootnow and detection enabled:
- Read previous reboot metadata file.
- Compare current and previous context fields.
- If same reason within window:
- Increment counter, or
- If threshold reached, set stop flag and schedule cron-based deferred reboot.
- If reason differs or outside window:
- Reset reboot counter.
- Disable stop flag RFC and remove reboot-stop file/cron.
- Return
0to defer reboot,1to proceed immediately.
flowchart TD
A[Start handle_cyclic_reboot] --> B[Read RFC detection and duration]
B --> C{Reboot triggered by rebootnow and detection enabled?}
C -- No --> Z[Return 1]
C -- Yes --> D[Read previousreboot.info]
D --> E{Same reason and within reboot window?}
E -- No --> F[Reset counter + disable stop + remove cron]
F --> Z
E -- Yes --> G{Counter >= threshold?}
G -- No --> H[Increment counter]
H --> Z
G -- Yes --> I[Set rebootStop + publish RFC/telemetry + schedule cron]
I --> Y[Return 0]
- Pre-reboot signaling and service stop operations.
- Log synchronization and directory cleanup operations.
- Single-instance process guard and PID lifecycle.
- Signal
telemetry2_0andparoduswithSIGUSR1. - Optional cleanups for RDM, temp logs, and transient directories.
- Conditional bluetooth stack/service stop if enabled.
- Call
sync()and short delay before reboot.
pidfile_write_and_guard()uses atomic create (O_CREAT|O_EXCL) on/tmp/.rebootNow.pid.- If PID file exists:
- acquire advisory write lock via
fcntl - inspect existing pid cmdline under
/proc/<pid>/cmdline - if running rebootnow instance exists, return failure
- otherwise overwrite PID file with current PID under lock
- acquire advisory write lock via
cleanup_pidfile()removes PID file on normal and signal exits.
- Maintain singleton RBUS handle state.
- Provide typed get/set wrappers with parameter validation and logging.
g_rbusHandlestores active RBUS handle.g_rbusInitializedtracks initialization state.- All getters/setters require initialized RBUS state.
rbus_initopens RBUS handle once (RebootInfoLogs).rbus_cleanupcloses handle safely.rbus_get_*reads value viarbus_get, converts and logs.rbus_set_*creates temporaryrbusValue_t, sets and commits viarbus_set.
timestamp_update: writes UTC timestamp in%a %b %d %H:%M:%S UTC %Yformat.write_rebootinfo_log: appends one line to the target log file.t2CountNotify/t2ValNotify: compile-time gated telemetry wrappers.
- File open/read/write failures return error or log and continue depending on criticality.
- RBUS failures return false and are logged with function context.
- Reboot path uses fallback sequence for resilience.
- Buffer writes are bounded using fixed-size arrays and
snprintf/vsnprintf.
Autotools-based build from repository root:
autoreconf -fi
./configure
make -j$(nproc)unit_test.sh builds and executes:
reboot_utils_gtestreboot_rbus_gtestreboot_cyclic_gtestreboot_system_gtestreboot_main_gtest
Coverage is generated via lcov by default.
run_l2.sh executes pytest suites under tests/functional_tests/test and stores JSON reports in /tmp/l2_test_report.