--- AfterStep-APPS-990329/xiterm-2.0/src/utmp.c.xiutmp Fri Sep 25 04:12:13 1998 +++ AfterStep-APPS-990329/xiterm-2.0/src/utmp.c Mon Mar 29 18:52:13 1999 @@ -1,14 +1,8 @@ +#include /*--------------------------------*-C-*---------------------------------* * File: utmp.c *----------------------------------------------------------------------* - * - * Copyright (c) 1992 John Bovey - * Copyright (c) 1993 lipka - * Copyright (c) 1993 Brian Stempien - * Copyright (c) 1995 Raul Garcia Garcia - * Copyright (c) 1995 Piet W. Plomp - * Copyright (c) 1997 Raul Garcia Garcia - * Copyright (c) 1997 1998 Geoff Wing + * Copyright 1997,1998 Geoff Wing * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,210 +17,43 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------* + * Originally written: + * 1992 John Bovey + * Modifications: + * 1993 lipka + * 1993 Brian Stempien + * 1995 Raul Garcia Garcia + * 1995 Piet W. Plomp + * 1997 Raul Garcia Garcia + * 1997,1998 Geoff Wing + *----------------------------------------------------------------------*/ +/*----------------------------------------------------------------------* + * Public: + * extern void cleanutent (void); + * extern void makeutent (const char * pty, const char * hostname); * + * Private: + * write_utmp (); + * update_wtmp (); *----------------------------------------------------------------------*/ -#include "misc.h" /* NECESSARY */ - -/* - * HAVE_SETUTENT corresponds to SYSV-style utmp support. - * Without it corresponds to using BSD utmp support. - * SYSV-style utmp support is further divided in normal utmp support - * and utmpx support (Solaris 2.x) by HAVE_UTMPX_H - */ - -/* - * update wtmp entries - only for SYSV style UTMP systems - */ -#ifdef UTMP_SUPPORT -static char ut_id[5]; /* remember if entry to utmp made */ - -#ifndef USE_SYSV_UTMP -static int utmp_pos; /* BSD position of utmp-stamp */ - +#ifndef lint +static const char rcsid[] = "$Id$"; #endif -#endif - -/* ------------------------------------------------------------------------- */ -#ifndef HAVE_UTMPX_H /* supposedly we have updwtmpx ? */ -#ifdef WTMP_SUPPORT -/* PROTO */ -void -xiterm_update_wtmp(char *fname, struct utmp *putmp) -{ - int fd, retry = 10; /* 10 attempts at locking */ - struct flock lck; /* fcntl locking scheme */ - if ((fd = open(fname, O_WRONLY | O_APPEND, 0)) < 0) - return; - - lck.l_whence = SEEK_END; /* start lock at current eof */ - lck.l_len = 0; /* end at ``largest possible eof'' */ - lck.l_start = 0; - lck.l_type = F_WRLCK; /* we want a write lock */ - - while (retry--) - /* attempt lock with F_SETLK - F_SETLKW would cause a deadlock! */ - if ((fcntl(fd, F_SETLK, &lck) < 0) && errno != EACCESS) { - close(fd); - return; /* failed for unknown reason: give up */ - } - write(fd, putmp, sizeof(struct utmp)); - -/* unlocking the file */ - lck.l_type = F_UNLCK; - fcntl(fd, F_SETLK, &lck); - - close(fd); -} - -#endif /* WTMP_SUPPORT */ -#endif /* !HAVE_UTMPX_H */ -/* ------------------------------------------------------------------------- */ -#ifdef UTMP_SUPPORT /* * make a utmp entry */ /* PROTO */ void -makeutent(const char *pty, const char *hostname) +makeutent(const char *pty, const char *hostname, int fd) { - - struct passwd *pwent = getpwuid(getuid()); - UTMP utmp; - -#ifndef USE_SYSV_UTMP -/* - * BSD style utmp entry - * ut_line, ut_name, ut_host, ut_time - */ - int rval = 0, i; - FILE *fd0, *fd1; - char buf[256], name[256]; - -#else -/* - * SYSV style utmp entry - * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time - */ - char *colon; - -#endif /* !USE_SYSV_UTMP */ - -/* BSD naming is of the form /dev/tty?? or /dev/pty?? */ - - rmemset(&utmp, 0, sizeof(UTMP)); - if (!strncmp(pty, "/dev/", 5)) - pty += 5; /* skip /dev/ prefix */ - if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3)) - strncpy(ut_id, (pty + 3), sizeof(ut_id)); - else -#ifndef USE_SYSV_UTMP - { - print_error("can't parse tty name \"%s\"", pty); - ut_id[0] = '\0'; /* entry not made */ - return; - } - - strncpy(utmp.ut_line, pty, sizeof(utmp.ut_line)); - strncpy(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", - sizeof(utmp.ut_name)); - strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host)); - utmp.ut_time = time(NULL); - - if ((fd0 = fopen(UTMP_FILENAME, "r+")) == NULL) - ut_id[0] = '\0'; /* entry not made */ - else { - utmp_pos = -1; - if ((fd1 = fopen(TTYTAB_FILENAME, "r")) != NULL) { - for (i = 1; (fgets(buf, sizeof(buf), fd1) != NULL); i++) { - if (*buf == '#' || sscanf(buf, "%s", name) != 1) - continue; - if (!strcmp(utmp.ut_line, name)) { - fclose(fd1); - utmp_pos = i * sizeof(struct utmp); - - break; - } - } - fclose(fd1); - } - if (utmp_pos < 0) - ut_id[0] = '\0'; /* entry not made */ - else { - fseek(fd0, utmp_pos, 0); - fwrite(&utmp, sizeof(UTMP), 1, fd0); - rval = 1; - } - fclose(fd0); - } - -#else /* USE_SYSV_UTMP */ - { - int n; - - if (sscanf(pty, "pts/%d", &n) == 1) - sprintf(ut_id, "vt%02x", (n % 256)); /* sysv naming */ - else { - print_error("can't parse tty name \"%s\"", pty); - ut_id[0] = '\0'; /* entry not made */ - return; - } - } - - utmpname(UTMP_FILENAME); - - setutent(); /* XXX: should be unnecessaray */ - - strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id)); - utmp.ut_type = DEAD_PROCESS; - (void)getutid(&utmp); /* position to entry in utmp file */ - -/* set up the new entry */ - utmp.ut_type = USER_PROCESS; -#ifndef linux - utmp.ut_exit.e_exit = 2; -#endif - strncpy(utmp.ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", - sizeof(utmp.ut_user)); - strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id)); - strncpy(utmp.ut_line, pty, sizeof(utmp.ut_line)); - -#ifdef HAVE_UTMP_HOST - strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host)); -#ifndef linux - if ((colon = strrchr(utmp.ut_host, ':')) != NULL) - *colon = '\0'; -#endif -#endif /* HAVE_UTMP_HOST */ - -/* ut_name is normally the same as ut_user, but .... */ - strncpy(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", - sizeof(utmp.ut_name)); - - utmp.ut_pid = getpid(); - -#ifdef HAVE_UTMPX_H - utmp.ut_session = getsid(0); - utmp.ut_tv.tv_sec = time(NULL); - utmp.ut_tv.tv_usec = 0; -#else - utmp.ut_time = time(NULL); -#endif /* HAVE_UTMPX_H */ - - pututline(&utmp); - -#ifdef WTMP_SUPPORT - update_wtmp(WTMP_FILENAME, &utmp); -#endif - - endutent(); /* close the file */ -#endif /* !USE_SYSV_UTMP */ + addToUtmp(pty, hostname, fd); } -#endif /* UTMP_SUPPORT */ /* ------------------------------------------------------------------------- */ -#ifdef UTMP_SUPPORT /* * remove a utmp entry */ @@ -234,52 +61,5 @@ void cleanutent(void) { - UTMP utmp; - -#ifndef USE_SYSV_UTMP - FILE *fd; - - if (ut_id[0] && ((fd = fopen(UTMP_FILENAME, "r+")) != NULL)) { - rmemset(&utmp, 0, sizeof(struct utmp)); - - fseek(fd, utmp_pos, 0); - fwrite(&utmp, sizeof(struct utmp), 1, fd); - - fclose(fd); - } -#else /* USE_SYSV_UTMP */ - UTMP *putmp; - - if (!ut_id[0]) - return; /* entry not made */ - - utmpname(UTMP_FILENAME); - rmemset(&utmp, 0, sizeof(UTMP)); - strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id)); - utmp.ut_type = USER_PROCESS; - - setutent(); /* XXX: should be unnecessaray */ - - putmp = getutid(&utmp); - if (!putmp || putmp->ut_pid != getpid()) - return; - - putmp->ut_type = DEAD_PROCESS; - -#ifdef HAVE_UTMPX_H - putmp->ut_session = getsid(0); - putmp->ut_tv.tv_sec = time(NULL); - putmp->ut_tv.tv_usec = 0; -#else /* HAVE_UTMPX_H */ - putmp->ut_time = time(NULL); -#endif /* HAVE_UTMPX_H */ - pututline(putmp); - -#ifdef WTMP_SUPPORT - update_wtmp(WTMP_FILENAME, putmp); -#endif - - endutent(); -#endif /* !USE_SYSV_UTMP */ + removeFromUtmp(); } -#endif --- AfterStep-APPS-990329/xiterm-2.0/src/command.c.xiutmp Fri Sep 25 04:12:13 1998 +++ AfterStep-APPS-990329/xiterm-2.0/src/command.c Mon Mar 29 18:40:33 1999 @@ -1031,7 +1031,7 @@ #ifdef UTMP_SUPPORT privileges(RESTORE); if (!(Options & Opt_utmpInhibit)) - makeutent(ttydev, display_name); /* stamp /etc/utmp */ + makeutent(ttydev, display_name, ptyfd); /* stamp /etc/utmp */ privileges(IGNORE); #endif --- AfterStep-APPS-990329/xiterm-2.0/configure.xiutmp Fri Sep 25 11:24:03 1998 +++ AfterStep-APPS-990329/xiterm-2.0/configure Mon Mar 29 18:40:33 1999 @@ -1803,49 +1803,6 @@ echo "$ac_t""no" 1>&6 fi - if test $ac_cv_func_connect = no; then - echo $ac_n "checking for connect in -lsocket""... $ac_c" 1>&6 -echo "configure:1809: checking for connect in -lsocket" >&5 -ac_lib_var=`echo socket'_'connect | sed 'y%./+-%__p_%'` -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - ac_save_LIBS="$LIBS" -LIBS="-lsocket $X_EXTRA_LIBS $LIBS" -cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=yes" -else - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - eval "ac_cv_lib_$ac_lib_var=no" -fi -rm -f conftest* -LIBS="$ac_save_LIBS" - -fi -if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then - echo "$ac_t""yes" 1>&6 - X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS" -else - echo "$ac_t""no" 1>&6 -fi - - fi - # gomez@mi.uni-erlangen.de says -lposix is necessary on A/UX. echo $ac_n "checking for remove""... $ac_c" 1>&6 echo "configure:1852: checking for remove" >&5