]>
Commit | Line | Data |
---|---|---|
f605c4c0 JR |
1 | --- AfterStep-APPS-990329/xiterm-2.0/src/utmp.c.xiutmp Fri Sep 25 04:12:13 1998 |
2 | +++ AfterStep-APPS-990329/xiterm-2.0/src/utmp.c Mon Mar 29 18:52:13 1999 | |
3 | @@ -1,14 +1,8 @@ | |
4 | +#include <stdio.h> | |
5 | /*--------------------------------*-C-*---------------------------------* | |
6 | * File: utmp.c | |
7 | *----------------------------------------------------------------------* | |
8 | - * | |
9 | - * Copyright (c) 1992 John Bovey <jdb@ukc.ac.uk> | |
10 | - * Copyright (c) 1993 lipka | |
11 | - * Copyright (c) 1993 Brian Stempien <stempien@cs.wmich.edu> | |
12 | - * Copyright (c) 1995 Raul Garcia Garcia <rgg@tid.es> | |
13 | - * Copyright (c) 1995 Piet W. Plomp <piet@idefix.icce.rug.nl> | |
14 | - * Copyright (c) 1997 Raul Garcia Garcia <rgg@tid.es> | |
15 | - * Copyright (c) 1997 1998 Geoff Wing <mason@primenet.com.au> | |
16 | + * Copyright 1997,1998 Geoff Wing <gcw@pobox.com> | |
17 | * | |
18 | * This program is free software; you can redistribute it and/or modify | |
19 | * it under the terms of the GNU General Public License as published by | |
20 | @@ -23,210 +17,43 @@ | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | + *----------------------------------------------------------------------*/ | |
25 | +/*----------------------------------------------------------------------* | |
26 | + * Originally written: | |
27 | + * 1992 John Bovey <jdb@ukc.ac.uk> | |
28 | + * Modifications: | |
29 | + * 1993 lipka | |
30 | + * 1993 Brian Stempien <stempien@cs.wmich.edu> | |
31 | + * 1995 Raul Garcia Garcia <rgg@tid.es> | |
32 | + * 1995 Piet W. Plomp <piet@idefix.icce.rug.nl> | |
33 | + * 1997 Raul Garcia Garcia <rgg@tid.es> | |
34 | + * 1997,1998 Geoff Wing <mason@primenet.com.au> | |
35 | + *----------------------------------------------------------------------*/ | |
36 | +/*----------------------------------------------------------------------* | |
37 | + * Public: | |
38 | + * extern void cleanutent (void); | |
39 | + * extern void makeutent (const char * pty, const char * hostname); | |
40 | * | |
41 | + * Private: | |
42 | + * write_utmp (); | |
43 | + * update_wtmp (); | |
44 | *----------------------------------------------------------------------*/ | |
45 | ||
46 | -#include "misc.h" /* NECESSARY */ | |
47 | - | |
48 | -/* | |
49 | - * HAVE_SETUTENT corresponds to SYSV-style utmp support. | |
50 | - * Without it corresponds to using BSD utmp support. | |
51 | - * SYSV-style utmp support is further divided in normal utmp support | |
52 | - * and utmpx support (Solaris 2.x) by HAVE_UTMPX_H | |
53 | - */ | |
54 | - | |
55 | -/* | |
56 | - * update wtmp entries - only for SYSV style UTMP systems | |
57 | - */ | |
58 | -#ifdef UTMP_SUPPORT | |
59 | -static char ut_id[5]; /* remember if entry to utmp made */ | |
60 | - | |
61 | -#ifndef USE_SYSV_UTMP | |
62 | -static int utmp_pos; /* BSD position of utmp-stamp */ | |
63 | - | |
64 | +#ifndef lint | |
65 | +static const char rcsid[] = "$Id$"; | |
66 | #endif | |
67 | -#endif | |
68 | - | |
69 | -/* ------------------------------------------------------------------------- */ | |
70 | -#ifndef HAVE_UTMPX_H /* supposedly we have updwtmpx ? */ | |
71 | -#ifdef WTMP_SUPPORT | |
72 | -/* PROTO */ | |
73 | -void | |
74 | -xiterm_update_wtmp(char *fname, struct utmp *putmp) | |
75 | -{ | |
76 | - int fd, retry = 10; /* 10 attempts at locking */ | |
77 | - struct flock lck; /* fcntl locking scheme */ | |
78 | ||
79 | - if ((fd = open(fname, O_WRONLY | O_APPEND, 0)) < 0) | |
80 | - return; | |
81 | - | |
82 | - lck.l_whence = SEEK_END; /* start lock at current eof */ | |
83 | - lck.l_len = 0; /* end at ``largest possible eof'' */ | |
84 | - lck.l_start = 0; | |
85 | - lck.l_type = F_WRLCK; /* we want a write lock */ | |
86 | - | |
87 | - while (retry--) | |
88 | - /* attempt lock with F_SETLK - F_SETLKW would cause a deadlock! */ | |
89 | - if ((fcntl(fd, F_SETLK, &lck) < 0) && errno != EACCESS) { | |
90 | - close(fd); | |
91 | - return; /* failed for unknown reason: give up */ | |
92 | - } | |
93 | - write(fd, putmp, sizeof(struct utmp)); | |
94 | - | |
95 | -/* unlocking the file */ | |
96 | - lck.l_type = F_UNLCK; | |
97 | - fcntl(fd, F_SETLK, &lck); | |
98 | - | |
99 | - close(fd); | |
100 | -} | |
101 | - | |
102 | -#endif /* WTMP_SUPPORT */ | |
103 | -#endif /* !HAVE_UTMPX_H */ | |
104 | -/* ------------------------------------------------------------------------- */ | |
105 | -#ifdef UTMP_SUPPORT | |
106 | /* | |
107 | * make a utmp entry | |
108 | */ | |
109 | /* PROTO */ | |
110 | void | |
111 | -makeutent(const char *pty, const char *hostname) | |
112 | +makeutent(const char *pty, const char *hostname, int fd) | |
113 | { | |
114 | - | |
115 | - struct passwd *pwent = getpwuid(getuid()); | |
116 | - UTMP utmp; | |
117 | - | |
118 | -#ifndef USE_SYSV_UTMP | |
119 | -/* | |
120 | - * BSD style utmp entry | |
121 | - * ut_line, ut_name, ut_host, ut_time | |
122 | - */ | |
123 | - int rval = 0, i; | |
124 | - FILE *fd0, *fd1; | |
125 | - char buf[256], name[256]; | |
126 | - | |
127 | -#else | |
128 | -/* | |
129 | - * SYSV style utmp entry | |
130 | - * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time | |
131 | - */ | |
132 | - char *colon; | |
133 | - | |
134 | -#endif /* !USE_SYSV_UTMP */ | |
135 | - | |
136 | -/* BSD naming is of the form /dev/tty?? or /dev/pty?? */ | |
137 | - | |
138 | - rmemset(&utmp, 0, sizeof(UTMP)); | |
139 | - if (!strncmp(pty, "/dev/", 5)) | |
140 | - pty += 5; /* skip /dev/ prefix */ | |
141 | - if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3)) | |
142 | - strncpy(ut_id, (pty + 3), sizeof(ut_id)); | |
143 | - else | |
144 | -#ifndef USE_SYSV_UTMP | |
145 | - { | |
146 | - print_error("can't parse tty name \"%s\"", pty); | |
147 | - ut_id[0] = '\0'; /* entry not made */ | |
148 | - return; | |
149 | - } | |
150 | - | |
151 | - strncpy(utmp.ut_line, pty, sizeof(utmp.ut_line)); | |
152 | - strncpy(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", | |
153 | - sizeof(utmp.ut_name)); | |
154 | - strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host)); | |
155 | - utmp.ut_time = time(NULL); | |
156 | - | |
157 | - if ((fd0 = fopen(UTMP_FILENAME, "r+")) == NULL) | |
158 | - ut_id[0] = '\0'; /* entry not made */ | |
159 | - else { | |
160 | - utmp_pos = -1; | |
161 | - if ((fd1 = fopen(TTYTAB_FILENAME, "r")) != NULL) { | |
162 | - for (i = 1; (fgets(buf, sizeof(buf), fd1) != NULL); i++) { | |
163 | - if (*buf == '#' || sscanf(buf, "%s", name) != 1) | |
164 | - continue; | |
165 | - if (!strcmp(utmp.ut_line, name)) { | |
166 | - fclose(fd1); | |
167 | - utmp_pos = i * sizeof(struct utmp); | |
168 | - | |
169 | - break; | |
170 | - } | |
171 | - } | |
172 | - fclose(fd1); | |
173 | - } | |
174 | - if (utmp_pos < 0) | |
175 | - ut_id[0] = '\0'; /* entry not made */ | |
176 | - else { | |
177 | - fseek(fd0, utmp_pos, 0); | |
178 | - fwrite(&utmp, sizeof(UTMP), 1, fd0); | |
179 | - rval = 1; | |
180 | - } | |
181 | - fclose(fd0); | |
182 | - } | |
183 | - | |
184 | -#else /* USE_SYSV_UTMP */ | |
185 | - { | |
186 | - int n; | |
187 | - | |
188 | - if (sscanf(pty, "pts/%d", &n) == 1) | |
189 | - sprintf(ut_id, "vt%02x", (n % 256)); /* sysv naming */ | |
190 | - else { | |
191 | - print_error("can't parse tty name \"%s\"", pty); | |
192 | - ut_id[0] = '\0'; /* entry not made */ | |
193 | - return; | |
194 | - } | |
195 | - } | |
196 | - | |
197 | - utmpname(UTMP_FILENAME); | |
198 | - | |
199 | - setutent(); /* XXX: should be unnecessaray */ | |
200 | - | |
201 | - strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id)); | |
202 | - utmp.ut_type = DEAD_PROCESS; | |
203 | - (void)getutid(&utmp); /* position to entry in utmp file */ | |
204 | - | |
205 | -/* set up the new entry */ | |
206 | - utmp.ut_type = USER_PROCESS; | |
207 | -#ifndef linux | |
208 | - utmp.ut_exit.e_exit = 2; | |
209 | -#endif | |
210 | - strncpy(utmp.ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", | |
211 | - sizeof(utmp.ut_user)); | |
212 | - strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id)); | |
213 | - strncpy(utmp.ut_line, pty, sizeof(utmp.ut_line)); | |
214 | - | |
215 | -#ifdef HAVE_UTMP_HOST | |
216 | - strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host)); | |
217 | -#ifndef linux | |
218 | - if ((colon = strrchr(utmp.ut_host, ':')) != NULL) | |
219 | - *colon = '\0'; | |
220 | -#endif | |
221 | -#endif /* HAVE_UTMP_HOST */ | |
222 | - | |
223 | -/* ut_name is normally the same as ut_user, but .... */ | |
224 | - strncpy(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", | |
225 | - sizeof(utmp.ut_name)); | |
226 | - | |
227 | - utmp.ut_pid = getpid(); | |
228 | - | |
229 | -#ifdef HAVE_UTMPX_H | |
230 | - utmp.ut_session = getsid(0); | |
231 | - utmp.ut_tv.tv_sec = time(NULL); | |
232 | - utmp.ut_tv.tv_usec = 0; | |
233 | -#else | |
234 | - utmp.ut_time = time(NULL); | |
235 | -#endif /* HAVE_UTMPX_H */ | |
236 | - | |
237 | - pututline(&utmp); | |
238 | - | |
239 | -#ifdef WTMP_SUPPORT | |
240 | - update_wtmp(WTMP_FILENAME, &utmp); | |
241 | -#endif | |
242 | - | |
243 | - endutent(); /* close the file */ | |
244 | -#endif /* !USE_SYSV_UTMP */ | |
245 | + addToUtmp(pty, hostname, fd); | |
246 | } | |
247 | -#endif /* UTMP_SUPPORT */ | |
248 | ||
249 | /* ------------------------------------------------------------------------- */ | |
250 | -#ifdef UTMP_SUPPORT | |
251 | /* | |
252 | * remove a utmp entry | |
253 | */ | |
254 | @@ -234,52 +61,5 @@ | |
255 | void | |
256 | cleanutent(void) | |
257 | { | |
258 | - UTMP utmp; | |
259 | - | |
260 | -#ifndef USE_SYSV_UTMP | |
261 | - FILE *fd; | |
262 | - | |
263 | - if (ut_id[0] && ((fd = fopen(UTMP_FILENAME, "r+")) != NULL)) { | |
264 | - rmemset(&utmp, 0, sizeof(struct utmp)); | |
265 | - | |
266 | - fseek(fd, utmp_pos, 0); | |
267 | - fwrite(&utmp, sizeof(struct utmp), 1, fd); | |
268 | - | |
269 | - fclose(fd); | |
270 | - } | |
271 | -#else /* USE_SYSV_UTMP */ | |
272 | - UTMP *putmp; | |
273 | - | |
274 | - if (!ut_id[0]) | |
275 | - return; /* entry not made */ | |
276 | - | |
277 | - utmpname(UTMP_FILENAME); | |
278 | - rmemset(&utmp, 0, sizeof(UTMP)); | |
279 | - strncpy(utmp.ut_id, ut_id, sizeof(utmp.ut_id)); | |
280 | - utmp.ut_type = USER_PROCESS; | |
281 | - | |
282 | - setutent(); /* XXX: should be unnecessaray */ | |
283 | - | |
284 | - putmp = getutid(&utmp); | |
285 | - if (!putmp || putmp->ut_pid != getpid()) | |
286 | - return; | |
287 | - | |
288 | - putmp->ut_type = DEAD_PROCESS; | |
289 | - | |
290 | -#ifdef HAVE_UTMPX_H | |
291 | - putmp->ut_session = getsid(0); | |
292 | - putmp->ut_tv.tv_sec = time(NULL); | |
293 | - putmp->ut_tv.tv_usec = 0; | |
294 | -#else /* HAVE_UTMPX_H */ | |
295 | - putmp->ut_time = time(NULL); | |
296 | -#endif /* HAVE_UTMPX_H */ | |
297 | - pututline(putmp); | |
298 | - | |
299 | -#ifdef WTMP_SUPPORT | |
300 | - update_wtmp(WTMP_FILENAME, putmp); | |
301 | -#endif | |
302 | - | |
303 | - endutent(); | |
304 | -#endif /* !USE_SYSV_UTMP */ | |
305 | + removeFromUtmp(); | |
306 | } | |
307 | -#endif | |
308 | --- AfterStep-APPS-990329/xiterm-2.0/src/command.c.xiutmp Fri Sep 25 04:12:13 1998 | |
309 | +++ AfterStep-APPS-990329/xiterm-2.0/src/command.c Mon Mar 29 18:40:33 1999 | |
310 | @@ -1031,7 +1031,7 @@ | |
311 | #ifdef UTMP_SUPPORT | |
312 | privileges(RESTORE); | |
313 | if (!(Options & Opt_utmpInhibit)) | |
314 | - makeutent(ttydev, display_name); /* stamp /etc/utmp */ | |
315 | + makeutent(ttydev, display_name, ptyfd); /* stamp /etc/utmp */ | |
316 | privileges(IGNORE); | |
317 | #endif | |
318 | ||
319 | --- AfterStep-APPS-990329/xiterm-2.0/configure.xiutmp Fri Sep 25 11:24:03 1998 | |
320 | +++ AfterStep-APPS-990329/xiterm-2.0/configure Mon Mar 29 18:40:33 1999 | |
321 | @@ -1803,49 +1803,6 @@ | |
322 | echo "$ac_t""no" 1>&6 | |
323 | fi | |
324 | ||
325 | - if test $ac_cv_func_connect = no; then | |
326 | - echo $ac_n "checking for connect in -lsocket""... $ac_c" 1>&6 | |
327 | -echo "configure:1809: checking for connect in -lsocket" >&5 | |
328 | -ac_lib_var=`echo socket'_'connect | sed 'y%./+-%__p_%'` | |
329 | -if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then | |
330 | - echo $ac_n "(cached) $ac_c" 1>&6 | |
331 | -else | |
332 | - ac_save_LIBS="$LIBS" | |
333 | -LIBS="-lsocket $X_EXTRA_LIBS $LIBS" | |
334 | -cat > conftest.$ac_ext <<EOF | |
335 | -#line 1817 "configure" | |
336 | -#include "confdefs.h" | |
337 | -/* Override any gcc2 internal prototype to avoid an error. */ | |
338 | -/* We use char because int might match the return type of a gcc2 | |
339 | - builtin and then its argument prototype would still apply. */ | |
340 | -char connect(); | |
341 | - | |
342 | -int main() { | |
343 | -connect() | |
344 | -; return 0; } | |
345 | -EOF | |
346 | -if { (eval echo configure:1828: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then | |
347 | - rm -rf conftest* | |
348 | - eval "ac_cv_lib_$ac_lib_var=yes" | |
349 | -else | |
350 | - echo "configure: failed program was:" >&5 | |
351 | - cat conftest.$ac_ext >&5 | |
352 | - rm -rf conftest* | |
353 | - eval "ac_cv_lib_$ac_lib_var=no" | |
354 | -fi | |
355 | -rm -f conftest* | |
356 | -LIBS="$ac_save_LIBS" | |
357 | - | |
358 | -fi | |
359 | -if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then | |
360 | - echo "$ac_t""yes" 1>&6 | |
361 | - X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS" | |
362 | -else | |
363 | - echo "$ac_t""no" 1>&6 | |
364 | -fi | |
365 | - | |
366 | - fi | |
367 | - | |
368 | # gomez@mi.uni-erlangen.de says -lposix is necessary on A/UX. | |
369 | echo $ac_n "checking for remove""... $ac_c" 1>&6 | |
370 | echo "configure:1852: checking for remove" >&5 |