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