From aa292cbf824c04d77669c77eda812bf8894d60d5 Mon Sep 17 00:00:00 2001 From: Max Khon Date: Tue, 10 Feb 2004 23:28:21 +0000 Subject: New port: open 1.4 Open opens a new vt and runs a command on it. It can be used as a simple way to start several console logins without having to type your passwd on each VT in turn. open can be used as a simpler to use replacement for the doshell(8) command. open is similar in functionality to the AIX/RS6000 command of the same name. --- sysutils/open/files/patch-Makefile | 25 +++++++++ sysutils/open/files/patch-open.c | 108 +++++++++++++++++++++++++++++++++++++ sysutils/open/files/patch-open.h | 35 ++++++++++++ sysutils/open/files/pkg-message.in | 9 ++++ 4 files changed, 177 insertions(+) create mode 100644 sysutils/open/files/patch-Makefile create mode 100644 sysutils/open/files/patch-open.c create mode 100644 sysutils/open/files/patch-open.h create mode 100644 sysutils/open/files/pkg-message.in (limited to 'sysutils/open/files') diff --git a/sysutils/open/files/patch-Makefile b/sysutils/open/files/patch-Makefile new file mode 100644 index 000000000000..1078281e9979 --- /dev/null +++ b/sysutils/open/files/patch-Makefile @@ -0,0 +1,25 @@ +--- Makefile.orig Fri Jul 19 07:32:07 1996 ++++ Makefile Wed Feb 11 05:18:21 2004 +@@ -1,6 +1,7 @@ + +-CC=gcc +-CFLAGS=-O2 -Wall -ansi ++CC?=gcc ++CFLAGS?=-O2 -Wall -ansi ++CFLAGS+=-Wall + LDFLAGS=$(CFLAGS) -s + + SRC1=open.c +@@ -20,10 +21,10 @@ + + + open: $(OBJ1) +- $(CC) $(LDLAGS) -o $@ $< ++ $(CC) $(LDLAGS) -o $@ $> + + switchto: $(OBJ2) +- $(CC) $(LDLAGS) -o $@ $< ++ $(CC) $(LDLAGS) -o $@ $> + + open.o: open.h + diff --git a/sysutils/open/files/patch-open.c b/sysutils/open/files/patch-open.c new file mode 100644 index 000000000000..ce317f5b5645 --- /dev/null +++ b/sysutils/open/files/patch-open.c @@ -0,0 +1,108 @@ +--- open.c.orig Fri Jul 19 22:49:03 1996 ++++ open.c Wed Feb 11 05:02:34 2004 +@@ -24,7 +24,12 @@ + + int fd = 0; + int opt, pid; ++#if !defined(__FreeBSD__) + struct vt_stat vt; ++#define vt_active vt.v_active ++#else ++ int vt_active; ++#endif + struct passwd *pwnam=NULL; + int vtno = -1; + char show = FALSE; +@@ -33,7 +38,7 @@ + char do_wait = FALSE; + char as_user= FALSE; + char vtname[sizeof VTNAME + 2]; /* allow 999 possible VTs */ +- char *cmd, *def_cmd = NULL; ++ char *cmd = NULL, *def_cmd = NULL; + + /* + * I don't like using getopt for this, but otherwise this gets messy. +@@ -44,7 +49,7 @@ + switch (opt) { + case 'c': + vtno = (int) atol(optarg); +- if (vtno < 0 || vtno > 99) { ++ if (vtno <= 0 || vtno > 99) { + fprintf(stderr, "open: %s illegal vt number\n", optarg); + return 5; + } +@@ -92,14 +97,19 @@ + return(3); + } + ++#if !defined(__FreeBSD__) + if (ioctl(fd, VT_GETSTATE, &vt) < 0) { + perror("open: can't get VTstate\n"); ++#else ++ if (ioctl(fd, VT_GETACTIVE, &vt_active) < 0) { ++ perror("open: can't get active VT\n"); ++#endif + close(fd); + return(4); + } + } + +- sprintf(vtname, VTNAME, vtno); ++ sprintf(vtname, VTNAME, vtno - 1); + + /* support for Spawn_Console; running from init + added by Joshua Spoerri, Thu Jul 18 21:13:16 EDT 1996 */ +@@ -110,7 +120,7 @@ + dev_t console_dev; + ino_t console_ino; + uid_t console_uid; +- char filename[NAME_MAX+12]; ++ char filename[sizeof VTNAME + 2]; + + if (!(dp=opendir("/proc"))) { + perror("/proc"); +@@ -118,7 +128,7 @@ + } + + /* get the current tty */ +- sprintf(filename,"/dev/tty%d",vt.v_active); ++ sprintf(filename,VTNAME,vt_active - 1); + if (stat(filename,&buf)) { + perror(filename); + exit(1); +@@ -204,15 +214,18 @@ + _exit (4); /* silently die */ + } + dup(fd); dup(fd); +- ++ if (ioctl(fd, TIOCSCTTY, NULL) < 0) ++ _exit(4); + if (show) { + /* + * Can't tell anyone if any of these fail, so throw away + * the return values + */ +- (void) ioctl(fd, VT_ACTIVATE, vtno); ++ if (ioctl(fd, VT_ACTIVATE, vtno) < 0) ++ _exit(4); + /* wait to be really sure we have switched */ +- (void) ioctl(fd, VT_WAITACTIVE, vtno); ++ if (ioctl(fd, VT_WAITACTIVE, vtno) < 0) ++ _exit(4); + } + if(as_user) + execlp("login","login","-f",pwnam->pw_name,NULL); +@@ -230,9 +243,11 @@ + if ( do_wait ) { + wait(NULL); + if (show) { /* Switch back... */ +- (void) ioctl(fd, VT_ACTIVATE, vt.v_active); ++ if (ioctl(fd, VT_ACTIVATE, vt_active) < 0) ++ _exit(4); + /* wait to be really sure we have switched */ +- (void) ioctl(fd, VT_WAITACTIVE, vt.v_active); ++ if (ioctl(fd, VT_WAITACTIVE, vt_active) < 0) ++ _exit(4); + } + } + diff --git a/sysutils/open/files/patch-open.h b/sysutils/open/files/patch-open.h new file mode 100644 index 000000000000..88aaed29d3bc --- /dev/null +++ b/sysutils/open/files/patch-open.h @@ -0,0 +1,35 @@ +--- open.h.orig Tue Feb 10 18:10:58 2004 ++++ open.h Tue Feb 10 18:24:48 2004 +@@ -1,14 +1,21 @@ + #include + #include + #include ++#if !defined(__FreeBSD__) + #include ++#endif + #include + #include + #include + #include ++#include + #include + #include ++#if defined(__FreeBSD__) ++#include ++#else + #include ++#endif + #include + #include + +@@ -29,6 +36,10 @@ + */ + #ifdef __linux__ + #define VTNAME "/dev/tty%d" ++#endif ++ ++#ifdef __FreeBSD__ ++#define VTNAME "/dev/ttyv%x" + #endif + + #ifdef ESIX_5_3_2_D diff --git a/sysutils/open/files/pkg-message.in b/sysutils/open/files/pkg-message.in new file mode 100644 index 000000000000..f3ce36747f4f --- /dev/null +++ b/sysutils/open/files/pkg-message.in @@ -0,0 +1,9 @@ +To use open it must be installed setuid root +(type "chmod u+s %%PREFIX%%/bin/open") + +or + +all the VT devices that are not allocated +to getty should be read/write by all, e.g. + +chmod a=rw /dev/ttyv[9abc] -- cgit v1.2.3