diff options
author | Roy Marples <roy@marples.name> | 2007-04-26 11:24:07 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-04-26 11:24:07 +0000 |
commit | cf9aa106c615211abc642fc596c98a39d072dd5b (patch) | |
tree | 2ee926e25df8c9dbaab5b4b072d3a549b7ebb4c1 | |
parent | 431e8cc84fe960ec91c3463493ce94df65ef41f2 (diff) |
Set fonts in init-early.sh, don't stop services twice when shutting down and lock prefixed output.
-rw-r--r-- | sh.Linux/Makefile | 2 | ||||
-rwxr-xr-x | sh.Linux/init.sh | 9 | ||||
-rw-r--r-- | src/rc.c | 37 | ||||
-rw-r--r-- | src/runscript.c | 28 |
4 files changed, 57 insertions, 19 deletions
diff --git a/sh.Linux/Makefile b/sh.Linux/Makefile index cd286002..446d624d 100644 --- a/sh.Linux/Makefile +++ b/sh.Linux/Makefile @@ -1,5 +1,5 @@ DIR = /$(LIB)/rcscripts/sh -EXES = init.sh +EXES = init.sh init-early.sh TOPDIR = .. include $(TOPDIR)/default.mk diff --git a/sh.Linux/init.sh b/sh.Linux/init.sh index b8be7237..6490c74f 100755 --- a/sh.Linux/init.sh +++ b/sh.Linux/init.sh @@ -86,15 +86,6 @@ get_KV() { return $? } -# Try and set a font as early as we can -termencoding="(K" -[ -e "${RC_LIBDIR}"/console/unicode ] && termencoding="%G" -printf "\033%s" "${termencoding}" >/dev/console -if [ -r "${RC_LIBDIR}"/console/font ] ; then - font="$(cat "${RC_LIBDIR}"/console/font)" - setfont -C /dev/console "${RC_LIBDIR}"/console/"${font}" -fi - . /etc/init.d/functions.sh . "${RC_LIBDIR}"/sh/init-functions.sh . "${RC_LIBDIR}"/sh/rc-functions.sh @@ -33,15 +33,16 @@ #include "rc-plugin.h" #include "strlist.h" -#define INITSH RC_LIBDIR "sh/init.sh" -#define HALTSH RC_INITDIR "halt.sh" +#define INITSH RC_LIBDIR "sh/init.sh" +#define INITEARLYSH RC_LIBDIR "sh/init-early.sh" +#define HALTSH RC_INITDIR "halt.sh" -#define RC_SVCDIR_STARTING RC_SVCDIR "starting/" -#define RC_SVCDIR_INACTIVE RC_SVCDIR "inactive/" -#define RC_SVCDIR_STARTED RC_SVCDIR "started/" -#define RC_SVCDIR_COLDPLUGGED RC_SVCDIR "coldplugged/" +#define RC_SVCDIR_STARTING RC_SVCDIR "starting/" +#define RC_SVCDIR_INACTIVE RC_SVCDIR "inactive/" +#define RC_SVCDIR_STARTED RC_SVCDIR "started/" +#define RC_SVCDIR_COLDPLUGGED RC_SVCDIR "coldplugged/" -#define INTERACTIVE RC_SVCDIR "interactive" +#define INTERACTIVE RC_SVCDIR "interactive" #define DEVBOOT "/dev/.rcboot" @@ -699,6 +700,27 @@ int main (int argc, char **argv) FILE *fp; #endif + /* exec init-early.sh if it exists + * This should just setup the console to use the correct + * font. Maybe it should setup the keyboard too? */ + if (rc_exists (INITEARLYSH)) { + if ((pid = vfork ()) == -1) + eerrorx ("%s: vfork: %s", applet, strerror (errno)); + + if (pid == 0) { + execl (INITEARLYSH, INITEARLYSH, (char *) NULL); + eerror ("%s: unable to exec `" INITEARLYSH "': %s", + applet, strerror (errno)); + _exit (EXIT_FAILURE); + } + + do { + wpid = waitpid (pid, &status, 0); + if (wpid < 1) + eerror ("waitpid: %s", strerror (errno)); + } while (! WIFEXITED (status) && ! WIFSIGNALED (status)); + } + uname (&uts); printf ("\n"); @@ -1071,6 +1093,7 @@ int main (int argc, char **argv) pid_t pid = rc_stop_service (service); if (pid > 0 && ! rc_is_env ("RC_PARALLEL", "yes")) rc_waitpid (pid); + continue; } /* If we're in the start list then don't bother stopping us */ diff --git a/src/runscript.c b/src/runscript.c index 2a41c9ba..c6f61181 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -33,6 +33,8 @@ #define RCSCRIPT_HELP RC_LIBDIR "/sh/rc-help.sh" #define SELINUX_LIB RC_LIBDIR "/runscript_selinux.so" +#define PREFIX_LOCK RC_SVCDIR "/prefix.lock" + static char *applet = NULL; static char *exclusive = NULL; static char *mtime_test = NULL; @@ -53,8 +55,7 @@ static bool in_background = false; static rc_hook_t hook_out = 0; static pid_t service_pid = 0; static char *prefix = NULL; - -/* Pipes for prefixed output */ +static bool prefix_locked = false; extern char **environ; @@ -203,6 +204,9 @@ static void uncoldplug (char *service) static void cleanup (void) { + if (prefix_locked) + unlink (PREFIX_LOCK); + /* Flush our buffered output if any */ eclose (); @@ -381,6 +385,22 @@ static bool svc_exec (const char *service, const char *arg1, const char *arg2) } else if (retval) { ssize_t nr; + /* Wait until we get a lock */ + while (true) { + struct timeval tv; + + if (mkfifo (PREFIX_LOCK, 0700) == 0) { + prefix_locked = true; + break; + } + + if (errno != EEXIST) + eerror ("mkfifo `%s': %s\n", PREFIX_LOCK, strerror (errno)); + tv.tv_sec = 0; + tv.tv_usec = 20000; + select (0, NULL, NULL, NULL, &tv); + } + if (FD_ISSET (stdout_pipes[0], &fds)) { if ((nr = read (stdout_pipes[0], buffer, sizeof (buffer))) <= 0) @@ -398,6 +418,10 @@ static bool svc_exec (const char *service, const char *arg1, const char *arg2) write_prefix (fileno (stderr), buffer, nr, &stderr_prefix_shown); } + + /* Clear the lock */ + unlink (PREFIX_LOCK); + prefix_locked = false; } } |