From a6eb691955eff84eb7e0470bbdbbe8008f0dbb0f Mon Sep 17 00:00:00 2001 From: "W. Eric Norum" Date: Wed, 20 Jul 2005 19:37:31 +0000 Subject: [PATCH] Set POSIX TZ environment variable from EPICS_TIMEZONE. Allow for simultaneous local and remote filesystems. --- src/RTEMS/base/rtems_init.c | 79 +++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/src/RTEMS/base/rtems_init.c b/src/RTEMS/base/rtems_init.c index 2c9d95243..e84821853 100644 --- a/src/RTEMS/base/rtems_init.c +++ b/src/RTEMS/base/rtems_init.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,8 @@ #include #include +#include +#include #include #include #include @@ -201,38 +204,39 @@ initialize_local_filesystem(const char **argv) printf ("***** Unpack in-memory file system (IMFS) *****\n"); if (rtems_tarfs_load("/", header, (unsigned long)_FlashSize - flashIndex) != 0) { printf("Can't unpack tar filesystem\n"); - return -1; + return 0; } if ((fd = open(rtems_bsdnet_bootp_cmdline, 0)) >= 0) { close(fd); printf ("***** Found startup script (%s) in IMFS *****\n", rtems_bsdnet_bootp_cmdline); argv[1] = rtems_bsdnet_bootp_cmdline; - return 0; + return 1; } printf ("***** Startup script (%s) not in IMFS *****\n", rtems_bsdnet_bootp_cmdline); } #endif - return -1; + return 0; } static void -initialize_remote_filesystem(const char **argv) +initialize_remote_filesystem(const char **argv, int hasLocalFilesystem) { #ifdef OMIT_NFS_SUPPORT - char *path; - int pathsize = 200; - int l; - printf ("***** Initializing TFTP *****\n"); rtems_bsdnet_initialize_tftp_filesystem (); + if (!hasLocalFilesystem) { + char *path; + int pathsize = 200; + int l; - path = mustMalloc(pathsize, "Command path name "); - strcpy (path, "/TFTP/BOOTP_HOST/epics/"); - l = strlen (path); - if (gethostname (&path[l], pathsize - l - 10) || (path[l] == '\0')) - LogFatal ("Can't get host name"); - strcat (path, "/st.cmd"); - argv[1] = path; + path = mustMalloc(pathsize, "Command path name "); + strcpy (path, "/TFTP/BOOTP_HOST/epics/"); + l = strlen (path); + if (gethostname (&path[l], pathsize - l - 10) || (path[l] == '\0')) + LogFatal ("Can't get host name"); + strcat (path, "/st.cmd"); + argv[1] = path; + } #else extern char *env_nfsServer; extern char *env_nfsPath; @@ -261,6 +265,9 @@ initialize_remote_filesystem(const char **argv) } argv[1] = rtems_bsdnet_bootp_cmdline; } + else if (hasLocalFilesystem) { + return; + } else { /* * Use first component of nvram/bootp command line pathname @@ -488,15 +495,14 @@ Init (rtems_task_argument ignored) putenv ("TERM=xterm"); putenv ("IOCSH_HISTSIZE=20"); if (rtems_bsdnet_config.hostname) { - char *cp = mustMalloc(strlen(rtems_bsdnet_config.hostname)+15, "iocsh prompt"); - sprintf(cp, "IOCSH_PS1=%s> ", rtems_bsdnet_config.hostname); - putenv (cp); - sprintf(cp, "IOC_NAME=%s", rtems_bsdnet_config.hostname); - putenv (cp); + char *cp = mustMalloc(strlen(rtems_bsdnet_config.hostname)+3, "iocsh prompt"); + sprintf(cp, "%s> ", rtems_bsdnet_config.hostname); + epicsEnvSet ("IOCSH_PS1", cp); + epicsEnvSet("IOC_NAME", rtems_bsdnet_config.hostname); } else { - putenv ("IOCSH_PS1=epics> "); - putenv ("IOC_NAME=:UnnamedIoc:"); + epicsEnvSet ("IOCSH_PS1", "epics> "); + epicsEnvSet ("IOC_NAME", ":UnnamedIoc:"); } /* @@ -508,10 +514,9 @@ Init (rtems_task_argument ignored) == epicsThreadBooleanStatusSuccess) rtems_bsdnet_config.network_task_priority = epicsThreadGetOssPriorityValue(p); } - printf ("\n***** Initializing network *****\n"); - rtems_bsdnet_initialize_network (); - if (initialize_local_filesystem (argv) != 0) - initialize_remote_filesystem (argv); + printf("\n***** Initializing network *****\n"); + rtems_bsdnet_initialize_network(); + initialize_remote_filesystem(argv, initialize_local_filesystem(argv)); /* * Use BSP-supplied time of day if available @@ -540,6 +545,28 @@ Init (rtems_task_argument ignored) } } } + if (getenv("TZ") == NULL) { + const char *tzp = envGetConfigParamPtr(&EPICS_TIMEZONE); + if (tzp == NULL) { + printf("Warning -- no timezone information available -- times will be displayed as GMT.\n"); + } + else { + char tz[10]; + int minWest, toDst = 0, fromDst = 0; + if(sscanf(tzp, "%9[^:]::%d:%d:%d", tz, &minWest, &toDst, &fromDst) < 2) { + printf("Warning: EPICS_TIMEZONE (%s) unrecognizable -- times will be displayed as GMT.\n", tzp); + } + else { + char posixTzBuf[40]; + char *p = posixTzBuf; + p += sprintf(p, "%cST %d:%d", tz[0], minWest/60, minWest%60); + if (toDst != fromDst) + p += sprintf(p, " %cDT", tz[0]); + epicsEnvSet("TZ", posixTzBuf); + } + } + } + tzset(); /* * Run the EPICS startup script