From isupov@moonhe.jinr.ru Wed Jun 16 04:07:09 1999
Return-Path: <isupov@moonhe.jinr.ru>
Received: from jimex.jinr.ru (jimex.jinr.ru [159.93.17.7])
	by hub.freebsd.org (Postfix) with ESMTP id 1BB4B14CBB
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 16 Jun 1999 04:07:04 -0700 (PDT)
	(envelope-from isupov@moonhe.jinr.ru)
Received: from moonhe.jinr.ru (root@moonhe.jinr.ru [159.93.18.27])
          by jimex.jinr.ru (8.8.8/8.8.4) with ESMTP
	  id PAA17263 for <FreeBSD-gnats-submit@freebsd.org>; Wed, 16 Jun 1999 15:06:56 +0400 (MSD)
Received: (from isupov@localhost)
	by moonhe.jinr.ru (8.8.8/8.8.8) id OAA24531;
	Wed, 16 Jun 1999 14:32:05 +0400 (MSD)
	(envelope-from isupov)
Message-Id: <199906161032.OAA24531@moonhe.jinr.ru>
Date: Wed, 16 Jun 1999 14:32:05 +0400 (MSD)
From: isupov@moonhe.jinr.ru
Reply-To: isupov@moonhe.jinr.ru
To: FreeBSD-gnats-submit@freebsd.org
Subject: KLD module's load/unload errors handled in strange way (or ignored ?)
X-Send-Pr-Version: 3.2

>Number:         12239
>Category:       kern
>Synopsis:       KLD module's load/unload errors handled in strange way (or ignored ?)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 16 04:10:01 PDT 1999
>Closed-Date:    Sun Jun 27 02:39:38 PDT 1999
>Last-Modified:  Sun Jun 27 02:41:10 PDT 1999
>Originator:     Isupov A.Yu.
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
JINR, LHE
>Environment:

	FreeBSD 3.2-RELEASE i386 (need nothing else than standard installation)

>Description:

	1) If in a KLD module <sometning_mod>.ko the function
	<sometning_mod>_modevent(struct module *module, int cmd, void *arg)
	returns error at loading time (f.e. :

		case MOD_LOAD :
			if (...) {
				error = ENXIO;
				break;
			}

	), kldload(8) returns 0 (success !!!) and we have picture of the
	following style:

	% kldstat -v
	Id Refs Address    Size     Name
	...
	30    1 0xc0921000 2000     <something_mod>.ko
		Contains modules:
			Id Name

	instead of full absence of <something_mod>.ko here (as was in the
	3.0-RELEASE).
	Such strange object not contains syscall, realised in
	<something_mod>.ko, and can be successfully removed by kldunload(8),
	but what the reasons for its appearing at all ?!!

	2) If in a KLD module <sometning_mod>.ko the same function
	returns error at unloading time (f.e. :

		case MOD_UNLOAD :
			if (...) {
				error = ETXTBSY;
				break;
			}

	), kldunload(8) returns 1 (nonzero, this seems correct...),
	<something_mod>.ko still appear in the kldstat output (

	% kldstat -v
	Id Refs Address    Size     Name
	...
	31    1 0xc0921000 2000     <something_mod>.ko
		Contains modules:
			Id Name
			45 <something_mod>

	), but syscall, which <something_mod> realises, already removed:

	% /usr/share/examples/kld/syscall/test/test
	Bad system call - core dumped

	(test obtains 12 signal) !!!

>How-To-Repeat:

	Play with /usr/share/examples/kld/syscall/module/syscall.c .

>Fix:
	
	1) Don't know, at least because module_register_init() in
	/sys/kern/kern_module.c of type void now.
	2) ???
	What are you think, described behaviour is a bug or a feature ?


>Release-Note:
>Audit-Trail:

From: "A.Yu.Isupov" <isupov@moonhe.jinr.ru>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/12239
Date: Sat, 26 Jun 1999 19:19:06 +0400

    Hi !
 
 Following fixes problem with MOD_UNLOAD for syscalls (more serious, as I
 think) (now kern_syscalls.c:syscall_module_handler() will be very close to
 kern_conf.c:[bc]devsw_module_handler(), which was already patched for
 the same reasons :) Patch produced for v 1.3 of kern_syscalls.c
 
 -------------------------------------------------
 *** kern_syscalls.c.orig	Sat Jun 26 18:57:46 1999
 --- kern_syscalls.c	Sat Jun 26 18:39:22 1999
 ***************
 *** 95,107 ****
                          return error;
   	       ms.intval = *data->offset;
   	       module_setspecific(mod, &ms);
 !                break;
          case MOD_UNLOAD :
                  error = syscall_deregister(data->offset, &data->old_sysent);
 !                if (error)
 !                        return error;
 !                break;
          }
          if (data->chainevh)
                  return data->chainevh(mod, what, data->chainarg);
          else
 --- 95,114 ----
                          return error;
   	       ms.intval = *data->offset;
   	       module_setspecific(mod, &ms);
 !                if (data->chainevh)
 !                        error = data->chainevh(mod, what, data->chainarg);
 !                return error;
 ! 
          case MOD_UNLOAD :
 +                if (data->chainevh) {
 +                        error = data->chainevh(mod, what, data->chainarg);
 +                        if (error)
 +                                return error;
 +                }
                  error = syscall_deregister(data->offset, &data->old_sysent);
 !                return error;
          }
 + 
          if (data->chainevh)
                  return data->chainevh(mod, what, data->chainarg);
          else
 -------------------------------------------------
 
   But what about kern_module.c:module_register_init() and
 kern_linker.c:linker_file_sysinit() , which still void in both -stable and
 -current ?
 
     Isupov A.
 
 
State-Changed-From-To: open->closed 
State-Changed-By: dfr 
State-Changed-When: Sun Jun 27 02:39:38 PDT 1999 
State-Changed-Why:  
Fixed in version 1.4 of kern_syscalls.c 
>Unformatted:
