… | |
… | |
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)) |
… | |
… | |
249 | memset (ut, 0, sizeof (struct utmp)); |
241 | memset (ut, 0, sizeof (struct utmp)); |
250 | setutent (); |
242 | setutent (); |
251 | strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); |
243 | strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); |
252 | ut->ut_type = USER_PROCESS; |
244 | ut->ut_type = USER_PROCESS; |
253 | { |
245 | { |
254 | struct utmp *tmput = getutid (ut); |
246 | struct utmp *tmput = getutid (ut); |
255 | |
247 | |
256 | if (tmput) /* position to entry in utmp file */ |
248 | if (tmput) /* position to entry in utmp file */ |
257 | ut = tmput; |
249 | ut = tmput; |
258 | } |
250 | } |
259 | ut->ut_type = DEAD_PROCESS; |
251 | ut->ut_type = DEAD_PROCESS; |
… | |
… | |
294 | updwtmp (RXVT_WTMP_FILE, ut); |
286 | updwtmp (RXVT_WTMP_FILE, ut); |
295 | # else |
287 | # else |
296 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
288 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
297 | # endif |
289 | # endif |
298 | # endif |
290 | # endif |
299 | # ifdef HAVE_STRUCT_UTMPX |
291 | # if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX) |
300 | # if HAVE_UPDWTMPX |
|
|
301 | updwtmpx (RXVT_WTMPX_FILE, utx); |
292 | updwtmpx (RXVT_WTMPX_FILE, utx); |
302 | # else |
|
|
303 | pututxline (utx); |
|
|
304 | # endif |
|
|
305 | # endif |
293 | # endif |
306 | } |
294 | } |
307 | #endif |
295 | #endif |
308 | |
296 | |
309 | /* |
297 | /* |
… | |
… | |
328 | |
316 | |
329 | /* ------------------------------------------------------------------------- */ |
317 | /* ------------------------------------------------------------------------- */ |
330 | /* |
318 | /* |
331 | * Write a BSD style utmp entry |
319 | * Write a BSD style utmp entry |
332 | */ |
320 | */ |
333 | #ifdef HAVE_UTMP_H |
321 | #if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |
334 | int |
322 | static int |
335 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
323 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
336 | { |
324 | { |
337 | int fd; |
325 | int fd; |
338 | |
326 | |
339 | if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1) |
327 | if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1) |
… | |
… | |
349 | /* ------------------------------------------------------------------------- */ |
337 | /* ------------------------------------------------------------------------- */ |
350 | /* |
338 | /* |
351 | * Update a BSD style wtmp entry |
339 | * Update a BSD style wtmp entry |
352 | */ |
340 | */ |
353 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
341 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
354 | void |
342 | static void |
355 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
343 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
356 | { |
344 | { |
357 | int fd, gotlock, retry; |
345 | int fd, gotlock, retry; |
358 | struct flock lck; /* fcntl locking scheme */ |
346 | struct flock lck; /* fcntl locking scheme */ |
359 | struct stat sbuf; |
347 | struct stat sbuf; |
… | |
… | |
390 | } |
378 | } |
391 | #endif |
379 | #endif |
392 | |
380 | |
393 | /* ------------------------------------------------------------------------- */ |
381 | /* ------------------------------------------------------------------------- */ |
394 | #ifdef LASTLOG_SUPPORT |
382 | #ifdef LASTLOG_SUPPORT |
395 | void |
383 | static void |
396 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
384 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
397 | { |
385 | { |
398 | # ifdef HAVE_STRUCT_LASTLOGX |
386 | # ifdef HAVE_STRUCT_LASTLOGX |
399 | struct lastlogx llx; |
387 | struct lastlogx llx; |
400 | # endif |
388 | # endif |