File:  [Coherent Logic Development] / freem / src / init.c
Revision 1.7: download - view: text, annotated - select for diffs
Mon Mar 24 04:05:36 2025 UTC (6 months ago) by snw
Branches: MAIN
CVS tags: HEAD
Replace crlf with frm_crlf to avoid symbol conflict with readline on OS/2

    1: /*
    2:  *   $Id: init.c,v 1.7 2025/03/24 04:05:36 snw Exp $
    3:  *    FreeM initialization 
    4:  *
    5:  *  
    6:  *   Author: Serena Willis <snw@coherent-logic.com>
    7:  *    Copyright (C) 1998 MUG Deutschland
    8:  *    Copyright (C) 2020, 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: init.c,v $
   27:  *   Revision 1.7  2025/03/24 04:05:36  snw
   28:  *   Replace crlf with frm_crlf to avoid symbol conflict with readline on OS/2
   29:  *
   30:  *   Revision 1.6  2025/03/09 19:14:25  snw
   31:  *   First phase of REUSE compliance and header reformat
   32:  *
   33:  *
   34:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
   35:  * SPDX-License-Identifier: AGPL-3.0-or-later
   36:  **/
   37: 
   38: #include <stdio.h>
   39: #include <stdlib.h>
   40: #include <string.h>
   41: #include <unistd.h>
   42: #include <limits.h>
   43: #include <sys/types.h>
   44: #include <sys/stat.h>
   45: #include <pwd.h>
   46: #include <time.h>
   47: #include <errno.h>
   48: #include <sys/ioctl.h>
   49: 
   50: #if !defined(__APPLE__) && !defined(__gnu_hurd__) && !defined(EMSCRIPTEN)
   51: # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__AMIGA)
   52: #  include <termios.h>
   53: #  if !defined(__AMIGA)
   54: #   define TCGETA TIOCGETA
   55: #   define TCSETA TIOCSETA
   56: #  endif
   57: #  define termio termios
   58: # else
   59: #  if !defined(MSDOS)
   60: #    include <termio.h>
   61: #  endif
   62: # endif
   63: #else
   64: # include <termios.h>
   65: #endif
   66: 
   67: #include "config.h"
   68: 
   69: #if defined(HAVE_MWAPI_MOTIF)
   70: # include <Xm/Xm.h>
   71: #endif
   72: 
   73: #include "mpsdef.h"
   74: #include "transact.h"
   75: #include "namespace.h"
   76: #include "events.h"
   77: #include "mdebug.h"
   78: #include "shmmgr.h"
   79: #include "locktab.h"
   80: #include "jobtab.h"
   81: #include "datatypes.h"
   82: #include "objects.h"
   83: 
   84: #ifdef HAVE_LIBREADLINE
   85: #  if defined(HAVE_READLINE_READLINE_H)
   86: #    include <readline/readline.h>
   87: #  elif defined(HAVE_READLINE_H)
   88: #    include <readline.h>
   89: #  else /* !defined(HAVE_READLINE_H) */
   90: extern char *readline ();
   91: #  endif /* !defined(HAVE_READLINE_H) */
   92: char *cmdline = NULL;
   93: #else /* !defined(HAVE_READLINE_READLINE_H) */
   94:   /* no readline */
   95: #endif /* HAVE_LIBREADLINE */
   96: 
   97: #ifdef HAVE_READLINE_HISTORY
   98: #  if defined(HAVE_READLINE_HISTORY_H)
   99: #    include <readline/history.h>
  100: #  elif defined(HAVE_HISTORY_H)
  101: #    include <history.h>
  102: #  else /* !defined(HAVE_HISTORY_H) */
  103: extern void add_history ();
  104: extern int write_history ();
  105: extern int read_history ();
  106: #  endif /* defined(HAVE_READLINE_HISTORY_H) */
  107:   /* no history */
  108: #endif /* HAVE_READLINE_HISTORY */
  109: 
  110: #if defined(HAVE_WIRINGPI_H)
  111: # include <wiringPi.h>
  112: #endif
  113: 
  114: #if !defined(PATH_MAX) && defined(_SCO_DS)
  115: # define PATH_MAX 4096
  116: #endif
  117: 
  118: #if !defined(PATH_MAX) && defined(__gnu_hurd__)
  119: # define PATH_MAX 1024
  120: #endif
  121: 
  122: #if !defined(PATH_MAX) && defined(__sun__)
  123: # include <limits.h>
  124: #endif
  125: 
  126: #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
  127: # include <sys/syslimits.h>
  128: #endif
  129: 
  130: #define SHMKEY 0x990120
  131: #define SHMSIZ 1048576
  132: 
  133: void init_process(void);
  134: void init_devtable(void);
  135: void init_signals(void);
  136: void init_timezone(void);
  137: void init_freem_path(void);
  138: 
  139: #if defined(HAVE_LIBREADLINE)
  140: void init_readline(void);
  141: #endif
  142: 
  143: void init_execution_context(void);
  144: void init_io(void);
  145: void init_random_number(void);
  146: void init_ztrap(void);
  147: void init_ssvn(void);
  148: void init_terminal(void);
  149: void init_estack(void);
  150: 
  151: void init_mwapi(void);
  152: 
  153: short init (char *namespace_name) 
  154: {
  155:     short retval;
  156:     
  157:     init_process ();
  158:     init_devtable ();
  159:     init_signals ();
  160:     init_freem_path ();
  161:     init_timezone ();
  162: 
  163: #if defined(HAVE_LIBREADLINE)
  164:     init_readline ();
  165: #endif    
  166: 
  167:     init_execution_context ();
  168: 
  169:     if (run_daemon == FALSE) {
  170:         init_io ();
  171:     }
  172:     
  173:     init_random_number ();
  174:     init_ztrap ();
  175: 
  176:     retval = shm_init (shm_init_size);
  177: 
  178:     if (retval == SHMS_GET_ERR) {
  179:         fprintf (stderr, "init:  error initializing shared memory [errno %d]\r\n", errno);
  180:         exit (1);
  181:     }
  182: 
  183:     symtab_init ();
  184:     tp_init ();
  185:     
  186:     set_namespace (namespace_name, FALSE);
  187: 
  188:     if (first_process) {
  189:         fprintf (stderr, "init:  we are the first process in the environment (pid %d)\r\n", pid);
  190:     }
  191: 
  192:     if (first_process) fprintf (stderr, "init:  initializing job table\r\n");
  193:     jobtab_init ();
  194: 
  195:     if (first_process) fprintf (stderr, "init:  adding job to job table\r\n");
  196:     job_init (FALSE);
  197: 
  198:     if (first_process) fprintf (stderr, "init:  initializing structured system variables\r\n");
  199:     init_ssvn ();
  200: 
  201:     if (first_process) fprintf (stderr, "init:  initializing terminal\r\n");
  202:     init_terminal ();
  203: 
  204:     if (first_process) fprintf (stderr, "init:  initializing asynchronous events\r\n");
  205:     evt_init ();
  206: 
  207:     if (first_process) fprintf (stderr, "init:  initializing debugger\r\n");
  208:     dbg_init ();    
  209: 
  210:     if (first_process) fprintf (stderr, "init:  initializing error stack\r\n");
  211:     init_estack();
  212:     
  213:     etrap[0] = EOL;
  214:     ecode[0] = EOL;
  215:     estack = 0;
  216: 
  217:     init_mwapi();
  218:     
  219:     if (merr () == OK) {
  220:         return TRUE;
  221:     }
  222: 
  223:     return FALSE;
  224: }
  225: 
  226: void init_process (void)
  227: {
  228:     pid = getpid ();            /* get $J = process ID */
  229:     umask (0);              /* protection bits mask to full rights */
  230:     snprintf (fp_conversion, 9, "%%.%df\201", DBL_DIG);
  231: 
  232:     if (fp_mode) {
  233:         zprecise = DBL_DIG;
  234:     }
  235:     else {
  236:         zprecise = 100;
  237:     }
  238: }
  239: 
  240: void init_devtable (void)
  241: {
  242:     register int i;
  243:     register int j;
  244: 
  245:     for (j = 0; j <= MAXDEV; j++) { /* init. translation tables */
  246:         
  247:         for (i = 0; i < 256; i++) {
  248:             G0I[j][i] = (char) i;
  249:             G0O[j][i] = (char) i;
  250:             G1I[j][i] = (char) i;
  251:             G1O[j][i] = (char) i;
  252:         }
  253:         
  254:         G0I[j][UNSIGN (EOL)] = NUL;
  255:         G0O[j][UNSIGN (EOL)] = NUL;
  256:         G1I[j][UNSIGN (EOL)] = NUL;
  257:         G1O[j][UNSIGN (EOL)] = NUL;
  258:         G0I[j][UNSIGN (DELIM)] = NUL;
  259:         G0O[j][UNSIGN (DELIM)] = NUL;
  260:         G1I[j][UNSIGN (DELIM)] = NUL;
  261:         G1O[j][UNSIGN (DELIM)] = NUL;
  262:         G0I[j][256] = EOL;
  263:         G0O[j][256] = EOL;
  264:         G1I[j][256] = EOL;
  265:         G1O[j][256] = EOL;
  266:     
  267:     }
  268: 
  269:     #ifdef SCO
  270:         #ifndef HACK_NOXLATE
  271:             G0I[HOME][245] = 64;
  272:             G0O[HOME][64] = 245;        /* Paragraph */
  273:             G0I[HOME][142] = 91;
  274:             G0O[HOME][91] = 142;        /* A umlaut */
  275:             G0I[HOME][153] = 92;
  276:             G0O[HOME][92] = 153;        /* O umlaut */
  277:             G0I[HOME][154] = 93;
  278:             G0O[HOME][93] = 154;        /* U umlaut */
  279:             G0I[HOME][132] = 123;
  280:             G0O[HOME][123] = 132;       /* a umlaut */
  281:             G0I[HOME][148] = 124;
  282:             G0O[HOME][124] = 148;       /* o umlaut */
  283:             G0I[HOME][129] = 125;
  284:             G0O[HOME][125] = 129;       /* u umlaut */
  285:             G0I[HOME][225] = 126;
  286:             G0O[HOME][126] = 225;       /* sharp s  */
  287:         #endif/*HACK_NOXLATE*/
  288: 
  289:         /* DEC Special graphics                             */
  290:         G1I[HOME][254] = 96;
  291:         G1O[HOME][96] = 254;        /* diamond  */
  292:         G1I[HOME][176] = 97;
  293:         G1O[HOME][97] = 176;        /* checker board */
  294:         G1I[HOME][241] = 99;
  295:         G1O[HOME][99] = 241;        /* FF */
  296:         G1I[HOME][242] = 100;
  297:         G1O[HOME][100] = 242;       /* CR */
  298:         G1I[HOME][243] = 101;
  299:         G1O[HOME][101] = 243;       /* LF */
  300:         G1I[HOME][248] = 102;
  301:         G1O[HOME][102] = 248;       /* degree sign */
  302:         G1I[HOME][241] = 103;
  303:         G1O[HOME][103] = 241;       /* plus minus */
  304:         G1I[HOME][244] = 104;
  305:         G1O[HOME][104] = 244;       /* NL */
  306:         G1I[HOME][251] = 105;
  307:         G1O[HOME][105] = 251;       /* VT */
  308:         G1I[HOME][217] = 106;
  309:         G1O[HOME][106] = 217;       /* lower right corner */
  310:         G1I[HOME][191] = 107;
  311:         G1O[HOME][107] = 191;       /* upper right corner */
  312:         G1I[HOME][218] = 108;
  313:         G1O[HOME][108] = 218;       /* upper left corner */
  314:         G1I[HOME][192] = 109;
  315:         G1O[HOME][109] = 192;       /* lower left corner */
  316:         G1I[HOME][197] = 110;
  317:         G1O[HOME][110] = 197;       /* cross */
  318:         G1I[HOME][200] = 111;
  319:         G1O[HOME][111] = 200;       /* linescan 5 */
  320:         G1I[HOME][201] = 112;
  321:         G1O[HOME][112] = 201;       /* linescan 4 */
  322:         G1I[HOME][196] = 113;
  323:         G1O[HOME][113] = 196;       /* linescan 3 */
  324:         G1I[HOME][202] = 114;
  325:         G1O[HOME][114] = 202;       /* linescan 2 */
  326:         G1I[HOME][203] = 115;
  327:         G1O[HOME][115] = 203;       /* linescan 1 */
  328:         G1I[HOME][195] = 116;
  329:         G1O[HOME][116] = 195;       /* left  junction */
  330:         G1I[HOME][180] = 117;
  331:         G1O[HOME][117] = 180;       /* right junction */
  332:         G1I[HOME][193] = 118;
  333:         G1O[HOME][118] = 193;       /* lower junction */
  334:         G1I[HOME][194] = 119;
  335:         G1O[HOME][119] = 194;       /* upper junction */
  336:         G1I[HOME][179] = 120;
  337:         G1O[HOME][120] = 179;       /* vertival bar */
  338:         G1I[HOME][243] = 121;
  339:         G1O[HOME][121] = 243;       /* lower equals */
  340:         G1I[HOME][242] = 122;
  341:         G1O[HOME][122] = 242;       /* greater equals */
  342:         G1I[HOME][227] = 123;
  343:         G1O[HOME][123] = 227;       /* pi */
  344:         G1I[HOME][246] = 124;
  345:         G1O[HOME][124] = 246;       /* not equals */
  346:         G1I[HOME][128] = 125;
  347:         G1O[HOME][125] = 128;       /* euro sign */
  348:         G1I[HOME][250] = 126;
  349:         G1O[HOME][126] = 250;       /* centered dot */
  350:     #endif /* SCO */
  351: }
  352: 
  353: void init_signals (void)
  354: {
  355:     sig_init ();
  356: }
  357: 
  358: void init_timezone (void)
  359: {
  360:    
  361:     struct tm lt;
  362:     struct tm gt;
  363: 
  364:     unsigned long gmt;
  365:     unsigned long lmt;
  366: 
  367:     long clock;
  368: 
  369: #ifdef __CYGWIN__
  370: 
  371:     tzset ();                        /* may be required in order   */
  372:                                      /* to guarantee _timezone set */
  373: #else
  374: 
  375:     clock = time (0L);
  376:     lt = *localtime (&clock);
  377:     gt = *gmtime (&clock);
  378: 
  379:     /* This is awkward but I think it is portable: steve_morris */
  380:     gmt = gt.tm_year * 365;
  381:     gmt = (gmt + gt.tm_yday) * 24;
  382:     gmt = (gmt + gt.tm_hour) * 60;
  383:     gmt = (gmt + gt.tm_min);
  384: 
  385:     lmt = lt.tm_year * 365;
  386:     lmt = (lmt + lt.tm_yday) * 24;
  387:     lmt = (lmt + lt.tm_hour) * 60;
  388:     lmt = (lmt + lt.tm_min);
  389: 
  390:     FreeM_timezone = (gmt - lmt) * 60;
  391:     tzoffset = -FreeM_timezone;
  392:     
  393: #endif /* __CYGWIN__ */
  394:     
  395: 
  396: }
  397: 
  398: void init_freem_path (void)
  399: {
  400: 
  401:     if((freem_path = malloc(PATH_MAX + 1)) == NULL) {
  402:         fprintf(stderr, "Can't allocate freem_path. Exiting.");
  403: 
  404:         exit(1);
  405:     }
  406: 
  407:     freem_path[0] = NUL;
  408: 
  409:     /* check where I'm being executed from */
  410: #ifdef __linux__
  411:     readlink ("/proc/self/exe", freem_path, PATH_MAX);
  412: #endif
  413: #ifdef __FreeBSD__
  414:     readlink ("/proc/curproc/file", freem_path, PATH_MAX);
  415: #endif
  416: #ifdef __sun
  417:     readlink ("/proc/self/path/a.out", freem_path, PATH_MAX);
  418: #endif
  419: 
  420:     if(freem_path[0] == NUL) {
  421:         /* we don't know where we came from */
  422:     }
  423: 
  424:     getcwd (curdir, PATHLEN);
  425:     stcnv_c2m (curdir);
  426:     
  427: }
  428: 
  429: #if defined(HAVE_LIBREADLINE)
  430: void init_readline (void)
  431: {
  432:     uid_t uid = geteuid ();
  433:     struct passwd *pw = getpwuid (uid);
  434:     char *pw_buf;
  435: 
  436:     pw_buf = (char *) calloc (strlen(pw->pw_dir) + 1, sizeof(char));
  437:     strcpy (pw_buf, pw->pw_dir);
  438: 
  439:     snprintf (history_file, 256, "%s/.freem_history", pw_buf);
  440: 
  441:     free (pw_buf);
  442: 
  443:     using_history ();
  444:     read_history (history_file);
  445: }
  446: #endif    
  447: 
  448: void init_execution_context (void)
  449: {
  450:     register int i;
  451: 
  452:     obj_init ();
  453:     
  454:     merr_clear ();
  455:     
  456:     codptr = code;
  457:     code[0] = EOL;          /* init code_pointer */
  458:     partition = calloc ((unsigned) (PSIZE + 2), 1);
  459: 
  460:     if (partition == NULL) exit (2);            /* could not allocate stuff...     */
  461: 
  462:     for (i = 0; i < MAXNO_OF_RBUF; i++) {
  463:         rbuf_flags[i].standard = standard;
  464:     }
  465: 
  466:     for (i = 0; i < NESTLEVLS; i++) {
  467:         extr_types[i] = DT_STRING;
  468:     }
  469:     
  470:     symlen = PSIZE;
  471:     s = &partition[PSIZE] - 256;    /* pointer to symlen_offset        */
  472:     argptr = partition;         /* pointer to beg of tmp-storage   */
  473: 
  474:     svntable = calloc ((unsigned) (UDFSVSIZ + 1), 1);
  475:     if (svntable == NULL) exit (2);         /* could not allocate stuff...     */
  476:     
  477:     svnlen = UDFSVSIZ;          /* begin of udf_svn_table         */
  478:     buff = calloc ((unsigned) NO_OF_RBUF * (unsigned) PSIZE0, 1);   /* routine buffer pool          */
  479:     if (buff == NULL) exit (2);         /* could not allocate stuff...     */
  480: 
  481:     
  482:     newstack = calloc ((unsigned) NSIZE, 1); 
  483:     if (newstack == NULL) exit (2);         /* could not allocate stuff...     */
  484: 
  485:     #ifdef DEBUG_NEWPTR
  486:         printf("Allocating newptr stack...\r\n");
  487:     #endif
  488: 
  489:     newptr = newstack;
  490:     newlimit = newstack + NSIZE - 1024;
  491:     
  492: 
  493:     namstck = calloc ((unsigned) NESTLEVLS * 13, 1);
  494:     if (namstck == NULL) exit (2);          /* could not allocate stuff...     */
  495: 
  496:     *namstck = EOL;
  497:     *(namstck + 1) = EOL;
  498:     namptr = namstck;           /* routine name stack pointer       */
  499:     framstck = calloc ((unsigned) NESTLEVLS * 256, 1);
  500:     if (framstck == NULL) exit (2);         /* could not allocate stuff...     */
  501: 
  502:     *framstck = EOL;
  503:     *(framstck + 1) = EOL;
  504:     dofrmptr = framstck;        /* DO_frame stack pointer           */
  505:     cmdstack = calloc ((unsigned) NESTLEVLS * 256, 1);
  506:     if (cmdstack == NULL) exit (2);         /* could not allocate stuff...     */
  507: 
  508:     cmdptr = cmdstack;          /* command stack */
  509: 
  510:     rouend = rouins = rouptr = buff;
  511:     roucur = buff + (NO_OF_RBUF * PSIZE0 + 1);
  512:     *rouptr = EOL;
  513:     *(rouptr + 1) = EOL;
  514:     *(rouptr + 2) = EOL;
  515: 
  516:     err_suppl[0] = EOL; /* empty out supplemental error info */
  517: }
  518: 
  519: void init_estack (void)
  520: {
  521:     stcpy (merr_stack[0].PLACE, "xecline()\201");
  522: }
  523: 
  524: #if defined(HAVE_MWAPI_MOTIF)
  525: void init_mwapi (void)
  526: {
  527:     /*
  528:     if (getenv("DISPLAY") != NULL) {
  529:         gtk_init (0, NULL);
  530:     }
  531:     */
  532:     //TODO: init Motif/libXt
  533: }
  534: #else
  535: void init_mwapi (void)
  536: {
  537:     return;
  538: }
  539: #endif
  540: 
  541: void init_io (void)
  542: {
  543:     register int i;
  544: 
  545:     /* initialize screen */
  546:     setbuf (stdin, NULL);      /* no input buffering */
  547:     glvnflag.all = 0L;
  548:     stcpy (buff, "\201");
  549:     writeHOME (buff);
  550:     sq_modes[0] = '+';
  551:     for (i = 0; i <= MAXDEV; ug_buf[i++][0] = EOL); /* init read-buffers */
  552: 
  553:     frm_crlf[HOME] = frm_filter;
  554: 
  555:     if (hardcopy) zbreakon = ENABLE;        /* enable CTRL/B */
  556: 
  557:     set_io (MUMPS);         /* set i/o parameters */
  558: 
  559: #if !defined(__AMIGA)
  560:     if (ttyname (HOME)) {       /* for $IO of HOME */
  561:         strcpy (dev[HOME], ttyname (HOME));
  562:         dev[HOME][strlen (dev[HOME])] = EOL;
  563:     } 
  564:     else {
  565:         dev[HOME][0] = EOL;     /* ...we are in a pipe */
  566:     }
  567: #else
  568:     strcpy (dev[HOME], "CONSOLE:");
  569: #endif    
  570: 
  571:     /* init function keys */
  572:     for (i = 0; i < 44; zfunkey[i++][0] = EOL);
  573: }
  574: 
  575: void init_random_number (void)
  576: {
  577: 
  578:     srand (time (NULL));
  579: 
  580:     if ((nrandom = time (0L) * getpid ()) < 0) {
  581:         nrandom = (-nrandom);
  582:     }
  583: 
  584: }
  585: 
  586: void init_ztrap (void)
  587: {
  588: 
  589:     if (frm_filter) { 
  590:         ztrap[0][0] = EOL;      /* no default ztrap for filters */
  591:     }
  592:     else if (startuprou[0] == '^') {
  593:         stcpy (ztrap[0], startuprou);
  594:     }
  595:     else {
  596:         stcpy (ztrap[0], "^%SYSINIT\201");
  597:     }
  598: 
  599:     /* $ZT to be xecuted on startup */
  600:     
  601:     stcpy (ztrap[NESTLEVLS + 1], ztrap[0]); /* DSM V.2 error trapping */
  602: 
  603: }
  604: 
  605: void init_ssvn(void)
  606: {
  607:     ssvn_job_update ();
  608:     ssvn_display_update ();
  609:     ssvn_routine_update ();
  610:     ssvn_library_update ();
  611:     if (first_process) ssvn_system_update ();
  612: }
  613: 
  614: void init_terminal(void)
  615: {
  616:     xpos[HOME] = 80;
  617:     ypos[HOME] = 24;
  618: }
  619: 
  620: void reset_terminal(void)
  621: {
  622:     struct termio tpara;
  623: 
  624:     ioctl (0, TCGETA, &tpara);
  625: 
  626:     tpara.c_lflag |= (ECHO | ICANON);	/* enable echo/no cbreak mode */
  627:     tpara.c_iflag |= ICRNL;		/* cr-lf mapping */
  628:     tpara.c_oflag |= ONLCR;		/* cr-lf mapping */
  629:     tpara.c_cc[VMIN] = EOT;
  630:     tpara.c_cc[VTIME] = -1;
  631: 
  632:     ioctl (0, TCSETA, &tpara);
  633: }
  634: 
  635: void cleanup (void)
  636: {
  637:     char k_buf[256];
  638:     int ch;
  639: 
  640:     /* remove this job's entry from ^$JOB SSVN */
  641:     snprintf (k_buf, 255, "^$JOB\202%d\201", pid);
  642:     symtab_shm (kill_sym, k_buf, " \201");
  643:     
  644:     reset_terminal ();
  645: 
  646:     if (tp_level > 0) {
  647: 
  648:         if (direct_mode == TRUE) {
  649:             fprintf (stderr, "UNCOMMITTED TRANSACTIONS EXIST:\n\n");
  650:             tp_tdump ();
  651:             set_io (UNIX);
  652:             fprintf (stderr, "\nWould you like to c)ommit or r)ollback the above transactions and their operations? ($TLEVEL = %d) ", tp_level);
  653: 
  654:             for (;;) {
  655:                 ch = fgetc (stdin);
  656: 
  657:                 if (ch == 'c' || ch == 'C') {
  658:                     while (tp_level > 0) tp_tcommit ();
  659: 
  660:                     fprintf (stderr, "\n\nTransactions have been committed.\n");
  661: 
  662:                     break;
  663:                 }
  664:                 else if (ch == 'r' || ch == 'R') {
  665:                     tp_trollback (tp_level);
  666: 
  667:                     fprintf (stderr, "\n\nTransactions have been rolled back.\n");
  668: 
  669:                     break;
  670:                 }
  671:                 else {
  672:                     fprintf (stderr, "\n\nInvalid input '%c'. Must choose c)ommit or r)ollback.\n", ch);
  673:                 }
  674:             }
  675:         }
  676:         else {
  677:             fprintf (stderr, "Uncommitted transactions exist. Rolling back.\n");
  678:             tp_trollback (tp_level);
  679:         }
  680:     }
  681: 
  682: #if defined(HAVE_LIBREADLINE)
  683:     write_history (history_file);
  684: #endif
  685: 
  686:     locktab_unlock_all ();    
  687:     job_remove (pid);
  688: 
  689:     shm_exit ();
  690: 
  691:     if (run_daemon == TRUE) {
  692: 
  693:         if (pid_fd != -1) {
  694:             lockf (pid_fd, F_ULOCK, 0);
  695:             close (pid_fd);
  696:         }
  697: 
  698:         if (pid_file_path != NULL) {
  699:             unlink (pid_file_path);
  700:         }
  701: 
  702:     }
  703:         
  704:     
  705:     
  706:     free (buff);            /* free previously allocated space */
  707:     free (svntable);
  708:     if (partition) free (partition);
  709:     if (apartition) free (apartition);
  710: 
  711:    
  712:     free (newstack);
  713:     
  714:     
  715:     if (v22size) free (v22ali);    
  716:     
  717:     return;
  718: }                   /* end of cleanup */

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