… | |
… | |
104 | break; |
104 | break; |
105 | } |
105 | } |
106 | else if (errno != EAGAIN && errno != EACCES) |
106 | else if (errno != EAGAIN && errno != EACCES) |
107 | break; |
107 | break; |
108 | if (!gotlock) |
108 | if (!gotlock) |
|
|
109 | { |
109 | { /* give it up */ |
110 | /* give it up */ |
110 | close (fd); |
111 | close (fd); |
111 | return; |
112 | return; |
112 | } |
113 | } |
113 | if (fstat (fd, &sbuf) == 0) |
114 | if (fstat (fd, &sbuf) == 0) |
114 | if (write (fd, putmp, sizeof (struct utmp)) != sizeof (struct utmp)) |
115 | if (write (fd, putmp, sizeof (struct utmp)) != sizeof (struct utmp)) |
… | |
… | |
216 | #if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX) |
217 | #if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX) |
217 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
218 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
218 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
219 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
219 | else if (sscanf (pty, "pts/%d", &i) == 1) |
220 | else if (sscanf (pty, "pts/%d", &i) == 1) |
220 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
221 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
221 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
222 | else |
222 | { |
223 | { |
223 | ptytty_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
224 | ptytty_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
224 | return; |
225 | return; |
225 | } |
226 | } |
226 | #endif |
227 | #endif |
… | |
… | |
230 | # ifdef HAVE_UTMP_PID |
231 | # ifdef HAVE_UTMP_PID |
231 | setutent (); |
232 | setutent (); |
232 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
233 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
233 | ut->ut_type = DEAD_PROCESS; |
234 | ut->ut_type = DEAD_PROCESS; |
234 | getutid (ut); /* position to entry in utmp file */ |
235 | getutid (ut); /* position to entry in utmp file */ |
235 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
|
|
236 | # endif |
236 | # endif |
237 | #endif |
237 | #endif |
238 | |
238 | |
239 | #ifdef HAVE_STRUCT_UTMPX |
239 | #ifdef HAVE_STRUCT_UTMPX |
240 | memset (utx, 0, sizeof (struct utmpx)); |
240 | memset (utx, 0, sizeof (struct utmpx)); |
241 | setutxent (); |
241 | setutxent (); |
242 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
242 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
243 | utx->ut_type = DEAD_PROCESS; |
243 | utx->ut_type = DEAD_PROCESS; |
244 | getutxid (utx); /* position to entry in utmp file */ |
244 | getutxid (utx); /* position to entry in utmp file */ |
245 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
|
|
246 | #endif |
245 | #endif |
247 | |
246 | |
248 | #ifdef HAVE_STRUCT_UTMP |
247 | #ifdef HAVE_STRUCT_UTMP |
249 | strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); |
248 | strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); |
|
|
249 | # ifdef HAVE_UTMP_HOST |
|
|
250 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
|
|
251 | # endif |
250 | ut->ut_time = time (NULL); |
252 | ut->ut_time = time (NULL); |
251 | # ifdef HAVE_UTMP_PID |
253 | # ifdef HAVE_UTMP_PID |
252 | strncpy (ut->ut_user, name, sizeof (ut->ut_user)); |
254 | strncpy (ut->ut_user, name, sizeof (ut->ut_user)); |
253 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
255 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
254 | ut->ut_time = time (NULL); |
|
|
255 | ut->ut_pid = cmd_pid; |
256 | ut->ut_pid = cmd_pid; |
256 | # ifdef HAVE_UTMP_HOST |
|
|
257 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
|
|
258 | # endif |
|
|
259 | ut->ut_type = USER_PROCESS; |
257 | ut->ut_type = USER_PROCESS; |
260 | pututline (ut); |
258 | pututline (ut); |
261 | endutent (); /* close the file */ |
259 | endutent (); /* close the file */ |
262 | utmp_pos = 0; |
260 | utmp_pos = 0; |
263 | # else |
261 | # else |
264 | strncpy (ut->ut_name, name, sizeof (ut->ut_name)); |
262 | strncpy (ut->ut_name, name, sizeof (ut->ut_name)); |
265 | # ifdef HAVE_UTMP_HOST |
|
|
266 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
|
|
267 | # endif |
|
|
268 | # endif |
263 | # endif |
269 | #endif |
264 | #endif |
270 | |
265 | |
271 | #ifdef HAVE_STRUCT_UTMPX |
266 | #ifdef HAVE_STRUCT_UTMPX |
272 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
267 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |