david@muddcs.UUCP (David Goebel) (06/20/85)
Does anyone out there know of a quick way to log a user out from a C program without rummaging through memory for the pid of the login shell? Editing the /etc/ttys file and sending SIGHUPs to init will kill all processes associated with that terminal, not just the user's processes. If anyone has any clever idea's for doing this on 4.2BSD please email then to me and I will summarize to the net. Thanks. David Goebel (tektronix!reed, all
root@bu-cs.UUCP (Barry Shein) (06/24/85)
>From: david@muddcs.UUCP (David Goebel) >Subject: How can I log a user out? >Date: Wed, 19-Jun-85 19:17:08 EDT > >Does anyone out there know of a quick way to log a user out from a C >program without rummaging through memory for the pid of the login shell? I'm not sure exactly what you are after but this is a program I often use that just toggles DTR on the terminal line. I figure that's the best I can do being as Ma Bell might have done accidently anyhow: (the timeout's in case I get hung on carrier or something.) [dtr.c follows, a trivial program, obviously won't work with hard-wired lines but you should probably get rid of those anyhow :-] ---------- #include <stdio.h> #include <sgtty.h> #include <signal.h> #define TIMOUT 30 usage(s) char *s ; { fprintf(stderr,"Usage: %s terminal-line\n",s) ; exit(1) ; } tock() { fprintf(stderr,"Timed out...\n") ; exit(1) ; } main(argc,argv) int argc ; char **argv ; { int fd ; signal(SIGALRM,tock) ; alarm(TIMOUT) ; if(argc != 2) usage(*argv) ; if((fd = open(*++argv,2)) < 0) { perror(*argv) ; exit(1) ; } if(ioctl(fd,TIOCCDTR,0) < 0) { perror(*argv) ; exit(1) ; } exit(0) ; }
rob@ptsfa.UUCP (Rob Bernardo) (06/24/85)
In article <440@bu-cs.UUCP> root@bu-cs.UUCP (Barry Shein) writes: >>From: david@muddcs.UUCP (David Goebel) >>Subject: How can I log a user out? >>Date: Wed, 19-Jun-85 19:17:08 EDT >> >>Does anyone out there know of a quick way to log a user out from a C >>program without rummaging through memory for the pid of the login shell? > >I'm not sure exactly what you are after but this is a program I >often use that just toggles DTR on the terminal line. ... > if(ioctl(fd,TIOCCDTR,0) < 0) ... This must be a BSD-ism as TIOCCDTR is NOT a possible argument to ioctl(2) in SIII or SV. However, the good news is that you can drop DTR (and thereby cause the line to be hanged up) by setting the baud rate to "zero", either with the shell command stty 0 < /dev/ttyXX or by using ioctl(2) on the desired port. -- Rob Bernardo, San Ramon, California ihnp4!ptsfa!rob {nsc,ucbvax,decwrl,amd,fortune,zehntel}!dual!ptsfa!rob