--- rxvt-unicode/src/logging.C 2004/08/15 22:09:24 1.11 +++ rxvt-unicode/src/logging.C 2006/01/14 10:17:40 1.21 @@ -39,11 +39,19 @@ * rxvt_update_wtmp (); *----------------------------------------------------------------------*/ -#include "../config.h" /* NECESSARY */ -#include "rxvt.h" /* NECESSARY */ +#include "../config.h" +#include "rxvt.h" #include "logging.h" + #ifdef UTMP_SUPPORT +#if HAVE_STRUCT_UTMP +int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); +void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); +#endif + +void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); + /* * BSD style utmp entry * ut_line, ut_name, ut_host, ut_time @@ -60,33 +68,30 @@ rxvt_term::makeutent (const char *pty, const char *hostname) { #ifdef HAVE_STRUCT_UTMP - struct utmp *ut = & (this->ut); + struct utmp *ut = &this->ut; #endif #ifdef HAVE_STRUCT_UTMPX - struct utmpx *utx = & (this->utx); + struct utmpx *utx = &this->utx; #endif #ifdef HAVE_UTMP_PID - int i; + int i; #endif - char ut_id[5]; - struct passwd *pwent = getpwuid (getuid ()); + struct passwd *pwent = getpwuid (getuid ()); 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)); - } #ifdef HAVE_UTMP_PID + if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) + strncpy (ut_id, pty + 3, sizeof (ut_id)); else if (sscanf (pty, "pts/%d", &i) == 1) sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ -#endif else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) { rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); return; } +#endif #ifdef HAVE_STRUCT_UTMP memset (ut, 0, sizeof (struct utmp)); @@ -95,7 +100,7 @@ strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); ut->ut_type = DEAD_PROCESS; getutid (ut); /* position to entry in utmp file */ - strncpy (ut_id, ut_id, sizeof (ut_id)); + strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); # endif #endif @@ -105,7 +110,7 @@ strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); utx->ut_type = DEAD_PROCESS; getutxid (utx); /* position to entry in utmp file */ - strncpy (ut_id, ut_id, sizeof (ut_id)); + strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); #endif #ifdef HAVE_STRUCT_UTMP @@ -138,7 +143,9 @@ strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", sizeof (utx->ut_user)); strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); +# if HAVE_UTMPX_SESSION utx->ut_session = getsid (0); +# endif utx->ut_tv.tv_sec = time (NULL); utx->ut_tv.tv_usec = 0; utx->ut_pid = cmd_pid; @@ -172,7 +179,7 @@ if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) { - char buf[256], name[256]; + char buf[256], name[256]; buf[sizeof (buf) - 1] = '\0'; for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) @@ -198,7 +205,7 @@ #ifdef WTMP_SUPPORT # ifdef WTMP_ONLY_ON_LOGIN - if (options & Opt_loginShell) + if (OPTION (Opt_loginShell)) # endif { # ifdef HAVE_STRUCT_UTMP @@ -209,12 +216,16 @@ # endif # endif # ifdef HAVE_STRUCT_UTMPX +# if HAVE_UPDWTMPX updwtmpx (RXVT_WTMPX_FILE, utx); +# else + pututxline (utx); +# endif # endif } #endif #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) - if (options & Opt_loginShell) + if (OPTION (Opt_loginShell)) rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); #endif } @@ -227,17 +238,17 @@ rxvt_term::cleanutent () { #ifdef HAVE_STRUCT_UTMP - struct utmp *ut = & (this->ut); + struct utmp *ut = &this->ut; #endif #ifdef HAVE_STRUCT_UTMPX - struct utmpx *tmputx, *utx = & (this->utx); + struct utmpx *tmputx, *utx = &this->utx; #endif #ifdef HAVE_STRUCT_UTMP # ifdef HAVE_UTMP_PID memset (ut, 0, sizeof (struct utmp)); setutent (); - strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); + strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); ut->ut_type = USER_PROCESS; { struct utmp *tmput = getutid (ut); @@ -258,12 +269,14 @@ #ifdef HAVE_STRUCT_UTMPX memset (utx, 0, sizeof (struct utmpx)); setutxent (); - strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); + strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id)); utx->ut_type = USER_PROCESS; if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ utx = tmputx; utx->ut_type = DEAD_PROCESS; +# if HAVE_UTMPX_SESSION utx->ut_session = getsid (0); +# endif utx->ut_tv.tv_sec = time (NULL); utx->ut_tv.tv_usec = 0; #endif @@ -273,7 +286,7 @@ */ #ifdef WTMP_SUPPORT # ifdef WTMP_ONLY_ON_LOGIN - if (options & Opt_loginShell) + if (OPTION (Opt_loginShell)) # endif { # ifdef HAVE_STRUCT_UTMP @@ -284,7 +297,11 @@ # endif # endif # ifdef HAVE_STRUCT_UTMPX +# if HAVE_UPDWTMPX updwtmpx (RXVT_WTMPX_FILE, utx); +# else + pututxline (utx); +# endif # endif } #endif @@ -314,7 +331,6 @@ * Write a BSD style utmp entry */ #ifdef HAVE_UTMP_H -/* INTPROTO */ int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) { @@ -334,8 +350,7 @@ /* * Update a BSD style wtmp entry */ -#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) -/* INTPROTO */ +#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) void rxvt_update_wtmp (const char *fname, const struct utmp *putmp) { @@ -377,7 +392,6 @@ /* ------------------------------------------------------------------------- */ #ifdef LASTLOG_SUPPORT -/* INTPROTO */ void rxvt_update_lastlog (const char *fname, const char *pty, const char *host) {