From nobody@FreeBSD.org  Thu Jun 24 00:45:56 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B00931065670
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 Jun 2010 00:45:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 857678FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 Jun 2010 00:45:56 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o5O0jux9006678
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 Jun 2010 00:45:56 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o5O0juO4006677;
	Thu, 24 Jun 2010 00:45:56 GMT
	(envelope-from nobody)
Message-Id: <201006240045.o5O0juO4006677@www.freebsd.org>
Date: Thu, 24 Jun 2010 00:45:56 GMT
From: Christoph Weber-Fahr <cwf-ml@arcor.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: suggested addition to liux_base-* packages to set osreales variable correctly
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         148097
>Category:       ports
>Synopsis:       [patch] suggested addition to linux_base-* packages to set osrealese variable correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-emulation
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 24 00:50:03 UTC 2010
>Closed-Date:    
>Last-Modified:  Wed Jun  6 17:00:22 UTC 2012
>Originator:     Christoph Weber-Fahr
>Release:        FreeBSD 7.3
>Organization:
Vodafone
>Environment:
FreeBSD xxx.yyy.zzz.de 7.3-RELEASE FreeBSD 7.3-RELEASE #0: Mon Jun  7 14:29:18 UTC 2010     root@buildXXXX.yyy.net:/usr/obj/usr/src/sys/DL380DNS  amd64

>Description:
Right now the linux compatibility kernel module supports 2 abi versions: 2.4.2 and 2.6.16.   2.4.2 is the default, the other one can be set via a sysctl variable. 

But the current versions of all linux_base-*packages need the 2.6.16 setting. Unfortunately, though, the packages don't have any mechanism in place to actually set this permanently.

I venture to guess the maintainers wanted the user to put this setting into /etc/sysctl.conf . But, aside from the fact that at least the binary package installation makes no mention of this, this creates a unique problem: 

/etc/rc.d/sysctl (which implements sysctl.conf) is run *before* /etc/rc.d/abi (which loads the kernel module). So, at this point the osrelease setting fails silently. Later on (very late, actually) /etc/rc.d/sysctl is invoked a second time by /etc/rc.d/securelevel, which then sets the variable correctly. 

But unfortunatley, at this time, many third party package start scripts from /usr/local/etc/rc.d/ have already been run. Most of them either use REQUIRE LOGIN or no such setting at all, both of which results in them being run before securelevel. 

Any of those needing linux_base fail silently. 

Now, a workaround would be to have each linux-dependent package use "REQUIRE securelevel". But that is counter-intuitive and might even bring up other problems, especially if you actually use securelevel.

The correct way of course is to have the osrelease variable set earlier. A simple way to do this is for the respective linux_base package to install its own small start script that can run much earlier without any  adverse consequences. 

I include such a script below and suggest it or something similar to be added to all linux_base-* packages and installed by them to /usr/local/etc/rc.d/


>How-To-Repeat:

>Fix:
#!/bin/sh
#
# PROVIDE: linuxversion
# REQUIRE: abi
# BEFORE:  DAEMON
#
#

. /etc/rc.subr

name="linuxversion"
stop_cmd=":"
start_cmd="linuxversion_start"
reload_cmd="linuxversion_start"

linuxversion_start()
{
        echo "Settimg Linux ABI version:"
        sysctl compat.linux.osrelease=2.6.16
}

load_rc_config $name
run_rc_command "$1"


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->freebsd-emulation 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Jun 24 20:27:27 UTC 2010 
Responsible-Changed-Why:  
This is a script that would affect several ports.  Over to maintainers. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148097 

From: Chris Rees <crees@FreeBSD.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: ports/148097: [patch]
Date: Wed, 6 Jun 2012 17:49:57 +0100

 This IRC transcript from Freenode/##FreeBSD might be relevant.
 
 <fleximus> frag4: no, I am root under normal system
 <fleximus> frag4: The behaviour of the script is different when
 startet during boot. Don't forget to add linuxtest_enable="YES" to
 /etc/rc.conf
 <frag4> fleximus: I'm unable to reproduce your problem.
 <cmanns> yes but you need to call like /compat/linux/bin/bash first er somethin?
 <frag4> fleximus: please do procstat -f $$ in very same shell you run
 /bin/sh /usr/local/etc/rc.d/startscript
 <fleximus> frag4: It's the default /bin/csh for root from command
 line. The systems reboots at the moment, give you the other result in
 a second
 <fleximus> frag4: During boot it is /bin/sh. Anyway, if I call /bin/sh
 /usr/local/etc/rc.d/startscript it works fine
 <fleximus> frag4: The latter will also display /bin/sh.
 <frag4> fleximus: well, I'm running 9.0 here and cannot reproduce
 this. Eithery way, I'm going home now, some good luck with debugging.
 :)
 <frag4> fleximus: s/some/so/
 <fleximus> frag4: This is also 9.0, but I must leave soon, too ;-(
 <fleximus> frag4: Thank you for your ideas
 <fleximus> oh, that might be the solution, I will test now:
 http://www.FreeBSD.org/cgi/query-pr.cgi?pr=kern/159646
 <fleximus> and this one: http://www.FreeBSD.org/cgi/query-pr.cgi?pr=ports/148097
 <fleximus> PR148097 is the workaround for me! Now I can go home. bye bye
 <fleximus> frag4: =)
>Unformatted:
