Bug 12545

Summary: kldload(8) should be more sensitive to errors in *_module_handler(..., MOD_LOAD, ...)
Product: Base System Reporter: isupov <isupov>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description isupov 1999-07-07 09:00:00 UTC
	  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).

Fix: Here is a patches for kldload.c v 1.5 :

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



-----------------------------------------------------------------------------9zDE0TDMlx5txDS5G2HpQ2USAjHcfGyqZ725yX3o7DzJW9wy
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

*** 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);
  }
Comment 1 iedowse freebsd_committer freebsd_triage 2002-01-20 18:15:50 UTC
State Changed
From-To: open->feedback


Is this problem still present?
Comment 2 isupov 2002-01-21 08:34:13 UTC
At least kern_module.c:module_register_init() (ver. 1.28) and
kern_linker.c:linker_file_sysinit() (ver. 1.73) are still of type void, so
all it's errors aren't recognized by kldload(2) and kldload(8)...
Proposed patches for kldload(8) were workaround, which constatate, not
solves a problem, and not satisfactory for all possible situations.
Comment 3 Sheldon Hearn freebsd_committer freebsd_triage 2002-01-31 15:07:22 UTC
State Changed
From-To: feedback->open

Doug, are you still looking after kld* utilities? 


Comment 4 Sheldon Hearn freebsd_committer freebsd_triage 2002-01-31 15:07:22 UTC
Responsible Changed
From-To: freebsd-bugs->dfr

Feedback acquired.
Comment 5 Sheldon Hearn freebsd_committer freebsd_triage 2002-02-05 09:50:17 UTC
Responsible Changed
From-To: dfr->peter

Peter, Doug says you're my best bet for an interested party.  Are you 
still interested in kld*(8)-related PRs?
Comment 6 Peter Wemm freebsd_committer freebsd_triage 2012-12-27 04:50:52 UTC
State Changed
From-To: open->closed

The enclosed patch is still wrong, as per the previous comment. 
Closing as WONTFIX, if only gnats had such a state. 


Comment 7 Peter Wemm freebsd_committer freebsd_triage 2012-12-27 04:50:52 UTC
Responsible Changed
From-To: peter->freebsd-bugs

The enclosed patch is still wrong, as per the previous comment. 
Closing as WONTFIX, if only gnats had such a state.