Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Jul 1999 11:49:09 +0400 (MSD)
From:      isupov@moonhe.jinr.ru
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/12545: kldload(8) should be more sensitive to errors in *_module_handler(..., MOD_LOAD, ...)
Message-ID:  <199907070749.LAA11890@moonhe.jinr.ru>

next in thread | raw e-mail | index | archive | help

>Number:         12545
>Category:       bin
>Synopsis:       kldload(8) should be more sensitive to errors in *_module_handler(..., MOD_LOAD, ...)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul  7 01:00:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Isupov A.Yu.
>Release:        FreeBSD -current
>Organization:
JINR, LHE
>Environment:

	FreeBSD -current

>Description:

	  In the -current kldload(8) returns 0 (success), if error occur in
	*_module_handler(..., MOD_LOAD, ...), because of
	kern_module.c:module_register_init() and
	kern_linker.c:linker_file_sysinit() are of type void.
	  As I can see, change their type not so easy :) , so we can't (???)
	solve the problem in kldload(2). But kldload(8) can at least try to
	resolve post-loading situation and returns different exit status for:
	  1) loaded file doesn't contains modules at all (f.e. EX_SOFTWARE);
	  2) loaded file contains some modules (f.e. number_of_modules);
	  Unfortunately, so we will not success code (EX_OK), because of we
	can't know, what number of modules loaded file must contains, if
	loading is successful. But case 1) will be reliably distinguished.
	  We can also unload file in the case 1).

>How-To-Repeat:
>Fix:
	
	Here is a patches for kldload.c v 1.5 :

*** kldload.c.orig	Wed Jul  7 11:12:55 1999
--- kldload.c	Wed Jul  7 11:30:36 1999
***************
*** 34,39 ****
--- 34,41 ----
  #include <unistd.h>
  #include <sys/param.h>
  #include <sys/linker.h>
+ #include <sys/module.h>
+ #include <sysexits.h>
  
  static void
  usage(void)
***************
*** 48,53 ****
--- 50,56 ----
      int c;
      int verbose = 0;
      int fileid;
+     int modid, mod_cnt = 0;
  
      while ((c = getopt(argc, argv, "v")) != -1)
  	switch (c) {
***************
*** 65,74 ****
  
      fileid = kldload(argv[0]);
      if (fileid < 0)
! 	err(1, "can't load %s", argv[0]);
!     else
  	if (verbose)
! 	    printf("Loaded %s, id=%d\n", argv[0], fileid);
  
!     return 0;
  }
--- 68,86 ----
  
      fileid = kldload(argv[0]);
      if (fileid < 0)
! 	err(EX_OSERR, "can't load %s", argv[0]);
! 
!     for (modid = kldfirstmod(fileid); modid > 0; modid = modfnext(modid))
! 	mod_cnt++;
! 
!     if (!mod_cnt) {
! 	if (kldunload(fileid) < 0)
! 	    err(EX_OSERR, "can't unload file");
!     } else {
  	if (verbose)
! 	    printf("Loaded %s, id=%d with %d modules\n",
! 		argv[0], fileid, mod_cnt);
!     }
  
!     return (mod_cnt ? mod_cnt : EX_SOFTWARE);
  }

--------------------------------------------------------------------
	and for kldload.8 v 1.5 :

*** kldload.8.orig	Wed Jul  7 11:34:24 1999
--- kldload.8	Wed Jul  7 11:41:19 1999
***************
*** 54,62 ****
  .Sh DIAGNOSTICS
  The
  .Nm
! utility exits with a status of 0 on success
! and with a nonzero status if an error occurs.
  .Sh SEE ALSO
  .Xr kldstat 8 ,
  .Xr kldunload 8
  .Sh HISTORY
--- 54,64 ----
  .Sh DIAGNOSTICS
  The
  .Nm
! utility returns the number of modules in the loaded file as exit code,
! the EX_SOFTWARE if file doesn't contains any successful modules and was unloaded,
! and the EX_OSERR if other error occurs.
  .Sh SEE ALSO
+ .Xr sysexits 3 ,
  .Xr kldstat 8 ,
  .Xr kldunload 8
  .Sh HISTORY

---------------------------------------------------------------------------

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907070749.LAA11890>