… | |
… | |
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 |
49 | int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
49 | static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
50 | void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
50 | static void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
51 | #endif |
51 | #endif |
52 | |
52 | |
53 | void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); |
53 | static 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)) |
… | |
… | |
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)) |
… | |
… | |
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) |
334 | int |
326 | static int |
335 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
327 | rxvt_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) |
354 | void |
346 | static void |
355 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
347 | rxvt_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 |
395 | void |
387 | static void |
396 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
388 | rxvt_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 |