+Mon Aug 7 17:41:39 1995 Sam Hartman <hartmans@tertius.mit.edu>
+
+ * cleanup.c (pty_cleanup): Call pty_update_utmp using new interface.
+
+ * update_utmp.c logwtmp.c : Call ptyint_update_wtmp not pty_update_wtmp.
+
+ * cleanup.c (pty_cleanup): We can't use pid_t because we need to
+ use something in libpty.h and we can't wait for pid_t to be
+ defined there because we may not have configure.
+
+ * update_wtmp.c (pty_update_wtmp): Rename to ptyint_update_wtmp.
+
+ * update_utmp.c (pty_update_utmp): Change interface so it doesn't take a struct utmp.
+
+ * libpty.h: Remove pty_update_wtmp as it's becoming an internal interface.
+
Sat Aug 5 01:00:35 1995 Ezra Peisach <epeisach@kangaroo.mit.edu>
* open_slave.c (pty_open_slave): pty_open_ctty returns != 0 on
long pty_cleanup (slave, pid, update_utmp)
char *slave;
- pid_t pid; /* May be zero for unknown.*/
+ int pid; /* May be zero for unknown.*/
int update_utmp;
{
- struct utmp ut;
int retval, fd;
-#ifndef NO_UT_PID
- ut.ut_pid = 0;
- ut.ut_type = DEAD_PROCESS;
-#endif
- pty_update_utmp(&ut, "", slave, (char *)0);
+ pty_update_utmp(PTY_DEAD_PROCESS,0, "", slave, (char *)0);
(void)chmod(slave, 0666);
(void)chown(slave, 0, 0);
*/
#ifndef __LIBPTY_H__
-#include <sys/types.h>
-#ifdef HAVE_UTMP_H
-#include <utmp.h>
-#endif
-#ifdef HAVE_UTMPX_H
-#include <utmpx.h>
-#endif
+
+/* Constants for pty_update_utmp */
+#define PTY_LOGIN_PROCESS 0
+#define PTY_USER_PROCESS 1
+#define PTY_DEAD_PROCESS 2
#ifdef __STDC__ /* use prototypes */
long pty_open_ctty (const char *slave, int *fd);
long pty_initialize_slave ( int fd);
-long pty_update_utmp (struct utmp *ut, char *user, char *line, char *host);
+long pty_update_utmp (int process_type,int pid, char *user, char *line, char *host);
-long pty_update_wtmp (struct utmp *ut);
long pty_logwtmp (char *tty, char * user, char *host);
-long pty_cleanup(char *slave, pid_t pid, int update_utmp);
+long pty_cleanup(char *slave, int pid, int update_utmp);
#else /*__STDC__*/
long pty_init();
long pty_getpty();
long pty_initialize_slave();
long pty_update_utmp();
-long pty_utmp_wtmp();
long pty_logwtmp();
long pty_cleanup();
#endif /* __STDC__*/
strncpy(ut.ut_name, user, sizeof(ut.ut_name));
#endif
- return pty_update_wtmp(&ut);
+ return ptyint_update_wtmp(&ut);
#endif /*HAVE_LOGWTMP*/
}
#ifndef __PTY_INT_H__
#include <pty_err.h>
#include <sys/types.h>
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
void initialize_pty_error_table(void);
long ptyint_void_association(void);
long ptyint_open_ctty (char *slave, int *fd);
+long ptyint_update_wtmp (struct utmp *ut);
+
void ptyint_vhangup(void);
#else /*__STDC__*/
long ptyint_void_association();
void ptyint_vhangup();
void initialize_pty_error_table();
+long ptyint_update_wtmp();
#endif /* __STDC__*/
#define __PTY_INT_H__
error_code PTY_OPEN_SLAVE_REVOKEFAIL, "Failed to revoke slave side of pty"
+
+error_code PTY_UPDATE_UTMP_PROCTYPE_INVALID, "bad process type passed to pty_update_utmp"
#include "libpty.h"
#include "pty-int.h"
-long pty_update_utmp (ent, username, line, host)
- struct utmp *ent;
+#if !defined(UTMP_FILE) && defined(_UTMP_PATH)
+#define UTMP_FILE _UTMP_PATH
+#endif
+
+long pty_update_utmp (process_type, pid, username, line, host)
+ int process_type;
+ int pid;
char *username, *line, *host;
{
-#ifdef HAVE_SETUTENT
+ struct utmp ent;
+ #ifdef HAVE_SETUTENT
struct utmp ut;
#else
struct stat statb;
#endif
int fd;
- strncpy(ent->ut_line, line+sizeof("/dev/")-1, sizeof(ent->ut_line));
- ent->ut_time = time(0);
+ strncpy(ent.ut_line, line+sizeof("/dev/")-1, sizeof(ent.ut_line));
+ ent.ut_time = time(0);
+#ifdef NO_UT_PID
+ ent.ut_pid = pid;
+ switch ( process_type ) {
+ case PTY_LOGIN_PROCESS:
+ ent . ut_type = LOGIN_PROCESS;
+ break;
+ case PTY_USER_PROCESS:
+ ent.ut_type = USER_PROCESS;
+ break;
+ case PTY_DEAD_PROCESS:
+ ent.ut_type = DEAD_PROCESS;
+ break;
+ default:
+ return PTY_UPDATE_UTMP_PROCTYPE_INVALID;
+ }
+#endif /*NO_UT_PID*/
#ifndef NO_UT_HOST
if (host)
- strncpy(ent->ut_host, host, sizeof(ent->ut_host));
+ strncpy(ent.ut_host, host, sizeof(ent.ut_host));
else
- ent->ut_host[0] = '\0';
+ ent.ut_host[0] = '\0';
#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));
- strncpy(ent->ut_user, username, sizeof(ent->ut_user));
+ 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));
+ strncpy(ent.ut_name, username, sizeof(ent.ut_name));
#endif
#ifdef HAVE_SETUTENT
utmpname(UTMP_FILE);
setutent();
- pututline(ent);
+ pututline(&ent);
endutent();
#if 0
/* XXX -- NOT NEEDED ANYMORE */
- if (ent->ut_type == DEAD_PROCESS) {
+ if (ent.ut_type == DEAD_PROCESS) {
if ((fd = open(UTMP_FILE, O_RDWR)) >= 0) {
int cnt = 0;
while(read(fd, (char *)&ut, sizeof(ut)) == sizeof(ut)) {
- if (!strncmp(ut.ut_id, ent->ut_id, sizeof(ut.ut_id))) {
+ if (!strncmp(ut.ut_id, ent.ut_id, sizeof(ut.ut_id))) {
(void) memset(ut.ut_host, 0, sizeof(ut.ut_host));
(void) memset(ut.ut_user, 0, sizeof(ut.ut_user));
(void) time(&ut.ut_time);
#endif /* HAVE_SETUTENT */
- return pty_update_wtmp(ent);
+ return ptyint_update_wtmp(&ent);
}
/*
- * pty_update_utmp: Update or create a utmp entry
+ * ptyint_update_utmp: Update or create a utmp entry
*
* Copyright 1995 by the Massachusetts Institute of Technology.
*
#include "libpty.h"
#include "pty-int.h"
-long pty_update_wtmp (ent)
+#if !defined(WTMP_FILE) && defined(_PATH_WTMP)
+#define WTMP_FILE _PATH_WTMP
+#endif
+
+long ptyint_update_wtmp (ent)
struct utmp *ent;
{
struct utmp ut;