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.14 by root, Wed Feb 16 20:32:05 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);
137#ifdef HAVE_STRUCT_UTMPX 141#ifdef HAVE_STRUCT_UTMPX
138 strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); 142 strncpy (utx->ut_line, pty, sizeof (utx->ut_line));
139 strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", 143 strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
140 sizeof (utx->ut_user)); 144 sizeof (utx->ut_user));
141 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
142 utx->ut_session = getsid (0); 147 utx->ut_session = getsid (0);
148# endif
143 utx->ut_tv.tv_sec = time (NULL); 149 utx->ut_tv.tv_sec = time (NULL);
144 utx->ut_tv.tv_usec = 0; 150 utx->ut_tv.tv_usec = 0;
145 utx->ut_pid = cmd_pid; 151 utx->ut_pid = cmd_pid;
146# ifdef HAVE_UTMPX_HOST 152# ifdef HAVE_UTMPX_HOST
147 strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); 153 strncpy (utx->ut_host, hostname, sizeof (utx->ut_host));
171# else 177# else
172 FILE *fd0; 178 FILE *fd0;
173 179
174 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) 180 if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL)
175 { 181 {
176 char buf[256], name[256]; 182 char buf[256], name[256];
177 183
178 buf[sizeof (buf) - 1] = '\0'; 184 buf[sizeof (buf) - 1] = '\0';
179 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) 185 for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);)
180 { 186 {
181 if (*buf == '#' || sscanf (buf, "%s", name) != 1) 187 if (*buf == '#' || sscanf (buf, "%s", name) != 1)
197 } 203 }
198#endif 204#endif
199 205
200#ifdef WTMP_SUPPORT 206#ifdef WTMP_SUPPORT
201# ifdef WTMP_ONLY_ON_LOGIN 207# ifdef WTMP_ONLY_ON_LOGIN
202 if (options & Opt_loginShell) 208 if (OPTION (Opt_loginShell))
203# endif 209# endif
204 { 210 {
205# ifdef HAVE_STRUCT_UTMP 211# ifdef HAVE_STRUCT_UTMP
206# ifdef HAVE_UPDWTMP 212# ifdef HAVE_UPDWTMP
207 updwtmp (RXVT_WTMP_FILE, ut); 213 updwtmp (RXVT_WTMP_FILE, ut);
208# else 214# else
209 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 215 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
210# endif 216# endif
211# endif 217# endif
212# ifdef HAVE_STRUCT_UTMPX 218# ifdef HAVE_STRUCT_UTMPX
219# if HAVE_UPDWTMPX
213 updwtmpx (RXVT_WTMPX_FILE, utx); 220 updwtmpx (RXVT_WTMPX_FILE, utx);
221# else
222 pututxline (utx);
223# endif
214# endif 224# endif
215 } 225 }
216#endif 226#endif
217#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) 227#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE)
218 if (options & Opt_loginShell) 228 if (OPTION (Opt_loginShell))
219 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); 229 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname);
220#endif 230#endif
221} 231}
222 232
223/* ------------------------------------------------------------------------- */ 233/* ------------------------------------------------------------------------- */
236 246
237#ifdef HAVE_STRUCT_UTMP 247#ifdef HAVE_STRUCT_UTMP
238# ifdef HAVE_UTMP_PID 248# ifdef HAVE_UTMP_PID
239 memset (ut, 0, sizeof (struct utmp)); 249 memset (ut, 0, sizeof (struct utmp));
240 setutent (); 250 setutent ();
241 strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); 251 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id));
242 ut->ut_type = USER_PROCESS; 252 ut->ut_type = USER_PROCESS;
243 { 253 {
244 struct utmp *tmput = getutid (ut); 254 struct utmp *tmput = getutid (ut);
245 255
246 if (tmput) /* position to entry in utmp file */ 256 if (tmput) /* position to entry in utmp file */
257#endif 267#endif
258 268
259#ifdef HAVE_STRUCT_UTMPX 269#ifdef HAVE_STRUCT_UTMPX
260 memset (utx, 0, sizeof (struct utmpx)); 270 memset (utx, 0, sizeof (struct utmpx));
261 setutxent (); 271 setutxent ();
262 strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); 272 strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id));
263 utx->ut_type = USER_PROCESS; 273 utx->ut_type = USER_PROCESS;
264 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ 274 if ((tmputx = getutxid (utx))) /* position to entry in utmp file */
265 utx = tmputx; 275 utx = tmputx;
266 utx->ut_type = DEAD_PROCESS; 276 utx->ut_type = DEAD_PROCESS;
277# if HAVE_UTMPX_SESSION
267 utx->ut_session = getsid (0); 278 utx->ut_session = getsid (0);
279# endif
268 utx->ut_tv.tv_sec = time (NULL); 280 utx->ut_tv.tv_sec = time (NULL);
269 utx->ut_tv.tv_usec = 0; 281 utx->ut_tv.tv_usec = 0;
270#endif 282#endif
271 283
272 /* 284 /*
273 * Write ending wtmp entry 285 * Write ending wtmp entry
274 */ 286 */
275#ifdef WTMP_SUPPORT 287#ifdef WTMP_SUPPORT
276# ifdef WTMP_ONLY_ON_LOGIN 288# ifdef WTMP_ONLY_ON_LOGIN
277 if (options & Opt_loginShell) 289 if (OPTION (Opt_loginShell))
278# endif 290# endif
279 { 291 {
280# ifdef HAVE_STRUCT_UTMP 292# ifdef HAVE_STRUCT_UTMP
281# ifdef HAVE_UPDWTMP 293# ifdef HAVE_UPDWTMP
282 updwtmp (RXVT_WTMP_FILE, ut); 294 updwtmp (RXVT_WTMP_FILE, ut);
283# else 295# else
284 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 296 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
285# endif 297# endif
286# endif 298# endif
287# ifdef HAVE_STRUCT_UTMPX 299# ifdef HAVE_STRUCT_UTMPX
300# if HAVE_UPDWTMPX
288 updwtmpx (RXVT_WTMPX_FILE, utx); 301 updwtmpx (RXVT_WTMPX_FILE, utx);
302# else
303 pututxline (utx);
304# endif
289# endif 305# endif
290 } 306 }
291#endif 307#endif
292 308
293 /* 309 /*
313/* ------------------------------------------------------------------------- */ 329/* ------------------------------------------------------------------------- */
314/* 330/*
315 * Write a BSD style utmp entry 331 * Write a BSD style utmp entry
316 */ 332 */
317#ifdef HAVE_UTMP_H 333#ifdef HAVE_UTMP_H
318/* INTPROTO */
319int 334int
320rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) 335rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu)
321{ 336{
322 int fd; 337 int fd;
323 338
333 348
334/* ------------------------------------------------------------------------- */ 349/* ------------------------------------------------------------------------- */
335/* 350/*
336 * Update a BSD style wtmp entry 351 * Update a BSD style wtmp entry
337 */ 352 */
338#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) 353#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
339/* INTPROTO */
340void 354void
341rxvt_update_wtmp (const char *fname, const struct utmp *putmp) 355rxvt_update_wtmp (const char *fname, const struct utmp *putmp)
342{ 356{
343 int fd, gotlock, retry; 357 int fd, gotlock, retry;
344 struct flock lck; /* fcntl locking scheme */ 358 struct flock lck; /* fcntl locking scheme */
376} 390}
377#endif 391#endif
378 392
379/* ------------------------------------------------------------------------- */ 393/* ------------------------------------------------------------------------- */
380#ifdef LASTLOG_SUPPORT 394#ifdef LASTLOG_SUPPORT
381/* INTPROTO */
382void 395void
383rxvt_update_lastlog (const char *fname, const char *pty, const char *host) 396rxvt_update_lastlog (const char *fname, const char *pty, const char *host)
384{ 397{
385# ifdef HAVE_STRUCT_LASTLOGX 398# ifdef HAVE_STRUCT_LASTLOGX
386 struct lastlogx llx; 399 struct lastlogx llx;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines