|
RTE OSAdapter POSIX 0.1.0 build 41b3eb3
POSIX/Linux OAL OSAdapter for Platform_RTE
|
POSIX rte_reboot OSAdapter: execv() re-exec of the current binary (ADR-018 section 2.3), resolved portably per-OS since there is no single POSIX-standard way to ask "what is my own executable path.". More...
#include "rte/posix_osadapter/rte_posix_osadapter.h"#include <limits.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | _XOPEN_SOURCE 700 |
| #define | RTE_POSIX_REBOOT_MAX_ARGV 8U |
Functions | |
| static bool | resolve_self_exe_path (char *out_path, size_t out_path_size, const char *argv0) |
| static rte_status_t | osadapter_request (uint16_t reason_code) |
| void | rte_posix_osadapter_reboot_set_argv (int argc, char *const argv[]) |
| Registers the original process argv[] the POSIX reboot OSAdapter should re-exec with (instead of its own placeholder argv[0]). Call once, early in main(), with the same argc/argv main() itself received - e.g. right after this project's own argv parsing (role/site), so a REBOOT-triggered re-exec restarts the SAME role for the SAME site rather than losing that information and falling back to a placeholder command line the freshly re-exec'd process cannot make sense of. | |
| const rte_osadapter_reboot_t * | rte_posix_osadapter_reboot (void) |
| The POSIX rte_reboot OSAdapter (execv() re-exec of the current process image, self-path resolved portably per-OS - see rte_posix_osadapter_reboot.c's file header). | |
Variables | |
| char ** | environ |
| static char * | s_registered_argv [RTE_POSIX_REBOOT_MAX_ARGV+1U] |
| static bool | s_argv_registered = false |
| static const rte_osadapter_reboot_t | s_posix_reboot_osadapter = { osadapter_request } |
POSIX rte_reboot OSAdapter: execv() re-exec of the current binary (ADR-018 section 2.3), resolved portably per-OS since there is no single POSIX-standard way to ask "what is my own executable path.".
This is explicitly a stand-in, not a real safety-relevant reboot path. A normal (non-root, non-embedded) process cannot reset the CPU; re-exec is the closest available approximation - it restarts the process image from main() with the original argv, which exercises the same "system comes back up from a clean start" application-level contract a real reset would, without actually resetting anything below the process. A real deployment on real hardware needs a real reset mechanism (watchdog-triggered hardware reset, supervisory process that respawns this one, etc.) - see ADR-018 section 3.
Path resolution is the only genuinely OS-specific part:
reason_code is passed via an environment variable (RTE_REBOOT_REASON_CODE) rather than argv, so it survives the re-exec without disturbing the caller's original argv[] the new process image receives; a real OSAdapter on real hardware would instead persist it to NVM/black-box storage before resetting (REQ-OAL-REBOOT-010's doc comment), which is out of this stand-in's scope.
argv[] the re-exec'd image actually receives: rte_posix_osadapter_ reboot_set_argv() (rte_posix_osadapter.h), if the caller registered it, takes priority - execv()'ing with the SAME argv main() itself originally received is what lets a caller whose behavior depends on its own command-line arguments (e.g. safeAPIRBC2oo2's own role/site - see its main.c) resume as the same role after the reboot, not lose that information to a placeholder command line. Without it, this falls back to a self-contained placeholder argv (see osadapter_request() below) - fine for a caller with no argv-dependent behavior of its own.
Definition in file rte_posix_osadapter_reboot.c.
| #define _XOPEN_SOURCE 700 |
Definition at line 4 of file rte_posix_osadapter_reboot.c.
| #define RTE_POSIX_REBOOT_MAX_ARGV 8U |
Local makros
Definition at line 76 of file rte_posix_osadapter_reboot.c.
|
static |
Definition at line 159 of file rte_posix_osadapter_reboot.c.
|
static |
Local types declarations Local function declarations Resolves this process's own executable path into out_path (capacity out_path_size bytes, NUL-terminated on success).
Definition at line 122 of file rte_posix_osadapter_reboot.c.
| const rte_osadapter_reboot_t * rte_posix_osadapter_reboot | ( | void | ) |
The POSIX rte_reboot OSAdapter (execv() re-exec of the current process image, self-path resolved portably per-OS - see rte_posix_osadapter_reboot.c's file header).
Definition at line 114 of file rte_posix_osadapter_reboot.c.
| void rte_posix_osadapter_reboot_set_argv | ( | int | argc, |
| char *const | argv[] ) |
Registers the original process argv[] the POSIX reboot OSAdapter should re-exec with (instead of its own placeholder argv[0]). Call once, early in main(), with the same argc/argv main() itself received - e.g. right after this project's own argv parsing (role/site), so a REBOOT-triggered re-exec restarts the SAME role for the SAME site rather than losing that information and falling back to a placeholder command line the freshly re-exec'd process cannot make sense of.
Global variables declarations Global functions
Not calling this at all is still valid - the OSAdapter then falls back to its original placeholder-argv behavior (see rte_posix_osadapter_reboot.c), which is fine for a caller whose own main() takes no arguments it needs preserved across a reboot.
| argc | Argument count, as received by main(). Only the first RTE_POSIX_REBOOT_MAX_ARGV entries are retained (the OSAdapter has no dynamic allocation - REQ-OAL-REBOOT-001's fixed-storage convention). |
| argv | Argument vector, as received by main(). The pointers themselves are stored (not copied) - valid because argv's string storage is guaranteed to remain valid for the whole process lifetime, same as main()'s own copy of it. Must not be NULL if argc > 0. |
Definition at line 97 of file rte_posix_osadapter_reboot.c.
|
static |
Definition at line 90 of file rte_posix_osadapter_reboot.c.
|
static |
Definition at line 91 of file rte_posix_osadapter_reboot.c.
|
static |
Local variables declarations
Definition at line 89 of file rte_posix_osadapter_reboot.c.