Hi there,
I'm trying to compile a kernel module which will print the uptime since booting in seconds.
This is what I have so far:
Code:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
#include <linux/sysinfo.h>
int init_module(void)
{
printk("Uptime: ", sysinfo.uptime, "\n");
// A non 0 return means init_module failed; module can't be loaded.
return 0;
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}
MODULE_LICENSE("GPL");
However compiling it will error out with:
make[1]: Map '/usr/src/kernels/4.0.6-300.fc22.x86_64' wordt binnengegaan
CC [M] /home/mastag/time.o
/home/mastag/time.c: In functie ‘init_module’:
/home/mastag/time.c:14:23: fout: ‘sysinfo’ undeclared (first use in this function)
printk("Uptime: ", sysinfo.uptime, "\n");
^
/home/mastag/time.c:14:23: note: each undeclared identifier is reported only once for each function it appears in
scripts/Makefile.build:264: recept voor doel '/home/mastag/time.o' is mislukt
make[2]: *** [/home/mastag/time.o] Fout 1
Why is it undeclared?
I've included sysinfo.h which has the sysinfo struct right?
linux/sysinfo.h contains:
Code:
struct sysinfo {
__kernel_long_t uptime; /* Seconds since boot */
__kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */
__kernel_ulong_t totalram; /* Total usable main memory size */
__kernel_ulong_t freeram; /* Available memory size */
__kernel_ulong_t sharedram; /* Amount of shared memory */
__kernel_ulong_t bufferram; /* Memory used by buffers */
__kernel_ulong_t totalswap; /* Total swap space size */
__kernel_ulong_t freeswap; /* swap space still available */
__u16 procs; /* Number of current processes */
__u16 pad; /* Explicit padding for m68k */
__kernel_ulong_t totalhigh; /* Total high memory size */
__kernel_ulong_t freehigh; /* Available high memory size */
__u32 mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
};