--- freem/src/mumps.c	2025/04/02 02:16:27	1.12
+++ freem/src/mumps.c	2025/04/03 20:48:14	1.15
@@ -1,5 +1,5 @@
 /*
- *   $Id: mumps.c,v 1.12 2025/04/02 02:16:27 snw Exp $
+ *   $Id: mumps.c,v 1.15 2025/04/03 20:48:14 snw Exp $
  *    main module of freem
  *
  *  
@@ -24,6 +24,15 @@
  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
  *
  *   $Log: mumps.c,v $
+ *   Revision 1.15  2025/04/03 20:48:14  snw
+ *   Improve daemon error diagnostics and bump to 0.63.0-rc3
+ *
+ *   Revision 1.14  2025/04/02 04:50:49  snw
+ *   Allow vendor routines to be upgraded
+ *
+ *   Revision 1.13  2025/04/02 03:26:22  snw
+ *   Don't corrupt the terminal if FreeM runs before fmadm configure has been run
+ *
  *   Revision 1.12  2025/04/02 02:16:27  snw
  *   Add fmadm status environment command and move journals to a better location
  *
@@ -112,6 +121,8 @@ int main (int argc, char **argv, char **
     
     int option_index = 0;
 
+    char fm_initialized = FALSE;
+    
     char dx_mcode[512];
     char startup_routine[256];
     short routine_mode;
@@ -595,6 +606,7 @@ int main (int argc, char **argv, char **
             errsav = errno;
             
             if (pid_fd < 0) {
+                fprintf (stderr, "freem:  could not open PID file %s [%s]\n", pid_file_path, strerror (errsav));
                 m_log (1, "freem:  could not open PID file");
                 m_log (1, strerror (errsav));
                 exit (1);
@@ -602,6 +614,7 @@ int main (int argc, char **argv, char **
 
             if (lockf (pid_fd, F_TLOCK, 0) < 0) {
                 errsav = errno;
+                fprintf (stderr, "freem:  could not lock PID file [%s]\n", strerror (errsav));
                 m_log (1, "freem: could not lock PID file - perhaps already running?");
                 m_log (1, strerror (errsav));
                 exit (1);
@@ -642,12 +655,15 @@ int main (int argc, char **argv, char **
 	strncpy (nsnbuf, nsname, 255);    
 	if (init (nsnbuf) == FALSE) {
 	    
-	    set_io (UNIX);
+	    if (fm_initialized) set_io (UNIX);
 	    fprintf (stderr, "\nError initializing FreeM.\n");
 	    
 	    exit (1);            
 	    
-	}        
+	}
+        else {
+            fm_initialized = TRUE;
+        }
 
 	
         direct_mode = FALSE;
@@ -674,10 +690,6 @@ int main (int argc, char **argv, char **
             /* isolate the path from the routine file */
             strncpy (cli_rtn_path, argv[optind], strrchr (argv[optind], '/') - argv[optind]);      
 	    
-/*	    set_io (UNIX);
-	    printf ("cli_rtn_name = '%s' cli_rtn_path = '%s'\n", cli_rtn_name, cli_rtn_path);
-	    set_io (MUMPS);
-*/	    
         }
 
         /* do we have a file extension? */
@@ -714,10 +726,11 @@ int main (int argc, char **argv, char **
 
     }
 
-
+    
     if (!file_exists (config_file)) {
 
-        set_io (UNIX);
+        if (fm_initialized == TRUE) set_io (UNIX);
+        
         fprintf (stderr, "\nFreeM has not been configured. Please run 'fmadm configure'.\n\n\n\n");
         
         exit (2);
@@ -727,14 +740,15 @@ int main (int argc, char **argv, char **
     if (!skip_init) {
 	/* initialize FreeM environment */
 	strncpy (nsnbuf, nsname, 255);    
-	if (init (nsnbuf) == FALSE) {
-	    
+	if (init (nsnbuf) == FALSE) {	    
 	    set_io (UNIX);
 	    fprintf (stderr, "\nError initializing FreeM.\n");
 
 	    exit (1);
-
 	}
+        else {
+            fm_initialized = TRUE;
+        }
     }
 
     if (first_process == TRUE) {