File:  [Coherent Logic Development] / freem / src / fmadm.c
Revision 1.7: download - view: text, annotated - select for diffs
Sun Mar 9 19:14:25 2025 UTC (6 months, 3 weeks ago) by snw
Branches: MAIN
CVS tags: v0-62-1, v0-62-0, HEAD
First phase of REUSE compliance and header reformat

    1: /*
    2:  *   $Id: fmadm.c,v 1.7 2025/03/09 19:14:25 snw Exp $
    3:  *    FreeM Administration Tool
    4:  *
    5:  *  
    6:  *   Author: Serena Willis <snw@coherent-logic.com>
    7:  *    Copyright (C) 1998 MUG Deutschland
    8:  *    Copyright (C) 2020, 2023, 2025 Coherent Logic Development LLC
    9:  *
   10:  *
   11:  *   This file is part of FreeM.
   12:  *
   13:  *   FreeM is free software: you can redistribute it and/or modify
   14:  *   it under the terms of the GNU Affero Public License as published by
   15:  *   the Free Software Foundation, either version 3 of the License, or
   16:  *   (at your option) any later version.
   17:  *
   18:  *   FreeM is distributed in the hope that it will be useful,
   19:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   20:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21:  *   GNU Affero Public License for more details.
   22:  *
   23:  *   You should have received a copy of the GNU Affero Public License
   24:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
   25:  *
   26:  *   $Log: fmadm.c,v $
   27:  *   Revision 1.7  2025/03/09 19:14:25  snw
   28:  *   First phase of REUSE compliance and header reformat
   29:  *
   30:  *
   31:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
   32:  * SPDX-License-Identifier: AGPL-3.0-or-later 
   33:  **/
   34: 
   35: #include <sys/types.h>
   36: #include <sys/stat.h>
   37: #include <stddef.h>
   38: #include <stdio.h>
   39: #include <string.h>
   40: #include <dirent.h>
   41: #include <stdlib.h>
   42: #include <unistd.h>
   43: #include <errno.h>
   44: #include <ctype.h>
   45: #include "config.h"
   46: #include "transact.h"
   47: #include "namespace.h"
   48: #include "fs.h"
   49: 
   50: #ifdef HAVE_LIBREADLINE
   51: #  if defined(HAVE_READLINE_READLINE_H)
   52: #    include <readline/readline.h>
   53: #  elif defined(HAVE_READLINE_H)
   54: #    include <readline.h>
   55: #  else /* !defined(HAVE_READLINE_H) */
   56: extern char *readline ();
   57: #  endif /* !defined(HAVE_READLINE_H) */
   58: /*char *cmdline = NULL;*/
   59: #else /* !defined(HAVE_READLINE_READLINE_H) */
   60:   /* no readline */
   61: #endif /* HAVE_LIBREADLINE */
   62: 
   63: #ifdef HAVE_READLINE_HISTORY
   64: #  if defined(HAVE_READLINE_HISTORY_H)
   65: #    include <readline/history.h>
   66: #  elif defined(HAVE_HISTORY_H)
   67: #    include <history.h>
   68: #  else /* !defined(HAVE_HISTORY_H) */
   69: extern void add_history ();
   70: extern int write_history ();
   71: extern int read_history ();
   72: #  endif /* defined(HAVE_READLINE_HISTORY_H) */
   73:   /* no history */
   74: #endif /* HAVE_READLINE_HISTORY */
   75: 
   76: 
   77: #include "fmadm.h"
   78: #include "errmsg.h"
   79: #include "iniconf.h"
   80: #include "init.h"
   81: #include "version.h"
   82: #include "shmmgr.h"
   83: #include "jobtab.h"
   84: #include "locktab.h"
   85: 
   86: /* namespace configuration */
   87: char fma_environment[STRLEN];
   88: char fma_namespace[STRLEN];
   89: char fma_routine_path[STRLEN];
   90: char fma_global_path[STRLEN];
   91: char fma_journal_path[STRLEN];
   92: char fma_pct_global_path[STRLEN];
   93: char fma_pct_routine_path[STRLEN];
   94: char fma_journal_cut_threshold[STRLEN];
   95: char fma_locktab[STRLEN];
   96: short fma_base_opt = 1;
   97: short fma_min_args = 2;
   98: short fma_explicit_namespace = FALSE;
   99: short fma_explicit_environment = FALSE;
  100: 
  101: /* miscellaneous global state */
  102: char obj_str[STRLEN];
  103: 
  104: extern char config_file[4096];
  105: 
  106: int fm_shell(void);
  107: void fm_checkperms(void);
  108: void fm_reconfigure(void);
  109: void fm_configure(void);
  110: void fm_write (FILE *file, char *buf);
  111: int fma_jobs_remove (int optc, char **opts);
  112: 
  113: int main (int argc, char **argv)
  114: {
  115:     char action[STRLEN];    
  116: 
  117:     short act = -1;
  118:     short obj = -1;
  119: 
  120:     char **opts;
  121:     int optc = argc - 3;
  122: 
  123:     int i = 0;
  124:     int j = 1;
  125:     int base_arg = 4;
  126:     int k = 0;
  127: 
  128:     short got_action = FALSE;
  129:     short got_object = FALSE;
  130: 
  131: 
  132:     /* snprintf (config_file, 4096, "%s/freem.conf", SYSCONFDIR); */
  133: 
  134:     base_arg = 1;
  135: 
  136:     /* enforce action in argv[1] */
  137:     if (argc > 1) {
  138:         if (argv[1][0] == '-') {
  139:             fprintf (stderr, "fmadm:  first argument, if given, must be an action, not a flag\n");
  140:             fmadm_usage ();
  141:             exit (1);
  142:         }
  143:     }
  144:     
  145:     for (i = base_arg; i < argc; i++) {
  146:         if (i == 1 && isalpha (argv[i][0])) {
  147:             got_action = TRUE;
  148:             strncpy (action, argv[i], STRLEN - 1);
  149:             base_arg++;
  150:         }
  151:         if (i == 2 && isalpha (argv[i][0])) {
  152:             got_object = TRUE;
  153:             strncpy (obj_str, argv[i], STRLEN - 1);
  154:             base_arg++;
  155:         }
  156:         if (argv[i][0] == '-') {
  157:                         
  158:             switch (argv[i][1]) {
  159:                 
  160:                 case 'e':
  161:                     if (argv[i][2] != '=') {
  162:                         fprintf (stderr, "fmadm:  missing equals sign in flag -%c\n", argv[i][1]);
  163:                         fmadm_usage ();
  164:                         exit (1);
  165:                     }
  166: 
  167:                     k = 0;
  168:                     
  169:                     for (j = 3; j < strlen (argv[i]); j++) {
  170:                         fma_environment[k++] = argv[i][j];
  171:                     }
  172:                     
  173:                     fma_explicit_environment = TRUE;
  174:                     base_arg++;
  175:                     
  176:                     break;
  177:                     
  178:                 case 'n':
  179:                     if (argv[i][2] != '=') {
  180:                         fprintf (stderr, "fmadm:  missing equals sign in flag -%c\n", argv[i][1]);
  181:                         fmadm_usage ();
  182:                         exit (1);
  183:                     }
  184: 
  185:                     k = 0;
  186:                     
  187:                     for (j = 3; j < strlen (argv[i]); j++) {
  188:                         fma_namespace[k++] = argv[i][j];
  189:                     }
  190:                     
  191:                     fma_explicit_namespace = TRUE;
  192:                     base_arg++;
  193:                     
  194:                     break;                                                
  195: 
  196:             }
  197:         }
  198:     }
  199: 
  200:     if (!fma_explicit_environment) snprintf (fma_environment, 4096, "DEFAULT");
  201:     if (!fma_explicit_namespace) snprintf (fma_namespace, 4096, "SYSTEM");
  202:     
  203:     snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, fma_environment);
  204: 
  205:     /*
  206:     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]);
  207:     exit(1);
  208:     */
  209:     
  210:     /* override for fmadm configure */
  211:     if (got_action) {
  212:         if (strcmp (argv[1], "configure") == 0) {
  213:             fm_configure ();
  214:             exit (0);
  215:         }
  216:         else if (strcmp (argv[1], "reconfigure") == 0) {
  217:             fm_reconfigure ();
  218:             exit (0);
  219:         }
  220:     }
  221: 
  222:     pid = getpid ();
  223:     
  224:     shm_init (16777216);
  225:     tp_init ();
  226:     jobtab_init ();
  227:     job_init (TRUE);
  228: 
  229:     fm_sig_init ();
  230:     
  231:     /* go to fmadm shell if no arguments passed */
  232:     if (!got_action && !got_object) return fm_shell ();    
  233:     
  234:     if (argc > 1 && strcmp (argv[1], "checkperms") == 0) {
  235: 	fm_checkperms ();
  236: 	exit (0);
  237:     }
  238: 
  239: #if 0
  240:     /* how many args do we have? */
  241:     switch (argc) {
  242:         
  243:         case 3: /* action, object */
  244:             strncpy (action, argv[1], STRLEN - 1);
  245:             strncpy (obj_str, argv[2], STRLEN - 1);
  246:             strncpy (fma_namespace, "SYSTEM", STRLEN - 1);
  247: 
  248:             optc = argc - 2;
  249:             
  250:             fma_explicit_namespace = FALSE;
  251:             fma_min_args = 1;
  252:             base_arg = 3;
  253:             
  254:             break;
  255: 
  256:         case 4: /* action, object, namespace */
  257: 
  258:             strncpy (action, argv[1], STRLEN - 1);
  259:             strncpy (obj_str, argv[2], STRLEN - 1);
  260: 
  261:             if (validate_namespace (argv[3]) == TRUE) {
  262:                 strncpy (fma_namespace, argv[3], STRLEN - 1);
  263:                 fma_min_args = 2;
  264:                 fma_explicit_namespace = TRUE;
  265:                 base_arg = 4;
  266:                 optc = argc - 3;
  267:             }
  268:             else {
  269:                 strncpy (fma_namespace, "SYSTEM", 10);
  270:                 fma_min_args = 1;
  271:                 fma_explicit_namespace = FALSE;
  272:                 base_arg = 3;
  273:                 optc = argc - 2;
  274:             }
  275: 
  276:             break;
  277: 
  278:         default:
  279:             if (argc < 4) fmadm_usage();
  280: 
  281:             /* we don't know what any but the first two args actually mean */
  282:             strncpy (action, argv[1], STRLEN - 1);
  283:             strncpy (obj_str, argv[2], STRLEN - 1);
  284: 
  285:             if (validate_namespace (argv[3]) == TRUE) {
  286:                 strncpy (fma_namespace, argv[3], STRLEN - 1);
  287:                 fma_min_args = 2;
  288:                 fma_explicit_namespace = TRUE;
  289:                 base_arg = 4;
  290:                 optc = argc - 3;
  291:             }
  292:             else {
  293:                 strncpy (fma_namespace, "SYSTEM", 10);
  294:                 fma_min_args = 1;
  295:                 fma_explicit_namespace = FALSE;
  296:                 base_arg = 3;
  297:                 optc = argc - 2;
  298:             }
  299: 
  300: 
  301:     }
  302: #endif
  303:     
  304:     set_namespace (fma_namespace, FALSE);
  305:     
  306:     /* allocate opts array */
  307:     
  308:     /* first dimension */
  309:     if ((opts = (char **) malloc (FMA_MAXARGS * sizeof (char *))) == NULL) {	
  310:         fprintf (stderr, "fmadm [FATAL]:  could not acquire memory\n");
  311:         return 1;
  312:     } 
  313: 
  314:     /* second dimension */
  315:     for (i = 0; i < FMA_MAXARGS; i++) {
  316:         if ((opts[i] = (char *) malloc (STRLEN * sizeof (char *))) == NULL) {
  317:             fprintf (stderr, "fmadm [FATAL]:  could not acquire memory\n");
  318:             return 1;
  319:         } 
  320:     }
  321: 
  322:     /* copy argv[base_arg] through argv[argc - 1] to opts[1] through opts[argc - 3] */
  323:     
  324:     strncpy (opts[0], argv[0], STRLEN - 1); /* preserve argv[0] */
  325: 
  326:     j = 1;
  327:     for (i = base_arg; i < argc; i++) {
  328:         if (i > FMA_MAXARGS) return fmadm_usage(); /* bail if we're going to overrun the array */
  329:         strncpy (opts[j++], argv[i], STRLEN - 1);
  330:     }
  331:     
  332:     if (strncmp (action, "list", STRLEN - 1) == 0) act = ACT_LIST;
  333:     else if (strncmp (action, "examine", STRLEN - 1) == 0) act = ACT_EXAMINE;
  334:     else if (strncmp (action, "verify", STRLEN - 1) == 0) act = ACT_VERIFY;
  335:     else if (strncmp (action, "compact", STRLEN - 1) == 0) act = ACT_COMPACT;
  336:     else if (strncmp (action, "repair", STRLEN - 1) == 0) act = ACT_REPAIR;
  337:     else if (strncmp (action, "create", STRLEN - 1) == 0) act = ACT_CREATE;
  338:     else if (strncmp (action, "remove", STRLEN - 1) == 0) act = ACT_REMOVE;
  339:     else if (strncmp (action, "import", STRLEN - 1) == 0) act = ACT_IMPORT;
  340:     else if (strncmp (action, "export", STRLEN - 1) == 0) act = ACT_EXPORT;
  341:     else if (strncmp (action, "backup", STRLEN - 1) == 0) act = ACT_BACKUP;
  342:     else if (strncmp (action, "restore", STRLEN - 1) == 0) act = ACT_RESTORE;
  343:     else if (strncmp (action, "migrate", STRLEN - 1) == 0) act = ACT_MIGRATE;
  344:     else if (strncmp (action, "edit", STRLEN -1) == 0) act = ACT_EDIT;
  345:     else return fmadm_usage();
  346: 
  347:     if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK;
  348:     else if (strncmp (obj_str, "zallocate", STRLEN - 1) == 0) obj = OBJ_ZALLOC;
  349:     else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL;
  350:     else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE;
  351:     else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL;
  352:     else if (strncmp (obj_str, "routine", STRLEN - 1) == 0) obj = OBJ_ROUTINE;
  353:     else if (strncmp (obj_str, "job", STRLEN - 1) == 0) obj = OBJ_JOB;
  354:     else return fmadm_usage();
  355: 
  356:     if (get_conf (fma_namespace, "routines_path", fma_routine_path) == FALSE) {
  357:         fprintf (stderr, "fmadm:  cannot determine routine path for namespace %s\n", fma_namespace);
  358:         return 1;
  359:     }   
  360: 
  361:     if (get_conf (fma_namespace, "globals_path", fma_global_path) == FALSE) {
  362:         fprintf (stderr, "fmadm:  cannot determine global path for namespace %s\n", fma_namespace);
  363:         return 1;
  364:     }   
  365: 
  366:     if (get_conf ("SYSTEM", "globals_path", fma_pct_global_path) == FALSE) {
  367:         fprintf (stderr, "fmadm:  cannot determine %% global path for namespace %s\n", "SYSTEM");
  368:         return 1;
  369:     }
  370: 
  371:     if (get_conf ("SYSTEM", "routines_path", fma_pct_routine_path) == FALSE) {
  372:         fprintf (stderr, "fmadm:  cannot determine %% routine path for namespace %s\n", "SYSTEM");
  373:         return 1;
  374:     }
  375: 
  376:     if (get_conf ("SYSTEM", "journal_file", fma_journal_path) == FALSE) {
  377:         strcpy (fma_journal_path, "");
  378:     }
  379: 
  380:     if (get_conf ("SYSTEM", "journal_cut_threshold", fma_journal_cut_threshold) == FALSE) {
  381:         strcpy (fma_journal_cut_threshold, "1073741824");
  382:     }
  383:     
  384:     strcpy (gloplib, fma_pct_global_path);
  385:     stcnv_c2m (gloplib);
  386: 
  387:     strcpy (glopath, fma_global_path);
  388:     stcnv_c2m (glopath);
  389: 
  390: 
  391:     switch (act) {
  392: 
  393:         
  394:         case ACT_LIST:
  395:             fmadm_exit (fm_list (obj, optc, opts));
  396: 
  397: 
  398:         case ACT_EXAMINE:
  399:             fmadm_exit (fm_examine (obj, optc, opts));
  400: 
  401: 
  402:         case ACT_VERIFY:
  403:             fmadm_exit (fm_verify (obj, optc, opts));
  404: 
  405: 
  406:         case ACT_COMPACT:
  407:             fmadm_exit (fm_compact (obj, optc, opts));
  408: 
  409: 
  410:         case ACT_REPAIR:
  411:             fmadm_exit (fm_repair (obj, optc, opts));
  412: 
  413: 
  414:         case ACT_CREATE:
  415:             fmadm_exit (fm_create (obj, optc, opts));
  416: 
  417: 
  418:         case ACT_REMOVE:
  419:             fmadm_exit (fm_remove (obj, optc, opts));
  420: 
  421: 
  422:         case ACT_IMPORT:
  423:             fmadm_exit (fm_import (obj, optc, opts));
  424: 
  425: 
  426:         case ACT_EXPORT:
  427:             fmadm_exit (fm_export (obj, optc, opts));
  428: 
  429: 
  430:         case ACT_BACKUP:
  431:             fmadm_exit (fm_backup (obj, optc, opts));
  432: 
  433: 
  434:         case ACT_RESTORE:
  435:             fmadm_exit (fm_restore (obj, optc, opts));
  436: 
  437: 
  438:         case ACT_MIGRATE:
  439:             fmadm_exit (fm_migrate (obj, optc, opts));
  440: 
  441: 
  442:         case ACT_EDIT:
  443:             fmadm_exit (fm_edit (obj, optc, opts));
  444: 
  445: 
  446:         default:
  447:             return fmadm_usage();
  448:     }
  449: 
  450:     return 0;   /* should never be reached */
  451: 
  452: } /* main() */
  453: 
  454: int fm_shell (void)
  455: {
  456:     
  457: #if defined(HAVE_LIBREADLINE) && !defined(_AIX)
  458:     int cmd;
  459:     int i;
  460:     int j;
  461:     int obj;
  462:     int optc;
  463:     int argc;
  464:     char **args;
  465:     char **opts;    
  466:     char *fmarl_buf;
  467:     char *fma_prompt = (char *) malloc (STRLEN * sizeof (char));
  468:     char *cmdt = (char *) malloc (65535 * sizeof (char));
  469:     char *result = (char *) malloc (65535 * sizeof (char));
  470: 
  471:     /*
  472:     strcpy (fma_namespace, "SYSTEM");
  473:     set_namespace (fma_namespace, FALSE);
  474:     */
  475:     
  476:     snprintf (fma_prompt, STRLEN - 1, "fmadm [%s]> ", fma_namespace);
  477:     
  478:     if (get_conf (fma_namespace, "routines_path", fma_routine_path) == FALSE) {
  479:         fprintf (stderr, "fmadm:  cannot determine routine path for namespace %s\n", fma_namespace);
  480:         return 1;
  481:     }   
  482: 
  483:     if (get_conf (fma_namespace, "globals_path", fma_global_path) == FALSE) {
  484:         fprintf (stderr, "fmadm:  cannot determine global path for namespace %s\n", fma_namespace);
  485:         return 1;
  486:     }   
  487: 
  488:     if (get_conf ("SYSTEM", "globals_path", fma_pct_global_path) == FALSE) {
  489:         fprintf (stderr, "fmadm:  cannot determine %% global path for namespace %s\n", "SYSTEM");
  490:         return 1;
  491:     }
  492: 
  493:     if (get_conf ("SYSTEM", "routines_path", fma_pct_routine_path) == FALSE) {
  494:         fprintf (stderr, "fmadm:  cannot determine %% routine path for namespace %s\n", "SYSTEM");
  495:         return 1;
  496:     }
  497: 
  498:     if (get_conf ("SYSTEM", "journal_file", fma_journal_path) == FALSE) {
  499:         strcpy (fma_journal_path, "");
  500:     }
  501: 
  502:     if (get_conf ("SYSTEM", "journal_cut_threshold", fma_journal_cut_threshold) == FALSE) {
  503:         strcpy (fma_journal_cut_threshold, "1073741824");
  504:     }
  505:     
  506:     strcpy (gloplib, fma_pct_global_path);
  507:     stcnv_c2m (gloplib);
  508: 
  509:     strcpy (glopath, fma_global_path);
  510:     stcnv_c2m (glopath);
  511:     
  512:     /* allocate args array */
  513:     
  514:     /* first dimension */
  515:     if ((args = (char **) malloc (FMA_MAXARGS * sizeof (char *))) == NULL) {	
  516:         fprintf (stderr, "fmadm [FATAL]:  could not acquire memory\n");
  517:         return 1;
  518:     } 
  519: 
  520:     /* second dimension */
  521:     for (i = 0; i < FMA_MAXARGS; i++) {
  522:         if ((args[i] = (char *) malloc (STRLEN * sizeof (char *))) == NULL) {
  523:             fprintf (stderr, "fmadm [FATAL]:  could not acquire memory\n");
  524:             return 1;
  525:         } 
  526:     }
  527: 
  528:     /* allocate opts array */
  529:     
  530:     /* first dimension */
  531:     if ((opts = (char **) malloc (FMA_MAXARGS * sizeof (char *))) == NULL) {	
  532:         fprintf (stderr, "fmadm [FATAL]:  could not acquire memory\n");
  533:         return 1;
  534:     } 
  535: 
  536:     /* second dimension */
  537:     for (i = 0; i < FMA_MAXARGS; i++) {
  538:         if ((opts[i] = (char *) malloc (STRLEN * sizeof (char *))) == NULL) {
  539:             fprintf (stderr, "fmadm [FATAL]:  could not acquire memory\n");
  540:             return 1;
  541:         } 
  542:     }
  543: 
  544:     
  545:     for (;;) {
  546: 
  547:         fmarl_buf = readline (fma_prompt);
  548: 
  549:         if (fmarl_buf == (char *) NULL) continue;
  550:         
  551:         cmdt = strtok (fmarl_buf, " ");
  552: 
  553:         if (cmdt == (char *) NULL) continue;
  554:         
  555:         for (i = 0; i < strlen (cmdt); i++) cmdt[i] = cmdt[i] | 0140;        
  556:         
  557:         if (strcmp (cmdt, "exit") == 0) cmd = FMAC_EXIT;
  558:         else if (strcmp (cmdt, "quit") == 0) cmd = FMAC_EXIT;
  559:         else if (strcmp (cmdt, "select") == 0) cmd = FMAC_SELECT;
  560:         else if (strcmp (cmdt, "list") == 0) cmd = FMAC_LIST;
  561:         else if (strcmp (cmdt, "examine") == 0) cmd = FMAC_EXAMINE;
  562:         else if (strcmp (cmdt, "verify") == 0) cmd = FMAC_VERIFY;
  563:         else if (strcmp (cmdt, "compact") == 0) cmd = FMAC_COMPACT;
  564:         else if (strcmp (cmdt, "repair") == 0) cmd = FMAC_REPAIR;
  565:         else if (strcmp (cmdt, "create") == 0) cmd = FMAC_CREATE;
  566:         else if (strcmp (cmdt, "import") == 0) cmd = FMAC_IMPORT;
  567:         else if (strcmp (cmdt, "export") == 0) cmd = FMAC_EXPORT;
  568:         else if (strcmp (cmdt, "backup") == 0) cmd = FMAC_BACKUP;
  569:         else if (strcmp (cmdt, "restore") == 0) cmd = FMAC_RESTORE;
  570:         else if (strcmp (cmdt, "migrate") == 0) cmd = FMAC_MIGRATE;
  571:         else if (strcmp (cmdt, "edit") == 0) cmd = FMAC_EDIT;
  572:         else if (strcmp (cmdt, "set") == 0) cmd = FMAC_SET;
  573:         else if (strcmp (cmdt, "show") == 0) cmd = FMAC_SHOW;
  574:         else if (strcmp (cmdt, "remove") == 0) cmd = FMAC_REMOVE;
  575:         else cmd = FMAC_INVALID;            
  576: 
  577:         i = 0;
  578:         while ((result = strtok (NULL, " ")) != NULL) {
  579:             //    printf ("%d = %s\n", i, result);
  580:             strcpy (args[i++], result);
  581:         }
  582: 
  583:         argc = i;
  584:         j = 0;
  585:         
  586:         for (i = 1; i < argc; i++) {
  587:             strncpy (opts[j++], args[i], STRLEN - 1);
  588:         }
  589: 
  590:         optc = argc - 1;
  591:         
  592:         if (i > 0) {
  593:             
  594:             strcpy (obj_str, args[0]);
  595:         
  596:             if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK;
  597:             else if (strncmp (obj_str, "zallocate", STRLEN - 1) == 0) obj = OBJ_ZALLOC;
  598:             else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL;
  599:             else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE;
  600:             else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL;
  601:             else if (strncmp (obj_str, "routine", STRLEN - 1) == 0) obj = OBJ_ROUTINE;
  602:             else if (strncmp (obj_str, "job", STRLEN - 1) == 0) obj = OBJ_JOB;
  603: 
  604:         }
  605:         
  606:         switch (cmd) {
  607: 
  608:             
  609:             case FMAC_SELECT:
  610:                 
  611:                 
  612:                 break;
  613: 
  614:                 
  615:             case FMAC_LIST:
  616:                 fm_list (obj, optc, opts);
  617:                 break;
  618: 
  619:                 
  620:             case FMAC_EXAMINE:
  621:                 fm_examine (obj, optc, opts);
  622:                 break;
  623: 
  624: 
  625:             case FMAC_VERIFY:
  626:                 fm_verify (obj, optc, opts);
  627:                 break;
  628: 
  629: 
  630:             case FMAC_COMPACT:
  631:                 fm_compact (obj, optc, opts);
  632:                 break;
  633: 
  634: 
  635:             case FMAC_REPAIR:
  636:                 fm_repair (obj, optc, opts);
  637:                 break;
  638: 
  639: 
  640:             case FMAC_CREATE:
  641:                 fm_create (obj, optc, opts);
  642:                 break;
  643: 
  644: 
  645:             case FMAC_REMOVE:
  646:                 fm_remove (obj, optc, opts);
  647:                 break;
  648: 
  649: 
  650:             case FMAC_IMPORT:
  651:                 fm_import (obj, optc, opts);
  652:                 break;
  653: 
  654: 
  655:             case FMAC_EXPORT:
  656:                 fm_export (obj, optc, opts);
  657:                 break;
  658: 
  659: 
  660:             case FMAC_BACKUP:
  661:                 fm_backup (obj, optc, opts);
  662:                 break;
  663: 
  664: 
  665:             case FMAC_RESTORE:
  666:                 fm_restore (obj, optc, opts);
  667:                 break;
  668: 
  669: 
  670:             case FMAC_MIGRATE:
  671:                 fm_migrate (obj, optc, opts);
  672:                 break;
  673: 
  674: 
  675:             case FMAC_EDIT:
  676:                 fm_edit (obj, optc, opts);
  677:                 break;
  678: 
  679: 
  680:             case FMAC_SET:
  681: 
  682:                 if (i < 2) {
  683:                     printf ("fmadm:  syntax error\n");
  684:                     break;
  685:                 }
  686:                 
  687:                 if (strcmp (args[0], "namespace") == 0) {
  688:                     strcpy (fma_namespace, args[1]);
  689: 
  690:                     if (get_conf (fma_namespace, "routines_path", fma_routine_path) == FALSE) {
  691:                         fprintf (stderr, "fmadm:  cannot determine routine path for namespace %s\n", fma_namespace);
  692:                         return 1;
  693:                     }   
  694:                     
  695:                     if (get_conf (fma_namespace, "globals_path", fma_global_path) == FALSE) {
  696:                         fprintf (stderr, "fmadm:  cannot determine global path for namespace %s\n", fma_namespace);
  697:                         return 1;
  698:                     }   
  699:                     
  700:                     if (get_conf ("SYSTEM", "globals_path", fma_pct_global_path) == FALSE) {
  701:                         fprintf (stderr, "fmadm:  cannot determine %% global path for namespace %s\n", "SYSTEM");
  702:                         return 1;
  703:                     }
  704:                     
  705:                     if (get_conf ("SYSTEM", "routines_path", fma_pct_routine_path) == FALSE) {
  706:                         fprintf (stderr, "fmadm:  cannot determine %% routine path for namespace %s\n", "SYSTEM");
  707:                         return 1;
  708:                     }
  709:                     
  710:                     if (get_conf ("SYSTEM", "journal_file", fma_journal_path) == FALSE) {
  711:                         strcpy (fma_journal_path, "");
  712:                     }
  713:                     
  714:                     if (get_conf ("SYSTEM", "journal_cut_threshold", fma_journal_cut_threshold) == FALSE) {
  715:                         strcpy (fma_journal_cut_threshold, "1073741824");
  716:                     }
  717:                     
  718:                     strcpy (gloplib, fma_pct_global_path);
  719:                     stcnv_c2m (gloplib);
  720:                     
  721:                     strcpy (glopath, fma_global_path);
  722:                     stcnv_c2m (glopath);
  723: 
  724:                     snprintf (fma_prompt, STRLEN - 1, "fmadm [%s]> ", fma_namespace);
  725:                     
  726:                 }
  727:                 else if (strcmp (args[0], "maintenance") == 0) {
  728:                     if (strcmp (args[1], "on") == 0) {
  729:                         shm_config->hdr->maintenance_mode = 1;
  730:                         break;
  731:                     }
  732:                     else if (strcmp (args[1], "off") == 0) {
  733:                         shm_config->hdr->maintenance_mode = 0;
  734:                         break;
  735:                     }
  736:                     else {
  737:                         printf ("fmadm:  syntax error\n");
  738:                     }
  739: 
  740:                     printf ("fmadm:  syntax error\n");
  741:                         
  742:                 }
  743:                 else {
  744:                     printf ("fmadm:  syntax error\n");
  745:                     break;
  746:                 }
  747:                 
  748:                 break;
  749: 
  750:                 
  751:             case FMAC_SHOW:
  752:                 printf ("Namespace:                  %s\n", fma_namespace);
  753:                 printf ("Routine Path:               %s\n", fma_routine_path);
  754:                 printf ("%%-Routine Path:             %s\n", fma_pct_routine_path);
  755:                 printf ("Global Path:                %s\n", fma_global_path);
  756:                 printf ("%%-Global Path:              %s\n", fma_pct_global_path);
  757:                 printf ("Journal File:               %s\n", fma_journal_path);
  758:                 printf ("Journal Cut Threshold:      %s bytes\n", fma_journal_cut_threshold);
  759:                 break;
  760: 
  761:             case FMAC_EXIT:
  762:                 fmadm_exit (0);
  763:                 break;
  764: 
  765: 
  766:             default:
  767:                 printf ("fmadm:  '%s' is not a valid fmadm command\n", cmdt);
  768:                 break;
  769: 
  770:         }
  771:     }
  772: 
  773: #endif
  774:     
  775: }
  776: 
  777: void fmadm_exit (int retval)
  778: {
  779:     locktab_unlock_all ();
  780:     job_remove (pid);
  781:     
  782:     shm_exit ();
  783: 
  784:     exit (retval);
  785: }
  786: 
  787: int fmadm_usage (void)
  788: {
  789: 
  790:     fprintf (stdout, "\nusage:  fmadm <action> <object> [-e=<environment] [-n=<namespace>] [OPTIONS]\n");
  791:     fprintf (stdout, "        fmadm configure\n");
  792:     fprintf (stdout, "        fmadm reconfigure\n");
  793:     /* fprintf (stdout, "        fmadm checkperms\n\n"); */
  794:     
  795:     fprintf (stdout, "        <action> can be one of:\n");
  796:     fprintf (stdout, "            list, examine, verify, compact, repair, create, remove,\n");
  797:     fprintf (stdout, "            import, export, backup, restore, migrate, edit\n\n");
  798: 
  799:     fprintf (stdout, "        <object> can be one of:\n");
  800:     fprintf (stdout, "            lock, zallocate, journal, namespace, global, routine, job\n\n");
  801: 
  802:     fprintf (stdout, "    Not all actions are valid for all objects. Please see the FreeM manual\n");
  803:     fprintf (stdout, "    for details on fmadm usage and options.\n\n");
  804:     
  805:     return 1;
  806: 
  807: } /* fmadm_usage() */
  808: 
  809: int fm_list (short object, int optc, char **options)
  810: {
  811: 
  812:     switch (object) {
  813: 
  814:         case OBJ_LOCK:
  815:             return fma_locks_list (optc, options);
  816: 
  817:         case OBJ_ROUTINE:
  818:             return fma_routines_list (optc, options);
  819: 
  820:         case OBJ_GLOBAL:
  821:             return fma_globals_list (optc, options);
  822: 
  823:         case OBJ_JOB:
  824:             return fma_jobs_list (optc, options);
  825: 
  826:         default:
  827:             fprintf (stderr, "fmadm:  'list' is an invalid action for '%s'\n", obj_str);
  828:             return 1;
  829: 
  830:     }
  831: 
  832: 
  833: } /* fm_list() */
  834: 
  835: int fm_examine (short object, int optc, char **options)
  836: {
  837: 
  838:     switch (object) {
  839: 
  840:         case OBJ_ROUTINE:
  841:             return fma_routines_examine (optc, options);
  842: 
  843:         case OBJ_GLOBAL:
  844:             return fma_globals_examine (optc, options);
  845: 
  846:         case OBJ_JOB:
  847:             return fma_jobs_examine (optc, options);
  848: 
  849:         case OBJ_JOURNAL:
  850:             return fma_journals_examine (optc, options);
  851:             
  852:         default:
  853:             fprintf (stderr, "fmadm:  'examine' is an invalid action for '%s'\n", obj_str);
  854:             return 1;
  855: 
  856:     }
  857: 
  858: } /* fm_examine() */
  859: 
  860: int fm_verify (short object, int optc, char **options)
  861: {
  862: 
  863:     switch (object) {
  864: 
  865:         case OBJ_GLOBAL:
  866:             return fma_globals_verify (optc, options);
  867:         
  868:         default:
  869:             fprintf (stderr, "fmadm:  'examine' is an invalid action for '%s'\n", obj_str);
  870:             return 1;
  871: 
  872:     }
  873: 
  874: } /* fm_verify() */ 
  875: 
  876: int fm_compact (short object, int optc, char **options)
  877: {
  878: 
  879:     switch (object) {
  880: 
  881:         default:
  882:             fprintf (stderr, "fmadm:  'compact' is an invalid action for '%s'\n", obj_str);
  883:             return 1;
  884: 
  885:     }
  886: 
  887: } /* fm_compact() */
  888: 
  889: int fm_repair (short object, int optc, char **options)
  890: {
  891: 
  892:     switch (object) {
  893: 
  894:         default:
  895:             fprintf (stderr, "fmadm:  'repair' is an invalid action for '%s'\n", obj_str);
  896:             return 1;
  897: 
  898:     }
  899: 
  900: } /* fm_repair() */
  901: 
  902: int fm_create (short object, int optc, char **options)
  903: {
  904: 
  905:     switch (object) {
  906: 
  907:         default:
  908:             fprintf (stderr, "fmadm:  'create' is an invalid action for '%s'\n", obj_str);
  909:             return 1;
  910: 
  911:     }
  912: } /* fm_create() */
  913: 
  914: int fm_remove (short object, int optc, char **options)
  915: {
  916: 
  917:     switch (object) {
  918: 
  919:         case OBJ_JOB:
  920:             return fma_jobs_remove (optc, options);
  921:         
  922:         case OBJ_LOCK:
  923:             return fma_locks_remove (optc, options);
  924: 
  925:         case OBJ_ROUTINE:
  926:             return fma_routines_remove (optc, options);
  927: 
  928:         case OBJ_GLOBAL:
  929:             return fma_globals_remove (optc, options);
  930: 
  931:         default:
  932:             fprintf (stderr, "fmadm:  'remove' is an invalid action for '%s'\n", obj_str);
  933:             return 1;
  934: 
  935:     }
  936: 
  937: } /* fm_remove() */
  938: 
  939: int fm_import (short object, int optc, char **options)
  940: {
  941: 
  942:     switch (object) {
  943: 
  944:         case OBJ_ROUTINE: 
  945:             return fma_routines_import (optc, options);
  946: 
  947:         default:
  948:             fprintf (stderr, "fmadm:  'import' is an invalid action for '%s'\n", obj_str);
  949:             return 1;
  950: 
  951:     }
  952: 
  953: } /* fm_import() */
  954: 
  955: int fm_export (short object, int optc, char **options)
  956: {
  957: 
  958:     switch (object) {
  959: 
  960:         case OBJ_ROUTINE: 
  961:             return fma_routines_export (optc, options);
  962: 
  963:         default:
  964:             fprintf (stderr, "fmadm:  'export' is an invalid action for '%s'\n", obj_str);
  965:             return 1;
  966: 
  967:     }
  968: 
  969: } /* fm_export() */
  970: 
  971: int fm_backup (short object, int optc, char **options)
  972: {
  973: 
  974:     switch (object) {
  975: 
  976:         case OBJ_ROUTINE: 
  977:             return fma_routines_backup (optc, options);
  978: 
  979:         default:
  980:             fprintf (stderr, "fmadm:  'backup' is an invalid action for '%s'\n", obj_str);
  981:             return 1;
  982: 
  983:     }
  984: 
  985: } /* fm_backup() */
  986: 
  987: int fm_restore (short object, int optc, char **options)
  988: {
  989: 
  990:     switch (object) {
  991: 
  992:         case OBJ_JOURNAL:
  993:             return fma_journals_restore (optc, options);
  994:         
  995:         default:
  996:             fprintf (stderr, "fmadm:  'restore' is an invalid action for '%s'\n", obj_str);
  997:             return 1;
  998: 
  999:     }
 1000: 
 1001: } /* fm_restore() */
 1002: 
 1003: int fm_migrate (short object, int optc, char **options)
 1004: {
 1005: 
 1006:     switch (object) {
 1007: 
 1008:         default:
 1009:             fprintf (stderr, "fmadm:  'migrate' is an invalid action for '%s'\n", obj_str);
 1010:             return 1;
 1011: 
 1012:     }
 1013: 
 1014: } /* fm_migrate() */
 1015: 
 1016: int fm_edit (short object, int optc, char **options)
 1017: {
 1018: 
 1019:     switch (object) {
 1020: 
 1021:         case OBJ_ROUTINE:
 1022:             return fma_routines_edit (optc, options);
 1023: 
 1024:         /*
 1025:         case OBJ_GLOBAL:
 1026:             return fma_globals_edit (optc, options);
 1027:         */
 1028:             
 1029:         default:
 1030:             fprintf (stderr, "fmadm:  'edit' is an invalid action for '%s'\n", obj_str);
 1031:             return 1;
 1032: 
 1033:     }
 1034: 
 1035: } /* fm_edit() */
 1036: 
 1037: void fm_checkperms(void)
 1038: {
 1039: 
 1040: } /* fm_checkperms() */
 1041: 
 1042: 
 1043: void fm_reconfigure(void)
 1044: {
 1045:     char config_backup[4096];
 1046:     char vers[4096];
 1047:     
 1048:     int retval;   
 1049:     
 1050:     if (geteuid () != 0) {
 1051:         fprintf (stderr, "fmadm:  not superuser\n");
 1052:         exit (1);
 1053:     }
 1054:     
 1055:     snprintf (config_backup, 4095, "%s.orig", config_file);
 1056: 
 1057:     fprintf (stderr, "fmadm:  reconfiguring FreeM with system defaults for %s...\n", FREEM_VERSION_CSTR);
 1058:     fprintf (stderr, "fmadm:  backing up %s to %s...\t", config_file, config_backup);    
 1059: 
 1060:     retval = rename (config_file, config_backup);
 1061: 
 1062:     if (retval == 0) {
 1063: 	fprintf (stderr, "[OK]\n\n");
 1064: 	
 1065: 	fm_configure ();
 1066: 
 1067: 	fprintf (stderr, "\n\nYou may wish to edit %s if site-specific changes were made to the original FreeM configuration.\n", config_file);
 1068: 	exit (0);
 1069:     }
 1070:     else {
 1071: 	fprintf (stderr, "[FAIL (%s)]\n", strerror (errno));
 1072: 	exit (1);
 1073:     }
 1074:     
 1075: } /* fm_reconfigure() */
 1076: 
 1077: 
 1078: void fm_configure (void)
 1079: {
 1080: 
 1081:     char sysrtn[4096];
 1082:     char sysgbl[4096];
 1083:     char usrrtn[4096];
 1084:     char usrgbl[4096];
 1085: 
 1086:     char locktab[4096];
 1087:     char zalloctab[4096];
 1088:     char jnlfile[4096];
 1089:     char jnlmode[4];
 1090:     char jnlhostid[4096];    
 1091:     char jnlcut[4096];
 1092:     char hostid[4096];
 1093: 
 1094:     char confbase[4096];
 1095:     char envbase[4096];
 1096: 
 1097:     char nsbase[4096];
 1098:     
 1099:     char buf[4096];
 1100:     FILE *fp;
 1101: 
 1102:     struct stat etcstat;
 1103:     int stat_result;
 1104:     
 1105:     snprintf (sysrtn, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);
 1106:     snprintf (sysgbl, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment);
 1107:     snprintf (usrrtn, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment);
 1108:     snprintf (usrgbl, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment);
 1109:     snprintf (locktab, 4095, "/tmp/locktab");
 1110:     snprintf (zalloctab, 4095, "/tmp/zalloctab");
 1111:     snprintf (jnlfile, 4095, "/tmp/freem_journal_%s.dat", fma_environment);
 1112:     snprintf (jnlmode, 3, "on");
 1113:     snprintf (jnlhostid, 4095, "DEFAULT");
 1114:     snprintf (jnlcut, 4095, "4294967000");
 1115:     
 1116:     if (geteuid () != 0) {
 1117:         fprintf (stderr, "fmadm:  not superuser\n");
 1118:         exit (1);
 1119:     }
 1120:     
 1121:     if (file_exists (config_file)) {
 1122:         fprintf (stderr, "fmadm:  '%s' already exists.\n\n", config_file);
 1123:         fprintf (stderr, "'fmadm configure' may only be used on a fresh installation of FreeM.\n");
 1124:         exit (1);
 1125:     }
 1126: 
 1127: 
 1128:     gethostname (hostid, 4095);
 1129:     uuid_v4 (buf);
 1130: 
 1131:     snprintf (jnlhostid, 4095, "%s:%s", hostid, buf);
 1132: 
 1133:     snprintf (confbase, 4095, "%s/freem", SYSCONFDIR);
 1134:     snprintf (envbase, 4095, "%s/freem/%s", SYSCONFDIR, fma_environment); 
 1135:     snprintf (nsbase, 4095, "%s/freem/%s", LOCALSTATEDIR, fma_environment);
 1136: 
 1137:     printf ("\nFreeM Initial Configuration\n");
 1138:     printf ("---------------------------\n\n");
 1139: 
 1140:     printf ("This utility will create the initial configuration file for ");
 1141:     printf ("FreeM environment '%s' in %s.\n\n", fma_environment, config_file);    
 1142: 
 1143:     
 1144:     /* check for existence of needed directories */
 1145:     if (stat (SYSCONFDIR, &etcstat) == -1) {
 1146: 	fprintf (stderr, "fmadm:  creating %s\n", SYSCONFDIR);
 1147: 	mkdir (SYSCONFDIR, 0755);
 1148:     }
 1149: 
 1150:     if (stat (confbase, &etcstat) == -1) {
 1151:         fprintf (stderr, "fmadm:  creating %s\n", confbase);
 1152:         mkdir (confbase, 0755);
 1153:     }
 1154: 
 1155:     if (stat (envbase, &etcstat) == -1) {
 1156:         fprintf (stderr, "fmadm:  creating %s\n", envbase);
 1157:         mkdir (envbase, 0755);
 1158:     }
 1159: 
 1160:     if (stat (nsbase, &etcstat) == -1) {
 1161:         fprintf (stderr, "fmadm:  creating %s\n", nsbase);
 1162:         mkdir (nsbase, 0755);
 1163:     }
 1164: 
 1165:    
 1166: 
 1167:     if (strcmp (fma_environment, "DEFAULT") != 0) {
 1168: 
 1169:         DIR *dir;
 1170:         struct dirent *ent;
 1171:         char src_dir[4096];
 1172:         char dest_dir[4096];
 1173: 
 1174:         snprintf (src_dir, 4095, "%s/freem/DEFAULT/SYSTEM/routines", LOCALSTATEDIR);
 1175:         snprintf (dest_dir, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);
 1176:         
 1177:         fprintf (stderr, "fmadm:  populating new environment '%s'\n", fma_environment);
 1178:         
 1179:         snprintf (buf, 4095, "%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);
 1180:         mkdir (buf, 0755);
 1181: 
 1182:         snprintf (buf, 4095, "%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);
 1183:         mkdir (buf, 0755);
 1184: 
 1185:         snprintf (buf, 4095, "%s/freem/%s/SYSTEM/routines", LOCALSTATEDIR, fma_environment);
 1186:         mkdir (buf, 0755);
 1187: 
 1188:         snprintf (buf, 4095, "%s/freem/%s/USER/globals", LOCALSTATEDIR, fma_environment);
 1189:         mkdir (buf, 0755);
 1190: 
 1191:         snprintf (buf, 4095, "%s/freem/%s/SYSTEM/globals", LOCALSTATEDIR, fma_environment);
 1192:         mkdir (buf, 0755);
 1193: 
 1194:         snprintf (buf, 4095, "%s/freem/%s/USER/routines", LOCALSTATEDIR, fma_environment);
 1195:         mkdir (buf, 0755);
 1196: 
 1197:         fprintf (stderr, "fmadm:  copying routines from '%s' to '%s'...\n", src_dir, dest_dir);
 1198: 
 1199:         if ((dir = opendir (src_dir)) == NULL) {
 1200:             fprintf (stderr, "\nfmadm:  could not open source directory %s\n", src_dir);
 1201:             exit (1);
 1202:         }
 1203: 
 1204:         while ((ent = readdir (dir)) != NULL) {
 1205:             char infile[4096];
 1206:             char outfile[4096];
 1207:            
 1208:             if ((strcmp (ent->d_name, ".") != 0) && (strcmp (ent->d_name, "..") != 0)) {
 1209: 
 1210:                 fprintf (stderr, "\t%s\n", ent->d_name);
 1211:                 
 1212:                 snprintf (infile, 4095, "%s/%s", src_dir, ent->d_name);
 1213:                 snprintf (outfile, 4095, "%s/%s", dest_dir, ent->d_name);
 1214: 
 1215:                 if (cp (outfile, infile) != 0) {
 1216:                     fprintf (stderr, "fmadm:  failure copying %s to %s\n", infile, outfile);
 1217:                 }
 1218: 
 1219:             }
 1220:             
 1221:         }
 1222:             
 1223:         
 1224:     }
 1225:     
 1226:    
 1227:     fp = fopen (config_file, "a+");
 1228:     
 1229: 
 1230:     printf ("Creating %s... ", config_file); 
 1231:     
 1232:     snprintf (buf, 4095, "[SYSTEM]");
 1233:     fm_write (fp, buf);
 1234: 
 1235:     snprintf (buf, 4095, "root=%s/freem/%s/SYSTEM", LOCALSTATEDIR, fma_environment);
 1236:     fm_write (fp, buf);
 1237: 
 1238:     snprintf (buf, 4095, "routines_path=%s", sysrtn);
 1239:     fm_write (fp, buf);
 1240: 
 1241:     snprintf (buf, 4095, "globals_path=%s", sysgbl);
 1242:     fm_write (fp, buf);
 1243: 
 1244:     snprintf (buf, 4095, "journal_file=%s", jnlfile);
 1245:     fm_write (fp, buf);
 1246: 
 1247:     snprintf (buf, 4095, "journal_mode=%s", jnlmode);
 1248:     fm_write (fp, buf);
 1249: 
 1250:     snprintf (buf, 4095, "journal_host_id=%s", jnlhostid);
 1251:     fm_write (fp, buf);
 1252: 
 1253:     snprintf (buf, 4095, "journal_cut_threshold=%s", jnlcut);
 1254:     fm_write (fp, buf);
 1255: 
 1256:     snprintf (buf, 4095, "zdate_format=%%x");
 1257:     fm_write (fp, buf);
 1258: 
 1259:     snprintf (buf, 4095, "ztime_format=%%X");
 1260:     fm_write (fp, buf);
 1261:     
 1262:     snprintf (buf, 4095, "\n[USER]");
 1263:     fm_write (fp, buf);
 1264: 
 1265:     snprintf (buf, 4095, "root=%s/freem/%s/USER", LOCALSTATEDIR, fma_environment);
 1266:     fm_write (fp, buf);
 1267: 
 1268:     snprintf (buf, 4095, "routines_path=%s", usrrtn);
 1269:     fm_write (fp, buf);
 1270: 
 1271:     snprintf (buf, 4095, "globals_path=%s", usrgbl);
 1272:     fm_write (fp, buf);
 1273:     
 1274:     
 1275:     fclose (fp);
 1276: 
 1277:     printf ("[OK]\n\n");
 1278: 
 1279: /*
 1280:     printf ("Setting USER namespace permissions... ");
 1281: 
 1282:     snprintf (buf, 4095, "%s/freem/USER/globals", LOCALSTATEDIR);
 1283:     chmod (buf, 0777);
 1284: 
 1285:     snprintf (buf, 4095, "%s/freem/USER/routines", LOCALSTATEDIR);
 1286:     chmod (buf, 0777);
 1287: 
 1288:     printf ("[OK]\n");
 1289:     printf ("Setting SYSTEM namespace permissions... ");
 1290:     
 1291:     snprintf (buf, 4095, "%s/freem/SYSTEM/globals", LOCALSTATEDIR);
 1292:     chmod (buf, 0755);
 1293: 
 1294:     snprintf (buf, 4095, "%s/freem/SYSTEM/routines", LOCALSTATEDIR);
 1295:     chmod (buf, 0755);
 1296: 
 1297:     printf ("[OK]\n\n\n");
 1298: */
 1299:     printf ("FreeM initial configuration is complete.\n\n");
 1300: 
 1301:     printf (" USER globals:                   %s\n", usrgbl);
 1302:     printf (" USER routines:                  %s\n", usrrtn);
 1303:     printf (" SYSTEM globals:                 %s\n", sysgbl);
 1304:     printf (" SYSTEM routines:                %s\n", sysrtn);
 1305:     printf (" After-image journal:            %s [%s]\n", jnlfile, jnlmode);
 1306:     printf (" Journal cut threshold:          %s bytes\n", jnlcut);
 1307:     printf (" Distributed journaling host ID: %s\n", jnlhostid);
 1308: 
 1309:     
 1310: } /* fm_configure */
 1311: 
 1312: void fm_write (FILE *file, char *buf)
 1313: {
 1314:     fprintf (file, "%s\n", buf);
 1315: }
 1316: 
 1317: void fm_sig_attach (int sig, void *handler)
 1318: {
 1319:     struct sigaction act;
 1320: 
 1321:     act.sa_handler = handler;
 1322:     sigaction (sig, &act, NULL);
 1323:     
 1324: }
 1325: 
 1326: void fm_sig_init (void)
 1327: {
 1328:     sig_attach (SIGINT, &fm_on_sigint);
 1329:     sig_attach (SIGTERM, &fm_on_sigterm);
 1330: }
 1331: 
 1332: void fm_on_sigint (void)
 1333: {
 1334:     fprintf (stderr, "\nfmadm:  caught SIGINT\n");
 1335:     fmadm_exit (0);
 1336: }
 1337: 
 1338: void fm_on_sigterm (void)
 1339: {
 1340:     fprintf (stderr, "\nfmadm:  caught SIGTERM\n");
 1341:     fmadm_exit (0);
 1342: }

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