My original posting concerned "ghost" ttyp logins (visible in
the "w" or "who" listings) after a user exits openwindows.
As many people pointed out, these are the result of stale utmp
entries created by cmdtool. Two fixes were suggested. I've used
fix #1, and it works great. Fix #2 just came in, and I haven't
yet tried it, though I plan to soon, as it seems to address the
problem in a more direct fashion. (Sun Patches often do :) )
-Bob
--- 1 ---
From: rwolf@dretor.dciem.dnd.ca
Here you go, run it on a regular cron basis (say every few hours).
/*
* From Sun-Spots Digest, v6n9 (Fri 29 Jan 1988)
* Date: Wed, 20 Jan 88 11:37:51 EST
* From: Graham Campbell <gc@bnl-ewok.arpa>
* Subject: Program to help keep utmp clean
*
* Since the question of cleaning out the pseudo-tty entries from utmp has
* arisen again (Sun-Spots v6n5), I will contribute a small program that I
* run from my .logout that does this.
*
* Graham
*/
#include <utmp.h>
#include <sys/file.h>
#include <stdio.h>
main()
{
struct utmp ut;
int utmp, pty, ret_code;
long posn;
static char master[] = "/dev/pty??";
/* Open /etc/utmp */
utmp = open("/etc/utmp", O_RDWR);
if (utmp == -1) {
perror("Cannot open utmp");
exit (1);
}
/* Scan through /etc/utmp for entries */
ret_code = 0;
while (posn = lseek(utmp, 0L, L_INCR), read(utmp, &ut, sizeof(ut)) != 0) {
/* Skip over entries that are logged out already */
if (ut.ut_name[0] == 0)
continue;
/* Verify this is a actual login line */
if (strncmp(ut.ut_line, "tty", 3) == 0 &&
(ut.ut_line[3] == 'p' ||
ut.ut_line[3] == 'q' ||
ut.ut_line[3] == 'r')) {
master[8] = ut.ut_line[3];
master[9] = ut.ut_line[4];
/* Open this pseudo device, if it exists then this is a ghost */
/* user */
pty = open(master, O_RDWR);
if (pty >= 0)
{
printf("clearing out %s\n", master);
fflush(stdout);
if (close(pty) != 0) {
printf("Can not close %s\n", master);
fflush(stdout);
}
/* Clear out the utmp entry */
lseek(utmp, posn, L_SET);
ut.ut_name[0] = 0;
ut.ut_host[0] = 0;
if (write(utmp, &ut, sizeof(ut)) != sizeof(ut))
perror("error writing to /etc/tmp");
}
}
}
/* Close up /etc/utmp */
if (close(utmp) != 0) {
perror("Can not close /etc/utmp\n");
ret_code = 1;
}
exit(ret_code);
}
--- 2 ---
From: mike_p <mike_+a_WTL_+lmike+_p+r%Trans_Ocean_Express@mcimail.com>
Synopsis: OpenWindows 3.0 cmdtool patch
SunOS release: 4.1.3, 4.1.2, 4.1.1, 4.1
Unbundled Product: OpenWindows
Unbundled Release: 3.0
Patch-ID# 100943-01
Topic: cmdtool
BugId's fixed with this patch: 1075514
Changes incorporated in this version:
Architectures for which this patch is available: sun4(all)
Patches which may conflict with this patch:
Obsoleted by:
Files included with this patch: cmdtool
Problem Description: ttyp# is still used after existing OW3.
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:27 CDT