How can I log a user out?

Barry Shein root at bu-cs.UUCP
Mon Jun 24 11:26:21 AEST 1985


>From: david at 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) ;
}



More information about the Comp.unix.wizards mailing list