From e64d981e8f3a09cb7eb53d598f1d2ab4fa882946 Mon Sep 17 00:00:00 2001 From: Sang Woo Kim Date: Mon, 27 Jul 2026 15:56:25 +0900 Subject: [PATCH] RTEMS: don't fault when no startup script is provided epicsRtemsFSImage=NULL is the documented "none is needed" case, and it is the one initialize_local_filesystem() success path that leaves argv[1] unset, so set_directory() reached strrchr(NULL, '/') and killed the guest before main(). Same defect in the score/ and posix/ inits. --- modules/libcom/RTEMS/posix/rtems_init.c | 11 ++++++++--- modules/libcom/RTEMS/score/rtems_init.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/libcom/RTEMS/posix/rtems_init.c b/modules/libcom/RTEMS/posix/rtems_init.c index a709f8915..526117da7 100644 --- a/modules/libcom/RTEMS/posix/rtems_init.c +++ b/modules/libcom/RTEMS/posix/rtems_init.c @@ -1251,8 +1251,13 @@ POSIX_Init ( void *argument __attribute__((unused))) printf ("***** Preparing EPICS application *****\n"); iocshRegisterRTEMS (); - set_directory (argv[1]); - epicsEnvSet ("IOC_STARTUP_SCRIPT", argv[1]); + /* No startup script when the application declares that it needs no + * filesystem (epicsRtemsFSImage == NULL). + */ + if (argv[1] != NULL) { + set_directory (argv[1]); + epicsEnvSet ("IOC_STARTUP_SCRIPT", argv[1]); + } atexit(exitHandler); printf ("***** Starting EPICS application *****\n"); @@ -1270,7 +1275,7 @@ POSIX_Init ( void *argument __attribute__((unused))) NULL); #endif - result = main ((sizeof argv / sizeof argv[0]) - 1, argv); + result = main (argv[1] != NULL ? 2 : 1, argv); printf ("***** IOC application terminating *****\n"); epicsThreadSleep(1.0); epicsExit(result); diff --git a/modules/libcom/RTEMS/score/rtems_init.c b/modules/libcom/RTEMS/score/rtems_init.c index 77e2e3368..6ab677b67 100644 --- a/modules/libcom/RTEMS/score/rtems_init.c +++ b/modules/libcom/RTEMS/score/rtems_init.c @@ -681,11 +681,16 @@ Init (rtems_task_argument ignored) */ printf ("***** Preparing EPICS application *****\n"); iocshRegisterRTEMS (); - set_directory (argv[1]); - epicsEnvSet ("IOC_STARTUP_SCRIPT", argv[1]); + /* No startup script when the application declares that it needs no + * filesystem (epicsRtemsFSImage == NULL). + */ + if (argv[1] != NULL) { + set_directory (argv[1]); + epicsEnvSet ("IOC_STARTUP_SCRIPT", argv[1]); + } atexit(exitHandler); printf ("***** Starting EPICS application *****\n"); - result = main ((sizeof argv / sizeof argv[0]) - 1, argv); + result = main (argv[1] != NULL ? 2 : 1, argv); printf ("***** IOC application terminating *****\n"); epicsThreadSleep(1.0); epicsExit(result);