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.15 by root, Wed Feb 16 21:21:43 2005 UTC vs.
Revision 1.21 by root, Sat Jan 14 10:17:40 2006 UTC

37 * 37 *
38 * Private: 38 * Private:
39 * rxvt_update_wtmp (); 39 * rxvt_update_wtmp ();
40 *----------------------------------------------------------------------*/ 40 *----------------------------------------------------------------------*/
41 41
42#include "../config.h" /* NECESSARY */ 42#include "../config.h"
43#include "rxvt.h" /* NECESSARY */ 43#include "rxvt.h"
44#include "logging.h" 44#include "logging.h"
45
45#ifdef UTMP_SUPPORT 46#ifdef UTMP_SUPPORT
46 47
48#if HAVE_STRUCT_UTMP
47int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); 49int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu);
48void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); 50void rxvt_update_wtmp (const char *fname, const struct utmp *putmp);
51#endif
52
49void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); 53void rxvt_update_lastlog (const char *fname, const char *pty, const char *host);
50 54
51/* 55/*
52 * BSD style utmp entry 56 * BSD style utmp entry
53 * ut_line, ut_name, ut_host, ut_time 57 * ut_line, ut_name, ut_host, ut_time
70 struct utmpx *utx = &this->utx; 74 struct utmpx *utx = &this->utx;
71#endif 75#endif
72#ifdef HAVE_UTMP_PID 76#ifdef HAVE_UTMP_PID
73 int i; 77 int i;
74#endif 78#endif
75 struct passwd *pwent = getpwuid (getuid ()); 79 struct passwd *pwent = getpwuid (getuid ());
76 80
77 if (!strncmp (pty, "/dev/", 5)) 81 if (!strncmp (pty, "/dev/", 5))
78 pty += 5; /* skip /dev/ prefix */ 82 pty += 5; /* skip /dev/ prefix */
79 83
80#ifdef HAVE_UTMP_PID 84#ifdef HAVE_UTMP_PID
94# ifdef HAVE_UTMP_PID 98# ifdef HAVE_UTMP_PID
95 setutent (); 99 setutent ();
96 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); 100 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id));
97 ut->ut_type = DEAD_PROCESS; 101 ut->ut_type = DEAD_PROCESS;
98 getutid (ut); /* position to entry in utmp file */ 102 getutid (ut); /* position to entry in utmp file */
99 strncpy (ut_id, ut_id, sizeof (ut_id)); 103 strncpy (this->ut_id, ut_id, sizeof (this->ut_id));
100# endif 104# endif
101#endif 105#endif
102 106
103#ifdef HAVE_STRUCT_UTMPX 107#ifdef HAVE_STRUCT_UTMPX
104 memset (utx, 0, sizeof (struct utmpx)); 108 memset (utx, 0, sizeof (struct utmpx));
105 setutxent (); 109 setutxent ();
106 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 110 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id));
107 utx->ut_type = DEAD_PROCESS; 111 utx->ut_type = DEAD_PROCESS;
108 getutxid (utx); /* position to entry in utmp file */ 112 getutxid (utx); /* position to entry in utmp file */
109 strncpy (ut_id, ut_id, sizeof (ut_id)); 113 strncpy (this->ut_id, ut_id, sizeof (this->ut_id));
110#endif 114#endif
111 115
112#ifdef HAVE_STRUCT_UTMP 116#ifdef HAVE_STRUCT_UTMP
113 strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); 117 strncpy (ut->ut_line, pty, sizeof (ut->ut_line));
114 ut->ut_time = time (NULL); 118 ut->ut_time = time (NULL);
173# else 177# else
174 FILE *fd0; 178 FILE *fd0;
175 179
176 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) 180 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL)
177 { 181 {
178 char buf[256], name[256]; 182 char buf[256], name[256];
179 183
180 buf[sizeof (buf) - 1] = '\0'; 184 buf[sizeof (buf) - 1] = '\0';
181 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) 185 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);)
182 { 186 {
183 if (*buf == '#' || sscanf (buf, "%s", name) != 1) 187 if (*buf == '#' || sscanf (buf, "%s", name) != 1)
199 } 203 }
200#endif 204#endif
201 205
202#ifdef WTMP_SUPPORT 206#ifdef WTMP_SUPPORT
203# ifdef WTMP_ONLY_ON_LOGIN 207# ifdef WTMP_ONLY_ON_LOGIN
204 if (options & Opt_loginShell) 208 if (OPTION (Opt_loginShell))
205# endif 209# endif
206 { 210 {
207# ifdef HAVE_STRUCT_UTMP 211# ifdef HAVE_STRUCT_UTMP
208# ifdef HAVE_UPDWTMP 212# ifdef HAVE_UPDWTMP
209 updwtmp (RXVT_WTMP_FILE, ut); 213 updwtmp (RXVT_WTMP_FILE, ut);
212# endif 216# endif
213# endif 217# endif
214# ifdef HAVE_STRUCT_UTMPX 218# ifdef HAVE_STRUCT_UTMPX
215# if HAVE_UPDWTMPX 219# if HAVE_UPDWTMPX
216 updwtmpx (RXVT_WTMPX_FILE, utx); 220 updwtmpx (RXVT_WTMPX_FILE, utx);
221# else
222 pututxline (utx);
217# endif 223# endif
218# endif 224# endif
219 } 225 }
220#endif 226#endif
221#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) 227#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE)
222 if (options & Opt_loginShell) 228 if (OPTION (Opt_loginShell))
223 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); 229 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname);
224#endif 230#endif
225} 231}
226 232
227/* ------------------------------------------------------------------------- */ 233/* ------------------------------------------------------------------------- */
240 246
241#ifdef HAVE_STRUCT_UTMP 247#ifdef HAVE_STRUCT_UTMP
242# ifdef HAVE_UTMP_PID 248# ifdef HAVE_UTMP_PID
243 memset (ut, 0, sizeof (struct utmp)); 249 memset (ut, 0, sizeof (struct utmp));
244 setutent (); 250 setutent ();
245 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); 251 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id));
246 ut->ut_type = USER_PROCESS; 252 ut->ut_type = USER_PROCESS;
247 { 253 {
248 struct utmp *tmput = getutid (ut); 254 struct utmp *tmput = getutid (ut);
249 255
250 if (tmput) /* position to entry in utmp file */ 256 if (tmput) /* position to entry in utmp file */
261#endif 267#endif
262 268
263#ifdef HAVE_STRUCT_UTMPX 269#ifdef HAVE_STRUCT_UTMPX
264 memset (utx, 0, sizeof (struct utmpx)); 270 memset (utx, 0, sizeof (struct utmpx));
265 setutxent (); 271 setutxent ();
266 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 272 strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id));
267 utx->ut_type = USER_PROCESS; 273 utx->ut_type = USER_PROCESS;
268 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ 274 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */
269 utx = tmputx; 275 utx = tmputx;
270 utx->ut_type = DEAD_PROCESS; 276 utx->ut_type = DEAD_PROCESS;
271# if HAVE_UTMPX_SESSION 277# if HAVE_UTMPX_SESSION
278 /* 284 /*
279 * Write ending wtmp entry 285 * Write ending wtmp entry
280 */ 286 */
281#ifdef WTMP_SUPPORT 287#ifdef WTMP_SUPPORT
282# ifdef WTMP_ONLY_ON_LOGIN 288# ifdef WTMP_ONLY_ON_LOGIN
283 if (options & Opt_loginShell) 289 if (OPTION (Opt_loginShell))
284# endif 290# endif
285 { 291 {
286# ifdef HAVE_STRUCT_UTMP 292# ifdef HAVE_STRUCT_UTMP
287# ifdef HAVE_UPDWTMP 293# ifdef HAVE_UPDWTMP
288 updwtmp (RXVT_WTMP_FILE, ut); 294 updwtmp (RXVT_WTMP_FILE, ut);
291# endif 297# endif
292# endif 298# endif
293# ifdef HAVE_STRUCT_UTMPX 299# ifdef HAVE_STRUCT_UTMPX
294# if HAVE_UPDWTMPX 300# if HAVE_UPDWTMPX
295 updwtmpx (RXVT_WTMPX_FILE, utx); 301 updwtmpx (RXVT_WTMPX_FILE, utx);
302# else
303 pututxline (utx);
296# endif 304# endif
297# endif 305# endif
298 } 306 }
299#endif 307#endif
300 308
321/* ------------------------------------------------------------------------- */ 329/* ------------------------------------------------------------------------- */
322/* 330/*
323 * Write a BSD style utmp entry 331 * Write a BSD style utmp entry
324 */ 332 */
325#ifdef HAVE_UTMP_H 333#ifdef HAVE_UTMP_H
326/* INTPROTO */
327int 334int
328rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) 335rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu)
329{ 336{
330 int fd; 337 int fd;
331 338
341 348
342/* ------------------------------------------------------------------------- */ 349/* ------------------------------------------------------------------------- */
343/* 350/*
344 * Update a BSD style wtmp entry 351 * Update a BSD style wtmp entry
345 */ 352 */
346#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) 353#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
347/* INTPROTO */
348void 354void
349rxvt_update_wtmp (const char *fname, const struct utmp *putmp) 355rxvt_update_wtmp (const char *fname, const struct utmp *putmp)
350{ 356{
351 int fd, gotlock, retry; 357 int fd, gotlock, retry;
352 struct flock lck; /* fcntl locking scheme */ 358 struct flock lck; /* fcntl locking scheme */
384} 390}
385#endif 391#endif
386 392
387/* ------------------------------------------------------------------------- */ 393/* ------------------------------------------------------------------------- */
388#ifdef LASTLOG_SUPPORT 394#ifdef LASTLOG_SUPPORT
389/* INTPROTO */
390void 395void
391rxvt_update_lastlog (const char *fname, const char *pty, const char *host) 396rxvt_update_lastlog (const char *fname, const char *pty, const char *host)
392{ 397{
393# ifdef HAVE_STRUCT_LASTLOGX 398# ifdef HAVE_STRUCT_LASTLOGX
394 struct lastlogx llx; 399 struct lastlogx llx;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines