--- freem/src/init.c 2025/04/13 04:22:43 1.11 +++ freem/src/init.c 2025/04/20 03:13:17 1.14 @@ -1,5 +1,5 @@ /* - * $Id: init.c,v 1.11 2025/04/13 04:22:43 snw Exp $ + * $Id: init.c,v 1.14 2025/04/20 03:13:17 snw Exp $ * FreeM initialization * * @@ -24,6 +24,15 @@ * along with FreeM. If not, see . * * $Log: init.c,v $ + * Revision 1.14 2025/04/20 03:13:17 snw + * Updates to init_execution_context + * + * Revision 1.13 2025/04/17 14:34:27 snw + * Further logging improvements + * + * Revision 1.12 2025/04/15 14:39:06 snw + * Further improvements to logging + * * Revision 1.11 2025/04/13 04:22:43 snw * Fix snprintf calls * @@ -92,6 +101,7 @@ #include "jobtab.h" #include "datatypes.h" #include "objects.h" +#include "log.h" #ifdef HAVE_LIBREADLINE # if defined(HAVE_READLINE_READLINE_H) @@ -165,7 +175,9 @@ void init_mwapi(void); short init (char *namespace_name) { short retval; + int log_level; + init_log (); init_process (); init_devtable (); init_signals (); @@ -189,15 +201,11 @@ short init (char *namespace_name) if (retval == SHMS_GET_ERR) { if (errno != 13) { - fprintf (stderr, "init: error initializing shared memory [errno %d]\r\n", errno); + logprintf (FM_LOG_FATAL, "init: error initializing shared memory (error code %d [%s])", errno, strerror (errno)); } else { - fprintf (stderr, "init: error attaching to environment -- does your user belong to the group that owns environment '%s'?\r\n", shm_env); + logprintf (FM_LOG_FATAL, "init: error attaching to environment -- does your user belong to the group that owns environment '%s'?", shm_env); } - if (run_daemon == FALSE) { - set_io (UNIX); - } - exit (1); } symtab_init (); @@ -206,28 +214,35 @@ short init (char *namespace_name) set_namespace (namespace_name, FALSE); if (first_process) { - fprintf (stderr, "init: we are the first process in the environment (pid %d)\r\n", pid); + log_level = FM_LOG_INFO; + } + else { + log_level = FM_LOG_DEBUG; + } + + if (first_process) { + logprintf (log_level, "init: we are the first process in the environment (pid %d)", pid); } - if (first_process) fprintf (stderr, "init: initializing job table\r\n"); + logprintf (log_level, "init: initializing job table"); jobtab_init (); - if (first_process) fprintf (stderr, "init: adding job to job table\r\n"); + logprintf (log_level, "init: adding job to job table"); job_init (FALSE); - if (first_process) fprintf (stderr, "init: initializing structured system variables\r\n"); + logprintf (log_level, "init: initializing structured system variables"); init_ssvn (); - if (first_process) fprintf (stderr, "init: initializing terminal\r\n"); + logprintf (log_level, "init: initializing terminal"); init_terminal (); - if (first_process) fprintf (stderr, "init: initializing asynchronous events\r\n"); + logprintf (log_level, "init: initializing asynchronous events"); evt_init (); - if (first_process) fprintf (stderr, "init: initializing debugger\r\n"); + logprintf (log_level, "init: initializing debugger"); dbg_init (); - if (first_process) fprintf (stderr, "init: initializing error stack\r\n"); + logprintf (log_level, "init: initializing error stack"); init_estack(); etrap[0] = EOL; @@ -386,8 +401,7 @@ void init_timezone (void) long clock; -#ifdef __CYGWIN__ - +#if defined(__CYGWIN__) tzset (); /* may be required in order */ /* to guarantee _timezone set */ #else @@ -475,9 +489,10 @@ void init_execution_context (void) codptr = code; code[0] = EOL; /* init code_pointer */ - partition = calloc ((unsigned) (PSIZE + 2), 1); - if (partition == NULL) exit (2); /* could not allocate stuff... */ + if ((partition = calloc ((unsigned) (PSIZE + 2), 1)) == NULL) { + logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate symbol table (error code %d [%s])", errno, strerror (errno)); + } for (i = 0; i < MAXNO_OF_RBUF; i++) { rbuf_flags[i].standard = standard; @@ -491,39 +506,44 @@ void init_execution_context (void) s = &partition[PSIZE] - 256; /* pointer to symlen_offset */ argptr = partition; /* pointer to beg of tmp-storage */ - svntable = calloc ((unsigned) (UDFSVSIZ + 1), 1); - if (svntable == NULL) exit (2); /* could not allocate stuff... */ - + if ((svntable = calloc ((unsigned) (UDFSVSIZ + 1), 1)) == NULL) { + logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate user-defined ISV table (error code %d [%s])", errno, strerror (errno)); + } svnlen = UDFSVSIZ; /* begin of udf_svn_table */ - buff = calloc ((unsigned) NO_OF_RBUF * (unsigned) PSIZE0, 1); /* routine buffer pool */ - if (buff == NULL) exit (2); /* could not allocate stuff... */ + if ((buff = calloc ((unsigned) NO_OF_RBUF * (unsigned) PSIZE0, 1)) == NULL) { + logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate routine buffers (error code %d [%s])", errno, strerror (errno)); + } - newstack = calloc ((unsigned) NSIZE, 1); - if (newstack == NULL) exit (2); /* could not allocate stuff... */ + if ((newstack = calloc ((unsigned) NSIZE, 1)) == NULL) { + logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate NEW stack (error code %d [%s])", errno, strerror (errno)); + } - #ifdef DEBUG_NEWPTR - printf("Allocating newptr stack...\r\n"); - #endif + logprintf (FM_LOG_DEBUG, "allocating newptr stack..."); newptr = newstack; newlimit = newstack + NSIZE - 1024; - namstck = calloc ((unsigned) NESTLEVLS * 13, 1); - if (namstck == NULL) exit (2); /* could not allocate stuff... */ - + if ((namstck = calloc ((unsigned) NESTLEVLS * 13, 1)) == NULL) { + logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate newptr stack (error code %d [%s])", errno, strerror (errno)); + } + *namstck = EOL; *(namstck + 1) = EOL; namptr = namstck; /* routine name stack pointer */ - framstck = calloc ((unsigned) NESTLEVLS * 256, 1); - if (framstck == NULL) exit (2); /* could not allocate stuff... */ + + if ((framstck = calloc ((unsigned) NESTLEVLS * 256, 1)) == NULL) { + logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate DO frame stack stack (error code %d [%s])", errno, strerror (errno)); + } *framstck = EOL; *(framstck + 1) = EOL; dofrmptr = framstck; /* DO_frame stack pointer */ - cmdstack = calloc ((unsigned) NESTLEVLS * 256, 1); - if (cmdstack == NULL) exit (2); /* could not allocate stuff... */ + + if ((cmdstack = calloc ((unsigned) NESTLEVLS * 256, 1)) == NULL) { + logprintf (FM_LOG_FATAL, "init_execution_context: could not allocate command stack (error code %d [%s])", errno, strerror (errno)); + } cmdptr = cmdstack; /* command stack */