+Tue Apr 16 22:06:36 1996 Ken Raeburn <raeburn@cygnus.com>
+
+ * dump-utmp.c: New file. Not automatically used by anything, but
+ may be useful for examining utmp/wtmp files when comparing
+ behavior against system software.
+
+ Sun Mar 31 02:04:28 1996 Ken Raeburn <raeburn@cygnus.com>
+
+ * update_utmp.c (pty_update_utmp): Always use id "cons" for
+ console. For HP-UX, omit "kl" prefix. Reindent for readability.
+ * update_wtmp.c (ptyint_update_wtmp): For HP-UX, copy ut_id and
+ ut_type from input utmp structure. Reindent for readability.
+
+ Wed Mar 27 21:14:33 1996 Marc Horowitz <marc@mit.edu>
+
+ * init_slave.c (pty_initialize_slave): Spurious signal stuff
+ which did nothing deleted.
+
Tue Apr 16 13:43:43 1996 Sam Hartman <hartmans@mit.edu>
* configure.in : Don't use streams on HPUX.
--- /dev/null
+#include <stdio.h>
+#include <sys/file.h>
+#include <fcntl.h>
+
+#ifdef UTMPX
+#include <utmpx.h>
+#endif
+#include <utmp.h>
+
+char *ut_typename (t) {
+ switch (t) {
+#define S(N) case N : return #N
+ S(EMPTY);
+ S(RUN_LVL);
+ S(BOOT_TIME);
+ S(OLD_TIME);
+ S(NEW_TIME);
+ S(INIT_PROCESS);
+ S(LOGIN_PROCESS);
+ S(USER_PROCESS);
+ S(DEAD_PROCESS);
+ S(ACCOUNTING);
+ default: return "??";
+ }
+}
+
+int main (argc, argv) int argc; char *argv[]; {
+ int f;
+ char id[5], user[50];
+ char *file = 0;
+ int all = 0;
+
+ while (*++argv)
+ {
+ char *arg = *argv;
+ if (!arg)
+ break;
+ if (!strcmp ("-a", arg))
+ all = 1;
+ else if (file)
+ {
+ fprintf (stderr, "already got a file\n");
+ return 1;
+ }
+ else
+ file = arg;
+ }
+ f = open (file, O_RDONLY);
+ if (f < 0) {
+ perror (file);
+ exit (1);
+ }
+ id[4] = 0;
+#ifdef UTMPX
+ if ('x' != file[strlen(file) - 1]) {
+ struct utmpx u;
+ while (read (f, &u, sizeof (u)) == sizeof (u)) {
+ char c;
+ if ((u.ut_type == DEAD_PROCESS
+ || u.ut_type == EMPTY)
+ && !all)
+ continue;
+ strncpy (id, u.ut_id, 4);
+ printf ("%-8s:%-12s:%-4s:%6d %s",
+ u.ut_user, u.ut_line, id,
+ u.ut_pid, ut_typename (u.ut_type));
+ /* ctime (&u.ut_xtime) + 4 */
+ if (u.ut_syslen && u.ut_host[0])
+ printf (" %s", u.ut_host);
+ printf ("\n");
+ return 0;
+ }
+ }
+ /* else */
+#endif
+ {
+ struct utmp u;
+ user[sizeof(u.ut_user)] = 0;
+ while (read (f, &u, sizeof (u)) == sizeof (u)) {
+ char c;
+ if ((u.ut_type == DEAD_PROCESS
+ || u.ut_type == EMPTY)
+ && !all)
+ continue;
+ strncpy (id, u.ut_id, 4);
+ strncpy (user, u.ut_user, sizeof (u.ut_user));
+ printf ("%-8s:%-12s:%-4s:%6d %s", user, u.ut_line, id,
+ u.ut_pid, ut_typename (u.ut_type));
+ printf ("\n");
+#if 0
+ printf ("user: %-32s id: %s\n", user, id);
+ printf (" line: %-32s pid:%-6d type: %s\n",
+ u.ut_line, u.ut_pid, ut_typename (u.ut_type));
+ printf (" exit_status: %d,%d\n",
+ u.ut_exit.e_termination, u.ut_exit.e_exit);
+ printf (" time: %s\n", ctime (&u.ut_time) + 4);
+#endif
+ }
+ }
+
+ return 0;
+}
struct sgttyb b;
#endif /* POSIX_TERMIOS */
int pid;
-#ifdef POSIX_SIGNALS
- struct sigaction sa;
- /* Initialize "sa" structure. */
- (void) sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0;
-
-#endif
#ifdef HAVE_STREAMS
#ifdef HAVE_LINE_PUSH
#endif
#ifndef NO_UT_PID
- tmpx = line + strlen(line)-1;
- if (*(tmpx-1) != '/') tmpx--; /* last two characters, unless it's a / */
- sprintf(utmp_id, "kl%s", tmpx);
- strncpy(ent.ut_id, utmp_id, sizeof(ent.ut_id));
+ if (!strcmp (line, "/dev/console"))
+ strncpy (ent.ut_id, "cons", 4);
+ else {
+ tmpx = line + strlen(line)-1;
+ if (*(tmpx-1) != '/') tmpx--; /* last two characters, unless it's a / */
+#ifdef __hpux
+ strcpy(utmp_id, tmpx);
+#else
+ sprintf(utmp_id, "kl%s", tmpx);
+#endif
+ strncpy(ent.ut_id, utmp_id, sizeof(ent.ut_id));
+ }
strncpy(ent.ut_user, username, sizeof(ent.ut_user));
#else
strncpy(ent.ut_name, username, sizeof(ent.ut_name));
if (( !username[0]) && (flags&PTY_UTMP_USERNAME_VALID)
&&line)
{
-struct utmp *utptr;
-strncpy(ut.ut_line, line, sizeof(ut.ut_line));
-utptr = getutline(&ut);
-if (utptr)
- strncpy(userbuf,utptr->ut_user,sizeof(ut.ut_user));
+ struct utmp *utptr;
+ strncpy(ut.ut_line, line, sizeof(ut.ut_line));
+ utptr = getutline(&ut);
+ if (utptr)
+ strncpy(userbuf,utptr->ut_user,sizeof(ut.ut_user));
}
#endif
-
+
pututline(&ent);
endutent();
#ifdef HAVE_SETUTXENT
setutxent();
getutmpx(&ent, &utx);
-if (host)
- strncpy(utx.ut_host, host, sizeof(utx.ut_host));
- else utx.ut_host[0] = 0;
+ if (host)
+ strncpy(utx.ut_host, host, sizeof(utx.ut_host));
+ else
+ utx.ut_host[0] = 0;
pututxline(&utx);
endutxent();
#endif /* HAVE_SETUTXENT */
if (flags&PTY_TTYSLOT_USABLE)
tty = ttyslot();
else {
- int lc;
- tty = -1;
- if ((fd = open(UTMP_FILE, O_RDWR)) < 0)
- return errno;
- for (lc = 0;
- lseek(fd, (off_t)(lc * sizeof(struct utmp)), SEEK_SET) != -1;
- lc++) {
- if (read(fd, (char *) &ut, sizeof(struct utmp)) != sizeof(struct utmp))
- break;
- if (strncmp(ut.ut_line, ent.ut_line, sizeof(ut.ut_line)) == 0) {
- tty = lc;
+ int lc;
+ tty = -1;
+ if ((fd = open(UTMP_FILE, O_RDWR)) < 0)
+ return errno;
+ for (lc = 0;
+ lseek(fd, (off_t)(lc * sizeof(struct utmp)), SEEK_SET) != -1;
+ lc++) {
+ if (read(fd, (char *) &ut, sizeof(struct utmp)) != sizeof(struct utmp))
+ break;
+ if (strncmp(ut.ut_line, ent.ut_line, sizeof(ut.ut_line)) == 0) {
+ tty = lc;
#ifdef WTMP_REQUIRES_USERNAME
- if (!username&&(flags&PTY_UTMP_USERNAME_VALID))
- strncpy(userbuf, ut.ut_user, sizeof(ut.ut_user));
+ if (!username&&(flags&PTY_UTMP_USERNAME_VALID))
+ strncpy(userbuf, ut.ut_user, sizeof(ut.ut_user));
#endif
- break;
- }
+ break;
}
-close(fd);
+ }
+ close(fd);
}
- if (tty > 0 && (fd = open(UTMP_FILE, O_WRONLY, 0)) >= 0) {
- (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
- (void)write(fd, (char *)&ent, sizeof(struct utmp));
- (void)close(fd);
+ if (tty > 0 && (fd = open(UTMP_FILE, O_WRONLY, 0)) >= 0) {
+ (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
+ (void)write(fd, (char *)&ent, sizeof(struct utmp));
+ (void)close(fd);
}
-
+
#endif /* HAVE_SETUTENT */
return ptyint_update_wtmp(&ent, host, userbuf);
long ptyint_update_wtmp (ent , host, user)
struct utmp *ent;
- char *host;
-char *user;
- {
+ char *host;
+ char *user;
+{
struct utmp ut;
struct stat statb;
int fd;
struct utmpx utx;
getutmpx(ent, &utx);
-if (host)
- strncpy(utx.ut_host, host, sizeof(utx.ut_host) );
-else utx.ut_host[0] = 0;
-if (user)
- strncpy(utx.ut_user, user, sizeof(utx.ut_user));
+ if (host)
+ strncpy(utx.ut_host, host, sizeof(utx.ut_host) );
+ else
+ utx.ut_host[0] = 0;
+ if (user)
+ strncpy(utx.ut_user, user, sizeof(utx.ut_user));
updwtmpx(WTMPX_FILE, &utx);
#endif
if ((fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) >= 0) {
if (!fstat(fd, &statb)) {
(void)memset((char *)&ut, 0, sizeof(ut));
+#ifdef __hpux
+ strncpy (ut.ut_id, ent->ut_id, sizeof (ut.ut_id));
+#endif
(void)strncpy(ut.ut_line, ent->ut_line, sizeof(ut.ut_line));
(void)strncpy(ut.ut_name, ent->ut_name, sizeof(ut.ut_name));
#ifndef NO_UT_HOST
if (ent->ut_name) {
if (!ut.ut_pid)
ut.ut_pid = getpid();
+#ifndef __hpux
ut.ut_type = USER_PROCESS;
+#else
+ ut.ut_type = ent->ut_type;
+#endif
} else {
#ifdef EMPTY
ut.ut_type = EMPTY;