Annotation of coherent/d/usr/bin/uucpstuff/modemcap/dial.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *  dial.c
                      3:  *
                      4:  *  Implement the dial(3) function calls.
                      5:  *
                      6:  *  Copyright 1987 (c) John F. Haugh II
                      7:  *  Changes Copyright 1989-91 (c) Mark Williams Company
                      8:  */
                      9: 
                     10: #include <stdio.h>
                     11: #include <signal.h>
                     12: #include <fcntl.h>
                     13: #include "modemcap.h"
                     14: #include "dial.h"
                     15: #include "dcp.h"
                     16: #include "ldev.h"
                     17: 
                     18: 
                     19: char   *devname = NULL;        /* Communications Device Name Connected */
                     20: char   *rdevname = NULL;       /* Remote device name */
                     21: 
                     22: static char    login_lock[15];
                     23: static char    enableme[16];
                     24: static int     modemfd = -1;
                     25: extern char    *strtok();
                     26: extern int     hupcatch();
                     27: 
                     28: /*
                     29:  *  dial(cp)  CALL cp;
                     30:  *
                     31:  *  Dial and initiate the call specified via the given CALL data structure.
                     32:  *  Returns the opened file descriptor to be used for reads and writes to
                     33:  *  the determined device line.  If there is an error, then the return value
                     34:  *  is less than zero, and the variable "merror" is set appropriately.
                     35:  */
                     36: 
                     37: dial(cp)
                     38: CALL *cp;
                     39: {
                     40:        char    modemline[64];          /* device name                  */
                     41:        char    *modemname = "\0";
                     42:        char    *strcpy (),
                     43:        *strcat ();
                     44:        int     fd, err;
                     45:        
                     46:        fd = -1;                /* channel illegal until line is opened */
                     47:        if ( (err=findline(cp, &modemname)) <= 0 )
                     48:                goto error;
                     49:        strcat(strcpy(modemline, DEVDIR), cp->line);
                     50:        if ((fd = open (modemline, O_RDWR)) < 0) { /* can't open modem line */
                     51:                err = M_L_PROB;
                     52:                goto error;
                     53:        }
                     54:        if ( (err=ttyinit(fd, cp->baud)) != 0 )
                     55:                goto error;
                     56: 
                     57:        initmodem(modemname, fd);       /* setup modemcap variables */
                     58:        if (cp->telno == NULL)     /* no phone number, connection complete */
                     59:                goto okay;
                     60:        if (! DI) {                     /* modem has no ACU!!! */
                     61:                /* plog("Says no acu to attatch to???"); */
                     62:                err = M_A_PROB;         /* no ACU to attach to */
                     63:                goto error;
                     64:        }
                     65:        if (BD != cp->baud) {   /* is connection desired at high speed? */
                     66:                if (BL != cp->baud) {/* is connection desired at low speed? */
                     67:                        err = M_ILL_BD; /* modem can't handle this speed */
                     68:                        goto error;
                     69:                }
                     70:                BD = BL;                /* set baud to low baud rate */
                     71:                CO = CL;        /* set connect reply to low baud reply */
                     72:        }
                     73:        if (err = mdial (cp->telno, fd))        /* some error trying to dial */
                     74:                goto error;
                     75: 
                     76: okay:
                     77:        return (modemfd = fd);
                     78: error:
                     79:        hangup(fd);
                     80:        return (merrno = err);
                     81: }
                     82: 
                     83: /* undial()    
                     84:  * removes the lock on the remote device if it exists and reenables
                     85:  * the port. Undial() is called by hangup(), which was called by 
                     86:  * sysend(). Bob H. 11/22/91.
                     87: */
                     88: undial (fd)
                     89: int    fd;
                     90: {
                     91:        close (fd); /* close the port */
                     92: 
                     93:        /* If lock removal fails, print message. */
                     94: 
                     95:        /* unlock the port. If it fails, note this in the logfiles, but don't
                     96:         * abort, we will want to continue through uucico so that uuxqt
                     97:         * gets invoked as uucico exits.
                     98:         */
                     99: 
                    100:        if (lockttyexist(devname) && (unlocktty(devname) == -1) ){
                    101:                printmsg(M_DEBUG,"Undial(): %s lock file removal failed.",devname);
                    102:                plog(M_CALL,"%s lock file removal failed.",devname);
                    103:        }
                    104: 
                    105:        /* If lock removal failed, then do not re enable the port because we
                    106:         * no longer know who did what to the remote port. Re enabling the
                    107:         * port could result in a race condition we don't want.
                    108:        */
                    109: 
                    110:        if ((enableme[0] != '\0') && (lockttyexist(devname) == 0)){
                    111:                plog(M_CALL, "Enabling tty line %s", enableme);
                    112:                exec_stat("enable", enableme);
                    113:                strcpy(enableme, "");
                    114:        }else{
                    115:                if((enableme[0] != '\0') && (rdevname[0] != '\0') && (rdevname[0] != '-')){
                    116:                printmsg(M_DEBUG,"Undial: Can not re-enable port due to tty lock file.");
                    117:                plog(M_CALL,"Could not re-enable port due to tty lock file.");
                    118:                }
                    119:        }
                    120:        rdevname = NULL;
                    121: }
                    122: 
                    123: static
                    124: findline(callp, brand)
                    125: CALL *callp;
                    126: char **brand;
                    127: {
                    128:        int     exists = 0;             /* device exists at some baud rate */
                    129:        int     tried = 0;              /* found a device but it was locked */
                    130:        int     devflag, telflag;
                    131:        char    *l_lline;               /* tty device local name */
                    132:        char    *l_rline;               /* tty device remote name */
                    133:        char    *l_type;                /* ACU, DIR, etc. */
                    134:        char    *l_brand;               /* modemcap brand name */
                    135:        int     l_baud;                 /* tty baud rate */
                    136:        int     retval;                 /* Place to stash return of exec_stat */
                    137: 
                    138:        ldev_open();
                    139:        if ( ((devflag=(callp->line != NULL)) &&
                    140:              (telflag=(callp->telno != NULL))) || (!devflag && !telflag) )
                    141:                return(M_DEV_TEL);
                    142: 
                    143:        while ( ldev_next() ) {
                    144:                l_type  = ldev_value(type_e);
                    145:                l_lline = ldev_value(lline_e);
                    146:                l_rline = ldev_value(rline_e);
                    147:                l_baud  = atoi(ldev_value(baud_e));
                    148:                l_brand = ldev_value(brand_e);
                    149: 
                    150:                if ( strcmp(l_type, "ACU") == 0 ) {
                    151:                        if ( devflag )
                    152:                                continue;
                    153:                        exists++;
                    154:                        if (l_baud != callp->baud)
                    155:                                continue;
                    156:                } else if ( strcmp(l_type, "DIR") == 0 ) {
                    157:                        if ( telflag )
                    158:                                continue;
                    159:                        if ( strcmp(l_lline, callp->line) )
                    160:                                continue;
                    161:                        callp->baud = l_baud;
                    162:                } else {
                    163:                        continue;
                    164:                }
                    165:                ++tried;                /* found device at desired baud rate */
                    166: 
                    167:        /* July 29, 1992: I have removed the previous locking code. This code
                    168:         * looked for a remote device to enable and disable and would build a
                    169:         * lockfile if a remote device was specified. However, the advent of
                    170:         * locking kermit has changed our needs. Now we will always have to 
                    171:         * check for and lock the LOCAL device we are dialing out with. This
                    172:         * will, if anything, make things a bit more stable with regards to
                    173:         * locking. Bob H.
                    174:         */
                    175: 
                    176:        if (lockttyexist(l_lline)){
                    177:                plog(M_CALL,"Device %s already locked by another process", l_lline);
                    178:                exit(1);
                    179:        }
                    180: 
                    181: 
                    182: #ifndef _I386
                    183:        if (locktty(l_lline) != 0){
                    184:                plog(M_CALL,"Attempt to create lock file failed.");
                    185:                if(lockexist(rmtname)){
                    186:                        lockrm(rmtname);
                    187:                }
                    188:                exit(1);
                    189:        }
                    190: #else
                    191:        if (!locktty(l_lline)){
                    192:                plog(M_CALL,"Attempt to create lock file failed.");
                    193:                if(lockexist(rmtname)){
                    194:                        lockrm(rmtname);
                    195:                }
                    196:                exit(1);
                    197:        }
                    198: #endif         
                    199:        enableme[0] = '\0';
                    200:        if(strcmp(l_rline,"-") !=0){
                    201:        /* Disable the remote device.
                    202:         * Note that we will then sleep for 5 seconds to make sure that
                    203:         * the port gets closed after the disable.
                    204:         */
                    205: 
                    206:        /* Note that disable could be terminated by
                    207:         * a SIGHUP when the port is disabled.
                    208:         */
                    209:                        if (0!=(retval=exec_stat("disable", l_rline)) &&
                    210:                            SIGHUP<<8 != retval) {
                    211:                                plog(M_CALL,"Disable of tty line %s failed",
                    212:                                     l_rline);
                    213:                                continue;
                    214:                        }else{
                    215:                                plog(M_CALL,"Disabling tty line %s", l_rline);
                    216:                                        sleep(5);
                    217:                                        strcpy(enableme,l_rline);
                    218:                        }
                    219:                }
                    220:                devname = l_lline;
                    221:                rdevname = l_rline;
                    222:                *brand = l_brand;
                    223:                ldev_close();
                    224:                callp->line = l_lline;
                    225:                return (1);
                    226:        }
                    227:        if (tried)
                    228:                return (merrno = M_DV_NT_A);
                    229:        else if (exists) {
                    230:                return (merrno = M_ILL_BD);
                    231:        } else {
                    232:                /* plog("Device not known: %s", brand); */
                    233:                return (merrno = M_DV_NT_K);
                    234:        }
                    235: }
                    236: 
                    237: exec_stat(command, line)
                    238: char   *command;
                    239: char   *line;
                    240: {
                    241:        int     pid;
                    242:        int     waitstat;
                    243:        static  char    etccommand[32];
                    244: 
                    245:        strcpy(etccommand, "/etc/");
                    246:        strcat(etccommand, command);
                    247:        /* plog("%s (%s) on line %s", command, etccommand, line);
                    248:         */
                    249:        pid = fork();
                    250:        if (pid == 0) {
                    251:                execl(etccommand, command, line, NULL);
                    252:                exit(1);
                    253:        } else 
                    254:                wait(&waitstat);
                    255:         
                    256:        return waitstat;
                    257: }
                    258: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.