[arch-dev-public] Various initscripts patches
The following patches are some hacks at the initscripts I did recently, mostly provoked because our latest initscripts prevent my slice from even booting. Not cool. The most important one, by far, is the backgrounding of the udevadm trigger call. This one sets up a race condition and completely blows up the boot process when the /dev/sda2 node doesn't even exist yet. The rest of the patches are various other things, hopefully explained well within the patch header themselves. Let me know if there are concerns or questions on this stuff. -Dan
man hwclock implies this option is rarely necessary, and (almost) all systems Arch supports surely have a /dev/rtc device and load the rtc driver in the kernel. Even if this is not available, hwclock will fall back to direct I/O requests anyway. As a side note, the adjtime cronjob didn't even respect this setting anyway. Signed-off-by: Dan McGee <dan@archlinux.org> --- rc.conf | 2 -- rc.shutdown | 3 --- rc.sysinit | 3 --- 3 files changed, 0 insertions(+), 8 deletions(-) diff --git a/rc.conf b/rc.conf index 7177902..b9495f8 100644 --- a/rc.conf +++ b/rc.conf @@ -8,7 +8,6 @@ # # LOCALE: available languages can be listed with the 'locale -a' command # HARDWARECLOCK: set to "UTC" or "localtime" -# USEDIRECTISA: use direct I/O requests instead of /dev/rtc for hwclock # TIMEZONE: timezones are found in /usr/share/zoneinfo # KEYMAP: keymaps are found in /usr/share/kbd/keymaps # CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US) @@ -17,7 +16,6 @@ # LOCALE="en_US.UTF-8" HARDWARECLOCK="localtime" -USEDIRECTISA="no" TIMEZONE="Canada/Pacific" KEYMAP="us" CONSOLEFONT= diff --git a/rc.shutdown b/rc.shutdown index 39f762e..b0d8195 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -80,9 +80,6 @@ elif [ "$HARDWARECLOCK" = "localtime" ]; then else HWCLOCK_PARAMS="" fi -if [ "$USEDIRECTISA" = "yes" -o "$USEDIRECTISA" = "YES" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --directisa" -fi if [ "$HWCLOCK_PARAMS" != "" ]; then /sbin/hwclock $HWCLOCK_PARAMS fi diff --git a/rc.sysinit b/rc.sysinit index 3a8fab2..322b512 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -47,9 +47,6 @@ if [ "$HARDWARECLOCK" = "UTC" ]; then else HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" fi -if [ "$USEDIRECTISA" = "yes" -o "$USEDIRECTISA" = "YES" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --directisa" -fi # Set clock early to fix some bugs with filesystem checks # Clock is set again later to match rc.conf -- 1.6.4
For virtualized machines, the hardware clock doesn't actually exist, so all hwclock calls fail and print error messages during system startup, shutdown, and the hourly adjtime cronjob. By explicitly looking for HARDWARECLOCK to be set to 'UTC' or 'localtime', all other values will result in hwclock calls being skipped (e.g. set the variable to 'none'). Signed-off-by: Dan McGee <dan@archlinux.org> --- adjtime.cron | 18 ++++++++++++++++-- rc.conf | 3 ++- rc.shutdown | 2 +- rc.sysinit | 15 ++++++++++----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/adjtime.cron b/adjtime.cron index 40c02f2..b1c8950 100755 --- a/adjtime.cron +++ b/adjtime.cron @@ -1,3 +1,17 @@ -#!/bin/sh +#!/bin/bash # Update our hwclock for system drift -/sbin/hwclock --adjust + +. /etc/rc.conf + +HWCLOCK_PARAMS="--adjust" +if [ "$HARDWARECLOCK" = "UTC" ]; then + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" +elif [ "$HARDWARECLOCK" = "localtime" ]; then + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" +else + HWCLOCK_PARAMS="" +fi + +if [ -n "$HWCLOCK_PARAMS" ]; then + /sbin/hwclock $HWCLOCK_PARAMS +fi diff --git a/rc.conf b/rc.conf index b9495f8..252a9b1 100644 --- a/rc.conf +++ b/rc.conf @@ -7,7 +7,8 @@ # ----------------------------------------------------------------------- # # LOCALE: available languages can be listed with the 'locale -a' command -# HARDWARECLOCK: set to "UTC" or "localtime" +# HARDWARECLOCK: set to "UTC" or "localtime", any other value will result +# in the hardware clock being left untouched (useful for virtualization) # TIMEZONE: timezones are found in /usr/share/zoneinfo # KEYMAP: keymaps are found in /usr/share/kbd/keymaps # CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US) diff --git a/rc.shutdown b/rc.shutdown index b0d8195..e2a4a84 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -80,7 +80,7 @@ elif [ "$HARDWARECLOCK" = "localtime" ]; then else HWCLOCK_PARAMS="" fi -if [ "$HWCLOCK_PARAMS" != "" ]; then +if [ -n "$HWCLOCK_PARAMS" ]; then /sbin/hwclock $HWCLOCK_PARAMS fi stat_done diff --git a/rc.sysinit b/rc.sysinit index 322b512..0e67721 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -35,7 +35,8 @@ fi # enable rtc access /sbin/modprobe rtc-cmos >/dev/null 2>&1 -RTC_MAJOR=$(/bin/grep -w rtc /proc/devices 2>/dev/null); RTC_MAJOR="${RTC_MAJOR%% *}" +RTC_MAJOR=$(/bin/grep -w rtc /proc/devices 2>/dev/null) +RTC_MAJOR="${RTC_MAJOR%% *}" if [ -n "$RTC_MAJOR" ]; then /bin/mknod /dev/rtc0 c $RTC_MAJOR 0 /bin/ln -s /dev/rtc0 /dev/rtc @@ -44,13 +45,15 @@ fi HWCLOCK_PARAMS="--hctosys" if [ "$HARDWARECLOCK" = "UTC" ]; then HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" -else +elif [ "$HARDWARECLOCK" = "localtime" ]; then HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" +else + HWCLOCK_PARAMS="" fi # Set clock early to fix some bugs with filesystem checks # Clock is set again later to match rc.conf -if [ -f /etc/localtime ]; then +if [ -n "$HWCLOCK_PARAMS" -a -f /etc/localtime ]; then /sbin/hwclock $HWCLOCK_PARAMS --noadjfile fi @@ -302,8 +305,10 @@ if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi -/sbin/hwclock --adjust #Adjust for system drift -/sbin/hwclock $HWCLOCK_PARAMS +if [ -n "$HWCLOCK_PARAMS" ]; then + /sbin/hwclock --adjust #Adjust for system drift + /sbin/hwclock $HWCLOCK_PARAMS +fi stat_done RANDOM_SEED=/var/lib/misc/random-seed -- 1.6.4
This operation doesn't block for more than a half second, and backgrounding it invites race conditions if the settle operation ends up actually getting executed first. My slice won't even boot without this change. Signed-off-by: Dan McGee <dan@archlinux.org> --- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 0e67721..96966fb 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -71,7 +71,7 @@ fi # Trigger udev uevents if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then stat_busy "Triggering UDev uevents" - /sbin/udevadm trigger & + /sbin/udevadm trigger stat_done fi -- 1.6.4
Signed-off-by: Dan McGee <dan@archlinux.org> --- .gitignore | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da080cc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +minilogd -- 1.6.4
This allows building minilogd without installing the whole works, and is just a bit more suited to the task. Signed-off-by: Dan McGee <dan@archlinux.org> --- Makefile | 24 ++++++++++++++++++++++++ install.sh | 23 ----------------------- 2 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 Makefile delete mode 100755 install.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4b330f6 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +INSTALL = install -c -D +GEN = minilogd + +all: $(GEN) + +install: all + $(INSTALL) -m644 inittab $(DESTDIR)$(prefix)/etc/inittab + $(INSTALL) -m644 rc.conf $(DESTDIR)$(prefix)/etc/rc.conf + $(INSTALL) -m644 functions $(DESTDIR)$(prefix)/etc/rc.d/functions + $(INSTALL) -m755 rc.local $(DESTDIR)$(prefix)/etc/rc.local + $(INSTALL) -m755 rc.local.shutdown $(DESTDIR)$(prefix)/etc/rc.local.shutdown + $(INSTALL) -m755 rc.multi $(DESTDIR)$(prefix)/etc/rc.multi + $(INSTALL) -m755 rc.shutdown $(DESTDIR)$(prefix)/etc/rc.shutdown + $(INSTALL) -m755 rc.single $(DESTDIR)$(prefix)/etc/rc.single + $(INSTALL) -m755 rc.sysinit $(DESTDIR)$(prefix)/etc/rc.sysinit + $(INSTALL) -m755 network $(DESTDIR)$(prefix)/etc/rc.d/network + $(INSTALL) -m755 netfs $(DESTDIR)$(prefix)/etc/rc.d/netfs + $(INSTALL) -m755 adjtime.cron $(DESTDIR)$(prefix)/etc/cron.hourly/adjtime + $(INSTALL) -m755 minilogd $(DESTDIR)$(prefix)/sbin/minilogd + +clean: + rm -f $(GEN) + +.PHONY: all install diff --git a/install.sh b/install.sh deleted file mode 100755 index 2b2cbbc..0000000 --- a/install.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -install -d -m755 ${DESTDIR}/etc/rc.d || exit 1 -install -d -m755 ${DESTDIR}/etc/conf.d || exit 1 -install -d -m755 ${DESTDIR}/etc/rc.d/functions.d/ || exit 1 -install -d -m755 ${DESTDIR}/etc/cron.hourly/ || exit 1 - -for i in inittab rc.conf; do - install -D -m644 $i ${DESTDIR}/etc/$i || exit 1 -done -for i in rc.local rc.local.shutdown rc.multi rc.shutdown rc.single rc.sysinit; do - install -D -m755 $i ${DESTDIR}/etc/$i || exit 1 -done - -install -D -m755 adjtime.cron ${DESTDIR}/etc/cron.hourly/adjtime - -install -D -m644 functions ${DESTDIR}/etc/rc.d/functions || exit 1 -for i in network netfs; do - install -D -m755 $i ${DESTDIR}/etc/rc.d/$i || exit 1 -done - -gcc $CFLAGS -o minilogd minilogd.c || exit 1 -install -D -m755 minilogd ${DESTDIR}/sbin/minilogd || exit 1 -- 1.6.4
Signed-off-by: Dan McGee <dan@archlinux.org> --- minilogd.c | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) diff --git a/minilogd.c b/minilogd.c index 971fcb3..c86ab23 100644 --- a/minilogd.c +++ b/minilogd.c @@ -12,6 +12,7 @@ #include <stdlib.h> #include <string.h> #include <strings.h> +#include <stdarg.h> #include <syslog.h> #ifndef __USE_BSD # define __USE_BSD @@ -45,13 +46,13 @@ void freeBuffer() { int sock; int x=0,conn; - bzero(&addr,sizeof(addr)); + memset(&addr, 0, 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_STREAM,0); - conn=connect(sock,(struct sockaddr *) &addr,sizeof(addr)); + conn=connect(sock,(struct sockaddr *) &addr,(socklen_t)sizeof(addr)); while (x<buflines) { if (!conn) { /*printf("to syslog: %s\n", buffer[x]);*/ @@ -72,7 +73,8 @@ void cleanup(int exitcode) { } /* Don't try to free buffer if we were called from a signal handler */ if (exitcode<=0) { - if (buffer) freeBuffer(); + if (buffer) + freeBuffer(); exit(exitcode); } else exit(exitcode+128); @@ -80,8 +82,9 @@ void cleanup(int exitcode) { void runDaemon(int sock) { struct sockaddr_un addr; - int x,len,done=0; - socklen_t addrlen = sizeof(struct sockaddr_un); + int x,done=0; + ssize_t len; + socklen_t addrlen = (socklen_t)sizeof(struct sockaddr_un); char *message = NULL; struct stat s1,s2; struct pollfd pfds; @@ -103,15 +106,16 @@ void runDaemon(int sock) { /* 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)); + memset(&s1, 0, sizeof(struct stat)); while (!done) { pfds.fd = sock; pfds.events = POLLIN|POLLPRI; + pfds.revents = 0; if ( ( (x=poll(&pfds,1,500))==-1) && errno !=EINTR) { perror("poll"); cleanup(-1); } - if ( (x>0) && pfds.revents & (POLLIN | POLLPRI)) { + if ( (x>0) && (pfds.revents & (POLLIN | POLLPRI))) { if (message == NULL) { message = calloc(BUF_LINE_SIZE,sizeof(char)); } @@ -170,13 +174,13 @@ int main(int argc, char **argv) { dup2(sock,1); dup2(sock,2); - bzero(&addr, sizeof(addr)); + memset(&addr, 0, 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))) { + if (!bind(sock,(struct sockaddr *) &addr, (socklen_t)sizeof(addr))) { we_own_log = 1; listen(sock,5); if ((pid=fork())==-1) { -- 1.6.4
Dan McGee schrieb:
This allows building minilogd without installing the whole works, and is just a bit more suited to the task.
This doesn't create the empty /etc/conf.d/ and /etc/rc.d/functions/ directories which I'd like to have in there. Can you resend it, or should I just modify it and put my name on it?
On Sat, Aug 22, 2009 at 4:35 AM, Thomas Bächler<thomas@archlinux.org> wrote:
Dan McGee schrieb:
This allows building minilogd without installing the whole works, and is just a bit more suited to the task.
This doesn't create the empty /etc/conf.d/ and /etc/rc.d/functions/ directories which I'd like to have in there. Can you resend it, or should I just modify it and put my name on it?
Apparently Aaron has a Makefile patch in the queue already, so maybe wait and see. Isn't functions a file and not a directory? And I wouldn't mind creating dirs, but you'll notice no other ones are created by the script at the moment, so does that really make sense? -Dan
Dan McGee schrieb:
On Sat, Aug 22, 2009 at 4:35 AM, Thomas Bächler<thomas@archlinux.org> wrote:
This allows building minilogd without installing the whole works, and is just a bit more suited to the task. This doesn't create the empty /etc/conf.d/ and /etc/rc.d/functions/
Dan McGee schrieb: directories which I'd like to have in there. Can you resend it, or should I just modify it and put my name on it?
Apparently Aaron has a Makefile patch in the queue already, so maybe wait and see.
Isn't functions a file and not a directory? And I wouldn't mind creating dirs, but you'll notice no other ones are created by the script at the moment, so does that really make sense?
I meant functions.d, not functions. There are four directories now: /etc/rc.d, /etc/conf.d, /etc/rc.d/functions.d/, /etc/cron.hourly/ Two of those are created because files are in there, only conf.d and functions.d are empty, but IMO should be present so people know they can use them.
On Sat, Aug 22, 2009 at 10:24 AM, Dan McGee<dpmcgee@gmail.com> wrote:
On Sat, Aug 22, 2009 at 4:35 AM, Thomas Bächler<thomas@archlinux.org> wrote:
Dan McGee schrieb:
This allows building minilogd without installing the whole works, and is just a bit more suited to the task.
This doesn't create the empty /etc/conf.d/ and /etc/rc.d/functions/ directories which I'd like to have in there. Can you resend it, or should I just modify it and put my name on it?
Apparently Aaron has a Makefile patch in the queue already, so maybe wait and see.
I was totally wrong about that. The makefile patch from Loui was for mkinitcpio :S
Isn't functions a file and not a directory? And I wouldn't mind creating dirs, but you'll notice no other ones are created by the script at the moment, so does that really make sense?
He probably meant /etc/rc.d/functions.d/
participants (4)
-
Aaron Griffin
-
Dan McGee
-
Dan McGee
-
Thomas Bächler