Diff for /freem/src/fmadm.c between versions 1.29 and 1.40

version 1.29, 2025/04/03 01:41:02 version 1.40, 2025/04/15 18:19:40
Line 24 Line 24
  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.   *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
  *   *
  *   $Log$   *   $Log$
    *   Revision 1.40  2025/04/15 18:19:40  snw
    *   Further attempts to fix FreeBSD
    *
    *   Revision 1.39  2025/04/15 16:49:36  snw
    *   Make use of logprintf throughout codebase
    *
    *   Revision 1.38  2025/04/15 02:24:43  snw
    *   Improve FreeM logging capabilities
    *
    *   Revision 1.37  2025/04/14 19:20:20  snw
    *   Create LOCALSTATEDIR during fmadm configure if needed
    *
    *   Revision 1.36  2025/04/13 15:12:21  snw
    *   Fix transaction checkpoints on OS/2 [CLOSES #34]
    *
    *   Revision 1.35  2025/04/13 04:22:43  snw
    *   Fix snprintf calls
    *
    *   Revision 1.34  2025/04/10 15:31:25  snw
    *   Attempt to fix DosCopy calls for OS/2
    *
    *   Revision 1.33  2025/04/10 01:24:38  snw
    *   Remove C++ style comments
    *
    *   Revision 1.32  2025/04/09 19:52:02  snw
    *   Eliminate as many warnings as possible while building with -Wall
    *
    *   Revision 1.31  2025/04/04 19:43:18  snw
    *   Switch to using environment catalog to determine user and group for environment, and remove -u and -g flags from freem
    *
    *   Revision 1.30  2025/04/03 20:48:14  snw
    *   Improve daemon error diagnostics and bump to 0.63.0-rc3
    *
  *   Revision 1.29  2025/04/03 01:41:02  snw   *   Revision 1.29  2025/04/03 01:41:02  snw
  *   New features frozen; prepare 0.63.0-rc1   *   New features frozen; prepare 0.63.0-rc1
  *   *
Line 110 Line 143
 #include <unistd.h>  #include <unistd.h>
 #include <errno.h>  #include <errno.h>
 #include <ctype.h>  #include <ctype.h>
   #if defined(__OS2__)
   # include <os2.h>
   #endif
 #include "config.h"  #include "config.h"
 #include "transact.h"  #include "transact.h"
 #include "namespace.h"  #include "namespace.h"
 #include "fs.h"  #include "fs.h"
   #include "log.h"
 #if defined(__OS2__)  
 # include <os2.h>  
 #endif  
   
 #ifdef HAVE_LIBREADLINE  #ifdef HAVE_LIBREADLINE
 #  if defined(HAVE_READLINE_READLINE_H)  #  if defined(HAVE_READLINE_READLINE_H)
Line 178  extern char env_config_file[4096]; Line 211  extern char env_config_file[4096];
 extern char env_user[255];  extern char env_user[255];
 extern char env_group[255];  extern char env_group[255];
 extern char env_enabled[10];  extern char env_enabled[10];
   extern char shm_env[255];
   
 int fm_shell(void);  int fm_shell(void);
 void fm_checkperms(void);  void fm_checkperms(void);
Line 345  int main (int argc, char **argv) Line 379  int main (int argc, char **argv)
           
     if (obj != OBJ_DAEMON) {      if (obj != OBJ_DAEMON) {
         if (strlen (env_user) == 0) {          if (strlen (env_user) == 0) {
             snprintf (env_user, 6, "freem");              snprintf (env_user, sizeof (env_user) - 1, "freem");
         }          }
                   
         if (strlen (env_group) == 0) {          if (strlen (env_group) == 0) {
             snprintf (env_group, 6, "freem");              snprintf (env_group, sizeof (env_group) - 1, "freem");
         }          }
   
   
         if (!fma_explicit_environment) snprintf (fma_environment, 4096, "DEFAULT");          if (!fma_explicit_environment) snprintf (fma_environment, sizeof (fma_environment) - 1, "DEFAULT");
         if (!fma_explicit_namespace) snprintf (fma_namespace, 4096, "SYSTEM");          if (!fma_explicit_namespace) snprintf (fma_namespace, sizeof (fma_namespace) - 1, "SYSTEM");
           
         snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment);          snprintf (config_file, sizeof (config_file) - 1, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment);
     }      }
           
     snprintf (env_config_file, 4096, "%s/freem/env.conf", SYSCONFDIR);      snprintf (env_config_file, sizeof (env_config_file) - 1, "%s/freem/env.conf", SYSCONFDIR);
           
 /*  /*
     printf ("action = '%s' object = '%s' environment = '%s' namespace = '%s' config_file = '%s' base_arg = '%d' next argument = '%s'\n", action, obj_str, fma_environment, fma_namespace, config_file, base_arg, argv[base_arg]);      printf ("action = '%s' object = '%s' environment = '%s' namespace = '%s' config_file = '%s' base_arg = '%d' next argument = '%s'\n", action, obj_str, fma_environment, fma_namespace, config_file, base_arg, argv[base_arg]);
     exit(1);      exit(1);
 */  */
       strncpy (shm_env, fma_environment, sizeof (shm_env) - 1);
       init_log ();
           
     /* override for fmadm configure and daemon stuff */      /* override for fmadm configure and daemon stuff */
     if (got_action) {      if (got_action) {
Line 597  int fm_shell (void) Line 633  int fm_shell (void)
     char *cmdt = (char *) malloc (65535 * sizeof (char));      char *cmdt = (char *) malloc (65535 * sizeof (char));
     char *result = (char *) malloc (65535 * sizeof (char));      char *result = (char *) malloc (65535 * sizeof (char));
   
     /*      obj = 0;
     strcpy (fma_namespace, "SYSTEM");  
     set_namespace (fma_namespace, FALSE);  
     */  
           
     snprintf (fma_prompt, STRLEN - 1, "fmadm [%s]> ", fma_namespace);      snprintf (fma_prompt, STRLEN - 1, "fmadm [%s]> ", fma_namespace);
           
Line 705  int fm_shell (void) Line 738  int fm_shell (void)
   
         i = 0;          i = 0;
         while ((result = strtok (NULL, " ")) != NULL) {          while ((result = strtok (NULL, " ")) != NULL) {
             //    printf ("%d = %s\n", i, result);  
             strcpy (args[i++], result);              strcpy (args[i++], result);
         }          }
   
Line 1165  long fm_get_pid (char *env) Line 1197  long fm_get_pid (char *env)
 {  {
     char pid_file[4096];      char pid_file[4096];
     char tmp_pid[255];      char tmp_pid[255];
     long res;  
       
     FILE *fp;      FILE *fp;
   
     snprintf (pid_file, 4095, "%s/freem/run/%s.pid", LOCALSTATEDIR, env);      snprintf (pid_file, sizeof (pid_file) - 1, "%s/freem/run/%s.pid", LOCALSTATEDIR, env);
   
     if ((fp = fopen (pid_file, "r")) != NULL) {      if ((fp = fopen (pid_file, "r")) != NULL) {
         if (fgets (tmp_pid, 255, fp)) {          if (fgets (tmp_pid, 255, fp)) {
Line 1192  int fm_validate_environment (char *env) Line 1222  int fm_validate_environment (char *env)
     char line[255];      char line[255];
     char chkline[255];      char chkline[255];
   
     snprintf (chkline, 254, "[%s]\n", env);      snprintf (chkline, sizeof (chkline) - 1, "[%s]\n", env);
           
     if ((fp = fopen (env_config_file, "r")) == NULL) {      if ((fp = fopen (env_config_file, "r")) == NULL) {
         fprintf (stderr, "fmadm:  could not open %s [%s]\n", env_config_file, strerror (errno));          fprintf (stderr, "fmadm:  could not open %s [%s]\n", env_config_file, strerror (errno));
Line 1210  int fm_validate_environment (char *env) Line 1240  int fm_validate_environment (char *env)
     return FALSE;      return FALSE;
 }  }
   
 int fm_start_environment (char *env, char *e_user, char *e_grp)  int fm_start_environment (char *env)
 {  {
     char basecmd[255];      char basecmd[255];
     char cmd[4096];          char cmd[4096];    
Line 1220  int fm_start_environment (char *env, cha Line 1250  int fm_start_environment (char *env, cha
     }      }
           
 #if !defined(__OS2__)  #if !defined(__OS2__)
     snprintf (basecmd, 254, "%s/bin/freem", PREFIX);      snprintf (basecmd, sizeof (basecmd) - 1, "%s/bin/freem", PREFIX);
 #else  #else
     snprintf (basecmd, 254, "%s/bin/freemd.exe", PREFIX);      snprintf (basecmd, sizeof (basecmd) - 1, "%s/bin/freemd.exe", PREFIX);
 #endif  #endif
   
 #if !defined(__OS2__)                      #if !defined(__OS2__)                    
     snprintf (cmd, 4095, "%s -d -e %s -u %s -g %s", basecmd, env, e_user, e_grp);      snprintf (cmd, sizeof (basecmd) - 1, "%s -d -e %s", basecmd, env);
 #else  #else
     sprintf (cmd, 4095, "%s -d -k -e %s -u %s -g %s", basecmd, env, e_user, e_grp);      sprintf (cmd, 4095, "%s -d -k -e %s", basecmd, env);
 #endif  #endif
   
     system (cmd);      system (cmd);
Line 1305  int fm_daemonctl (short action, short ob Line 1335  int fm_daemonctl (short action, short ob
     char *savptr;      char *savptr;
     int result;      int result;
     long epid;      long epid;
       int retval;
         
       retval = 0;
           
     switch (action) {      switch (action) {
         case ACT_START:          case ACT_START:
Line 1340  int fm_daemonctl (short action, short ob Line 1372  int fm_daemonctl (short action, short ob
             if (line[0] == '[') {              if (line[0] == '[') {
                 strncpy (env, &(line[1]), 255);                  strncpy (env, &(line[1]), 255);
                 env[strlen (env) - 2] = '\0';                  env[strlen (env) - 2] = '\0';
                 snprintf (tmps, 255, "%s,", env);                  snprintf (tmps, sizeof (tmps) - 1, "%s,", env);
                 strncat (envlist, tmps, BIGSTR - 1);                  strncat (envlist, tmps, BIGSTR - 1);
             }              }
         }          }
Line 1384  int fm_daemonctl (short action, short ob Line 1416  int fm_daemonctl (short action, short ob
             switch (action) {              switch (action) {
                                   
                 case ACT_START:                  case ACT_START:
                     result = fm_start_environment (cur_env, e_user, e_grp);                      result = fm_start_environment (cur_env);
                     if (result == TRUE) {                      if (result == TRUE) {
                         fprintf (stderr, "[OK]\n");                          fprintf (stderr, "[OK]\n");
                     }                      }
Line 1400  int fm_daemonctl (short action, short ob Line 1432  int fm_daemonctl (short action, short ob
                     }                      }
                     else {                      else {
                         fprintf (stderr, "[FAIL]\n");                          fprintf (stderr, "[FAIL]\n");
                           retval++;
                     }                                          }                    
                     break;                      break;
   
                 case ACT_RESTART:                  case ACT_RESTART:
                     if (fm_stop_environment (cur_env) == TRUE) {                      if (fm_stop_environment (cur_env) == TRUE) {
                         result = fm_start_environment (cur_env, e_user, e_grp);                          result = fm_start_environment (cur_env);
                         if (result == TRUE) {                          if (result == TRUE) {
                             fprintf (stderr, "[OK]\n");                              fprintf (stderr, "[OK]\n");
                         }                          }
                         else {                          else {
                             fprintf (stderr, "[FAIL]\n");                              fprintf (stderr, "[FAIL]\n");
                               retval++;
                         }                                                  }                        
                     }                      }
                     else {                      else {
                         fprintf (stderr, "[FAIL]\n");                          fprintf (stderr, "[FAIL]\n");
                           retval++;
                     }                                             }                       
   
                     break;                      break;
Line 1422  int fm_daemonctl (short action, short ob Line 1457  int fm_daemonctl (short action, short ob
                 case ACT_STATUS:                  case ACT_STATUS:
                     epid = fm_get_pid (cur_env);                      epid = fm_get_pid (cur_env);
                     if (epid > -1) {                      if (epid > -1) {
                         fprintf (stderr, " - %s environment daemon running as pid %d\n", cur_env, epid);                          fprintf (stderr, " - %s environment daemon running as pid %ld\n", cur_env, epid);
                     }                      }
                     else {                      else {
                         fprintf (stderr, " - %s environment daemon does not appear to be running\n", cur_env);                          fprintf (stderr, " - %s environment daemon does not appear to be running\n", cur_env);
Line 1435  int fm_daemonctl (short action, short ob Line 1470  int fm_daemonctl (short action, short ob
     } while ((cur_env = strtok_r (NULL, ",", &savptr)) != NULL);      } while ((cur_env = strtok_r (NULL, ",", &savptr)) != NULL);
   
     free (envlist);      free (envlist);
     exit (0);      exit (retval);
           
 } /* fm_daemonctl() */  } /* fm_daemonctl() */
   
Line 1448  void fm_checkperms(void) Line 1483  void fm_checkperms(void)
 void fm_reconfigure(void)  void fm_reconfigure(void)
 {  {
     char config_backup[4096];      char config_backup[4096];
     char vers[4096];  
           
     int retval;         int retval;   
           
Line 1457  void fm_reconfigure(void) Line 1491  void fm_reconfigure(void)
         exit (1);          exit (1);
     }      }
           
     snprintf (config_backup, 4095, "%s.orig", config_file);      snprintf (config_backup, sizeof (config_backup) - 1, "%s.orig", config_file);
   
     fprintf (stderr, "fmadm:  reconfiguring FreeM with system defaults for %s...\n", FREEM_VERSION_CSTR);      fprintf (stderr, "fmadm:  reconfiguring FreeM with system defaults for %s...\n", FREEM_VERSION_CSTR);
     fprintf (stderr, "fmadm:  backing up %s to %s...\t", config_file, config_backup);          fprintf (stderr, "fmadm:  backing up %s to %s...\t", config_file, config_backup);    
Line 1465  void fm_reconfigure(void) Line 1499  void fm_reconfigure(void)
 #if !defined(__OS2__)      #if !defined(__OS2__)    
     retval = cp (config_backup, config_file);      retval = cp (config_backup, config_file);
 #else  #else
     retval = DosCopy (config_file, config_backup);      retval = DosCopy (config_file, config_backup, 1);
 #endif      #endif    
   
     if (retval == 0) {      if (retval == 0) {
Line 1488  void update_conf (char *file, char *sect Line 1522  void update_conf (char *file, char *sect
     char old_value[255];      char old_value[255];
     char tbuf[255];      char tbuf[255];
   
     snprintf (tbuf, 254, "%s.%s", section, key);      snprintf (tbuf, sizeof (tbuf) - 1, "%s.%s", section, key);
                   
     read_profile_string (file, section, key, old_value);      read_profile_string (file, section, key, old_value);
     if (strcmp (old_value, new_value) != 0) {      if (strcmp (old_value, new_value) != 0) {
Line 1504  void fm_configure (void) Line 1538  void fm_configure (void)
 {  {
     char rundir[4096];      char rundir[4096];
     char varbase[4096];      char varbase[4096];
       char vardir[4096];
     char sysrtn[4096];      char sysrtn[4096];
     char sysgbl[4096];      char sysgbl[4096];
     char usrrtn[4096];      char usrrtn[4096];
Line 1515  void fm_configure (void) Line 1550  void fm_configure (void)
     char jnlhostid[4096];          char jnlhostid[4096];    
     char jnlcut[4096];      char jnlcut[4096];
     char hostid[4096];      char hostid[4096];
       char logdir[4096];
       
     char confbase[4096];      char confbase[4096];
     char envbase[4096];      char envbase[4096];
   
Line 1527  void fm_configure (void) Line 1563  void fm_configure (void)
     int reconfigure = FALSE;      int reconfigure = FALSE;
           
     struct stat etcstat;      struct stat etcstat;
     int stat_result;  
   
     DIR *dir;      DIR *dir;
     struct dirent *ent;      struct dirent *ent;
Line 1538  void fm_configure (void) Line 1573  void fm_configure (void)
     char *groupname = env_group;      char *groupname = env_group;
           
 #if !defined(__OS2__)  #if !defined(__OS2__)
       struct group *d_grp;
       struct passwd *d_user;
   
     if (geteuid () != 0) {      if (geteuid () != 0) {
         fprintf (stderr, "fmadm:  not superuser\n");          fprintf (stderr, "fmadm:  not superuser\n");
         exit (1);          exit (1);
     }      }
   
     struct group *d_grp;  
     struct passwd *d_user;  
     gid_t d_gid;  
     uid_t d_uid;  
   
     if ((d_grp = getgrnam (groupname)) == NULL) {      if ((d_grp = getgrnam (groupname)) == NULL) {
         fprintf (stderr, "fmadm:  '%s' group must exist before configuring\n", groupname);          fprintf (stderr, "fmadm:  '%s' group must exist before configuring\n", groupname);
         exit (1);          exit (1);
     }      }
     d_gid = d_grp->gr_gid;  
   
     if ((d_user = getpwnam (username)) == NULL) {      if ((d_user = getpwnam (username)) == NULL) {
         fprintf (stderr, "fmadm:  '%s' user must exist before configuring\n", username);          fprintf (stderr, "fmadm:  '%s' user must exist before configuring\n", username);
         exit (1);          exit (1);
     }      }
     d_uid = d_user->pw_uid;  
 #endif      #endif    
           
     snprintf (varbase, 4095, "%s/freem", LOCALSTATEDIR);      snprintf (logdir, sizeof (logdir) - 1, "/var/log/freem");
     snprintf (rundir, 4095, "%s/freem/run", LOCALSTATEDIR);      snprintf (vardir, sizeof (vardir) - 1, "%s", LOCALSTATEDIR);
     snprintf (sysrtn, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);      snprintf (varbase, sizeof (varbase) - 1, "%s/freem", LOCALSTATEDIR);
     snprintf (sysgbl, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment);      snprintf (rundir, sizeof (rundir) - 1, "%s/freem/run", LOCALSTATEDIR);
     snprintf (usrrtn, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment);      snprintf (sysrtn, sizeof (sysrtn) - 1, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);
     snprintf (usrgbl, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment);      snprintf (sysgbl, sizeof (sysgbl) - 1, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment);
     snprintf (jnldir, 4095, "%s/freem/%s/journals", LOCALSTATEDIR, fma_environment);      snprintf (usrrtn, sizeof (usrrtn) - 1, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment);
     snprintf (jnlfile, 4095, "%s/freem_journal_%s.dat", jnldir, fma_environment);      snprintf (usrgbl, sizeof (usrgbl) - 1, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment);
     snprintf (jnlmode, 3, "on");      snprintf (jnldir, sizeof (jnldir) - 1, "%s/freem/%s/journals", LOCALSTATEDIR, fma_environment);
     snprintf (jnlhostid, 4095, "DEFAULT");      snprintf (jnlfile, sizeof (jnlfile) - 1, "%s/freem_journal_%s.dat", jnldir, fma_environment);
     snprintf (jnlcut, 4095, "4294967000");      snprintf (jnlmode, sizeof (jnlmode) - 1, "on");
       snprintf (jnlhostid, sizeof (jnlhostid) - 1, "DEFAULT");
       snprintf (jnlcut, sizeof (jnlcut) - 1, "4294967000");
           
     if (geteuid () != 0) {      if (geteuid () != 0) {
         fprintf (stderr, "fmadm:  not superuser\n");          fprintf (stderr, "fmadm:  not superuser\n");
Line 1585  void fm_configure (void) Line 1617  void fm_configure (void)
     gethostname (hostid, 4095);      gethostname (hostid, 4095);
     uuid_v4 (buf);      uuid_v4 (buf);
   
     snprintf (jnlhostid, 4095, "%s:%s", hostid, buf);      snprintf (jnlhostid, sizeof (jnlhostid) - 1, "%s:%s", hostid, buf);
     snprintf (confbase, 4095, "%s/freem", SYSCONFDIR);      snprintf (confbase, sizeof (confbase) - 1, "%s/freem", SYSCONFDIR);
     snprintf (envbase, 4095, "%s/freem/%s", SYSCONFDIR, fma_environment);       snprintf (envbase, sizeof (envbase) - 1, "%s/freem/%s", SYSCONFDIR, fma_environment); 
     snprintf (nsbase, 4095, "%s/freem/%s", LOCALSTATEDIR, fma_environment);      snprintf (nsbase, sizeof (nsbase) - 1, "%s/freem/%s", LOCALSTATEDIR, fma_environment);
   
 #if defined(__OS2__)  #if defined(__OS2__)
     {      {
         char srcfile[PATHLEN];          char srcfile[PATHLEN];
         char dstfile[PATHLEN];                  char dstfile[PATHLEN];        
                   
         snprintf (srcfile, PATHLEN, "%s/bin/freem.exe", PREFIX);          snprintf (srcfile, PATHLEN - 1, "%s/bin/freem.exe", PREFIX);
         snprintf (dstfile, PATHLEN, "%s/bin/freemd.exe", PREFIX);          snprintf (dstfile, PATHLEN - 1, "%s/bin/freemd.exe", PREFIX);
   
         unlink (dstfile);          unlink (dstfile);
                   
Line 1627  void fm_configure (void) Line 1659  void fm_configure (void)
     }      }
           
     /* check for existence of needed directories */      /* check for existence of needed directories */
       if (stat (logdir, &etcstat) == -1) {
           fprintf (stderr, "fmadm:  creating %s [logdir]\n", logdir);
           mkdir (logdir, 0775);
           set_permissions (logdir, username, groupname, 0775);
       }
   
     if (stat (SYSCONFDIR, &etcstat) == -1) {      if (stat (SYSCONFDIR, &etcstat) == -1) {
         fprintf (stderr, "fmadm:  creating %s [SYSCONFDIR]\n", SYSCONFDIR);          fprintf (stderr, "fmadm:  creating %s [SYSCONFDIR]\n", SYSCONFDIR);
         mkdir (SYSCONFDIR, 0775);          mkdir (SYSCONFDIR, 0775);
Line 1639  void fm_configure (void) Line 1677  void fm_configure (void)
         set_permissions (confbase, username, groupname, 0775);          set_permissions (confbase, username, groupname, 0775);
     }      }
   
       if (stat (vardir, &etcstat) == -1) {
           fprintf (stderr, "fmadm:  creating %s [vardir]\n", vardir);
           mkdir (vardir, 0775);
           set_permissions (vardir, username, groupname, 0775);
       }    
       
     if (stat (varbase, &etcstat) == -1) {      if (stat (varbase, &etcstat) == -1) {
         fprintf (stderr, "fmadm:  creating %s [varbase]\n", varbase);          fprintf (stderr, "fmadm:  creating %s [varbase]\n", varbase);
         mkdir (varbase, 0775);          mkdir (varbase, 0775);
Line 1670  void fm_configure (void) Line 1714  void fm_configure (void)
     }      }
   
           
     snprintf (src_dir, 4095, "%s/freem/mlib", DATADIR);      snprintf (src_dir, sizeof (src_dir) - 1, "%s/freem/mlib", DATADIR);
     snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);      snprintf (dest_dir, sizeof (dest_dir) - 1, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);
   
     if (reconfigure == FALSE) {      if (reconfigure == FALSE) {
         fprintf (stderr, "fmadm:  populating new environment '%s'\n", fma_environment);          fprintf (stderr, "fmadm:  populating new environment '%s'\n", fma_environment);
Line 1680  void fm_configure (void) Line 1724  void fm_configure (void)
         fprintf (stderr, "fmadm:  upgrading environment '%s'\n", fma_environment);          fprintf (stderr, "fmadm:  upgrading environment '%s'\n", fma_environment);
     }      }
           
     snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);      snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);
     mkdir (buf, 0775);      mkdir (buf, 0775);
     set_permissions (buf, username, groupname, 0775);      set_permissions (buf, username, groupname, 0775);
           
     snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);      snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);
     mkdir (buf, 0775);      mkdir (buf, 0775);
     set_permissions (buf, username, groupname, 0775);      set_permissions (buf, username, groupname, 0775);
           
     snprintf (buf, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);      snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);
     mkdir (buf, 0775);      mkdir (buf, 0775);
     set_permissions (buf, username, groupname, 0775);      set_permissions (buf, username, groupname, 0775);
           
     snprintf (buf, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment);      snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment);
     mkdir (buf, 0775);      mkdir (buf, 0775);
     set_permissions (buf, username, groupname, 0775);      set_permissions (buf, username, groupname, 0775);
           
     snprintf (buf, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment);      snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment);
     mkdir (buf, 0775);      mkdir (buf, 0775);
     set_permissions (buf, username, groupname, 0775);      set_permissions (buf, username, groupname, 0775);
           
     snprintf (buf, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment);      snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment);
     mkdir (buf, 0775);      mkdir (buf, 0775);
     set_permissions (buf, username, groupname, 0775);      set_permissions (buf, username, groupname, 0775);
           
Line 1717  void fm_configure (void) Line 1761  void fm_configure (void)
                   
         if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) {                     if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) {           
                           
             snprintf (infile, 4095, "%s/%s", src_dir, ent->d_name);              snprintf (infile, sizeof (infile) - 1, "%s/%s", src_dir, ent->d_name);
             snprintf (outfile, 4095, "%s/%s", dest_dir, ent->d_name);              snprintf (outfile, sizeof (outfile) - 1, "%s/%s", dest_dir, ent->d_name);
   
             if (stat (outfile, &etcstat) == 0) {              if (stat (outfile, &etcstat) == 0) {
                 unlink (outfile);                  unlink (outfile);
Line 1748  void fm_configure (void) Line 1792  void fm_configure (void)
                   
         fprintf (stderr, "Creating %s... ", env_config_file);          fprintf (stderr, "Creating %s... ", env_config_file);
                   
         snprintf (buf, 4095, "[%s]", fma_environment);          snprintf (buf, sizeof (buf) - 1, "[%s]", fma_environment);
           fm_write (fp, buf);
           
           snprintf (buf, sizeof (buf) - 1, "user=%s", env_user);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "user=%s", env_user);          snprintf (buf, sizeof (buf) - 1, "group=%s", env_group);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "group=%s", env_group);          snprintf (buf, sizeof (buf) - 1, "enabled=%s", env_enabled);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "enabled=%s", env_enabled);          snprintf (buf, sizeof (buf) - 1, "env_path=%s/freem/%s", LOCALSTATEDIR, fma_environment);
           fm_write (fp, buf);
   
           snprintf (buf, sizeof (buf) - 1, "log_threshold_file=info");
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "env_path=%s/freem/%s", LOCALSTATEDIR, fma_environment);          snprintf (buf, sizeof (buf) - 1, "log_threshold_syslog=info");
           fm_write (fp, buf);
   
           snprintf (buf, sizeof (buf) - 1, "log_threshold_stderr=warning");
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         fclose (fp);          fclose (fp);
         fprintf (stderr, "[OK]\n");          fprintf (stderr, "[OK]\n");
     }      }
     else {      else {
         char modtmp[255];  
           
         fprintf (stderr, "\nUpdating %s: \n", env_config_file);          fprintf (stderr, "\nUpdating %s: \n", env_config_file);
   
         update_conf (env_config_file, fma_environment, "user", env_user);          update_conf (env_config_file, fma_environment, "user", env_user);
         update_conf (env_config_file, fma_environment, "group", env_group);          update_conf (env_config_file, fma_environment, "group", env_group);
         update_conf (env_config_file, fma_environment, "enabled", env_enabled);          update_conf (env_config_file, fma_environment, "enabled", env_enabled);
           update_conf (env_config_file, fma_environment, "log_threshold_file", "info");
           update_conf (env_config_file, fma_environment, "log_threshold_syslog", "info");
           update_conf (env_config_file, fma_environment, "log_threshold_stderr", "warning");        
     }      }
   
     if (reconfigure == FALSE) {      if (reconfigure == FALSE) {
Line 1781  void fm_configure (void) Line 1835  void fm_configure (void)
                   
         fprintf (stderr, "Creating %s... ", config_file);           fprintf (stderr, "Creating %s... ", config_file); 
                   
         snprintf (buf, 4095, "[SYSTEM]");          snprintf (buf, sizeof (buf) - 1, "[SYSTEM]");
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "root=%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);          snprintf (buf, sizeof (buf) - 1, "root=%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "routines_path=%s", sysrtn);          snprintf (buf, sizeof (buf) - 1, "routines_path=%s", sysrtn);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "globals_path=%s", sysgbl);          snprintf (buf, sizeof (buf) - 1, "globals_path=%s", sysgbl);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "journal_file=%s", jnlfile);          snprintf (buf, sizeof (buf) - 1, "journal_file=%s", jnlfile);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "journal_mode=%s", jnlmode);          snprintf (buf, sizeof (buf) - 1, "journal_mode=%s", jnlmode);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "journal_host_id=%s", jnlhostid);          snprintf (buf, sizeof (buf) - 1, "journal_host_id=%s", jnlhostid);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "journal_cut_threshold=%s", jnlcut);          snprintf (buf, sizeof (buf) - 1, "journal_cut_threshold=%s", jnlcut);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "zdate_format=%%x");          snprintf (buf, sizeof (buf) - 1, "zdate_format=%%x");
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "ztime_format=%%X");          snprintf (buf, sizeof (buf) - 1, "ztime_format=%%X");
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "\n[USER]");          snprintf (buf, sizeof (buf) - 1, "\n[USER]");
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "root=%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);          snprintf (buf, sizeof (buf) - 1, "root=%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "routines_path=%s", usrrtn);          snprintf (buf, sizeof (buf) - 1, "routines_path=%s", usrrtn);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         snprintf (buf, 4095, "globals_path=%s", usrgbl);          snprintf (buf, sizeof (buf) - 1, "globals_path=%s", usrgbl);
         fm_write (fp, buf);          fm_write (fp, buf);
                   
         fclose (fp);          fclose (fp);
Line 1836  void fm_configure (void) Line 1890  void fm_configure (void)
         /* existing configuration */          /* existing configuration */
         fprintf (stderr, "\nUpdating environment configuration for %s:\n", fma_environment);          fprintf (stderr, "\nUpdating environment configuration for %s:\n", fma_environment);
   
         snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);          snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);
         update_conf (config_file, "SYSTEM", "root", buf);          update_conf (config_file, "SYSTEM", "root", buf);
         update_conf (config_file, "SYSTEM", "routines_path", sysrtn);                 update_conf (config_file, "SYSTEM", "routines_path", sysrtn);       
         update_conf (config_file, "SYSTEM", "globals_path", sysgbl);          update_conf (config_file, "SYSTEM", "globals_path", sysgbl);
Line 1845  void fm_configure (void) Line 1899  void fm_configure (void)
         update_conf (config_file, "SYSTEM", "journal_host_id", tmpsd);          update_conf (config_file, "SYSTEM", "journal_host_id", tmpsd);
         update_conf (config_file, "SYSTEM", "journal_cut_threshold", jnlcut);          update_conf (config_file, "SYSTEM", "journal_cut_threshold", jnlcut);
   
         snprintf (buf, 4095, "%%x");          snprintf (buf, sizeof (buf) - 1, "%%x");
         update_conf (config_file, "SYSTEM", "zdate_format", buf);          update_conf (config_file, "SYSTEM", "zdate_format", buf);
                   
         snprintf (buf, 4095, "%%X");          snprintf (buf, sizeof (buf) - 1, "%%X");
         update_conf (config_file, "SYSTEM", "ztime_format", buf);          update_conf (config_file, "SYSTEM", "ztime_format", buf);
   
         /* USER */                  /* USER */        
         snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);          snprintf (buf, sizeof (buf) - 1, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);
         update_conf (config_file, "USER", "root", buf);                  update_conf (config_file, "USER", "root", buf);        
         update_conf (config_file, "USER", "routines_path", usrrtn);          update_conf (config_file, "USER", "routines_path", usrrtn);
         update_conf (config_file, "USER", "globals_path", usrgbl);          update_conf (config_file, "USER", "globals_path", usrgbl);

Removed from v.1.29  
changed lines
  Added in v.1.40


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>