Path: utzoo!utgpu!jarvis.csri.toronto.edu!torsqnt!tmsoft!masnet!canremote!perry@macom1.uucp From: perry@macom1.uucp@canremote.uucp (perry@macom1.UUCP) Newsgroups: comp.dcom.modems Subject: Re: Telebit config Question c Message-ID: <89122504055265@masnet.uucp> Date: 21 Dec 89 05:05:00 GMT Organization: Canada Remote Systems Limited, Mississauga, ON, Canada Lines: 98 From: perry@macom1.UUCP (Guru's Inc.) Subj: Telebit config Question c-code uugetty Orga: CENTEL Federal Systems, Reston, VA. 22091-1506 *-*-*-*-* Message continued from prior message *-*-*-*-* conprint(60); } xlucent( pterm, &targ ); /* make port translucent */ ioctl( pterm, TCFLSH, 2 ); sprintf(buf, "chown uucp %s", port ); system(buf); /* give ownership */ fd = open( "/etc/utmp", 2); /* clear last who */ while( read(fd, buf2, 8) ) { if (!(strcmp(buf2, argv[4]))) { write(fd, nuls, 8); break; } else lseek(fd, offset, 1); } close(fd); while(wait_on_CR( pterm )) intread(); /* wait for connect request */ while(inithookup) { parent = getpid(); /* get id of this process */ if ((child = fork()) == 0) { sleep(5); exit(0); /* child holds line open */ } else { if (inithookup) { inithookup = 0; /* hookup is done */ execl("/etc/getty", "getty", optt, optn, device, speed, 0); } } } return(0); } /*** end main ***/ /*** ---Wait for input; determine direction of line.--- Listen for incoming character other than null. If a lock file already exists the line is outgoing. While lock exists sleep 20 sec; when gone die. If no lock exists line is incoming; exec getty. ***/ wait_on_CR( term ) int term; { char c,k=CR; track("listen"); while (1) { if (read( term, &c, 1 ) <= 0) /* get a character from unix */ { c = '\0'; return (1); /* interrupt returned */ } if (( c == k )) { if (!(access(lock, 0))) checkout(lock,2); mask = umask(0); /* change mask */ lockfd = creat( lock, 0444 ); /* create the lock file */ umask(mask); /* restore mask */ if ( lockfd < 0) { sprintf(buf, "%s: cannot create lock %s\n",prg, device); conprint(60); } write( lockfd, pbuf, (unsigned)strlen(pbuf) ); close( lockfd ); track("incoming"); return(0); } k=c; signal( SIGHUP, hangup ); /* 01 watch for hangups */ ioctl( pterm, TCFLSH, 2 ); } } /*** Read lockfile for pid; set hangup pointer; see if lock active. If lock inactive unlink it if first time here and die. else wait on outgoing lock to release before dying. ***/ checkout(latch,n) char *latch, n; { dbf = fopen(latch, "r"); fgets(buf, 20, dbf); fclose(dbf); if(!(strcmp(pbuf, buf))) {track("selflock"); hangup();} sprintf(buf+10, " >/dev/null"); /* remove \n */ sprintf(cbuf, "ps -p%s", buf ); if( n == 1 ) sleep(2); r=system(cbuf); if( r == 0) *-*-*-*-* Message continued in next message *-*-*-*-* --- * Via MaSNet/HST96/HST144/V32 - UN Datacommun./Modems * Via Usenet Newsgroup comp.dcom.modems