aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJudd Vinet <judd@archlinux.org>2003-12-21 00:48:23 (GMT)
committerJudd Vinet <judd@archlinux.org>2003-12-21 00:48:23 (GMT)
commita71e42c461da1672582143a829654049399616e7 (patch)
tree5a3c3e41a80a1781198159988e2ddf44a8395edb
parent53ae13821436183990e40cffefa8c9cff4b4f2ae (diff)
downloadinitscripts-a71e42c461da1672582143a829654049399616e7.tar.xz
upgpkg: initscripts 0.6
-rw-r--r--inittab14
-rw-r--r--minilogd.c184
-rw-r--r--rc.conf2
-rwxr-xr-xrc.shutdown14
-rwxr-xr-xrc.single21
-rwxr-xr-xrc.sysinit75
6 files changed, 257 insertions, 53 deletions
diff --git a/inittab b/inittab
index 3844d74..234ee38 100644
--- a/inittab
+++ b/inittab
@@ -3,13 +3,13 @@
#
# Runlevels:
-# 0 Halt
-# 1(S) Single-user
-# 2 Not used
-# 3 Multi-user
-# 4 Not used
-# 5 X11
-# 6 Reboot
+# 0 Halt
+# 1(S) Single-user
+# 2 Not used
+# 3 Multi-user
+# 4 Not used
+# 5 X11
+# 6 Reboot
id:3:initdefault:
diff --git a/minilogd.c b/minilogd.c
new file mode 100644
index 0000000..76e4a9c
--- /dev/null
+++ b/minilogd.c
@@ -0,0 +1,184 @@
+
+/* minilogd.c
+ *
+ * A pale imitation of syslogd. Most notably, doesn't write anything
+ * anywhere except possibly back to syslogd.
+ *
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include <unistd.h>
+
+#include <sys/poll.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/un.h>
+
+static int we_own_log=0;
+static char **buffer=NULL;
+static int buflines=0;
+
+int debug;
+
+int recvsock;
+
+void alarm_handler(int x) {
+ alarm(0);
+ close(recvsock);
+ recvsock = -1;
+}
+
+void freeBuffer() {
+ struct sockaddr_un addr;
+ int sock;
+ int x=0,conn;
+
+ bzero(&addr,sizeof(addr));
+ addr.sun_family = AF_LOCAL;
+ strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
+ /* wait for klogd to hit syslog */
+ sleep(2);
+ sock = socket(AF_LOCAL, SOCK_DGRAM,0);
+ conn=connect(sock,(struct sockaddr *) &addr,sizeof(addr));
+ while (x<buflines) {
+ if (!conn) {
+ /*printf("to syslog: %s\n", buffer[x]);*/
+ write(sock,buffer[x],strlen(buffer[x])+1);
+ }
+ free(buffer[x]);
+ x++;
+ }
+}
+
+void cleanup(int exitcode) {
+ /* If we own the log, unlink it before trying to free our buffer.
+ * Otherwise, sending the buffer to /dev/log doesn't make much sense.... */
+ if (we_own_log) {
+ perror("wol");
+ unlink(_PATH_LOG);
+ }
+ /* Don't try to free buffer if we were called from a signal handler */
+ if (exitcode<=0) {
+ if (buffer) freeBuffer();
+ exit(exitcode);
+ } else
+ exit(exitcode+128);
+}
+
+void runDaemon(int sock) {
+ struct sockaddr_un addr;
+ int x,len,addrlen,done=0;
+ char *message;
+ struct stat s1,s2;
+ struct pollfd pfds;
+
+ daemon(0,-1);
+ /* try not to leave stale sockets lying around */
+ /* Hopefully, we won't actually get any of these */
+ signal(SIGHUP,cleanup);
+ signal(SIGINT,cleanup);
+ signal(SIGQUIT,cleanup);
+ signal(SIGILL,cleanup);
+ signal(SIGABRT,cleanup);
+ signal(SIGFPE,cleanup);
+ signal(SIGSEGV,cleanup);
+ signal(SIGPIPE,cleanup);
+ signal(SIGBUS,cleanup);
+ signal(SIGTERM,cleanup);
+ done = 0;
+ /* Get stat info on /dev/log so we can later check to make sure we
+ * still own it... */
+ if (stat(_PATH_LOG,&s1) != 0)
+ memset(&s1, '\0', sizeof(struct stat));
+ while (!done) {
+ pfds.fd = sock;
+ pfds.events = POLLIN|POLLPRI;
+ if ( ( (x=poll(&pfds,1,500))==-1) && errno !=EINTR) {
+ perror("poll");
+ cleanup(-1);
+ }
+ if ( (x>0) && pfds.revents & (POLLIN | POLLPRI)) {
+ message = calloc(8192,sizeof(char));
+ recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen);
+ alarm(2);
+ signal(SIGALRM, alarm_handler);
+ len = read(recvsock,message,8192);
+ alarm(0);
+ close(recvsock);
+ if (len>0) {
+ /*printf("line recv'd: %s\n", message);*/
+ if (buflines < 200000) {
+ if (buffer)
+ buffer = realloc(buffer,(buflines+1)*sizeof(char *));
+ else
+ buffer = malloc(sizeof(char *));
+ message[strlen(message)]='\n';
+ buffer[buflines]=message;
+ buflines++;
+ }
+ }
+ else {
+ recvsock=-1;
+ }
+ }
+ if ( (x>0) && ( pfds.revents & (POLLHUP | POLLNVAL)) )
+ done = 1;
+ /* Check to see if syslogd's yanked our socket out from under us */
+ if ( (stat(_PATH_LOG,&s2)!=0) ||
+ (s1.st_ino != s2.st_ino ) || (s1.st_ctime != s2.st_ctime) ||
+ (s1.st_mtime != s2.st_mtime) ) { /*|| (s1.st_atime != s2.st_atime) ) {*/
+ done = 1;
+ we_own_log = 0;
+ /*printf("someone stole our %s\n", _PATH_LOG);
+ printf("st_ino: %d %d\n", s1.st_ino, s2.st_ino);
+ printf("st_ctime: %d %d\n", s1.st_ctime, s2.st_ctime);
+ printf("st_atime: %d %d\n", s1.st_atime, s2.st_atime);
+ printf("st_mtime: %d %d\n", s1.st_mtime, s2.st_mtime);*/
+ }
+ }
+ cleanup(0);
+}
+
+int main(int argc, char **argv) {
+ struct sockaddr_un addr;
+ int sock;
+ int pid;
+
+ /* option processing made simple... */
+ if (argc>1) debug=1;
+ /* just in case */
+ sock = open("/dev/null",O_RDWR);
+ dup2(sock,0);
+ dup2(sock,1);
+ dup2(sock,2);
+
+ bzero(&addr, sizeof(addr));
+ addr.sun_family = AF_LOCAL;
+ strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1);
+ sock = socket(AF_LOCAL, SOCK_STREAM,0);
+ unlink(_PATH_LOG);
+ /* Bind socket before forking, so we know if the server started */
+ if (!bind(sock,(struct sockaddr *) &addr, sizeof(addr))) {
+ we_own_log = 1;
+ listen(sock,5);
+ if ((pid=fork())==-1) {
+ perror("fork");
+ exit(3);
+ }
+ if (pid) {
+ exit(0);
+ } else {
+ /*printf("starting daemon...\n");*/
+ runDaemon(sock);
+ /* shouldn't get back here... */
+ exit(4);
+ }
+ } else {
+ exit(5);
+ }
+}
diff --git a/rc.conf b/rc.conf
index 6b37163..d1c9501 100644
--- a/rc.conf
+++ b/rc.conf
@@ -51,6 +51,6 @@ ROUTES=(!gateway)
# Daemons to start at boot-up (in this order)
# (prefix a daemon with a ! to disable it)
#
-DAEMONS=(!pcmcia network crond inetd)
+DAEMONS=(syslogd klogd !pcmcia network crond)
# End of file
diff --git a/rc.shutdown b/rc.shutdown
index 78c85bb..4f6b6d6 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -42,6 +42,7 @@ stat_done
stat_busy "Sending SIGKILL To Processes"
/sbin/killall5 -9 &> /dev/null
+/usr/bin/sleep 1
stat_done
stat_busy "Saving Random Seed"
@@ -70,21 +71,24 @@ stat_done
stat_busy "Remounting Root Filesystem Read-only"
/bin/mount -n -o remount,ro /
stat_done
-echo ""
# Power off or reboot
if [ "$RUNLEVEL" = "0" ]; then
if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
- echo -e ">>> \033[1;33mPOWER OFF\033[1;0m"
+ echo -e "\033[1;32m|\033[1;0m"
+ echo -e "\033[1;31m| \033[1;33mPOWER OFF\033[1;0m"
else
- echo ">>> POWER OFF"
+ echo "|"
+ echo "| POWER OFF"
fi
/sbin/poweroff -d -f -i
else
if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
- echo -e ">>> \033[1;33mREBOOTING\033[1;0m"
+ echo -e "\033[1;32m|\033[1;0m"
+ echo -e "\033[1;31m| \033[1;33mREBOOTING\033[1;0m"
else
- echo ">>> REBOOTING"
+ echo "|"
+ echo "| REBOOTING"
fi
/sbin/reboot -d -f -i
fi
diff --git a/rc.single b/rc.single
index f96c0fe..3b0e610 100755
--- a/rc.single
+++ b/rc.single
@@ -30,21 +30,24 @@ if [ "$PREVLEVEL" != "N" ]; then
stat_done
stat_busy "Sending SIGKILL To Processes"
- /sbin/killall5 -9 &> /dev/null
+ /sbin/killall5 -9
+ /usr/bin/sleep 1
stat_done
- stat_busy "Starting DevFS Daemon"
- /sbin/devfsd /dev
- stat_done
+ status "Starting DevFS Daemon" /sbin/devfsd /dev
- stat_busy "Starting Log Daemons"
- /usr/sbin/syslogd -m 0
- /usr/sbin/klogd -c 4
- stat_done
+ [ -x /etc/rc.d/syslogd ] && /etc/rc.d/syslogd start
+ [ -x /etc/rc.d/klogd ] && /etc/rc.d/klogd start
fi
if [ "$RUNLEVEL" = "1" ]; then
- echo "Entering single-user mode..."
+ if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
+ echo -e "\033[1;32m|\033[1;0m"
+ echo -e "\033[1;31m| \033[1;33mEntering single-user mode...\033[1;0m"
+ else
+ echo "|"
+ echo "| Entering single-user mode..."
+ fi
exec /sbin/init -t1 S
fi
diff --git a/rc.sysinit b/rc.sysinit
index e9d6e9d..747c321 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -7,22 +7,30 @@
. /etc/rc.d/functions
if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
- echo -e "\n\033[1;32mArch Linux v0.5 \033[1;37m(\033[1;33mNova\033[1;37m)"
+ echo -e "\n\033[1;32mArch Linux v0.6 \033[1;37m(\033[1;33mWidget\033[1;37m)"
echo -e "\033[1;32m|\033[1;0m"
echo -e "\033[1;32m|\033[1;37m http://www.archlinux.org\033[1;0m"
echo -e "\033[1;32m|\033[1;0m Copyright 2002-2003 Judd Vinet"
echo -e "\033[1;32m|\033[1;0m Distributed under the GNU General Public License (GPL)"
echo -e "\033[1;32m|\033[1;0m"
else
- echo -e "\nArch Linux v0.5 (Nova)"
+ echo -e "\nArch Linux v0.6 (Widget)"
echo "|"
echo "| http://www.archlinux.org"
echo "| Copyright 2002-2003 Judd Vinet"
- echo "| Distributed under the GNU Public License (GPL)"
+ echo "| Distributed under the GNU General Public License (GPL)"
echo "|"
fi
-status "Starting DevFS Daemon" /sbin/devfsd /dev
+# start up our mini logger until syslog takes over
+/sbin/minilogd
+
+# anything more serious than KERN_WARNING goes to the console
+/bin/dmesg -n 3
+
+if [ -e /dev/.devfsd -a -x /sbin/devfsd ]; then
+ status "Starting DevFS Daemon" /sbin/devfsd /dev
+fi
if [ -f /etc/lvmtab ]; then
# /proc is temporarily mounted to check for LVM support - it is
@@ -40,36 +48,41 @@ status "Activating Swap" /sbin/swapon -a
status "Mounting Root Read-only" /bin/mount -n -o remount,ro /
-stat_busy "Checking Filesystems"
-/sbin/fsck -A -T -C -a
-if [ $? -gt 1 ]; then
- stat_fail
- echo
- echo "***************** FILESYSTEM CHECK FAILED ****************"
- echo "* *"
- echo "* Please repair manually and reboot. Note that the root *"
- echo "* file system is currently mounted read-only. To remount *"
- echo "* it read-write type: mount -n -o remount,rw / *"
- echo "* When you exit the maintainance shell the system will *"
- echo "* reboot automatically. *"
- echo "* *"
- echo "************************************************************"
- echo
- /sbin/sulogin -p
- echo "Automatic reboot in progress..."
- /bin/umount -a
- /bin/mount -n -o remount,ro /
- /sbin/reboot -f
- exit 0
+if [ -x /sbin/fsck ]; then
+ stat_busy "Checking Filesystems"
+ /sbin/fsck -A -T -C -a
+ if [ $? -gt 1 ]; then
+ stat_fail
+ echo
+ echo "***************** FILESYSTEM CHECK FAILED ****************"
+ echo "* *"
+ echo "* Please repair manually and reboot. Note that the root *"
+ echo "* file system is currently mounted read-only. To remount *"
+ echo "* it read-write type: mount -n -o remount,rw / *"
+ echo "* When you exit the maintenance shell the system will *"
+ echo "* reboot automatically. *"
+ echo "* *"
+ echo "************************************************************"
+ echo
+ /sbin/sulogin -p
+ echo "Automatic reboot in progress..."
+ /bin/umount -a
+ /bin/mount -n -o remount,ro /
+ /sbin/reboot -f
+ exit 0
+ fi
+ stat_done
fi
-stat_done
stat_busy "Mounting Local Filesystems"
/bin/mount -n -o remount,rw /
/bin/rm -f /etc/mtab*
+/bin/mount /proc
/bin/mount -a -t nonfs
stat_done
+/usr/bin/logger "LOGGER TEST!"
+
stat_busy "Configuring System Clock"
if [ "$HARDWARECLOCK" = "UTC" ]; then
/sbin/hwclock --utc --hctosys
@@ -77,7 +90,7 @@ else
/sbin/hwclock --localtime --hctosys
fi
if [ ! -f /var/lib/hwclock/adjtime ]; then
- echo "0.0 0 0.0" > /var/lib/hwclock/adjtime
+ echo "0.0 0 0.0" > /var/lib/hwclock/adjtime
fi
if [ "$TIMEZONE" != "" ]; then
/bin/ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
@@ -100,9 +113,7 @@ if [ "$HOSTNAME" != "" ]; then
status "Setting Hostname: $HOSTNAME" /bin/hostname $HOSTNAME
fi
-status "Starting System Logger" /usr/sbin/syslogd -m 0
-
-status "Starting Kernel Logger" /usr/sbin/klogd -c 4
+# syslog
kernel_version=`uname -r`
if [ -e "/lib/modules/$kernel_version/modules.dep" ]; then
@@ -115,7 +126,9 @@ else
fi
if [ -f /var/run/random-seed ]; then
- status "Initializing Random Seed" /bin/cat /var/run/random-seed > /dev/urandom
+ stat_busy "Initializing Random Seed"
+ /bin/cat /var/run/random-seed >/dev/urandom
+ stat_done
fi
if [ "$KEYMAP" != "" ]; then