Xref: utzoo comp.unix.xenix:4151 comp.unix.wizards:13412 Path: utzoo!attcan!uunet!ccicpg!turnkey!sandy From: sandy@turnkey.TCC.COM (Sanford 'Sandy' Zelkovitz) Newsgroups: comp.unix.xenix,comp.unix.wizards Subject: Re: ungetty Summary: This is basically how it works Keywords: ungetty getty init Message-ID: <4106@turnkey.TCC.COM> Date: 12 Dec 88 13:29:46 GMT References: <6@rsoft.UUCP> Organization: Turnkey Computer Consultants, Costa Mesa, Ca. Lines: 119 In article <6@rsoft.UUCP>, frank@rsoft.UUCP (Frank I. Reiter) writes: > SCO Xenix 2.2.x allows cu, uucico etc, to call out on a line enabled for > dialin access by running ungetty before and after the outgoing call. > > We run an 8 line bulletin board service on !rsoft and use an init/getty like > procedure to answer incomming calls. I would like to modify our code so that > we can use these same 8 lines for outgoing calls when they are not in use. > > It would not be difficult to write our own version of ungetty to work with > our own version of init, but for the sake of compatibility etc. it would be > much nicer if we could have the standard unix communications commands able > to suspend and restart our getty-like processes. > > Can anybody tell me how ungetty interacts with getty or point me at a good > source of information? > > -- > *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* > Frank I. Reiter \ / UUCP: {uunet,ubc-cs}!van-bc!rsoft!frank > Langley, British Columbia / \ BBS: Mind Link @ (604)533-2312 > *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* Ungetty basically uses SIGUSR1 and SIGUSR2 to communicate with getty. What happens is that when ungetty is called, it sends a SIGUSR1 to getty and then the following steps are performed: 1) getty closes 0, 1, and 2 2) getty does an fclose on stdin, stderr, and stdout 3) getty changes the appropriate entry in utmp 4) getty goes to sleep When ungetty is called again to awaken getty by using SIGUSR2, getty simply terminates which causes init to spawn a new getty. In my version of getty, I also update wtmp in addition to utmp so that I have a record of outgoing calls. This addition causes absolutely no problems in the operation and really should have been included by SCO. The following code is what I used: int ungetty_call() { register in ownpid; register struct utmp *u; extern struct utmp *getutent(), *pututline(); register FILE *fp; if(ungetty_flag) return; /* You want to disallow ungetty calls when getty is in transition between the user entering his name and login being execed */ fclose(stdin); fclose(stdout); fclose(stderr); close(1); close(2); close(3); delock(Line); /* Look in utmp file for our own entry and change it to LOGIN */ ownpid = getpid(); while ((u=getutent()) != NULL ) { if( u->ut_type == LOGIN_PROCESS && u->ut_pid == ownpid) { strncpy(u->ut_line, Line, sizeof(u->ut_line)); strncpy(u-ut_user,"DIALOUT", sizeof(u->ut_user)); u->ut_type = USER_PROCESS; pututline(u); break; } } if( u!= NULL && (fp=fopen(WTMP_FILE, "r+")) != NULL) { fseek(fp,0L, 2); fwrite(u, sizeof(*u), 1, fp); fclose(fp); } endutent(); /* pause until ungetty says that it is ok */ (void)pause; exit(0); } ------------------------- Additions required for uugetty_call() ------------- Before your main(), add the following code: int ungetty_flag; char Line[20]; Somewhere in your code, do a strcpy of the line name to Line. The first exectuable instruction in your main, add the following code: if(signal(SIGUSR1, ungetty_call) == (int(*)())-1) { printout and error message exit(1); } I hope that this helps!!!! Sanford Zelkovitz XBBS 714-898-8634 -- Sanford Zelkovitz XBBS 714-898-8634 UUCP: ....att!hermix!alphacm!sandy ....trwrb!ucla-an!alphacm!sandy ....uunet!turnkey!alphacm!sandy ....ucbvax!ucivax!icnvax!alphacm!sandy DATA: 714-898-8634 VOICE: 714-894-7898