RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
app_main_common.c File Reference

See app_main_common.h. More...

#include "app_main_common.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "rte/app/appmanager/rte_appmanager.h"
#include "rte/redundancy/checksum/rte_checksum.h"
#include "rte/oal/log/rte_log.h"
#include "rte/oal/platform/rte_platform.h"
#include "rte/posix_osadapter/rte_posix_osadapter.h"
#include "rte/oal/reboot/rte_reboot.h"
#include "rte/utils/safestate/rte_safestate.h"
#include "rte/redundancy/watchdog/rte_watchdog.h"
#include "common_config.h"
Include dependency graph for app_main_common.c:

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200809L

Functions

static void reboot_safestate_handler (rte_safestate_level_t level, rte_safestate_reason_t reason, const char *file, int32_t line, const char *message)
static void safe_safestate_handler (rte_safestate_level_t level, rte_safestate_reason_t reason, const char *file, int32_t line, const char *message)
static void degraded_safestate_handler (rte_safestate_level_t level, rte_safestate_reason_t reason, const char *file, int32_t line, const char *message)
rte_status_t app_main_common_init (int argc, char **argv)
 Runs this process's one-time runtime setup, common to every role: unbuffered stdout, POSIX OSAdapter registration, reboot argv capture, CRC-64 init, watchdog manager init, best-effort log init, best-effort default signal handlers, and the REBOOT safe-state handler registration - see this file's own header and each step's own inline doc in app_main_common.c for why each is fatal or best-effort.

Detailed Description

See app_main_common.h.

Definition in file app_main_common.c.

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

Definition at line 3 of file app_main_common.c.

Function Documentation

◆ reboot_safestate_handler()

void reboot_safestate_handler ( rte_safestate_level_t level,
rte_safestate_reason_t reason,
const char * file,
int32_t line,
const char * message )
static

Local makros Local types declarations Local variables declarations Global variables declarations Local function declarations Generic REBOOT-level safe-state handler (RTE_SAFESTATE_LEVEL_REBOOT): hands off to the registered rte_reboot OSAdapter, which on this demo's POSIX targets re-execs the current process image (see posix_osadapter/rte_posix_osadapter_reboot.c) - the closest available stand-in for a real hardware reset (ADR-018). What to persist BEFORE rebooting (e.g. ab_gp_channel_crosscompare.c setting ctx->own_faulted) is application-specific and happens at the call site, not here - this handler only knows "how do I physically restart," matching the framework's own separation of concerns for safestate handlers.

Before actually restarting, this mocks a real hardware reboot's observable delay (RTE_EXAMPLE_REBOOT_DELAY_MS - see common_config.h) with clear console/log messaging, so a demo run makes the fault -> reboot -> resume sequence visible rather than an instantaneous re-exec that looks like nothing happened.

rte_reboot_request() does not return on success; if it does return (OSAdapter unsupported or execv() itself failed), rte_safestate_enter() still guarantees no control returns to the REBOOT call site (REQ-COMMON-SAFESTATE-002) - it falls back to its own defensive halt.

Definition at line 246 of file app_main_common.c.

◆ safe_safestate_handler()

void safe_safestate_handler ( rte_safestate_level_t level,
rte_safestate_reason_t reason,
const char * file,
int32_t line,
const char * message )
static

Generic SAFE-level safe-state handler (RTE_SAFESTATE_LEVEL_SAFE): ensures every SAFE-level halt (e.g. rte_checkpoint.c's own REQ-CHECKPOINT-003 rendezvous-timeout trigger) is logged rather than silent - without a registered handler for this level, a process simply stops responding and pins its CPU in rte_safestate_enter()'s own defensive infinite loop, with no log line anywhere explaining why, the main obstacle to diagnosing a real, reproducible permanent-hang bug found under full-container-reboot fault injection (ADR-029 section 2.6 addendum). Unlike reboot_safestate_handler, this deliberately does NOT try to recover or restart anything: SAFE means "this process can no longer trust its own state enough to keep operating," and per REQ-COMMON-SAFESTATE-002 the only correct reaction is to log the reason and then genuinely halt - returning here lets rte_safestate_enter()'s own defensive infinite loop take over.

Definition at line 282 of file app_main_common.c.

◆ degraded_safestate_handler()

void degraded_safestate_handler ( rte_safestate_level_t level,
rte_safestate_reason_t reason,
const char * file,
int32_t line,
const char * message )
static

DEGRADED-level handler (RTE_SAFESTATE_LEVEL_DEGRADED, which returns to the caller): makes the platform's reported OSA rule violations visible - a setup-only resource requested after the setup phase was locked (REQ-LIFECYCLE-003, logged as ERROR) and a real-time attribute the OSAdapter could not apply (thread priority, stack size; logged as WARNING, expected on an unprivileged host). A refused mutex priority inheritance is reported once with the same reason (RTE_SAFESTATE_REASON_OSA_RT_ATTRIBUTE, also logged as WARNING) but is not a tolerated platform limit: it fails the mutex create or the memory-pool init. Logs only; whether to escalate is a deployment decision (an RT target should run with the privileges these need).

Definition at line 294 of file app_main_common.c.

◆ app_main_common_init()

rte_status_t app_main_common_init ( int argc,
char ** argv )

Runs this process's one-time runtime setup, common to every role: unbuffered stdout, POSIX OSAdapter registration, reboot argv capture, CRC-64 init, watchdog manager init, best-effort log init, best-effort default signal handlers, and the REBOOT safe-state handler registration - see this file's own header and each step's own inline doc in app_main_common.c for why each is fatal or best-effort.

Global functions

Parameters
argcThis process's own argc, forwarded to rte_posix_osadapter_reboot_set_argv() so a later REBOOT re-execs with the same command line.
argvThis process's own argv, same reason as argc.
Returns
RTE_STATUS_OK if every fatal step succeeded (best-effort steps only log a warning and never fail this call); the first fatal step's own failure status otherwise - the caller should print nothing further and return a non-zero exit code.

Definition at line 85 of file app_main_common.c.