Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 80021 - [PATCH] GNU/kFreeBSD support
Summary: [PATCH] GNU/kFreeBSD support
Status: VERIFIED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-29 20:00 UTC by Robert Millan
Modified: 2006-01-27 11:40 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
ttyname-based implementation (consoletype.c,818 bytes, text/plain)
2005-08-20 02:46 UTC, Robert Millan
Details
consoletype.c (consoletype.c,1.34 KB, text/plain)
2006-01-25 21:56 UTC, SpanKY
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Millan 2005-01-29 20:00:13 UTC
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
Comment 1 Robert Millan 2005-05-12 03:34:34 UTC
Any news on this?
Comment 2 SpanKY gentoo-dev 2005-05-12 22:26:37 UTC
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 ...
Comment 3 Robert Millan 2005-05-13 02:59:14 UTC
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.
Comment 4 Robert Millan 2005-05-13 04:40:36 UTC
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).
Comment 5 SpanKY gentoo-dev 2005-08-11 20:49:15 UTC
changed the __linux__ to __GLIBC__ as you suggested

sorry for the delay, but could you post the ttyname() C fix ?
Comment 6 Robert Millan 2005-08-20 02:46:42 UTC
Created attachment 66374 [details]
ttyname-based implementation
Comment 7 Robert Millan 2006-01-25 09:56:54 UTC
Was that ok?
Comment 8 SpanKY gentoo-dev 2006-01-25 21:56:23 UTC
Created attachment 78136 [details]
consoletype.c

try this one instead please
Comment 9 Robert Millan 2006-01-25 23:24:21 UTC
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))
Comment 10 SpanKY gentoo-dev 2006-01-26 15:59:53 UTC
ok, added to baselayout including your last fixes

sorry for the delay
Comment 11 Robert Millan 2006-01-27 11:40:22 UTC
Looks fine.  Thank you!