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.12 by root, Wed Jan 19 15:20:47 2005 UTC vs.
Revision 1.20 by root, Fri Jan 13 07:03:48 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
47
48#if HAVE_STRUCT_UTMP
49int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu);
50void rxvt_update_wtmp (const char *fname, const struct utmp *putmp);
51#endif
52
53void rxvt_update_lastlog (const char *fname, const char *pty, const char *host);
46 54
47/* 55/*
48 * BSD style utmp entry 56 * BSD style utmp entry
49 * ut_line, ut_name, ut_host, ut_time 57 * ut_line, ut_name, ut_host, ut_time
50 * SYSV style utmp (and utmpx) entry 58 * SYSV style utmp (and utmpx) entry
66 struct utmpx *utx = &this->utx; 74 struct utmpx *utx = &this->utx;
67#endif 75#endif
68#ifdef HAVE_UTMP_PID 76#ifdef HAVE_UTMP_PID
69 int i; 77 int i;
70#endif 78#endif
71 struct passwd *pwent = getpwuid (getuid ()); 79 struct passwd *pwent = getpwuid (getuid ());
72 80
73 if (!strncmp (pty, "/dev/", 5)) 81 if (!strncmp (pty, "/dev/", 5))
74 pty += 5; /* skip /dev/ prefix */ 82 pty += 5; /* skip /dev/ prefix */
75 83
84#ifdef HAVE_UTMP_PID
76 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) 85 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3))
77 strncpy (ut_id, (pty + 3), sizeof (ut_id)); 86 strncpy (ut_id, pty + 3, sizeof (ut_id));
78#ifdef HAVE_UTMP_PID
79 else if (sscanf (pty, "pts/%d", &i) == 1) 87 else if (sscanf (pty, "pts/%d", &i) == 1)
80 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ 88 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */
81#endif
82 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) 89 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3))
83 { 90 {
84 rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); 91 rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty);
85 return; 92 return;
86 } 93 }
94#endif
87 95
88#ifdef HAVE_STRUCT_UTMP 96#ifdef HAVE_STRUCT_UTMP
89 memset (ut, 0, sizeof (struct utmp)); 97 memset (ut, 0, sizeof (struct utmp));
90# ifdef HAVE_UTMP_PID 98# ifdef HAVE_UTMP_PID
91 setutent (); 99 setutent ();
133#ifdef HAVE_STRUCT_UTMPX 141#ifdef HAVE_STRUCT_UTMPX
134 strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); 142 strncpy (utx->ut_line, pty, sizeof (utx->ut_line));
135 strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", 143 strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
136 sizeof (utx->ut_user)); 144 sizeof (utx->ut_user));
137 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 145 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id));
146# if HAVE_UTMPX_SESSION
138 utx->ut_session = getsid (0); 147 utx->ut_session = getsid (0);
148# endif
139 utx->ut_tv.tv_sec = time (NULL); 149 utx->ut_tv.tv_sec = time (NULL);
140 utx->ut_tv.tv_usec = 0; 150 utx->ut_tv.tv_usec = 0;
141 utx->ut_pid = cmd_pid; 151 utx->ut_pid = cmd_pid;
142# ifdef HAVE_UTMPX_HOST 152# ifdef HAVE_UTMPX_HOST
143 strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); 153 strncpy (utx->ut_host, hostname, sizeof (utx->ut_host));
167# else 177# else
168 FILE *fd0; 178 FILE *fd0;
169 179
170 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) 180 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL)
171 { 181 {
172 char buf[256], name[256]; 182 char buf[256], name[256];
173 183
174 buf[sizeof (buf) - 1] = '\0'; 184 buf[sizeof (buf) - 1] = '\0';
175 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) 185 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);)
176 { 186 {
177 if (*buf == '#' || sscanf (buf, "%s", name) != 1) 187 if (*buf == '#' || sscanf (buf, "%s", name) != 1)
193 } 203 }
194#endif 204#endif
195 205
196#ifdef WTMP_SUPPORT 206#ifdef WTMP_SUPPORT
197# ifdef WTMP_ONLY_ON_LOGIN 207# ifdef WTMP_ONLY_ON_LOGIN
198 if (options & Opt_loginShell) 208 if (OPTION (Opt_loginShell))
199# endif 209# endif
200 { 210 {
201# ifdef HAVE_STRUCT_UTMP 211# ifdef HAVE_STRUCT_UTMP
202# ifdef HAVE_UPDWTMP 212# ifdef HAVE_UPDWTMP
203 updwtmp (RXVT_WTMP_FILE, ut); 213 updwtmp (RXVT_WTMP_FILE, ut);
204# else 214# else
205 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 215 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
206# endif 216# endif
207# endif 217# endif
208# ifdef HAVE_STRUCT_UTMPX 218# ifdef HAVE_STRUCT_UTMPX
219# if HAVE_UPDWTMPX
209 updwtmpx (RXVT_WTMPX_FILE, utx); 220 updwtmpx (RXVT_WTMPX_FILE, utx);
221# else
222 pututxline (utx);
223# endif
210# endif 224# endif
211 } 225 }
212#endif 226#endif
213#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) 227#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE)
214 if (options & Opt_loginShell) 228 if (OPTION (Opt_loginShell))
215 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); 229 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname);
216#endif 230#endif
217} 231}
218 232
219/* ------------------------------------------------------------------------- */ 233/* ------------------------------------------------------------------------- */
258 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 272 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id));
259 utx->ut_type = USER_PROCESS; 273 utx->ut_type = USER_PROCESS;
260 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ 274 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */
261 utx = tmputx; 275 utx = tmputx;
262 utx->ut_type = DEAD_PROCESS; 276 utx->ut_type = DEAD_PROCESS;
277# if HAVE_UTMPX_SESSION
263 utx->ut_session = getsid (0); 278 utx->ut_session = getsid (0);
279# endif
264 utx->ut_tv.tv_sec = time (NULL); 280 utx->ut_tv.tv_sec = time (NULL);
265 utx->ut_tv.tv_usec = 0; 281 utx->ut_tv.tv_usec = 0;
266#endif 282#endif
267 283
268 /* 284 /*
269 * Write ending wtmp entry 285 * Write ending wtmp entry
270 */ 286 */
271#ifdef WTMP_SUPPORT 287#ifdef WTMP_SUPPORT
272# ifdef WTMP_ONLY_ON_LOGIN 288# ifdef WTMP_ONLY_ON_LOGIN
273 if (options & Opt_loginShell) 289 if (OPTION (Opt_loginShell))
274# endif 290# endif
275 { 291 {
276# ifdef HAVE_STRUCT_UTMP 292# ifdef HAVE_STRUCT_UTMP
277# ifdef HAVE_UPDWTMP 293# ifdef HAVE_UPDWTMP
278 updwtmp (RXVT_WTMP_FILE, ut); 294 updwtmp (RXVT_WTMP_FILE, ut);
279# else 295# else
280 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 296 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
281# endif 297# endif
282# endif 298# endif
283# ifdef HAVE_STRUCT_UTMPX 299# ifdef HAVE_STRUCT_UTMPX
300# if HAVE_UPDWTMPX
284 updwtmpx (RXVT_WTMPX_FILE, utx); 301 updwtmpx (RXVT_WTMPX_FILE, utx);
302# else
303 pututxline (utx);
304# endif
285# endif 305# endif
286 } 306 }
287#endif 307#endif
288 308
289 /* 309 /*
309/* ------------------------------------------------------------------------- */ 329/* ------------------------------------------------------------------------- */
310/* 330/*
311 * Write a BSD style utmp entry 331 * Write a BSD style utmp entry
312 */ 332 */
313#ifdef HAVE_UTMP_H 333#ifdef HAVE_UTMP_H
314/* INTPROTO */
315int 334int
316rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) 335rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu)
317{ 336{
318 int fd; 337 int fd;
319 338
329 348
330/* ------------------------------------------------------------------------- */ 349/* ------------------------------------------------------------------------- */
331/* 350/*
332 * Update a BSD style wtmp entry 351 * Update a BSD style wtmp entry
333 */ 352 */
334#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) 353#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
335/* INTPROTO */
336void 354void
337rxvt_update_wtmp (const char *fname, const struct utmp *putmp) 355rxvt_update_wtmp (const char *fname, const struct utmp *putmp)
338{ 356{
339 int fd, gotlock, retry; 357 int fd, gotlock, retry;
340 struct flock lck; /* fcntl locking scheme */ 358 struct flock lck; /* fcntl locking scheme */
372} 390}
373#endif 391#endif
374 392
375/* ------------------------------------------------------------------------- */ 393/* ------------------------------------------------------------------------- */
376#ifdef LASTLOG_SUPPORT 394#ifdef LASTLOG_SUPPORT
377/* INTPROTO */
378void 395void
379rxvt_update_lastlog (const char *fname, const char *pty, const char *host) 396rxvt_update_lastlog (const char *fname, const char *pty, const char *host)
380{ 397{
381# ifdef HAVE_STRUCT_LASTLOGX 398# ifdef HAVE_STRUCT_LASTLOGX
382 struct lastlogx llx; 399 struct lastlogx llx;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines