1 --- aterm-0.3.4/src/utmp.c.ewt Wed Mar 24 22:28:48 1999
2 +++ aterm-0.3.4/src/utmp.c Wed Mar 24 22:42:32 1999
4 static const char rcsid[] = "$Id$";
7 -#include "rxvt.h" /* NECESSARY */
10 - * HAVE_SETUTENT corresponds to SYSV-style utmp support.
11 - * Without it corresponds to using BSD utmp support.
12 - * SYSV-style utmp support is further divided in normal utmp support
13 - * and utmpx support (Solaris 2.x) by HAVE_UTMPX_H
17 - * update wtmp entries - only for SYSV style UTMP systems
20 -static char ut_id[5]; /* remember if entry to utmp made */
21 -# ifndef USE_SYSV_UTMP
22 -static int utmp_pos; /* BSD position of utmp-stamp */
26 -/* ------------------------------------------------------------------------- */
27 -#ifndef HAVE_UTMPX_H /* supposedly we have updwtmpx ? */
31 -rxvt_update_wtmp(char *fname, struct utmp *putmp)
33 - int fd, retry = 10; /* 10 attempts at locking */
34 - struct flock lck; /* fcntl locking scheme */
36 - if ((fd = open(fname, O_WRONLY | O_APPEND, 0)) < 0)
39 - lck.l_whence = SEEK_END; /* start lock at current eof */
40 - lck.l_len = 0; /* end at ``largest possible eof'' */
42 - lck.l_type = F_WRLCK; /* we want a write lock */
45 - /* attempt lock with F_SETLK - F_SETLKW would cause a deadlock! */
46 - if ((fcntl(fd, F_SETLK, &lck) < 0) && errno != EACCESS) {
48 - return; /* failed for unknown reason: give up */
50 - write(fd, putmp, sizeof(struct utmp));
52 -/* unlocking the file */
53 - lck.l_type = F_UNLCK;
54 - fcntl(fd, F_SETLK, &lck);
58 -#endif /* WTMP_SUPPORT */
59 -#endif /* !HAVE_UTMPX_H */
60 -/* ------------------------------------------------------------------------- */
67 -makeutent(const char *pty, const char *hostname)
68 +makeutent(const char *pty, const char *hostname, int fd)
71 - struct passwd *pwent = getpwuid(getuid());
74 -#ifndef USE_SYSV_UTMP
76 - * BSD style utmp entry
77 - * ut_line, ut_name, ut_host, ut_time
81 - char buf[256], name[256];
85 - * SYSV style utmp entry
86 - * ut_user, ut_id, ut_line, ut_pid, ut_type, ut_exit, ut_time
90 -#endif /* !USE_SYSV_UTMP */
92 -/* BSD naming is of the form /dev/tty?? or /dev/pty?? */
94 - MEMSET(&utmp, 0, sizeof(UTMP));
95 - if (!strncmp(pty, "/dev/", 5))
96 - pty += 5; /* skip /dev/ prefix */
97 - if (!strncmp(pty, "pty", 3) || !strncmp(pty, "tty", 3))
98 - STRNCPY(ut_id, (pty + 3), sizeof(ut_id));
100 -#ifndef USE_SYSV_UTMP
102 - print_error("can't parse tty name \"%s\"", pty);
103 - ut_id[0] = '\0'; /* entry not made */
107 - STRNCPY(utmp.ut_line, pty, sizeof(utmp.ut_line));
108 - STRNCPY(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
109 - sizeof(utmp.ut_name));
110 - STRNCPY(utmp.ut_host, hostname, sizeof(utmp.ut_host));
111 - utmp.ut_time = time(NULL);
113 - if ((fd0 = fopen(UTMP_FILENAME, "r+")) == NULL)
114 - ut_id[0] = '\0'; /* entry not made */
117 - if ((fd1 = fopen(TTYTAB_FILENAME, "r")) != NULL) {
118 - for (i = 1; (fgets(buf, sizeof(buf), fd1) != NULL); i++) {
119 - if (*buf == '#' || sscanf(buf, "%s", name) != 1)
121 - if (!strcmp(utmp.ut_line, name)) {
123 - utmp_pos = i * sizeof(struct utmp);
131 - ut_id[0] = '\0'; /* entry not made */
133 - fseek(fd0, utmp_pos, 0);
134 - fwrite(&utmp, sizeof(UTMP), 1, fd0);
139 -#else /* USE_SYSV_UTMP */
143 - if (sscanf(pty, "pts/%d", &n) == 1)
144 - sprintf(ut_id, "vt%02x", (n % 256)); /* sysv naming */
146 - print_error("can't parse tty name \"%s\"", pty);
147 - ut_id[0] = '\0'; /* entry not made */
152 - utmpname(UTMP_FILENAME);
154 - setutent(); /* XXX: should be unnecessaray */
156 - STRNCPY(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
157 - utmp.ut_type = DEAD_PROCESS;
158 - (void)getutid(&utmp); /* position to entry in utmp file */
160 -/* set up the new entry */
161 - utmp.ut_type = USER_PROCESS;
163 - utmp.ut_exit.e_exit = 2;
165 - STRNCPY(utmp.ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
166 - sizeof(utmp.ut_user));
167 - STRNCPY(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
168 - STRNCPY(utmp.ut_line, pty, sizeof(utmp.ut_line));
170 -#ifdef HAVE_UTMP_HOST
171 - STRNCPY(utmp.ut_host, hostname, sizeof(utmp.ut_host));
173 - if ((colon = strrchr(utmp.ut_host, ':')) != NULL)
176 -#endif /* HAVE_UTMP_HOST */
178 -/* ut_name is normally the same as ut_user, but .... */
179 - STRNCPY(utmp.ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
180 - sizeof(utmp.ut_name));
182 - utmp.ut_pid = getpid();
185 - utmp.ut_session = getsid(0);
186 - utmp.ut_tv.tv_sec = time(NULL);
187 - utmp.ut_tv.tv_usec = 0;
189 - utmp.ut_time = time(NULL);
190 -#endif /* HAVE_UTMPX_H */
195 - update_wtmp(WTMP_FILENAME, &utmp);
198 - endutent(); /* close the file */
199 -#endif /* !USE_SYSV_UTMP */
200 + addToUtmp(pty, hostname, fd);
202 -#endif /* UTMP_SUPPORT */
204 /* ------------------------------------------------------------------------- */
207 * remove a utmp entry
215 -#ifndef USE_SYSV_UTMP
218 - if (ut_id[0] && ((fd = fopen(UTMP_FILENAME, "r+")) != NULL)) {
219 - MEMSET(&utmp, 0, sizeof(struct utmp));
221 - fseek(fd, utmp_pos, 0);
222 - fwrite(&utmp, sizeof(struct utmp), 1, fd);
226 -#else /* USE_SYSV_UTMP */
230 - return; /* entry not made */
232 - utmpname(UTMP_FILENAME);
233 - MEMSET(&utmp, 0, sizeof(UTMP));
234 - STRNCPY(utmp.ut_id, ut_id, sizeof(utmp.ut_id));
235 - utmp.ut_type = USER_PROCESS;
237 - setutent(); /* XXX: should be unnecessaray */
239 - putmp = getutid(&utmp);
240 - if (!putmp || putmp->ut_pid != getpid())
243 - putmp->ut_type = DEAD_PROCESS;
246 - putmp->ut_session = getsid(0);
247 - putmp->ut_tv.tv_sec = time(NULL);
248 - putmp->ut_tv.tv_usec = 0;
249 -#else /* HAVE_UTMPX_H */
250 - putmp->ut_time = time(NULL);
251 -#endif /* HAVE_UTMPX_H */
255 - update_wtmp(WTMP_FILENAME, putmp);
259 -#endif /* !USE_SYSV_UTMP */
263 --- aterm-0.3.4/src/command.c.ewt Wed Mar 24 22:30:36 1999
264 +++ aterm-0.3.4/src/command.c Wed Mar 24 22:31:18 1999
265 @@ -1037,7 +1037,7 @@
268 if (!(Options & Opt_utmpInhibit))
269 - makeutent(ttydev, display_name); /* stamp /etc/utmp */
270 + makeutent(ttydev, display_name, ptyfd); /* stamp /etc/utmp */
274 --- aterm-0.3.4/src/Makefile.in.ewt Wed Mar 24 22:31:24 1999
275 +++ aterm-0.3.4/src/Makefile.in Wed Mar 24 22:31:33 1999
279 aterm: version.h $(PROS) $(OBJS)
280 - $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(XLIB) $(DLIB)
281 + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(XLIB) $(DLIB) -lutempter
284 $(SED) -n -f $(srcdir)/makeprotos-sed $< > $@