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.21 by root, Sat Jan 14 10:17:40 2006 UTC vs.
Revision 1.27 by root, Tue Jan 17 10:14:26 2006 UTC

28 * 28 *
29 * You should have received a copy of the GNU General Public License 29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software 30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 *----------------------------------------------------------------------*/ 32 *----------------------------------------------------------------------*/
33/*----------------------------------------------------------------------*
34 * Public:
35 * extern void cleanutent (void);
36 * extern void makeutent (const char * pty, const char * hostname);
37 *
38 * Private:
39 * rxvt_update_wtmp ();
40 *----------------------------------------------------------------------*/
41 33
42#include "../config.h" 34#include "../config.h"
43#include "rxvt.h" 35#include "rxvt.h"
44#include "logging.h" 36#include "ptytty.h"
45 37
46#ifdef UTMP_SUPPORT 38#if UTMP_SUPPORT
47 39
48#if HAVE_STRUCT_UTMP 40#if HAVE_STRUCT_UTMP
49int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); 41static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu);
50void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); 42static void rxvt_update_wtmp (const char *fname, const struct utmp *putmp);
51#endif 43#endif
52 44
53void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); 45static void rxvt_update_lastlog (const char *fname, const char *pty, const char *host);
54 46
55/* 47/*
56 * BSD style utmp entry 48 * BSD style utmp entry
57 * ut_line, ut_name, ut_host, ut_time 49 * ut_line, ut_name, ut_host, ut_time
58 * SYSV style utmp (and utmpx) entry 50 * SYSV style utmp (and utmpx) entry
63 55
64/* 56/*
65 * make and write utmp and wtmp entries 57 * make and write utmp and wtmp entries
66 */ 58 */
67void 59void
68rxvt_term::makeutent (const char *pty, const char *hostname) 60rxvt_ptytty::login (int cmd_pid, bool login_shell, const char *hostname)
69{ 61{
62 this->cmd_pid = cmd_pid;
63 this->login_shell = login_shell;
64
65 const char *pty = name;
66
70#ifdef HAVE_STRUCT_UTMP 67#ifdef HAVE_STRUCT_UTMP
71 struct utmp *ut = &this->ut; 68 struct utmp *ut = &this->ut;
72#endif 69#endif
73#ifdef HAVE_STRUCT_UTMPX 70#ifdef HAVE_STRUCT_UTMPX
74 struct utmpx *utx = &this->utx; 71 struct utmpx *utx = &this->utx;
75#endif 72#endif
76#ifdef HAVE_UTMP_PID
77 int i; 73 int i;
78#endif
79 struct passwd *pwent = getpwuid (getuid ()); 74 struct passwd *pwent = getpwuid (getuid ());
80 75
81 if (!strncmp (pty, "/dev/", 5)) 76 if (!strncmp (pty, "/dev/", 5))
82 pty += 5; /* skip /dev/ prefix */ 77 pty += 5; /* skip /dev/ prefix */
83 78
84#ifdef HAVE_UTMP_PID 79#if defined(HAVE_UTMP_PID) || defined(HAVE_STRUCT_UTMPX)
85 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) 80 if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3))
86 strncpy (ut_id, pty + 3, sizeof (ut_id)); 81 strncpy (ut_id, pty + 3, sizeof (ut_id));
87 else if (sscanf (pty, "pts/%d", &i) == 1) 82 else if (sscanf (pty, "pts/%d", &i) == 1)
88 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ 83 sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */
89 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) 84 else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3))
167#endif 162#endif
168 163
169#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) 164#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
170 165
171 { 166 {
172 int i;
173# ifdef HAVE_TTYSLOT 167# ifdef HAVE_TTYSLOT
174 i = ttyslot (); 168 i = ttyslot ();
175 if (rxvt_write_bsd_utmp (i, ut)) 169 if (rxvt_write_bsd_utmp (i, ut))
176 utmp_pos = i; 170 utmp_pos = i;
177# else 171# else
197 i++; 191 i++;
198 } 192 }
199 fclose (fd0); 193 fclose (fd0);
200 } 194 }
201# endif 195# endif
202
203 } 196 }
204#endif 197#endif
205 198
206#ifdef WTMP_SUPPORT 199#ifdef WTMP_SUPPORT
207# ifdef WTMP_ONLY_ON_LOGIN 200# ifdef WTMP_ONLY_ON_LOGIN
208 if (OPTION (Opt_loginShell)) 201 if (login_shell)
209# endif 202# endif
210 { 203 {
211# ifdef HAVE_STRUCT_UTMP 204# ifdef HAVE_STRUCT_UTMP
212# ifdef HAVE_UPDWTMP 205# ifdef HAVE_UPDWTMP
213 updwtmp (RXVT_WTMP_FILE, ut); 206 updwtmp (RXVT_WTMP_FILE, ut);
214# else 207# else
215 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 208 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
216# endif 209# endif
217# endif 210# endif
218# ifdef HAVE_STRUCT_UTMPX 211# if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX)
219# if HAVE_UPDWTMPX
220 updwtmpx (RXVT_WTMPX_FILE, utx); 212 updwtmpx (RXVT_WTMPX_FILE, utx);
221# else
222 pututxline (utx);
223# endif
224# endif 213# endif
225 } 214 }
226#endif 215#endif
227#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) 216#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE)
228 if (OPTION (Opt_loginShell)) 217 if (login_shell)
229 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); 218 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname);
230#endif 219#endif
231} 220}
232 221
233/* ------------------------------------------------------------------------- */ 222/* ------------------------------------------------------------------------- */
234/* 223/*
235 * remove utmp and wtmp entries 224 * remove utmp and wtmp entries
236 */ 225 */
237void 226void
238rxvt_term::cleanutent () 227rxvt_ptytty::logout ()
239{ 228{
240#ifdef HAVE_STRUCT_UTMP 229#ifdef HAVE_STRUCT_UTMP
241 struct utmp *ut = &this->ut; 230 struct utmp *tmput, *ut = &this->ut;
242#endif 231#endif
243#ifdef HAVE_STRUCT_UTMPX 232#ifdef HAVE_STRUCT_UTMPX
244 struct utmpx *tmputx, *utx = &this->utx; 233 struct utmpx *tmputx, *utx = &this->utx;
245#endif 234#endif
246 235
248# ifdef HAVE_UTMP_PID 237# ifdef HAVE_UTMP_PID
249 memset (ut, 0, sizeof (struct utmp)); 238 memset (ut, 0, sizeof (struct utmp));
250 setutent (); 239 setutent ();
251 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); 240 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id));
252 ut->ut_type = USER_PROCESS; 241 ut->ut_type = USER_PROCESS;
253 {
254 struct utmp *tmput = getutid (ut);
255
256 if (tmput) /* position to entry in utmp file */ 242 if ((tmput = getutid (ut))) /* position to entry in utmp file */
257 ut = tmput; 243 ut = tmput;
258 }
259 ut->ut_type = DEAD_PROCESS; 244 ut->ut_type = DEAD_PROCESS;
260# else 245# else
261 memset (ut->ut_name, 0, sizeof (ut->ut_name)); 246 memset (ut->ut_name, 0, sizeof (ut->ut_name));
262# ifdef HAVE_UTMP_HOST 247# ifdef HAVE_UTMP_HOST
263 memset (ut->ut_host, 0, sizeof (ut->ut_host)); 248 memset (ut->ut_host, 0, sizeof (ut->ut_host));
284 /* 269 /*
285 * Write ending wtmp entry 270 * Write ending wtmp entry
286 */ 271 */
287#ifdef WTMP_SUPPORT 272#ifdef WTMP_SUPPORT
288# ifdef WTMP_ONLY_ON_LOGIN 273# ifdef WTMP_ONLY_ON_LOGIN
289 if (OPTION (Opt_loginShell)) 274 if (login_shell)
290# endif 275# endif
291 { 276 {
292# ifdef HAVE_STRUCT_UTMP 277# ifdef HAVE_STRUCT_UTMP
293# ifdef HAVE_UPDWTMP 278# ifdef HAVE_UPDWTMP
294 updwtmp (RXVT_WTMP_FILE, ut); 279 updwtmp (RXVT_WTMP_FILE, ut);
295# else 280# else
296 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 281 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
297# endif 282# endif
298# endif 283# endif
299# ifdef HAVE_STRUCT_UTMPX 284# if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX)
300# if HAVE_UPDWTMPX
301 updwtmpx (RXVT_WTMPX_FILE, utx); 285 updwtmpx (RXVT_WTMPX_FILE, utx);
302# else
303 pututxline (utx);
304# endif
305# endif 286# endif
306 } 287 }
307#endif 288#endif
308 289
309 /* 290 /*
328 309
329/* ------------------------------------------------------------------------- */ 310/* ------------------------------------------------------------------------- */
330/* 311/*
331 * Write a BSD style utmp entry 312 * Write a BSD style utmp entry
332 */ 313 */
333#ifdef HAVE_UTMP_H 314#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
334int 315static int
335rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) 316rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu)
336{ 317{
337 int fd; 318 int fd;
338 319
339 if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1) 320 if (utmp_pos <= 0 || (fd = open (RXVT_UTMP_FILE, O_WRONLY)) == -1)
349/* ------------------------------------------------------------------------- */ 330/* ------------------------------------------------------------------------- */
350/* 331/*
351 * Update a BSD style wtmp entry 332 * Update a BSD style wtmp entry
352 */ 333 */
353#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) 334#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
354void 335static void
355rxvt_update_wtmp (const char *fname, const struct utmp *putmp) 336rxvt_update_wtmp (const char *fname, const struct utmp *putmp)
356{ 337{
357 int fd, gotlock, retry; 338 int fd, gotlock, retry;
358 struct flock lck; /* fcntl locking scheme */ 339 struct flock lck; /* fcntl locking scheme */
359 struct stat sbuf; 340 struct stat sbuf;
390} 371}
391#endif 372#endif
392 373
393/* ------------------------------------------------------------------------- */ 374/* ------------------------------------------------------------------------- */
394#ifdef LASTLOG_SUPPORT 375#ifdef LASTLOG_SUPPORT
395void 376static void
396rxvt_update_lastlog (const char *fname, const char *pty, const char *host) 377rxvt_update_lastlog (const char *fname, const char *pty, const char *host)
397{ 378{
398# ifdef HAVE_STRUCT_LASTLOGX 379# ifdef HAVE_STRUCT_LASTLOGX
399 struct lastlogx llx; 380 struct lastlogx llx;
400# endif 381# endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines