[Question] Recently I did some work on the Linux kernel, and want to use 'print' to continue a previous log message in the same line. So I tried to use pr_cont in <linux/kernel.h> to replace printk in the function.
The code is here:
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/printk.h>
typedef struct {
TEST_PRINTF printf;
TEST_UDELAY udelay;
TEST_MALLOC malloc;
TEST_FREE free;
} TEST_INIT_PARAM_T;
static int __init test_init(void) {
TEST_INIT_PARAM_T my_init_param = { 0 };
/* The problem is here */
my_init_param.printf = pr_cont;
my_init_param.udelya = my_udelay;
my_init_param.malloc = my_malloc;
my_init_param.free = my_free;
my_init(&my_init_param);
....
}
and GCC shows an error: 'pr_cont' undeclared (first use in this function). However, if use
my_init_param.printf = printk;
and this will be ok.
I have also tried using
void test_printk(some_variables) {
printk(KERN_CONT some_variables)
}
And make my_init_param.printf = test_printk.
But I don't know what the 'some_variable' should be?
Also, I really want to know why the equation my_init_param.printf = pr_cont is wrong?
[Attempt]
I have realized that the true reason why the equation
my_init_param.printf = pr_cont;doesn't hold. Just like I can't define a = int b. So I add typedef as below
typedef int
(*TEST_PRINTK)(
const char *fmt,
...);
TEST_PRINTK test_pr_cont;
#define test_pr_cont(fmt, ...) \
printk(KERN_CONT fmt, ##__VA_ARGS__)
Then the equationmy_init_param.printf = test_pr_cont;can pass the GCC.
However, other functions called this 'print' cannot print anything.