--- freem/src/init.c 2025/02/25 18:53:14 1.3 +++ freem/src/init.c 2025/04/15 14:39:06 1.12 @@ -1,23 +1,11 @@ /* - * * - * * * - * * * - * *************** - * * * * * - * * MUMPS * - * * * * * - * *************** - * * * - * * * - * * - * - * init.c + * $Id: init.c,v 1.12 2025/04/15 14:39:06 snw Exp $ * FreeM initialization * * - * Author: Serena Willis + * Author: Serena Willis * Copyright (C) 1998 MUG Deutschland - * Copyright (C) 2020 Coherent Logic Development LLC + * Copyright (C) 2020, 2025 Coherent Logic Development LLC * * * This file is part of FreeM. @@ -35,6 +23,31 @@ * You should have received a copy of the GNU Affero Public License * along with FreeM. If not, see . * + * $Log: init.c,v $ + * 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 + * + * Revision 1.10 2025/04/10 01:24:38 snw + * Remove C++ style comments + * + * Revision 1.9 2025/04/03 16:58:34 snw + * Make error message for shm_init error during initialization more friendly + * + * Revision 1.8 2025/03/24 04:44:55 snw + * Don't call ttyname on OS/2 + * + * Revision 1.7 2025/03/24 04:05:36 snw + * Replace crlf with frm_crlf to avoid symbol conflict with readline on OS/2 + * + * Revision 1.6 2025/03/09 19:14:25 snw + * First phase of REUSE compliance and header reformat + * + * + * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC + * SPDX-License-Identifier: AGPL-3.0-or-later **/ #include @@ -49,8 +62,19 @@ #include #include -#if defined(__sun) || defined(__FreeBSD__) || defined(__NetBSD__) -# include +#if !defined(__APPLE__) && !defined(__gnu_hurd__) && !defined(EMSCRIPTEN) +# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__AMIGA) +# include +# if !defined(__AMIGA) +# define TCGETA TIOCGETA +# define TCSETA TIOCSETA +# endif +# define termio termios +# else +# if !defined(MSDOS) +# include +# endif +# endif #else # include #endif @@ -71,6 +95,7 @@ #include "jobtab.h" #include "datatypes.h" #include "objects.h" +#include "log.h" #ifdef HAVE_LIBREADLINE # if defined(HAVE_READLINE_READLINE_H) @@ -144,7 +169,8 @@ void init_mwapi(void); short init (char *namespace_name) { short retval; - + + init_log (); init_process (); init_devtable (); init_signals (); @@ -167,7 +193,15 @@ short init (char *namespace_name) retval = shm_init (shm_init_size); if (retval == SHMS_GET_ERR) { - fprintf (stderr, "init: error initializing shared memory [errno %d]\r\n", errno); + if (errno != 13) { + fprintf (stderr, "init: error initializing shared memory [errno %d]\r\n", errno); + } + else { + fprintf (stderr, "init: error attaching to environment -- does your user belong to the group that owns environment '%s'?\r\n", shm_env); + } + if (run_daemon == FALSE) { + set_io (UNIX); + } exit (1); } @@ -218,7 +252,7 @@ void init_process (void) { pid = getpid (); /* get $J = process ID */ umask (0); /* protection bits mask to full rights */ - snprintf (fp_conversion, 9, "%%.%df\201", DBL_DIG); + snprintf (fp_conversion, sizeof (fp_conversion) - 1, "%%.%df\201", DBL_DIG); if (fp_mode) { zprecise = DBL_DIG; @@ -427,7 +461,7 @@ void init_readline (void) pw_buf = (char *) calloc (strlen(pw->pw_dir) + 1, sizeof(char)); strcpy (pw_buf, pw->pw_dir); - snprintf (history_file, 256, "%s/.freem_history", pw_buf); + snprintf (history_file, sizeof (history_file) - 1, "%s/.freem_history", pw_buf); free (pw_buf); @@ -520,7 +554,7 @@ void init_mwapi (void) gtk_init (0, NULL); } */ - //TODO: init Motif/libXt + /* TODO: init Motif/libXt */ } #else void init_mwapi (void) @@ -541,13 +575,13 @@ void init_io (void) sq_modes[0] = '+'; for (i = 0; i <= MAXDEV; ug_buf[i++][0] = EOL); /* init read-buffers */ - crlf[HOME] = frm_filter; + frm_crlf[HOME] = frm_filter; if (hardcopy) zbreakon = ENABLE; /* enable CTRL/B */ set_io (MUMPS); /* set i/o parameters */ -#if !defined(__AMIGA) +#if !defined(__AMIGA) && !defined(__OS2__) if (ttyname (HOME)) { /* for $IO of HOME */ strcpy (dev[HOME], ttyname (HOME)); dev[HOME][strlen (dev[HOME])] = EOL; @@ -556,7 +590,13 @@ void init_io (void) dev[HOME][0] = EOL; /* ...we are in a pipe */ } #else +#if defined(__AMIGA) strcpy (dev[HOME], "CONSOLE:"); +#else +#if defined(__OS2__) + strcpy (dev[HOME], "CON:"); +#endif +#endif #endif /* init function keys */ @@ -629,7 +669,7 @@ void cleanup (void) int ch; /* remove this job's entry from ^$JOB SSVN */ - snprintf (k_buf, 255, "^$JOB\202%d\201", pid); + snprintf (k_buf, sizeof (k_buf) - 1, "^$JOB\202%d\201", pid); symtab_shm (kill_sym, k_buf, " \201"); reset_terminal ();