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
5 /*--------------------------------*-C-*---------------------------------*
7 *----------------------------------------------------------------------*
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>
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
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>
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 +/*----------------------------------------------------------------------*
38 + * extern void cleanutent (void);
39 + * extern void makeutent (const char * pty, const char * hostname);
44 *----------------------------------------------------------------------*/
46 -#include "misc.h" /* NECESSARY */
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
56 - * update wtmp entries - only for SYSV style UTMP systems
59 -static char ut_id[5]; /* remember if entry to utmp made */
61 -#ifndef USE_SYSV_UTMP
62 -static int utmp_pos; /* BSD position of utmp-stamp */
65 +static const char rcsid[] = "$Id$";
69 -/* ------------------------------------------------------------------------- */
70 -#ifndef HAVE_UTMPX_H /* supposedly we have updwtmpx ? */
74 -xiterm_update_wtmp(char *fname, struct utmp *putmp)
76 - int fd, retry = 10; /* 10 attempts at locking */
77 - struct flock lck; /* fcntl locking scheme */
79 - if ((fd = open(fname, O_WRONLY | O_APPEND, 0)) < 0)
82 - lck.l_whence = SEEK_END; /* start lock at current eof */
83 - lck.l_len = 0; /* end at ``largest possible eof'' */
85 - lck.l_type = F_WRLCK; /* we want a write lock */
88 - /* attempt lock with F_SETLK - F_SETLKW would cause a deadlock! */
89 - if ((fcntl(fd, F_SETLK, &lck) < 0) && errno != EACCESS) {
91 - return; /* failed for unknown reason: give up */
93 - write(fd, putmp, sizeof(struct utmp));
95 -/* unlocking the file */
96 - lck.l_type = F_UNLCK;
97 - fcntl(fd, F_SETLK, &lck);
102 -#endif /* WTMP_SUPPORT */
103 -#endif /* !HAVE_UTMPX_H */
104 -/* ------------------------------------------------------------------------- */
111 -makeutent(const char *pty, const char *hostname)
112 +makeutent(const char *pty, const char *hostname, int fd)
115 - struct passwd *pwent = getpwuid(getuid());
118 -#ifndef USE_SYSV_UTMP
120 - * BSD style utmp entry
121 - * ut_line, ut_name, ut_host, ut_time
125 - char buf[256], name[256];
129 - * SYSV style utmp entry
130 - * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time
134 -#endif /* !USE_SYSV_UTMP */
136 -/* BSD naming is of the form /dev/tty?? or /dev/pty?? */
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));
144 -#ifndef USE_SYSV_UTMP
146 - print_error("can't parse tty name \"%s\"", pty);
147 - ut_id[0] = '\0'; /* entry not made */
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);
157 - if ((fd0 = fopen(UTMP_FILENAME, "r+")) == NULL)
158 - ut_id[0] = '\0'; /* entry not made */
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)
165 - if (!strcmp(utmp.ut_line, name)) {
167 - utmp_pos = i * sizeof(struct utmp);
175 - ut_id[0] = '\0'; /* entry not made */
177 - fseek(fd0, utmp_pos, 0);
178 - fwrite(&utmp, sizeof(UTMP), 1, fd0);
184 -#else /* USE_SYSV_UTMP */
188 - if (sscanf(pty, "pts/%d", &n) == 1)
189 - sprintf(ut_id, "vt%02x", (n % 256)); /* sysv naming */
191 - print_error("can't parse tty name \"%s\"", pty);
192 - ut_id[0] = '\0'; /* entry not made */
197 - utmpname(UTMP_FILENAME);
199 - setutent(); /* XXX: should be unnecessaray */
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 */
205 -/* set up the new entry */
206 - utmp.ut_type = USER_PROCESS;
208 - utmp.ut_exit.e_exit = 2;
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));
215 -#ifdef HAVE_UTMP_HOST
216 - strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
218 - if ((colon = strrchr(utmp.ut_host, ':')) != NULL)
221 -#endif /* HAVE_UTMP_HOST */
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));
227 - utmp.ut_pid = getpid();
230 - utmp.ut_session = getsid(0);
231 - utmp.ut_tv.tv_sec = time(NULL);
232 - utmp.ut_tv.tv_usec = 0;
234 - utmp.ut_time = time(NULL);
235 -#endif /* HAVE_UTMPX_H */
240 - update_wtmp(WTMP_FILENAME, &utmp);
243 - endutent(); /* close the file */
244 -#endif /* !USE_SYSV_UTMP */
245 + addToUtmp(pty, hostname, fd);
247 -#endif /* UTMP_SUPPORT */
249 /* ------------------------------------------------------------------------- */
252 * remove a utmp entry
260 -#ifndef USE_SYSV_UTMP
263 - if (ut_id[0] && ((fd = fopen(UTMP_FILENAME, "r+")) != NULL)) {
264 - rmemset(&utmp, 0, sizeof(struct utmp));
266 - fseek(fd, utmp_pos, 0);
267 - fwrite(&utmp, sizeof(struct utmp), 1, fd);
271 -#else /* USE_SYSV_UTMP */
275 - return; /* entry not made */
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;
282 - setutent(); /* XXX: should be unnecessaray */
284 - putmp = getutid(&utmp);
285 - if (!putmp || putmp->ut_pid != getpid())
288 - putmp->ut_type = DEAD_PROCESS;
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 */
300 - update_wtmp(WTMP_FILENAME, putmp);
304 -#endif /* !USE_SYSV_UTMP */
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 @@
313 if (!(Options & Opt_utmpInhibit))
314 - makeutent(ttydev, display_name); /* stamp /etc/utmp */
315 + makeutent(ttydev, display_name, ptyfd); /* stamp /etc/utmp */
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
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
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. */
346 -if { (eval echo configure:1828: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
348 - eval "ac_cv_lib_$ac_lib_var=yes"
350 - echo "configure: failed program was:" >&5
351 - cat conftest.$ac_ext >&5
353 - eval "ac_cv_lib_$ac_lib_var=no"
356 -LIBS="$ac_save_LIBS"
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"
363 - echo "$ac_t""no" 1>&6
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