+2001-07-02 Tom Yu <tlyu@mit.edu>
+
+ * update_utmp.c (pty_update_utmp): Remember to chop off leading
+ "/dev/" for the non-sysV case. Handle lseek() returning non-zero
+ yet non-negative values (it usually does... :-), so that we can
+ actually write somewhere not at the beginning of the utmp file if
+ necessary.
+
2001-06-28 Ken Raeburn <raeburn@mit.edu>
* update_utmp.c (pty_update_utmp): Don't copy host if it's a null
const char *line, const char *host, int flags)
{
struct utmp ent, ut;
+ const char *cp;
int tty, lc, fd;
+ off_t seekpos;
+ ssize_t ret;
struct stat statb;
memset(&ent, 0, sizeof(ent));
strncpy(ent.ut_host, host, sizeof(ent.ut_host));
#endif
strncpy(ent.ut_name, username, sizeof(ent.ut_name));
- strncpy(ent.ut_line, line, sizeof(ent.ut_line));
+ cp = line;
+ if (strncmp(cp, "/dev/", sizeof("/dev/") - 1) == 0)
+ cp += sizeof("/dev/") - 1;
+ strncpy(ent.ut_line, cp, sizeof(ent.ut_line));
(void)time(&ent.ut_time);
- if (flags & PTY_TTYSLOT_USABLE)
+ if (flags & PTY_TTYSLOT_USABLE)
tty = ttyslot();
else {
tty = -1;
if (fd == -1)
return errno;
for (lc = 0; ; lc++) {
- if (lseek(fd, (off_t)(lc * sizeof(struct utmp)),
- SEEK_SET))
+ seekpos = lseek(fd, (off_t)(lc * sizeof(struct utmp)), SEEK_SET);
+ if (seekpos != (off_t)(lc * sizeof(struct utmp)))
break;
if (read(fd, (char *) &ut, sizeof(struct utmp))
!= sizeof(struct utmp))
close(fd);
return 0;
}
- if (lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET)) {
+ seekpos = lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
+ if (seekpos != (off_t)(tty * sizeof(struct utmp))) {
close(fd);
return 0;
}
- if (write(fd, (char *)&ent, sizeof(struct utmp))
- != sizeof(struct utmp)) {
+ ret = write(fd, (char *)&ent, sizeof(struct utmp));
+ if (ret != sizeof(struct utmp)) {
ftruncate(fd, statb.st_size);
}
close(fd);