Hello,
I can not understand why it is not working on your module, perhaps you are forgetting some basic step:
I tried to simulate your problem this way:
1) put the global variable and the exported function on somewhere on the kernel, I choose the init/main.c file:
Code:
diff --git a/init/main.c b/init/main.c
index 63f5f6f..e4e0d33 100644
--- a/init/main.c
+++ b/init/main.c
@@ -844,3 +844,11 @@ static int __init kernel_init(void * unused)
init_post();
return 0;
}
+int trace_flag = 0;
+void my_set_trace(int pass)
+{
+ printk(KERN_INFO "setting trace_flag to %d\n",pass);
+ trace_flag = pass;
+ printk(KERN_INFO "trace_flag is now %d\n",trace_flag);
+}
+EXPORT_SYMBOL(my_set_trace);
2) put the function prototype on some header, so my module can get it, I choose the header linux/kernel.h:
Code:
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4c0d3b2..4696ec1 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -728,7 +728,7 @@ extern int __build_bug_on_failed;
struct sysinfo;
extern int do_sysinfo(struct sysinfo *info);
-
+void my_set_trace (int pass);
#endif /* __KERNEL__ */
#define SI_LOAD_SHIFT 16
3) create a module to call the function:
Code:
#include <linux/kernel.h>
#include <linux/module.h>
int trace_init(void)
{
printk(KERN_ERR "hello\n");
my_set_trace(23);
return 0;
}
void trace_exit(void)
{
printk(KERN_ERR "bye\n");
}
module_init(trace_init);
module_exit(trace_exit);
so, when I insmod the module it I got:
Quote:
[ 5575.130326] hello
[ 5575.130761] setting trace_flag to 23
[ 5575.130779] trace_flag is now 23
|
is something like this that you are trying to do?
if yes, this is quite simple, there is no reason to fail.
please review your code and write here what you found.
happy hollyday!