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.11 by root, Sun Aug 15 22:09:24 2004 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
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
58 */ 66 */
59void 67void
60rxvt_term::makeutent (const char *pty, const char *hostname) 68rxvt_term::makeutent (const char *pty, const char *hostname)
61{ 69{
62#ifdef HAVE_STRUCT_UTMP 70#ifdef HAVE_STRUCT_UTMP
63 struct utmp *ut = & (this->ut); 71 struct utmp *ut = &this->ut;
64#endif 72#endif
65#ifdef HAVE_STRUCT_UTMPX 73#ifdef HAVE_STRUCT_UTMPX
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 char ut_id[5];
72 struct passwd *pwent = getpwuid (getuid ()); 79 struct passwd *pwent = getpwuid (getuid ());
73 80
74 if (!strncmp (pty, "/dev/", 5)) 81 if (!strncmp (pty, "/dev/", 5))
75 pty += 5; /* skip /dev/ prefix */ 82 pty += 5; /* skip /dev/ prefix */
76 83
84#ifdef HAVE_UTMP_PID
77 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) 85 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3))
78 {
79 strncpy (ut_id, (pty + 3), sizeof (ut_id)); 86 strncpy (ut_id, pty + 3, sizeof (ut_id));
80 }
81#ifdef HAVE_UTMP_PID
82 else if (sscanf (pty, "pts/%d", &i) == 1) 87 else if (sscanf (pty, "pts/%d", &i) == 1)
83 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ 88 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */
84#endif
85 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) 89 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3))
86 { 90 {
87 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);
88 return; 92 return;
89 } 93 }
94#endif
90 95
91#ifdef HAVE_STRUCT_UTMP 96#ifdef HAVE_STRUCT_UTMP
92 memset (ut, 0, sizeof (struct utmp)); 97 memset (ut, 0, sizeof (struct utmp));
93# ifdef HAVE_UTMP_PID 98# ifdef HAVE_UTMP_PID
94 setutent (); 99 setutent ();
95 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); 100 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id));
96 ut->ut_type = DEAD_PROCESS; 101 ut->ut_type = DEAD_PROCESS;
97 getutid (ut); /* position to entry in utmp file */ 102 getutid (ut); /* position to entry in utmp file */
98 strncpy (ut_id, ut_id, sizeof (ut_id)); 103 strncpy (this->ut_id, ut_id, sizeof (this->ut_id));
99# endif 104# endif
100#endif 105#endif
101 106
102#ifdef HAVE_STRUCT_UTMPX 107#ifdef HAVE_STRUCT_UTMPX
103 memset (utx, 0, sizeof (struct utmpx)); 108 memset (utx, 0, sizeof (struct utmpx));
104 setutxent (); 109 setutxent ();
105 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 110 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id));
106 utx->ut_type = DEAD_PROCESS; 111 utx->ut_type = DEAD_PROCESS;
107 getutxid (utx); /* position to entry in utmp file */ 112 getutxid (utx); /* position to entry in utmp file */
108 strncpy (ut_id, ut_id, sizeof (ut_id)); 113 strncpy (this->ut_id, ut_id, sizeof (this->ut_id));
109#endif 114#endif
110 115
111#ifdef HAVE_STRUCT_UTMP 116#ifdef HAVE_STRUCT_UTMP
112 strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); 117 strncpy (ut->ut_line, pty, sizeof (ut->ut_line));
113 ut->ut_time = time (NULL); 118 ut->ut_time = time (NULL);
136#ifdef HAVE_STRUCT_UTMPX 141#ifdef HAVE_STRUCT_UTMPX
137 strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); 142 strncpy (utx->ut_line, pty, sizeof (utx->ut_line));
138 strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", 143 strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
139 sizeof (utx->ut_user)); 144 sizeof (utx->ut_user));
140 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
141 utx->ut_session = getsid (0); 147 utx->ut_session = getsid (0);
148# endif
142 utx->ut_tv.tv_sec = time (NULL); 149 utx->ut_tv.tv_sec = time (NULL);
143 utx->ut_tv.tv_usec = 0; 150 utx->ut_tv.tv_usec = 0;
144 utx->ut_pid = cmd_pid; 151 utx->ut_pid = cmd_pid;
145# ifdef HAVE_UTMPX_HOST 152# ifdef HAVE_UTMPX_HOST
146 strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); 153 strncpy (utx->ut_host, hostname, sizeof (utx->ut_host));
170# else 177# else
171 FILE *fd0; 178 FILE *fd0;
172 179
173 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) 180 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL)
174 { 181 {
175 char buf[256], name[256]; 182 char buf[256], name[256];
176 183
177 buf[sizeof (buf) - 1] = '\0'; 184 buf[sizeof (buf) - 1] = '\0';
178 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) 185 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);)
179 { 186 {
180 if (*buf == '#' || sscanf (buf, "%s", name) != 1) 187 if (*buf == '#' || sscanf (buf, "%s", name) != 1)
196 } 203 }
197#endif 204#endif
198 205
199#ifdef WTMP_SUPPORT 206#ifdef WTMP_SUPPORT
200# ifdef WTMP_ONLY_ON_LOGIN 207# ifdef WTMP_ONLY_ON_LOGIN
201 if (options & Opt_loginShell) 208 if (OPTION (Opt_loginShell))
202# endif 209# endif
203 { 210 {
204# ifdef HAVE_STRUCT_UTMP 211# ifdef HAVE_STRUCT_UTMP
205# ifdef HAVE_UPDWTMP 212# ifdef HAVE_UPDWTMP
206 updwtmp (RXVT_WTMP_FILE, ut); 213 updwtmp (RXVT_WTMP_FILE, ut);
207# else 214# else
208 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 215 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
209# endif 216# endif
210# endif 217# endif
211# ifdef HAVE_STRUCT_UTMPX 218# ifdef HAVE_STRUCT_UTMPX
219# if HAVE_UPDWTMPX
212 updwtmpx (RXVT_WTMPX_FILE, utx); 220 updwtmpx (RXVT_WTMPX_FILE, utx);
221# else
222 pututxline (utx);
223# endif
213# endif 224# endif
214 } 225 }
215#endif 226#endif
216#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) 227#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE)
217 if (options & Opt_loginShell) 228 if (OPTION (Opt_loginShell))
218 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); 229 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname);
219#endif 230#endif
220} 231}
221 232
222/* ------------------------------------------------------------------------- */ 233/* ------------------------------------------------------------------------- */
225 */ 236 */
226void 237void
227rxvt_term::cleanutent () 238rxvt_term::cleanutent ()
228{ 239{
229#ifdef HAVE_STRUCT_UTMP 240#ifdef HAVE_STRUCT_UTMP
230 struct utmp *ut = & (this->ut); 241 struct utmp *ut = &this->ut;
231#endif 242#endif
232#ifdef HAVE_STRUCT_UTMPX 243#ifdef HAVE_STRUCT_UTMPX
233 struct utmpx *tmputx, *utx = & (this->utx); 244 struct utmpx *tmputx, *utx = &this->utx;
234#endif 245#endif
235 246
236#ifdef HAVE_STRUCT_UTMP 247#ifdef HAVE_STRUCT_UTMP
237# ifdef HAVE_UTMP_PID 248# ifdef HAVE_UTMP_PID
238 memset (ut, 0, sizeof (struct utmp)); 249 memset (ut, 0, sizeof (struct utmp));
239 setutent (); 250 setutent ();
240 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); 251 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id));
241 ut->ut_type = USER_PROCESS; 252 ut->ut_type = USER_PROCESS;
242 { 253 {
243 struct utmp *tmput = getutid (ut); 254 struct utmp *tmput = getutid (ut);
244 255
245 if (tmput) /* position to entry in utmp file */ 256 if (tmput) /* position to entry in utmp file */
256#endif 267#endif
257 268
258#ifdef HAVE_STRUCT_UTMPX 269#ifdef HAVE_STRUCT_UTMPX
259 memset (utx, 0, sizeof (struct utmpx)); 270 memset (utx, 0, sizeof (struct utmpx));
260 setutxent (); 271 setutxent ();
261 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 272 strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id));
262 utx->ut_type = USER_PROCESS; 273 utx->ut_type = USER_PROCESS;
263 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ 274 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */
264 utx = tmputx; 275 utx = tmputx;
265 utx->ut_type = DEAD_PROCESS; 276 utx->ut_type = DEAD_PROCESS;
277# if HAVE_UTMPX_SESSION
266 utx->ut_session = getsid (0); 278 utx->ut_session = getsid (0);
279# endif
267 utx->ut_tv.tv_sec = time (NULL); 280 utx->ut_tv.tv_sec = time (NULL);
268 utx->ut_tv.tv_usec = 0; 281 utx->ut_tv.tv_usec = 0;
269#endif 282#endif
270 283
271 /* 284 /*
272 * Write ending wtmp entry 285 * Write ending wtmp entry
273 */ 286 */
274#ifdef WTMP_SUPPORT 287#ifdef WTMP_SUPPORT
275# ifdef WTMP_ONLY_ON_LOGIN 288# ifdef WTMP_ONLY_ON_LOGIN
276 if (options & Opt_loginShell) 289 if (OPTION (Opt_loginShell))
277# endif 290# endif
278 { 291 {
279# ifdef HAVE_STRUCT_UTMP 292# ifdef HAVE_STRUCT_UTMP
280# ifdef HAVE_UPDWTMP 293# ifdef HAVE_UPDWTMP
281 updwtmp (RXVT_WTMP_FILE, ut); 294 updwtmp (RXVT_WTMP_FILE, ut);
282# else 295# else
283 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 296 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
284# endif 297# endif
285# endif 298# endif
286# ifdef HAVE_STRUCT_UTMPX 299# ifdef HAVE_STRUCT_UTMPX
300# if HAVE_UPDWTMPX
287 updwtmpx (RXVT_WTMPX_FILE, utx); 301 updwtmpx (RXVT_WTMPX_FILE, utx);
302# else
303 pututxline (utx);
304# endif
288# endif 305# endif
289 } 306 }
290#endif 307#endif
291 308
292 /* 309 /*
312/* ------------------------------------------------------------------------- */ 329/* ------------------------------------------------------------------------- */
313/* 330/*
314 * Write a BSD style utmp entry 331 * Write a BSD style utmp entry
315 */ 332 */
316#ifdef HAVE_UTMP_H 333#ifdef HAVE_UTMP_H
317/* INTPROTO */
318int 334int
319rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) 335rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu)
320{ 336{
321 int fd; 337 int fd;
322 338
332 348
333/* ------------------------------------------------------------------------- */ 349/* ------------------------------------------------------------------------- */
334/* 350/*
335 * Update a BSD style wtmp entry 351 * Update a BSD style wtmp entry
336 */ 352 */
337#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) 353#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
338/* INTPROTO */
339void 354void
340rxvt_update_wtmp (const char *fname, const struct utmp *putmp) 355rxvt_update_wtmp (const char *fname, const struct utmp *putmp)
341{ 356{
342 int fd, gotlock, retry; 357 int fd, gotlock, retry;
343 struct flock lck; /* fcntl locking scheme */ 358 struct flock lck; /* fcntl locking scheme */
375} 390}
376#endif 391#endif
377 392
378/* ------------------------------------------------------------------------- */ 393/* ------------------------------------------------------------------------- */
379#ifdef LASTLOG_SUPPORT 394#ifdef LASTLOG_SUPPORT
380/* INTPROTO */
381void 395void
382rxvt_update_lastlog (const char *fname, const char *pty, const char *host) 396rxvt_update_lastlog (const char *fname, const char *pty, const char *host)
383{ 397{
384# ifdef HAVE_STRUCT_LASTLOGX 398# ifdef HAVE_STRUCT_LASTLOGX
385 struct lastlogx llx; 399 struct lastlogx llx;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines