Declare a global variable in kernel 2.6

From: Maurice Hoeneveld (mhoeneveld_at_zonnet.nl)
Date: 04/15/05


Date: 15 Apr 2005 07:31:15 -0700

Sorry I disturb all the die hards but kenel programming is no daily
stuff for me.
I want to do the following in kernel 2.6

In init/main.c I create a funtion in which a variable can be set as
boot parameter.

static int __init rigtime(char *line){
        shift_time = simple_strtol(line, (char **)(line +
sizeof(line)), (unsigned int)10);
        return 0;
}

__setup("shifttime=", rigtime);

So far so good.

Now in fs/proc/proc_misc.c I want to use the variable shift_time
again.

Where and how I have to declare this new variable?

If I declare it in main.c as long `shift_time' and use an `extern long
shift_time' in proc_misc.c it complaines about "undefined reference to
`shift_time'" while compiling.

When I declare it as a `long shift_time' in a shared header file like
proc_fs.h as `long shift_time' it complains about "multiple
declaration of `shift_time" while compiling the main module.

When I declare it in a shared header file like proc_fs.h as `#define
shift_time' I get a complain that lvar can't be set in the function
rigtime which seems logical to me.

After 4 days of playing with it I don't have any clue nomore. So maybe
there is someone who can help me with this because I need it for a
research project in our institute.

Al help is appreciated.

Maurice Hoeneveld
Landelijk Instituut Beveiliging RO
Leeuwarden - The Netherlands
mhoeneveld@zonnet.nl