File kterm-6.2.0-utempter.patch of Package kterm
--- kterm-6.2.0/Imakefile.utempter Fri Jul 12 07:01:04 1996
+++ kterm-6.2.0/Imakefile Thu Jan 31 13:38:41 2002
@@ -23,6 +23,7 @@
PUCCPTYDDEF = -DPUCC_PTYD /* does not need to be setuid */
PTYLIB = -lpucc
#endif
+ PTYLIB = -lutempter
OSMAJORVERSION = OSMajorVersion
OSMINORVERSION = OSMinorVersion
--- kterm-6.2.0/main.c.utempter Thu Jan 31 13:38:41 2002
+++ kterm-6.2.0/main.c Thu Jan 31 13:44:21 2002
@@ -2930,189 +2930,6 @@
#endif
#endif /* !USE_SYSV_PGRP */
-#ifdef UTMP
- pw = getpwuid(screen->uid);
- if (pw && pw->pw_name)
- Setenv ("LOGNAME=", pw->pw_name); /* for POSIX */
-#ifdef USE_SYSV_UTMP
- /* Set up our utmp entry now. We need to do it here
- ** for the following reasons:
- ** - It needs to have our correct process id (for
- ** login).
- ** - If our parent was to set it after the fork(),
- ** it might make it out before we need it.
- ** - We need to do it before we go and change our
- ** user and group id's.
- */
-#ifdef CRAY
-#define PTYCHARLEN 4
-#else
-#ifdef __osf__
-#define PTYCHARLEN 5
-#else
-#define PTYCHARLEN 2
-#endif
-#endif
-
- (void) setutent ();
- /* set up entry to search for */
- ptyname = ttydev;
-#ifndef __sgi
- if (PTYCHARLEN >= (int)strlen(ptyname))
- ptynameptr = ptyname;
- else
- ptynameptr = ptyname + strlen(ptyname) - PTYCHARLEN;
- (void) strncpy(utmp.ut_id, ptynameptr, sizeof (utmp.ut_id));
-#else
- (void) strncpy(utmp.ut_id,ptyname + sizeof("/dev/tty")-1,
- sizeof (utmp.ut_id));
-
-#endif
- utmp.ut_type = DEAD_PROCESS;
-
- /* position to entry in utmp file */
- (void) getutid(&utmp);
-
- /* set up the new entry */
- utmp.ut_type = USER_PROCESS;
-#if !(defined(linux) && (!defined(__GLIBC__) || (__GLIBC__ < 2))) && !defined(SVR4)
- utmp.ut_exit.e_exit = 2;
-#endif
- (void) strncpy(utmp.ut_user,
- (pw && pw->pw_name) ? pw->pw_name : "????",
- sizeof(utmp.ut_user));
-
-#ifndef __sgi
- (void)strncpy(utmp.ut_id, ptynameptr, sizeof(utmp.ut_id));
-#else
- (void) strncpy(utmp.ut_id,ptyname + sizeof("/dev/tty")-1,
- sizeof (utmp.ut_id));
-#endif
- (void) strncpy (utmp.ut_line,
- ptyname + strlen("/dev/"), sizeof (utmp.ut_line));
-
-#ifdef HAS_UTMP_UT_HOST
- (void) strncpy(buf, DisplayString(screen->display),
- sizeof(buf));
-#ifndef linux
- {
- char *disfin = strrchr(buf, ':');
- if (disfin)
- *disfin = '\0';
- }
-#endif
- (void) strncpy(utmp.ut_host, buf, sizeof(utmp.ut_host));
-#endif
- (void) strncpy(utmp.ut_name, pw->pw_name,
- sizeof(utmp.ut_name));
-
- utmp.ut_pid = getpid();
-#if defined(SVR4) || defined(SCO325) || (defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2))
- utmp.ut_session = getsid(0);
- utmp.ut_xtime = time ((Time_t *) 0);
- utmp.ut_tv.tv_usec = 0;
-#else
- utmp.ut_time = time ((Time_t *) 0);
-#endif
-
- /* write out the entry */
- if (!resource.utmpInhibit)
- (void) pututline(&utmp);
-#ifdef WTMP
-#if defined(SVR4) || defined(SCO325)
- if (term->misc.login_shell)
- updwtmpx(WTMPX_FILE, &utmp);
-#elif defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2)
- if (term->misc.login_shell)
- updwtmp(etc_wtmp, &utmp);
-#else
- if (term->misc.login_shell &&
- (i = open(etc_wtmp, O_WRONLY|O_APPEND)) >= 0) {
- write(i, (char *)&utmp, sizeof(struct utmp));
- close(i);
- }
-#endif
-#endif
- /* close the file */
- (void) endutent();
-
-#else /* USE_SYSV_UTMP */
- /* We can now get our ttyslot! We can also set the initial
- * UTMP entry.
- */
- tslot = ttyslot();
- added_utmp_entry = False;
- {
- if (pw && !resource.utmpInhibit &&
- (i = open(etc_utmp, O_WRONLY)) >= 0) {
- bzero((char *)&utmp, sizeof(struct utmp));
- (void) strncpy(utmp.ut_line,
- ttydev + strlen("/dev/"),
- sizeof(utmp.ut_line));
- (void) strncpy(utmp.ut_name, pw->pw_name,
- sizeof(utmp.ut_name));
-#ifdef HAS_UTMP_UT_HOST
- (void) strncpy(utmp.ut_host,
- XDisplayString (screen->display),
- sizeof(utmp.ut_host));
-#endif
- /* cast needed on Ultrix 4.4 */
- time((Time_t*)&utmp.ut_time);
- lseek(i, (long)(tslot * sizeof(struct utmp)), 0);
- write(i, (char *)&utmp, sizeof(struct utmp));
- close(i);
- added_utmp_entry = True;
-#ifdef WTMP
- if (term->misc.login_shell &&
- (i = open(etc_wtmp, O_WRONLY|O_APPEND)) >= 0) {
- int status;
- status = write(i, (char *)&utmp,
- sizeof(struct utmp));
- status = close(i);
- }
-#endif /* WTMP */
-#ifdef LASTLOG
- if (term->misc.login_shell &&
- (i = open(etc_lastlog, O_WRONLY)) >= 0) {
- bzero((char *)&lastlog,
- sizeof (struct lastlog));
- (void) strncpy(lastlog.ll_line, ttydev +
- sizeof("/dev"),
- sizeof (lastlog.ll_line));
- (void) strncpy(lastlog.ll_host,
- XDisplayString (screen->display),
- sizeof (lastlog.ll_host));
- time(&lastlog.ll_time);
- lseek(i, (long)(screen->uid *
- sizeof (struct lastlog)), 0);
- write(i, (char *)&lastlog,
- sizeof (struct lastlog));
- close(i);
- }
-#endif /* LASTLOG */
- } else
- tslot = -tslot;
- }
-
- /* Let's pass our ttyslot to our parent so that it can
- * clean up after us.
- */
-#ifdef USE_HANDSHAKE
- handshake.tty_slot = tslot;
-#endif /* USE_HANDSHAKE */
-#endif /* USE_SYSV_UTMP */
-
-#ifdef USE_HANDSHAKE
- /* Let our parent know that we set up our utmp entry
- * so that it can clean up after us.
- */
- handshake.status = UTMP_ADDED;
- handshake.error = 0;
- strcpy(handshake.buffer, ttydev);
- (void)write(cp_pipe[1], (char *)&handshake, sizeof(handshake));
-#endif /* USE_HANDSHAKE */
-#endif/* UTMP */
-
(void) setgid (screen->gid);
#ifdef HAS_BSD_GROUPS
if (geteuid() == 0 && pw)
@@ -3361,6 +3178,8 @@
#endif /* USE_HANDSHAKE */
} /* end if no slave */
+ addToUtmp(ttydev, NULL, screen->respond);
+
/*
* still in parent (xterm process)
*/
@@ -3422,102 +3241,13 @@
{
register TScreen *screen = &term->screen;
int pty = term->screen.respond; /* file descriptor of pty */
-#ifdef UTMP
-#ifdef USE_SYSV_UTMP
-#ifdef SVR4
- struct utmpx utmp;
- struct utmpx *utptr;
-#else
- struct utmp utmp;
- struct utmp *utptr;
-#endif
- char* ptyname;
- char* ptynameptr;
-#if defined(WTMP) && !defined(SVR4) && !(defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2))
- int fd; /* for /etc/wtmp */
- int i;
-#endif
/* don't do this more than once */
if (xterm_exiting)
SIGNAL_RETURN;
xterm_exiting = True;
+ removeFromUtmp();
-#ifdef PUCC_PTYD
- closepty(ttydev, ptydev, (resource.utmpInhibit ? OPTY_NOP : OPTY_LOGIN), Ptyfd);
-#endif /* PUCC_PTYD */
-
- /* cleanup the utmp entry we forged earlier */
- if (!resource.utmpInhibit
-#ifdef USE_HANDSHAKE /* without handshake, no way to know */
- && added_utmp_entry
-#endif /* USE_HANDSHAKE */
- ) {
- ptyname = ttydev;
- utmp.ut_type = USER_PROCESS;
- if (PTYCHARLEN >= (int)strlen(ptyname))
- ptynameptr = ptyname;
- else
- ptynameptr = ptyname + strlen(ptyname) - PTYCHARLEN;
- (void) strncpy(utmp.ut_id, ptynameptr, sizeof(utmp.ut_id));
- (void) setutent();
- utptr = getutid(&utmp);
- /* write it out only if it exists, and the pid's match */
- if (utptr && (utptr->ut_pid == screen->pid)) {
- utptr->ut_type = DEAD_PROCESS;
-#if defined(SVR4) || defined(SCO325) || (defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2))
- utmp.ut_session = getsid(0);
- utmp.ut_xtime = time ((Time_t *) 0);
- utmp.ut_tv.tv_usec = 0;
-#else
- utptr->ut_time = time((Time_t *) 0);
-#endif
- (void) pututline(utptr);
-#ifdef WTMP
-#if defined(SVR4) || defined(SCO325)
- if (term->misc.login_shell)
- updwtmpx(WTMPX_FILE, utptr);
-#elif defined(linux) && defined(__GLIBC__) && (__GLIBC__ >= 2)
- strncpy (utmp.ut_line, utptr->ut_line, sizeof (utmp.ut_line));
- if (term->misc.login_shell)
- updwtmp(etc_wtmp, utptr);
-#else
- /* set wtmp entry if wtmp file exists */
- if (term->misc.login_shell &&
- (fd = open(etc_wtmp, O_WRONLY | O_APPEND)) >= 0) {
- i = write(fd, utptr, sizeof(*utptr));
- i = close(fd);
- }
-#endif
-#endif
-
- }
- (void) endutent();
- }
-#else /* not USE_SYSV_UTMP */
- register int wfd;
- register int i;
- struct utmp utmp;
-
- if (!resource.utmpInhibit && added_utmp_entry &&
- (!am_slave && tslot > 0 && (wfd = open(etc_utmp, O_WRONLY)) >= 0)){
- bzero((char *)&utmp, sizeof(struct utmp));
- lseek(wfd, (long)(tslot * sizeof(struct utmp)), 0);
- write(wfd, (char *)&utmp, sizeof(struct utmp));
- close(wfd);
-#ifdef WTMP
- if (term->misc.login_shell &&
- (wfd = open(etc_wtmp, O_WRONLY | O_APPEND)) >= 0) {
- (void) strncpy(utmp.ut_line, ttydev +
- sizeof("/dev"), sizeof (utmp.ut_line));
- time(&utmp.ut_time);
- i = write(wfd, (char *)&utmp, sizeof(struct utmp));
- i = close(wfd);
- }
-#endif /* WTMP */
- }
-#endif /* USE_SYSV_UTMP */
-#endif /* UTMP */
close(pty); /* close explicitly to avoid race with slave side */
#ifdef ALLOWLOGGING
if(screen->logging)