This patch fixes baselayout to build on GNU/kFreeBSD. It includes the following changes: - consoletype.c used major/minor device numbers and it is very unportable (even for different versions of Linux). I rewrote it in bash to use tty names instead. Currently supports Linux and kFreeBSD name scheme but more can be added easily. - For start-stop-daemon.c I pulled this hunk from Debian dpkg HEAD branch (in Scott's arch repository). diff -Nur rc-scripts-1.6.8.old/src/Makefile rc-scripts-1.6.8/src/Makefile --- rc-scripts-1.6.8.old/src/Makefile 2004-12-07 16:40:06 +0000 +++ rc-scripts-1.6.8/src/Makefile 2005-01-27 20:40:38 +0000 @@ -9,15 +9,12 @@ DESTDIR = BIN_TARGETS = -SBIN_TARGETS = consoletype runscript start-stop-daemon +SBIN_TARGETS = runscript start-stop-daemon TARGET = $(BIN_TARGETS) $(SBIN_TARGETS) all: $(TARGET) -consoletype: consoletype.o - $(LD) -o $@ $^ - runscript: runscript.o $(LD) -o $@ $^ -ldl diff -Nur rc-scripts-1.6.8.old/src/consoletype.sh rc-scripts-1.6.8/src/consoletype.sh --- rc-scripts-1.6.8.old/src/consoletype.sh 1970-01-01 00:00:00 +0000 +++ rc-scripts-1.6.8/src/consoletype.sh 2005-01-27 20:38:40 +0000 @@ -0,0 +1,21 @@ +#!/bin/sh +# +# consoletype.sh +# simple app to figure out whether the current terminal +# is serial, console (vt), or remote (pty). +# +# Copyright 2005 Robert Millan <robertmh@gnu.org> +# Distributed under the terms of the GNU General Public License v2 +# +set -e + +case `tty | sed "s,^/dev/,,g"` in + ttyS[0-9]* | cuaa[0-9]*) + echo serial ;; + tty[0-9]* | ttyv[0-9]*) + echo console ;; + pts/[0-9]* | ttyp[0-9]*) + echo pty ;; + *) + echo unknown ;; +esac diff -Nur rc-scripts-1.6.8.old/src/start-stop-daemon.c rc-scripts-1.6.8/src/start-stop-daemon.c --- rc-scripts-1.6.8.old/src/start-stop-daemon.c 2004-12-07 16:40:06 +0000 +++ rc-scripts-1.6.8/src/start-stop-daemon.c 2005-01-27 20:54:53 +0000 @@ -38,7 +38,7 @@ #define NONRETURNING \ __attribute__((noreturn)) -#if defined(linux) +#if defined(linux) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__)) # define OSLinux #elif defined(__GNU__) # define OSHURD
Any news on this?
ive committed the start-stop-daemon.c change, but i dont really want to take a step back with consoletype and use bash ... the bsd guys gave me a fix which ifdef's out the linux-specific code so current baselayout-1.11.11* should build fine on kfbsd ...
I'm not sure if that'd work. Can I see the patch? If you just don't like bash, I could rewrite it in C using ttyname() without much problem.
Ok, now that I've seen it, there are two problems with the patch as committed to current CVS: - major/minor numbers are not portable. In consoletype.c, the Linux-specific ioctl that causes build failure is #ifdef'ed out, but the node number checks won't work since every kernel has its own numbering policy for devices. We could test for each kernel using the numbers or use ttyname() as i mentioned before which is more intuitive. - headers.h defines HAVE_ERROR_H and HAVE_SYS_SYSMACROS_H only for __linux__ but these in fact are not Linux-specific. They're Glibc-specific so the __GLIBC__ macro should be used instead (otherwise it breaks on Glibc systems that don't use Linux).
changed the __linux__ to __GLIBC__ as you suggested sorry for the delay, but could you post the ttyname() C fix ?
Created attachment 66374 [details] ttyname-based implementation
Was that ok?
Created attachment 78136 [details] consoletype.c try this one instead please
You have to use strncmp, otherwise it'll compare the next character after '/' with '\0' and fail (see patch below). OTOH, the check_devnode function is Linux-specific, because it hardcodes major numbers. On non-Linux, it'll always return IS_PTY, which I don't think is the intended. I suggest protecting the whole function with #ifdef __linux__. (Note: it's not an option to hardcode major numbers of kFreeBSD because, on that kernel, they're assigned dynamicaly) --- test.c.old 2006-01-26 08:17:02.000000000 +0100 +++ test.c 2006-01-26 08:19:26.000000000 +0100 @@ -25,7 +25,7 @@ if (tty == NULL) return IS_UNK; - if (strcmp(tty, "/dev/") == 0) + if (strncmp(tty, "/dev/", 5) == 0) tty += 5; if (!strncmp (tty, "ttyS", 4) || !strncmp (tty, "cuaa", 4))
ok, added to baselayout including your last fixes sorry for the delay
Looks fine. Thank you!