summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorncopa <ncopa@f176ef85-8d20-0410-844a-e957b5a1c371>2007-03-26 15:51:04 +0000
committerncopa <ncopa@f176ef85-8d20-0410-844a-e957b5a1c371>2007-03-26 15:51:04 +0000
commitf3bf41bba7d32f88dece419efd5d5a806ee68b7b (patch)
tree0bd9557123f5ce9d4642fb71d1b241b7a28b8ea4
parent0a40ac61d56d4bb3c62b51e40d8216abcf2737dd (diff)
downloadalpine-baselayout-f3bf41bba7d32f88dece419efd5d5a806ee68b7b.tar.bz2
alpine-baselayout-f3bf41bba7d32f88dece419efd5d5a806ee68b7b.tar.xz
support for serial login using cttyhack. remove the needed mountoints from /etc/fstab. rc_delete should remove links even if target is missing
-rw-r--r--Makefile2
-rw-r--r--fstab7
-rwxr-xr-xinit.d/mdev6
-rw-r--r--init.d/mountall7
-rwxr-xr-xinit.d/rcS4
-rw-r--r--inittab2
-rwxr-xr-xrc_delete2
-rw-r--r--src/Makefile2
-rw-r--r--src/cttyhack.c83
9 files changed, 99 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 07761ee..c557bee 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION=1.3_alpha7
+VERSION=1.3_beta1
PV =alpine-baselayout-$(VERSION)
TARBALL =$(PV).tar.gz
diff --git a/fstab b/fstab
index 9233073..1ef44b6 100644
--- a/fstab
+++ b/fstab
@@ -1,9 +1,4 @@
-none /proc proc defaults 0 0
-none /sys sysfs defaults 0 0
-mdev /dev tmpfs size=100k 0 0
-none /dev/pts devpts defaults 0 0
-tmpfs /dev/shm tmpfs defaults 0 0
/dev/cdrom /media/cdrom iso9660 noauto,ro 0 0
/dev/fd0 /media/floppy vfat noauto 0 0
/dev/usba1 /media/usb vfat noauto 0 0
-none /proc/bus/usb usbfs noauto 0 0
+usbfs /proc/bus/usb usbfs noauto 0 0
diff --git a/init.d/mdev b/init.d/mdev
index c474175..3fba3ba 100755
--- a/init.d/mdev
+++ b/init.d/mdev
@@ -10,7 +10,7 @@ start() {
mkdir -p /dev
# start mdev
- mount /dev
+ mount -t tmpfs -o exec,nosuid,mode=0755 mdev /dev
mknod -m 666 /dev/null c 1 3
# use mdev for hotplug
@@ -23,9 +23,9 @@ start() {
# create pts file system
[ -d /dev/pts ] || mkdir -m 755 /dev/pts
[ -c /dev/ptmx ] || mknod -m 666 /dev/ptmx c 5 2
- mount /dev/pts
+ mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
[ -d /dev/shm ] || mkdir /dev/shm
- mount /dev/shm
+ mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
eend $RC
}
diff --git a/init.d/mountall b/init.d/mountall
index 8d0f306..d574eb2 100644
--- a/init.d/mountall
+++ b/init.d/mountall
@@ -2,7 +2,12 @@
start() {
ebegin "Mounting local filesystems"
- mount -a -t nonfs,nonfs4,nosmbfs,nocifs,noncp,noncpfs,nocoda,noocfs2,nogfs 2>&1 >/tmp/mountdebug
+ mount -a -t nonfs,nonfs4,nosmbfs,nocifs,noncp,noncpfs,nocoda,noocfs2,nogfsi 2>&1 >/tmp/mountdebug
eend $?
}
+stop() {
+ ebegin "Unmounting local filesystems"
+ umount -a
+ eend $?
+}
diff --git a/init.d/rcS b/init.d/rcS
index 017d105..1fa1a86 100755
--- a/init.d/rcS
+++ b/init.d/rcS
@@ -2,8 +2,8 @@
# we need the proc to be able to install busybox
/bin/busybox mkdir -p /proc /usr/sbin /sys
-/bin/busybox mount -t proc proc /proc
-/bin/busybox mount -t sysfs none /sys
+/bin/busybox mount -t proc -o noexec,nosuid,nodev proc /proc
+/bin/busybox mount -t sysfs -o noexec,nosuid,nodev sysfs /sys
# install busybox links
/bin/busybox --install -s
diff --git a/inittab b/inittab
index f170b8b..e07f9ae 100644
--- a/inittab
+++ b/inittab
@@ -4,7 +4,7 @@
::wait:/etc/init.d/rcL
# Set up a couple of getty's
-tty1::respawn:/sbin/getty 38400 tty1
+::respawn:/sbin/cttyhack /sbin/getty - 9600 vt100
tty2::respawn:/sbin/getty 38400 tty2
tty3::respawn:/sbin/getty 38400 tty3
tty4::respawn:/sbin/getty 38400 tty4
diff --git a/rc_delete b/rc_delete
index 0b63aa8..319d44b 100755
--- a/rc_delete
+++ b/rc_delete
@@ -52,7 +52,7 @@ while [ $# -gt 0 ] ; do
for rcl in $ROOT/etc/rcS.d/[S][0-9][0-9]$SCRIPT \
$ROOT/etc/rcL.d/[SK][0-9][0-9]$SCRIPT \
$ROOT/etc/rcK.d/[SK][0-9][0-9]$SCRIPT ; do
- [ -e "$rcl" ] || continue
+ [ -e "$rcl" -o -L "$rcl" ] || continue
echo "$rcl"
rclinks="$rclinks $rcl"
done
diff --git a/src/Makefile b/src/Makefile
index 23d1a84..006fd76 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,7 @@
CC = gcc
LD = gcc
-SBIN_TARGETS = runscript readahead
+SBIN_TARGETS = runscript readahead cttyhack
TARGET = $(BIN_TARGETS) $(SBIN_TARGETS)
.PHONY: all clean
diff --git a/src/cttyhack.c b/src/cttyhack.c
new file mode 100644
index 0000000..e54c1ec
--- /dev/null
+++ b/src/cttyhack.c
@@ -0,0 +1,83 @@
+/* This code is adapted from busybox project
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+
+/* From <linux/vt.h> */
+struct vt_stat {
+ unsigned short v_active; /* active vt */
+ unsigned short v_signal; /* signal to send */
+ unsigned short v_state; /* vt bitmask */
+};
+enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
+
+/* From <linux/serial.h> */
+struct serial_struct {
+ int type;
+ int line;
+ unsigned int port;
+ int irq;
+ int flags;
+ int xmit_fifo_size;
+ int custom_divisor;
+ int baud_base;
+ unsigned short close_delay;
+ char io_type;
+ char reserved_char[1];
+ int hub6;
+ unsigned short closing_wait; /* time to wait before closing */
+ unsigned short closing_wait2; /* no longer used... */
+ unsigned char *iomem_base;
+ unsigned short iomem_reg_shift;
+ unsigned int port_high;
+ unsigned long iomap_base; /* cookie passed into ioremap */
+ int reserved[1];
+};
+
+int main(int ergc, char **argv)
+{
+ int fd;
+ char console[sizeof(int)*3 + 16];
+ union {
+ struct vt_stat vt;
+ struct serial_struct sr;
+ char paranoia[sizeof(struct serial_struct) * 3];
+ } u;
+
+ if (!argv[1]) {
+ fprintf(stderr, "Usage: cttyhack cmd [arg1] [arg2]...\n");
+ return -1;
+ }
+
+ strcpy(console, "/dev/tty");
+ if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) {
+ /* this is a serial console */
+ sprintf(console + 8, "S%d", u.sr.line);
+ } else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) {
+ /* this is linux virtual tty */
+ sprintf(console + 8, "%d", u.vt.v_active);
+ }
+
+ if (console[8]) {
+ fd = open(console, O_RDWR);
+ if (fd >= 0) {
+ //fprintf(stderr, "cttyhack: switching to '%s'\n", console);
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ while (fd > 2) close(fd--);
+ }
+ }
+
+ execvp(argv[1], argv + 1);
+ fprintf(stderr, "cttyhack: failed to exec %s: %s\n",
+ argv[1], strerror(errno));
+ return -1;
+}