ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/logging.C
(Generate patch)

Comparing rxvt-unicode/src/logging.C (file contents):
Revision 1.20 by root, Fri Jan 13 07:03:48 2006 UTC vs.
Revision 1.23 by root, Mon Jan 16 09:10:16 2006 UTC

44#include "logging.h" 44#include "logging.h"
45 45
46#ifdef UTMP_SUPPORT 46#ifdef UTMP_SUPPORT
47 47
48#if HAVE_STRUCT_UTMP 48#if HAVE_STRUCT_UTMP
49int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); 49static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu);
50void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); 50static void rxvt_update_wtmp (const char *fname, const struct utmp *putmp);
51#endif 51#endif
52 52
53void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); 53static void rxvt_update_lastlog (const char *fname, const char *pty, const char *host);
54 54
55/* 55/*
56 * BSD style utmp entry 56 * BSD style utmp entry
57 * ut_line, ut_name, ut_host, ut_time 57 * ut_line, ut_name, ut_host, ut_time
58 * SYSV style utmp (and utmpx) entry 58 * SYSV style utmp (and utmpx) entry
71 struct utmp *ut = &this->ut; 71 struct utmp *ut = &this->ut;
72#endif 72#endif
73#ifdef HAVE_STRUCT_UTMPX 73#ifdef HAVE_STRUCT_UTMPX
74 struct utmpx *utx = &this->utx; 74 struct utmpx *utx = &this->utx;
75#endif 75#endif
76#ifdef HAVE_UTMP_PID
77 int i; 76 int i;
78#endif
79 struct passwd *pwent = getpwuid (getuid ()); 77 struct passwd *pwent = getpwuid (getuid ());
80 78
81 if (!strncmp (pty, "/dev/", 5)) 79 if (!strncmp (pty, "/dev/", 5))
82 pty += 5; /* skip /dev/ prefix */ 80 pty += 5; /* skip /dev/ prefix */
83 81
84#ifdef HAVE_UTMP_PID 82#if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX)
85 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) 83 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3))
86 strncpy (ut_id, pty + 3, sizeof (ut_id)); 84 strncpy (ut_id, pty + 3, sizeof (ut_id));
87 else if (sscanf (pty, "pts/%d", &i) == 1) 85 else if (sscanf (pty, "pts/%d", &i) == 1)
88 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ 86 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */
89 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) 87 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3))
98# ifdef HAVE_UTMP_PID 96# ifdef HAVE_UTMP_PID
99 setutent (); 97 setutent ();
100 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); 98 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id));
101 ut->ut_type = DEAD_PROCESS; 99 ut->ut_type = DEAD_PROCESS;
102 getutid (ut); /* position to entry in utmp file */ 100 getutid (ut); /* position to entry in utmp file */
103 strncpy (ut_id, ut_id, sizeof (ut_id)); 101 strncpy (this->ut_id, ut_id, sizeof (this->ut_id));
104# endif 102# endif
105#endif 103#endif
106 104
107#ifdef HAVE_STRUCT_UTMPX 105#ifdef HAVE_STRUCT_UTMPX
108 memset (utx, 0, sizeof (struct utmpx)); 106 memset (utx, 0, sizeof (struct utmpx));
109 setutxent (); 107 setutxent ();
110 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 108 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id));
111 utx->ut_type = DEAD_PROCESS; 109 utx->ut_type = DEAD_PROCESS;
112 getutxid (utx); /* position to entry in utmp file */ 110 getutxid (utx); /* position to entry in utmp file */
113 strncpy (ut_id, ut_id, sizeof (ut_id)); 111 strncpy (this->ut_id, ut_id, sizeof (this->ut_id));
114#endif 112#endif
115 113
116#ifdef HAVE_STRUCT_UTMP 114#ifdef HAVE_STRUCT_UTMP
117 strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); 115 strncpy (ut->ut_line, pty, sizeof (ut->ut_line));
118 ut->ut_time = time (NULL); 116 ut->ut_time = time (NULL);
167#endif 165#endif
168 166
169#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) 167#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
170 168
171 { 169 {
172 int i;
173# ifdef HAVE_TTYSLOT 170# ifdef HAVE_TTYSLOT
174 i = ttyslot (); 171 i = ttyslot ();
175 if (rxvt_write_bsd_utmp (i, ut)) 172 if (rxvt_write_bsd_utmp (i, ut))
176 utmp_pos = i; 173 utmp_pos = i;
177# else 174# else
197 i++; 194 i++;
198 } 195 }
199 fclose (fd0); 196 fclose (fd0);
200 } 197 }
201# endif 198# endif
202
203 } 199 }
204#endif 200#endif
205 201
206#ifdef WTMP_SUPPORT 202#ifdef WTMP_SUPPORT
207# ifdef WTMP_ONLY_ON_LOGIN 203# ifdef WTMP_ONLY_ON_LOGIN
213 updwtmp (RXVT_WTMP_FILE, ut); 209 updwtmp (RXVT_WTMP_FILE, ut);
214# else 210# else
215 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 211 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
216# endif 212# endif
217# endif 213# endif
218# ifdef HAVE_STRUCT_UTMPX 214# if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX)
219# if HAVE_UPDWTMPX
220 updwtmpx (RXVT_WTMPX_FILE, utx); 215 updwtmpx (RXVT_WTMPX_FILE, utx);
221# else
222 pututxline (utx);
223# endif
224# endif 216# endif
225 } 217 }
226#endif 218#endif
227#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) 219#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE)
228 if (OPTION (Opt_loginShell)) 220 if (OPTION (Opt_loginShell))
246 238
247#ifdef HAVE_STRUCT_UTMP 239#ifdef HAVE_STRUCT_UTMP
248# ifdef HAVE_UTMP_PID 240# ifdef HAVE_UTMP_PID
249 memset (ut, 0, sizeof (struct utmp)); 241 memset (ut, 0, sizeof (struct utmp));
250 setutent (); 242 setutent ();
251 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); 243 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id));
252 ut->ut_type = USER_PROCESS; 244 ut->ut_type = USER_PROCESS;
253 { 245 {
254 struct utmp *tmput = getutid (ut); 246 struct utmp *tmput = getutid (ut);
255 247
256 if (tmput) /* position to entry in utmp file */ 248 if (tmput) /* position to entry in utmp file */
267#endif 259#endif
268 260
269#ifdef HAVE_STRUCT_UTMPX 261#ifdef HAVE_STRUCT_UTMPX
270 memset (utx, 0, sizeof (struct utmpx)); 262 memset (utx, 0, sizeof (struct utmpx));
271 setutxent (); 263 setutxent ();
272 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 264 strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id));
273 utx->ut_type = USER_PROCESS; 265 utx->ut_type = USER_PROCESS;
274 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ 266 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */
275 utx = tmputx; 267 utx = tmputx;
276 utx->ut_type = DEAD_PROCESS; 268 utx->ut_type = DEAD_PROCESS;
277# if HAVE_UTMPX_SESSION 269# if HAVE_UTMPX_SESSION
328 320
329/* ------------------------------------------------------------------------- */ 321/* ------------------------------------------------------------------------- */
330/* 322/*
331 * Write a BSD style utmp entry 323 * Write a BSD style utmp entry
332 */ 324 */
333#ifdef HAVE_UTMP_H 325#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
334int 326static int
335rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) 327rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu)
336{ 328{
337 int fd; 329 int fd;
338 330
339 if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1) 331 if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1)
349/* ------------------------------------------------------------------------- */ 341/* ------------------------------------------------------------------------- */
350/* 342/*
351 * Update a BSD style wtmp entry 343 * Update a BSD style wtmp entry
352 */ 344 */
353#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) 345#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
354void 346static void
355rxvt_update_wtmp (const char *fname, const struct utmp *putmp) 347rxvt_update_wtmp (const char *fname, const struct utmp *putmp)
356{ 348{
357 int fd, gotlock, retry; 349 int fd, gotlock, retry;
358 struct flock lck; /* fcntl locking scheme */ 350 struct flock lck; /* fcntl locking scheme */
359 struct stat sbuf; 351 struct stat sbuf;
390} 382}
391#endif 383#endif
392 384
393/* ------------------------------------------------------------------------- */ 385/* ------------------------------------------------------------------------- */
394#ifdef LASTLOG_SUPPORT 386#ifdef LASTLOG_SUPPORT
395void 387static void
396rxvt_update_lastlog (const char *fname, const char *pty, const char *host) 388rxvt_update_lastlog (const char *fname, const char *pty, const char *host)
397{ 389{
398# ifdef HAVE_STRUCT_LASTLOGX 390# ifdef HAVE_STRUCT_LASTLOGX
399 struct lastlogx llx; 391 struct lastlogx llx;
400# endif 392# endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines