Skip to contentSkip to conversation

weekly column and a question about module_init() error codes

DISCUSSION Robert P. J. Day 1 participant 1 message Jul 4, 2009

lore
Share & tools
lore
#0 lore raw

in a spate of self-promotion that probably has little interest for
members of *this* list, i'm now writing a weekly column for linux.com for kernel newbies, first two pieces here:

http://cli.gs/8WMgM9
http://cli.gs/Zd2MuG

yes, i know it's trivial stuff but look at it this way -- if i can explain it properly, then they won't be bugging *you* with those questions. :-)

and regarding return codes from module_init() routines, i realize
that you need to return zero to represent success so that the module is loaded but, if anything goes wrong, you should return a negative value corresponding to some value out of include/asm-generic/errno-base.h:

#define EPERM            1      /* Operation not permitted */
#define ENOENT           2      /* No such file or directory */
#define ESRCH            3      /* No such process */
#define EINTR            4      /* Interrupted system call */
#define EIO              5      /* I/O error */

... snip ...

however, based on some tests i ran, regardless of what error code i
return, a manual "insmod" always returns a shell error code ($?) of 1. the message *printed* will correspond to the actual error value returned, such as returning -EIO printing:

# insmod hi.ko
insmod: error inserting 'hi.ko': -1 Input/output error
#

i'm assuming that, if i'm running insmod as part of a script and can
check only the return code, all i'm going to get is 0 or 1 (success or fail), and there's no way to extract the actual value. (i could capture the error string printed, but that's a bit of a pain -- getting the numeric value would be so much easier.)

or am i missing something painfully obvious? thanks.

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Annoying Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Linked In:                             http://www.linkedin.com/in/rpjday
Twitter:                                       http://twitter.com/rpjday

========================================================================