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.43 by ayin, Mon Nov 19 11:26:34 2007 UTC vs.
Revision 1.47 by root, Sun May 3 21:48:53 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines