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.2 by pcg, Mon Nov 24 17:31:27 2003 UTC vs.
Revision 1.3 by pcg, Tue Nov 25 11:52:42 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: logging.c 2 * File: logging.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: logging.C,v 1.2 2003/11/24 17:31:27 pcg Exp $ 4 * $Id: logging.C,v 1.3 2003/11/25 11:52:42 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1992 John Bovey <jdb@ukc.ac.uk> 7 * Copyright (c) 1992 John Bovey <jdb@ukc.ac.uk>
8 * - original version 8 * - original version
9 * Copyright (c) 1993 lipka 9 * Copyright (c) 1993 lipka
59/* EXTPROTO */ 59/* EXTPROTO */
60void 60void
61rxvt_makeutent(pR_ const char *pty, const char *hostname) 61rxvt_makeutent(pR_ const char *pty, const char *hostname)
62{ 62{
63#ifdef HAVE_STRUCT_UTMP 63#ifdef HAVE_STRUCT_UTMP
64 struct utmp *ut = &(R->h->ut); 64 struct utmp *ut = &(R->ut);
65#endif 65#endif
66#ifdef HAVE_STRUCT_UTMPX 66#ifdef HAVE_STRUCT_UTMPX
67 struct utmpx *utx = &(R->h->utx); 67 struct utmpx *utx = &(R->utx);
68#endif 68#endif
69#ifdef HAVE_UTMP_PID 69#ifdef HAVE_UTMP_PID
70 int i; 70 int i;
71#endif 71#endif
72 char ut_id[5]; 72 char ut_id[5];
92# ifdef HAVE_UTMP_PID 92# ifdef HAVE_UTMP_PID
93 setutent(); 93 setutent();
94 STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id)); 94 STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id));
95 ut->ut_type = DEAD_PROCESS; 95 ut->ut_type = DEAD_PROCESS;
96 getutid(ut); /* position to entry in utmp file */ 96 getutid(ut); /* position to entry in utmp file */
97 STRNCPY(R->h->ut_id, ut_id, sizeof(R->h->ut_id)); 97 STRNCPY(R->ut_id, ut_id, sizeof(R->ut_id));
98# endif 98# endif
99#endif 99#endif
100 100
101#ifdef HAVE_STRUCT_UTMPX 101#ifdef HAVE_STRUCT_UTMPX
102 MEMSET(utx, 0, sizeof(struct utmpx)); 102 MEMSET(utx, 0, sizeof(struct utmpx));
103 setutxent(); 103 setutxent();
104 STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id)); 104 STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id));
105 utx->ut_type = DEAD_PROCESS; 105 utx->ut_type = DEAD_PROCESS;
106 getutxid(utx); /* position to entry in utmp file */ 106 getutxid(utx); /* position to entry in utmp file */
107 STRNCPY(R->h->ut_id, ut_id, sizeof(R->h->ut_id)); 107 STRNCPY(R->ut_id, ut_id, sizeof(R->ut_id));
108#endif 108#endif
109 109
110#ifdef HAVE_STRUCT_UTMP 110#ifdef HAVE_STRUCT_UTMP
111 STRNCPY(ut->ut_line, pty, sizeof(ut->ut_line)); 111 STRNCPY(ut->ut_line, pty, sizeof(ut->ut_line));
112 ut->ut_time = time(NULL); 112 ut->ut_time = time(NULL);
113# ifdef HAVE_UTMP_PID 113# ifdef HAVE_UTMP_PID
114 STRNCPY(ut->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", 114 STRNCPY(ut->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
115 sizeof(ut->ut_user)); 115 sizeof(ut->ut_user));
116 STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id)); 116 STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id));
117 ut->ut_time = time(NULL); 117 ut->ut_time = time(NULL);
118 ut->ut_pid = R->h->cmd_pid; 118 ut->ut_pid = R->cmd_pid;
119# ifdef HAVE_UTMP_HOST 119# ifdef HAVE_UTMP_HOST
120 STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host)); 120 STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host));
121# endif 121# endif
122 ut->ut_type = USER_PROCESS; 122 ut->ut_type = USER_PROCESS;
123 pututline(ut); 123 pututline(ut);
124 endutent(); /* close the file */ 124 endutent(); /* close the file */
125 R->h->utmp_pos = 0; 125 R->utmp_pos = 0;
126# else 126# else
127 STRNCPY(ut->ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", 127 STRNCPY(ut->ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
128 sizeof(ut->ut_name)); 128 sizeof(ut->ut_name));
129# ifdef HAVE_UTMP_HOST 129# ifdef HAVE_UTMP_HOST
130 STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host)); 130 STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host));
138 sizeof(utx->ut_user)); 138 sizeof(utx->ut_user));
139 STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id)); 139 STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id));
140 utx->ut_session = getsid(0); 140 utx->ut_session = getsid(0);
141 utx->ut_tv.tv_sec = time(NULL); 141 utx->ut_tv.tv_sec = time(NULL);
142 utx->ut_tv.tv_usec = 0; 142 utx->ut_tv.tv_usec = 0;
143 utx->ut_pid = R->h->cmd_pid; 143 utx->ut_pid = R->cmd_pid;
144# ifdef HAVE_UTMPX_HOST 144# ifdef HAVE_UTMPX_HOST
145 STRNCPY(utx->ut_host, hostname, sizeof(utx->ut_host)); 145 STRNCPY(utx->ut_host, hostname, sizeof(utx->ut_host));
146# if 0 146# if 0
147 { 147 {
148 char *colon; 148 char *colon;
153# endif 153# endif
154# endif 154# endif
155 utx->ut_type = USER_PROCESS; 155 utx->ut_type = USER_PROCESS;
156 pututxline(utx); 156 pututxline(utx);
157 endutxent(); /* close the file */ 157 endutxent(); /* close the file */
158 R->h->utmp_pos = 0; 158 R->utmp_pos = 0;
159#endif 159#endif
160 160
161#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) 161#if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
162 { 162 {
163 int i; 163 int i;
164# ifdef HAVE_TTYSLOT 164# ifdef HAVE_TTYSLOT
165 i = ttyslot(); 165 i = ttyslot();
166 if (rxvt_write_bsd_utmp(i, ut)) 166 if (rxvt_write_bsd_utmp(i, ut))
167 R->h->utmp_pos = i; 167 R->utmp_pos = i;
168# else 168# else
169 FILE *fd0; 169 FILE *fd0;
170 170
171 if ((fd0 = fopen(TTYTAB_FILENAME, "r")) != NULL) { 171 if ((fd0 = fopen(TTYTAB_FILENAME, "r")) != NULL) {
172 char buf[256], name[256]; 172 char buf[256], name[256];
176 if (*buf == '#' || sscanf(buf, "%s", name) != 1) 176 if (*buf == '#' || sscanf(buf, "%s", name) != 1)
177 continue; 177 continue;
178 if (!STRCMP(ut->ut_line, name)) { 178 if (!STRCMP(ut->ut_line, name)) {
179 if (!rxvt_write_bsd_utmp(i, ut)) 179 if (!rxvt_write_bsd_utmp(i, ut))
180 i = 0; 180 i = 0;
181 R->h->utmp_pos = i; 181 R->utmp_pos = i;
182 fclose(fd0); 182 fclose(fd0);
183 break; 183 break;
184 } 184 }
185 i++; 185 i++;
186 } 186 }
220/* EXTPROTO */ 220/* EXTPROTO */
221void 221void
222rxvt_cleanutent(pR) 222rxvt_cleanutent(pR)
223{ 223{
224#ifdef HAVE_STRUCT_UTMP 224#ifdef HAVE_STRUCT_UTMP
225 struct utmp *ut = &(R->h->ut); 225 struct utmp *ut = &(R->ut);
226#endif 226#endif
227#ifdef HAVE_STRUCT_UTMPX 227#ifdef HAVE_STRUCT_UTMPX
228 struct utmpx *tmputx, *utx = &(R->h->utx); 228 struct utmpx *tmputx, *utx = &(R->utx);
229#endif 229#endif
230 230
231#ifdef HAVE_STRUCT_UTMP 231#ifdef HAVE_STRUCT_UTMP
232# ifdef HAVE_UTMP_PID 232# ifdef HAVE_UTMP_PID
233 MEMSET(ut, 0, sizeof(struct utmp)); 233 MEMSET(ut, 0, sizeof(struct utmp));
234 setutent(); 234 setutent();
235 STRNCPY(ut->ut_id, R->h->ut_id, sizeof(ut->ut_id)); 235 STRNCPY(ut->ut_id, R->ut_id, sizeof(ut->ut_id));
236 ut->ut_type = USER_PROCESS; 236 ut->ut_type = USER_PROCESS;
237 { 237 {
238 struct utmp *tmput = getutid(ut); 238 struct utmp *tmput = getutid(ut);
239 239
240 if (tmput) /* position to entry in utmp file */ 240 if (tmput) /* position to entry in utmp file */
251#endif 251#endif
252 252
253#ifdef HAVE_STRUCT_UTMPX 253#ifdef HAVE_STRUCT_UTMPX
254 MEMSET(utx, 0, sizeof(struct utmpx)); 254 MEMSET(utx, 0, sizeof(struct utmpx));
255 setutxent(); 255 setutxent();
256 STRNCPY(utx->ut_id, R->h->ut_id, sizeof(utx->ut_id)); 256 STRNCPY(utx->ut_id, R->ut_id, sizeof(utx->ut_id));
257 utx->ut_type = USER_PROCESS; 257 utx->ut_type = USER_PROCESS;
258 if ((tmputx = getutxid(utx))) /* position to entry in utmp file */ 258 if ((tmputx = getutxid(utx))) /* position to entry in utmp file */
259 utx = tmputx; 259 utx = tmputx;
260 utx->ut_type = DEAD_PROCESS; 260 utx->ut_type = DEAD_PROCESS;
261 utx->ut_session = getsid(0); 261 utx->ut_session = getsid(0);
287 /* 287 /*
288 * Write utmp entry 288 * Write utmp entry
289 */ 289 */
290#ifdef HAVE_STRUCT_UTMP 290#ifdef HAVE_STRUCT_UTMP
291# ifdef HAVE_UTMP_PID 291# ifdef HAVE_UTMP_PID
292 if (ut->ut_pid == R->h->cmd_pid) 292 if (ut->ut_pid == R->cmd_pid)
293 pututline(ut); 293 pututline(ut);
294 endutent(); 294 endutent();
295# else 295# else
296 MEMSET(ut, 0, sizeof(struct utmp)); 296 MEMSET(ut, 0, sizeof(struct utmp));
297 rxvt_write_bsd_utmp(R->h->utmp_pos, ut); 297 rxvt_write_bsd_utmp(R->utmp_pos, ut);
298# endif
299#endif 298# endif
299#endif
300#ifdef HAVE_STRUCT_UTMPX 300#ifdef HAVE_STRUCT_UTMPX
301 if (utx->ut_pid == R->h->cmd_pid) 301 if (utx->ut_pid == R->cmd_pid)
302 pututxline(utx); 302 pututxline(utx);
303 endutxent(); 303 endutxent();
304#endif 304#endif
305} 305}
306 306

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines