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.22 by root, Sun Jan 15 05:14:12 2006 UTC vs.
Revision 1.29 by root, Tue Jan 17 10:59:32 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
49static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); 41static int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu);
50static void 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
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_unix::login (int cmd_pid, bool login_shell, const char *hostname)
69{ 61{
62 const char *pty = name;
63
64 if (!pty || !*pty)
65 return;
66
67 this->cmd_pid = cmd_pid;
68 this->login_shell = login_shell;
69
70#ifdef HAVE_STRUCT_UTMP 70#ifdef HAVE_STRUCT_UTMP
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;
194 i++; 194 i++;
195 } 195 }
196 fclose (fd0); 196 fclose (fd0);
197 } 197 }
198# endif 198# endif
199
200 } 199 }
201#endif 200#endif
202 201
203#ifdef WTMP_SUPPORT 202#ifdef WTMP_SUPPORT
204# ifdef WTMP_ONLY_ON_LOGIN 203# ifdef WTMP_ONLY_ON_LOGIN
205 if (OPTION (Opt_loginShell)) 204 if (login_shell)
206# endif 205# endif
207 { 206 {
208# ifdef HAVE_STRUCT_UTMP 207# ifdef HAVE_STRUCT_UTMP
209# ifdef HAVE_UPDWTMP 208# ifdef HAVE_UPDWTMP
210 updwtmp (RXVT_WTMP_FILE, ut); 209 updwtmp (RXVT_WTMP_FILE, ut);
211# else 210# else
212 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 211 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
213# endif 212# endif
214# endif 213# endif
215# ifdef HAVE_STRUCT_UTMPX 214# if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX)
216# if HAVE_UPDWTMPX
217 updwtmpx (RXVT_WTMPX_FILE, utx); 215 updwtmpx (RXVT_WTMPX_FILE, utx);
218# else
219 pututxline (utx);
220# endif
221# endif 216# endif
222 } 217 }
223#endif 218#endif
224#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) 219#if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE)
225 if (OPTION (Opt_loginShell)) 220 if (login_shell)
226 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); 221 rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname);
227#endif 222#endif
228} 223}
229 224
230/* ------------------------------------------------------------------------- */ 225/* ------------------------------------------------------------------------- */
231/* 226/*
232 * remove utmp and wtmp entries 227 * remove utmp and wtmp entries
233 */ 228 */
234void 229void
235rxvt_term::cleanutent () 230rxvt_ptytty_unix::logout ()
236{ 231{
232 if (!cmd_pid)
233 return;
234
237#ifdef HAVE_STRUCT_UTMP 235#ifdef HAVE_STRUCT_UTMP
238 struct utmp *ut = &this->ut; 236 struct utmp *tmput, *ut = &this->ut;
239#endif 237#endif
240#ifdef HAVE_STRUCT_UTMPX 238#ifdef HAVE_STRUCT_UTMPX
241 struct utmpx *tmputx, *utx = &this->utx; 239 struct utmpx *tmputx, *utx = &this->utx;
242#endif 240#endif
243 241
245# ifdef HAVE_UTMP_PID 243# ifdef HAVE_UTMP_PID
246 memset (ut, 0, sizeof (struct utmp)); 244 memset (ut, 0, sizeof (struct utmp));
247 setutent (); 245 setutent ();
248 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); 246 strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id));
249 ut->ut_type = USER_PROCESS; 247 ut->ut_type = USER_PROCESS;
250 {
251 struct utmp *tmput = getutid (ut);
252
253 if (tmput) /* position to entry in utmp file */ 248 if ((tmput = getutid (ut))) /* position to entry in utmp file */
254 ut = tmput; 249 ut = tmput;
255 }
256 ut->ut_type = DEAD_PROCESS; 250 ut->ut_type = DEAD_PROCESS;
257# else 251# else
258 memset (ut->ut_name, 0, sizeof (ut->ut_name)); 252 memset (ut->ut_name, 0, sizeof (ut->ut_name));
259# ifdef HAVE_UTMP_HOST 253# ifdef HAVE_UTMP_HOST
260 memset (ut->ut_host, 0, sizeof (ut->ut_host)); 254 memset (ut->ut_host, 0, sizeof (ut->ut_host));
281 /* 275 /*
282 * Write ending wtmp entry 276 * Write ending wtmp entry
283 */ 277 */
284#ifdef WTMP_SUPPORT 278#ifdef WTMP_SUPPORT
285# ifdef WTMP_ONLY_ON_LOGIN 279# ifdef WTMP_ONLY_ON_LOGIN
286 if (OPTION (Opt_loginShell)) 280 if (login_shell)
287# endif 281# endif
288 { 282 {
289# ifdef HAVE_STRUCT_UTMP 283# ifdef HAVE_STRUCT_UTMP
290# ifdef HAVE_UPDWTMP 284# ifdef HAVE_UPDWTMP
291 updwtmp (RXVT_WTMP_FILE, ut); 285 updwtmp (RXVT_WTMP_FILE, ut);
292# else 286# else
293 rxvt_update_wtmp (RXVT_WTMP_FILE, ut); 287 rxvt_update_wtmp (RXVT_WTMP_FILE, ut);
294# endif 288# endif
295# endif 289# endif
296# ifdef HAVE_STRUCT_UTMPX 290# if defined(HAVE_STRUCT_UTMPX) && defined(HAVE_UPDWTMPX)
297# if HAVE_UPDWTMPX
298 updwtmpx (RXVT_WTMPX_FILE, utx); 291 updwtmpx (RXVT_WTMPX_FILE, utx);
299# else
300 pututxline (utx);
301# endif
302# endif 292# endif
303 } 293 }
304#endif 294#endif
305 295
306 /* 296 /*
319#ifdef HAVE_STRUCT_UTMPX 309#ifdef HAVE_STRUCT_UTMPX
320 if (utx->ut_pid == cmd_pid) 310 if (utx->ut_pid == cmd_pid)
321 pututxline (utx); 311 pututxline (utx);
322 endutxent (); 312 endutxent ();
323#endif 313#endif
314
315 cmd_pid = 0;
324} 316}
325 317
326/* ------------------------------------------------------------------------- */ 318/* ------------------------------------------------------------------------- */
327/* 319/*
328 * Write a BSD style utmp entry 320 * Write a BSD style utmp entry

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines