From owner-freebsd-bugs Wed Jul 7 1: 0: 6 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id E77AD14E66 for ; Wed, 7 Jul 1999 01:00:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id BAA99777; Wed, 7 Jul 1999 01:00:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from jimex.jinr.ru (jimex.jinr.ru [159.93.17.7]) by hub.freebsd.org (Postfix) with ESMTP id 272D214C8B for ; Wed, 7 Jul 1999 00:49:51 -0700 (PDT) (envelope-from isupov@moonhe.jinr.ru) Received: from moonhe.jinr.ru (isupov@moonhe.jinr.ru [159.93.18.27]) by jimex.jinr.ru (8.8.8/8.8.4) with ESMTP id LAA18798 for ; Wed, 7 Jul 1999 11:49:33 +0400 (MSD) Received: (from isupov@localhost) by moonhe.jinr.ru (8.8.8/8.8.8) id LAA11890; Wed, 7 Jul 1999 11:49:09 +0400 (MSD) (envelope-from isupov) Message-Id: <199907070749.LAA11890@moonhe.jinr.ru> Date: Wed, 7 Jul 1999 11:49:09 +0400 (MSD) From: isupov@moonhe.jinr.ru Reply-To: isupov@moonhe.jinr.ru To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/12545: kldload(8) should be more sensitive to errors in *_module_handler(..., MOD_LOAD, ...) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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 #include #include + #include + #include 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