--- rxvt-unicode/src/logging.C 2006/01/16 10:37:32 1.24 +++ rxvt-unicode/src/logging.C 2006/01/18 16:34:53 1.34 @@ -14,7 +14,7 @@ * - extensive modifications * Copyright (c) 1999 D J Hawkey Jr * - lastlog support - * Copyright (c) 2004 Marc Lehmann + * Copyright (c) 2004-2006 Marc Lehmann * * 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 @@ -30,20 +30,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *----------------------------------------------------------------------*/ -/*----------------------------------------------------------------------* - * Public: - * extern void cleanutent (void); - * extern void makeutent (const char * pty, const char * hostname); - * - * Private: - * rxvt_update_wtmp (); - *----------------------------------------------------------------------*/ #include "../config.h" #include "rxvt.h" -#include "logging.h" +#include "ptytty.h" -#ifdef UTMP_SUPPORT +#if UTMP_SUPPORT #if HAVE_STRUCT_UTMP static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); @@ -65,8 +57,16 @@ * make and write utmp and wtmp entries */ void -rxvt_term::makeutent (const char *pty, const char *hostname) +rxvt_ptytty_unix::login (int cmd_pid, bool login_shell, const char *hostname) { + const char *pty = name; + + if (!pty || !*pty) + return; + + this->cmd_pid = cmd_pid; + this->login_shell = login_shell; + #ifdef HAVE_STRUCT_UTMP struct utmp *ut = &this->ut; #endif @@ -165,14 +165,19 @@ #endif #if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) - { # ifdef HAVE_TTYSLOT + int fdstdin = dup (STDIN_FILENO); + dup2 (tty, STDIN_FILENO); + i = ttyslot (); if (rxvt_write_bsd_utmp (i, ut)) utmp_pos = i; + + dup2 (fdstdin, STDIN_FILENO); + close (fdstdin); # else - FILE *fd0; + FILE *fd0; if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) { @@ -200,9 +205,9 @@ #endif #ifdef WTMP_SUPPORT -# ifdef WTMP_ONLY_ON_LOGIN - if (OPTION (Opt_loginShell)) -# endif +#ifdef LOG_ONLY_ON_LOGIN + if (login_shell) +#endif { # ifdef HAVE_STRUCT_UTMP # ifdef HAVE_UPDWTMP @@ -217,7 +222,9 @@ } #endif #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) - if (OPTION (Opt_loginShell)) +#ifdef LOG_ONLY_ON_LOGIN + if (login_shell) +#endif rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); #endif } @@ -227,10 +234,13 @@ * remove utmp and wtmp entries */ void -rxvt_term::cleanutent () +rxvt_ptytty_unix::logout () { + if (!cmd_pid) + return; + #ifdef HAVE_STRUCT_UTMP - struct utmp *ut = &this->ut; + struct utmp *tmput, *ut = &this->ut; #endif #ifdef HAVE_STRUCT_UTMPX struct utmpx *tmputx, *utx = &this->utx; @@ -242,12 +252,8 @@ setutent (); strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); ut->ut_type = USER_PROCESS; - { - struct utmp *tmput = getutid (ut); - - if (tmput) /* position to entry in utmp file */ - ut = tmput; - } + if ((tmput = getutid (ut))) /* position to entry in utmp file */ + ut = tmput; ut->ut_type = DEAD_PROCESS; # else memset (ut->ut_name, 0, sizeof (ut->ut_name)); @@ -277,9 +283,9 @@ * Write ending wtmp entry */ #ifdef WTMP_SUPPORT -# ifdef WTMP_ONLY_ON_LOGIN - if (OPTION (Opt_loginShell)) -# endif +#ifdef LOG_ONLY_ON_LOGIN + if (login_shell) +#endif { # ifdef HAVE_STRUCT_UTMP # ifdef HAVE_UPDWTMP @@ -312,6 +318,8 @@ pututxline (utx); endutxent (); #endif + + cmd_pid = 0; } /* ------------------------------------------------------------------------- */