decomp16 df dirname dosread du echo ed factor false fdisk fgrep fsck \
grep head id init kill ll ln logname ls man mkdir mkfs mkfifo mknod \
mount more mv od pagesize passwd patchcpm printenv prtroot ps pwd rm rmdir \
- sleep ssh sort stty sum su sync tee tail touch tr true umount uniq \
- uud uue wc which who whoami write xargs yes
+ sleep ssh sort stty sum su sync tee tail telinit touch tr true umount \
+ uniq uud uue wc which who whoami write xargs yes
# ...and in V7/cmd.
sum.c \
sync.c \
tee.c \
+ telinit.c \
touch.c \
tr.c \
true.c \
sync.c \
tee.c \
tail.c \
+ telinit.c \
touch.c \
tr.c \
true.c \
int default_rl;
int runlevel;
+volatile static int dingdong;
+
void sigalarm(int sig)
{
return;
}
+void sigusr1(int sig)
+{
+ signal(SIGUSR1, sigusr1);
+ dingdong = 1;
+}
+
int showfile(char *fname)
{
int fd, len;
char buf[80];
fd = open(fname, O_RDONLY);
- if (fd > 0) {
+ if (fd >= 0) {
do {
len = read(fd, buf, 80);
write(1, buf, len);
return 7; /* 1 << 7 is used for boot/single */
if (c >= '0' && c <= '6')
return c - '0';
- return -1;
+ return 0xFF;
}
/*
return;
}
bit = to_runlevel(*sdata++);
- if (bit == -1) {
+ if (bit == 0xFF) {
bad_line();
return;
}
int fdtty1;
signal(SIGINT, SIG_IGN);
-// signal(SIGHUP, telinit);
+ signal(SIGUSR1, sigusr1);
/* remove any stale /etc/mtab file */
for (;;) {
clear_zombies(0);
- /* FIXME: telinit handling, HUP handling */
+ if (dingdong) {
+ uint8_t newrl;
+ int fd = open("/var/run/intctl", O_RDONLY);
+ if (fd != -1 && read(fd, &newrl, 1) == 1) {
+ exit_runlevel(1 << runlevel, 1 << newrl);
+ runlevel = newrl;
+ enter_runlevel(1 << runlevel);
+ }
+ close(fd);
+ dingdong = 0;
+ }
}
}
--- /dev/null
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+
+/*
+ * Turn the character codes 0123456sS into run level numbers
+ */
+static uint8_t to_runlevel(uint8_t c)
+{
+ if (c == 's' || c == 'S')
+ return 7; /* 1 << 7 is used for boot/single */
+ if (c >= '0' && c <= '6')
+ return c - '0';
+ return 0xFF;
+}
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ uint8_t v;
+
+ if (argc != 2) {
+ write(2, "telinit: [runlevel]\n", 20);
+ exit(1);
+ }
+ if (argv[1][1] || (v = to_runlevel(argv[1][0])) == 0xFF) {
+ write(2, "telinit: invalid run level\n", 27);
+ exit(1);
+ }
+ fd = open("/var/run/initctl", O_WRONLY|O_TRUNC|O_CREAT, 0600);
+ if (fd < 0 || write(fd, &v, 1) != 1 || close(fd) == -1 ||
+ kill(1, SIGUSR1) < 0)
+ {
+ perror("telinit");
+ exit(1);
+ }
+ exit(0);
+}