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.4 2004/01/31 00:20:21 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 |
… | |
… | |
54 | /* ------------------------------------------------------------------------- */ |
54 | /* ------------------------------------------------------------------------- */ |
55 | |
55 | |
56 | /* |
56 | /* |
57 | * make and write utmp and wtmp entries |
57 | * make and write utmp and wtmp entries |
58 | */ |
58 | */ |
59 | /* EXTPROTO */ |
|
|
60 | void |
59 | void |
61 | rxvt_makeutent(pR_ const char *pty, const char *hostname) |
60 | rxvt_term::makeutent (const char *pty, const char *hostname) |
62 | { |
61 | { |
63 | #ifdef HAVE_STRUCT_UTMP |
62 | #ifdef HAVE_STRUCT_UTMP |
64 | struct utmp *ut = &(R->h->ut); |
63 | struct utmp *ut = &(this->ut); |
65 | #endif |
64 | #endif |
66 | #ifdef HAVE_STRUCT_UTMPX |
65 | #ifdef HAVE_STRUCT_UTMPX |
67 | struct utmpx *utx = &(R->h->utx); |
66 | struct utmpx *utx = &(this->utx); |
68 | #endif |
67 | #endif |
69 | #ifdef HAVE_UTMP_PID |
68 | #ifdef HAVE_UTMP_PID |
70 | int i; |
69 | int i; |
71 | #endif |
70 | #endif |
72 | char ut_id[5]; |
71 | char ut_id[5]; |
… | |
… | |
92 | # ifdef HAVE_UTMP_PID |
91 | # ifdef HAVE_UTMP_PID |
93 | setutent(); |
92 | setutent(); |
94 | STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id)); |
93 | STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id)); |
95 | ut->ut_type = DEAD_PROCESS; |
94 | ut->ut_type = DEAD_PROCESS; |
96 | getutid(ut); /* position to entry in utmp file */ |
95 | getutid(ut); /* position to entry in utmp file */ |
97 | STRNCPY(R->h->ut_id, ut_id, sizeof(R->h->ut_id)); |
96 | STRNCPY(ut_id, ut_id, sizeof(ut_id)); |
98 | # endif |
97 | # endif |
99 | #endif |
98 | #endif |
100 | |
99 | |
101 | #ifdef HAVE_STRUCT_UTMPX |
100 | #ifdef HAVE_STRUCT_UTMPX |
102 | MEMSET(utx, 0, sizeof(struct utmpx)); |
101 | MEMSET(utx, 0, sizeof(struct utmpx)); |
103 | setutxent(); |
102 | setutxent(); |
104 | STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id)); |
103 | STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id)); |
105 | utx->ut_type = DEAD_PROCESS; |
104 | utx->ut_type = DEAD_PROCESS; |
106 | getutxid(utx); /* position to entry in utmp file */ |
105 | getutxid(utx); /* position to entry in utmp file */ |
107 | STRNCPY(R->h->ut_id, ut_id, sizeof(R->h->ut_id)); |
106 | STRNCPY(ut_id, ut_id, sizeof(ut_id)); |
108 | #endif |
107 | #endif |
109 | |
108 | |
110 | #ifdef HAVE_STRUCT_UTMP |
109 | #ifdef HAVE_STRUCT_UTMP |
111 | STRNCPY(ut->ut_line, pty, sizeof(ut->ut_line)); |
110 | STRNCPY(ut->ut_line, pty, sizeof(ut->ut_line)); |
112 | ut->ut_time = time(NULL); |
111 | ut->ut_time = time(NULL); |
113 | # ifdef HAVE_UTMP_PID |
112 | # ifdef HAVE_UTMP_PID |
114 | STRNCPY(ut->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
113 | STRNCPY(ut->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
115 | sizeof(ut->ut_user)); |
114 | sizeof(ut->ut_user)); |
116 | STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id)); |
115 | STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id)); |
117 | ut->ut_time = time(NULL); |
116 | ut->ut_time = time(NULL); |
118 | ut->ut_pid = R->h->cmd_pid; |
117 | ut->ut_pid = cmd_pid; |
119 | # ifdef HAVE_UTMP_HOST |
118 | # ifdef HAVE_UTMP_HOST |
120 | STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host)); |
119 | STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host)); |
121 | # endif |
120 | # endif |
122 | ut->ut_type = USER_PROCESS; |
121 | ut->ut_type = USER_PROCESS; |
123 | pututline(ut); |
122 | pututline(ut); |
124 | endutent(); /* close the file */ |
123 | endutent(); /* close the file */ |
125 | R->h->utmp_pos = 0; |
124 | utmp_pos = 0; |
126 | # else |
125 | # else |
127 | STRNCPY(ut->ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
126 | STRNCPY(ut->ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
128 | sizeof(ut->ut_name)); |
127 | sizeof(ut->ut_name)); |
129 | # ifdef HAVE_UTMP_HOST |
128 | # ifdef HAVE_UTMP_HOST |
130 | STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host)); |
129 | STRNCPY(ut->ut_host, hostname, sizeof(ut->ut_host)); |
… | |
… | |
138 | sizeof(utx->ut_user)); |
137 | sizeof(utx->ut_user)); |
139 | STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id)); |
138 | STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id)); |
140 | utx->ut_session = getsid(0); |
139 | utx->ut_session = getsid(0); |
141 | utx->ut_tv.tv_sec = time(NULL); |
140 | utx->ut_tv.tv_sec = time(NULL); |
142 | utx->ut_tv.tv_usec = 0; |
141 | utx->ut_tv.tv_usec = 0; |
143 | utx->ut_pid = R->h->cmd_pid; |
142 | utx->ut_pid = cmd_pid; |
144 | # ifdef HAVE_UTMPX_HOST |
143 | # ifdef HAVE_UTMPX_HOST |
145 | STRNCPY(utx->ut_host, hostname, sizeof(utx->ut_host)); |
144 | STRNCPY(utx->ut_host, hostname, sizeof(utx->ut_host)); |
146 | # if 0 |
145 | # if 0 |
147 | { |
146 | { |
148 | char *colon; |
147 | char *colon; |
… | |
… | |
153 | # endif |
152 | # endif |
154 | # endif |
153 | # endif |
155 | utx->ut_type = USER_PROCESS; |
154 | utx->ut_type = USER_PROCESS; |
156 | pututxline(utx); |
155 | pututxline(utx); |
157 | endutxent(); /* close the file */ |
156 | endutxent(); /* close the file */ |
158 | R->h->utmp_pos = 0; |
157 | utmp_pos = 0; |
159 | #endif |
158 | #endif |
160 | |
159 | |
161 | #if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |
160 | #if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID) |
162 | { |
161 | { |
163 | int i; |
162 | int i; |
164 | # ifdef HAVE_TTYSLOT |
163 | # ifdef HAVE_TTYSLOT |
165 | i = ttyslot(); |
164 | i = ttyslot(); |
166 | if (rxvt_write_bsd_utmp(i, ut)) |
165 | if (rxvt_write_bsd_utmp(i, ut)) |
167 | R->h->utmp_pos = i; |
166 | utmp_pos = i; |
168 | # else |
167 | # else |
169 | FILE *fd0; |
168 | FILE *fd0; |
170 | |
169 | |
171 | if ((fd0 = fopen(TTYTAB_FILENAME, "r")) != NULL) { |
170 | if ((fd0 = fopen(TTYTAB_FILENAME, "r")) != NULL) { |
172 | char buf[256], name[256]; |
171 | char buf[256], name[256]; |
… | |
… | |
176 | if (*buf == '#' || sscanf(buf, "%s", name) != 1) |
175 | if (*buf == '#' || sscanf(buf, "%s", name) != 1) |
177 | continue; |
176 | continue; |
178 | if (!STRCMP(ut->ut_line, name)) { |
177 | if (!STRCMP(ut->ut_line, name)) { |
179 | if (!rxvt_write_bsd_utmp(i, ut)) |
178 | if (!rxvt_write_bsd_utmp(i, ut)) |
180 | i = 0; |
179 | i = 0; |
181 | R->h->utmp_pos = i; |
180 | utmp_pos = i; |
182 | fclose(fd0); |
181 | fclose(fd0); |
183 | break; |
182 | break; |
184 | } |
183 | } |
185 | i++; |
184 | i++; |
186 | } |
185 | } |
… | |
… | |
190 | } |
189 | } |
191 | #endif |
190 | #endif |
192 | |
191 | |
193 | #ifdef WTMP_SUPPORT |
192 | #ifdef WTMP_SUPPORT |
194 | # ifdef WTMP_ONLY_ON_LOGIN |
193 | # ifdef WTMP_ONLY_ON_LOGIN |
195 | if (R->Options & Opt_loginShell) |
194 | if (Options & Opt_loginShell) |
196 | # endif |
195 | # endif |
197 | { |
196 | { |
198 | # ifdef HAVE_STRUCT_UTMP |
197 | # ifdef HAVE_STRUCT_UTMP |
199 | # ifdef HAVE_UPDWTMP |
198 | # ifdef HAVE_UPDWTMP |
200 | updwtmp(RXVT_WTMP_FILE, ut); |
199 | updwtmp(RXVT_WTMP_FILE, ut); |
… | |
… | |
206 | updwtmpx(RXVT_WTMPX_FILE, utx); |
205 | updwtmpx(RXVT_WTMPX_FILE, utx); |
207 | # endif |
206 | # endif |
208 | } |
207 | } |
209 | #endif |
208 | #endif |
210 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
209 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
211 | if (R->Options & Opt_loginShell) |
210 | if (Options & Opt_loginShell) |
212 | rxvt_update_lastlog(RXVT_LASTLOG_FILE, pty, hostname); |
211 | rxvt_update_lastlog(RXVT_LASTLOG_FILE, pty, hostname); |
213 | #endif |
212 | #endif |
214 | } |
213 | } |
215 | |
214 | |
216 | /* ------------------------------------------------------------------------- */ |
215 | /* ------------------------------------------------------------------------- */ |
217 | /* |
216 | /* |
218 | * remove utmp and wtmp entries |
217 | * remove utmp and wtmp entries |
219 | */ |
218 | */ |
220 | /* EXTPROTO */ |
|
|
221 | void |
219 | void |
222 | rxvt_cleanutent(pR) |
220 | rxvt_term::cleanutent () |
223 | { |
221 | { |
224 | #ifdef HAVE_STRUCT_UTMP |
222 | #ifdef HAVE_STRUCT_UTMP |
225 | struct utmp *ut = &(R->h->ut); |
223 | struct utmp *ut = &(this->ut); |
226 | #endif |
224 | #endif |
227 | #ifdef HAVE_STRUCT_UTMPX |
225 | #ifdef HAVE_STRUCT_UTMPX |
228 | struct utmpx *tmputx, *utx = &(R->h->utx); |
226 | struct utmpx *tmputx, *utx = &(this->utx); |
229 | #endif |
227 | #endif |
230 | |
228 | |
231 | #ifdef HAVE_STRUCT_UTMP |
229 | #ifdef HAVE_STRUCT_UTMP |
232 | # ifdef HAVE_UTMP_PID |
230 | # ifdef HAVE_UTMP_PID |
233 | MEMSET(ut, 0, sizeof(struct utmp)); |
231 | MEMSET(ut, 0, sizeof(struct utmp)); |
234 | setutent(); |
232 | setutent(); |
235 | STRNCPY(ut->ut_id, R->h->ut_id, sizeof(ut->ut_id)); |
233 | STRNCPY(ut->ut_id, ut_id, sizeof(ut->ut_id)); |
236 | ut->ut_type = USER_PROCESS; |
234 | ut->ut_type = USER_PROCESS; |
237 | { |
235 | { |
238 | struct utmp *tmput = getutid(ut); |
236 | struct utmp *tmput = getutid(ut); |
239 | |
237 | |
240 | if (tmput) /* position to entry in utmp file */ |
238 | if (tmput) /* position to entry in utmp file */ |
… | |
… | |
251 | #endif |
249 | #endif |
252 | |
250 | |
253 | #ifdef HAVE_STRUCT_UTMPX |
251 | #ifdef HAVE_STRUCT_UTMPX |
254 | MEMSET(utx, 0, sizeof(struct utmpx)); |
252 | MEMSET(utx, 0, sizeof(struct utmpx)); |
255 | setutxent(); |
253 | setutxent(); |
256 | STRNCPY(utx->ut_id, R->h->ut_id, sizeof(utx->ut_id)); |
254 | STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id)); |
257 | utx->ut_type = USER_PROCESS; |
255 | utx->ut_type = USER_PROCESS; |
258 | if ((tmputx = getutxid(utx))) /* position to entry in utmp file */ |
256 | if ((tmputx = getutxid(utx))) /* position to entry in utmp file */ |
259 | utx = tmputx; |
257 | utx = tmputx; |
260 | utx->ut_type = DEAD_PROCESS; |
258 | utx->ut_type = DEAD_PROCESS; |
261 | utx->ut_session = getsid(0); |
259 | utx->ut_session = getsid(0); |
… | |
… | |
266 | /* |
264 | /* |
267 | * Write ending wtmp entry |
265 | * Write ending wtmp entry |
268 | */ |
266 | */ |
269 | #ifdef WTMP_SUPPORT |
267 | #ifdef WTMP_SUPPORT |
270 | # ifdef WTMP_ONLY_ON_LOGIN |
268 | # ifdef WTMP_ONLY_ON_LOGIN |
271 | if (R->Options & Opt_loginShell) |
269 | if (Options & Opt_loginShell) |
272 | # endif |
270 | # endif |
273 | { |
271 | { |
274 | # ifdef HAVE_STRUCT_UTMP |
272 | # ifdef HAVE_STRUCT_UTMP |
275 | # ifdef HAVE_UPDWTMP |
273 | # ifdef HAVE_UPDWTMP |
276 | updwtmp(RXVT_WTMP_FILE, ut); |
274 | updwtmp(RXVT_WTMP_FILE, ut); |
… | |
… | |
287 | /* |
285 | /* |
288 | * Write utmp entry |
286 | * Write utmp entry |
289 | */ |
287 | */ |
290 | #ifdef HAVE_STRUCT_UTMP |
288 | #ifdef HAVE_STRUCT_UTMP |
291 | # ifdef HAVE_UTMP_PID |
289 | # ifdef HAVE_UTMP_PID |
292 | if (ut->ut_pid == R->h->cmd_pid) |
290 | if (ut->ut_pid == cmd_pid) |
293 | pututline(ut); |
291 | pututline(ut); |
294 | endutent(); |
292 | endutent(); |
295 | # else |
293 | # else |
296 | MEMSET(ut, 0, sizeof(struct utmp)); |
294 | MEMSET(ut, 0, sizeof(struct utmp)); |
297 | rxvt_write_bsd_utmp(R->h->utmp_pos, ut); |
295 | rxvt_write_bsd_utmp(utmp_pos, ut); |
298 | # endif |
|
|
299 | #endif |
296 | # endif |
|
|
297 | #endif |
300 | #ifdef HAVE_STRUCT_UTMPX |
298 | #ifdef HAVE_STRUCT_UTMPX |
301 | if (utx->ut_pid == R->h->cmd_pid) |
299 | if (utx->ut_pid == cmd_pid) |
302 | pututxline(utx); |
300 | pututxline(utx); |
303 | endutxent(); |
301 | endutxent(); |
304 | #endif |
302 | #endif |
305 | } |
303 | } |
306 | |
304 | |