Skip to contentSkip to conversation

read proc entry

DISCUSSION Anthony Chee 3 participants 4 messages Apr 13, 2002 – Apr 18, 2002

lore
Share & tools
lore
#0 lore raw

I written the following code in a module

static struct proc_dir_entry *test_proc;
test_proc = create_proc_read_entry(test_proc, 0444, NULL, read_test_proc, NULL);

void show_kernel_message() {
    printk("\nkernel test\n");
}

int read_test_info(char* page, char** start, off_t off, int count, int* eof,

void* data) {
    show_kernel_message();
}

After I use "cat /proc/test_proc", it is found that there are three "kernel test" messages
appear. Why it happened like this? I expected the message should be shown once.

#1 lore raw
Quoted 7 lines · Anthony Chee

I written the following code in a module

static struct proc_dir_entry *test_proc;
test_proc = create_proc_read_entry(test_proc, 0444, NULL, read_test_proc, NULL);

Quoted 7 lines
void show_kernel_message() {
    printk("\nkernel test\n");
}

int read_test_info(char* page, char** start, off_t off, int count, int* eof,

void* data) {
    show_kernel_message();

I think you have to signal EOF

	*eof=1;
Quoted 7 lines

}

After I use "cat /proc/test_proc", it is found that there are three "kernel test" messages
appear. Why it happened like this? I expected the message should be shown once.

#2 lore raw
In reply to Anthony Chee

After I added *eof =1, that message appears two times. How can I reduce it only one?

----- Original Message -----
From: "Peter Wächtler" <[email protected]>
To: "Anthony Chee" <[email protected]>
Cc: <[email protected]>
Sent: Saturday, April 13, 2002 9:58 PM
Subject: Re: read proc entry

Quoted 6 lines
Quoted 5 lines · Anthony Chee

I written the following code in a module

static struct proc_dir_entry *test_proc; test_proc = create_proc_read_entry(test_proc, 0444, NULL,

read_test_proc,

Quoted 7 lines
Quoted 7 lines

NULL);

void show_kernel_message() {
    printk("\nkernel test\n");
}

int read_test_info(char* page, char** start, off_t off, int count, int*

eof,

Quoted 10 lines
Quoted 2 lines
void* data) {
    show_kernel_message();

I think you have to signal EOF

*eof=1;

Quoted 3 lines

}

After I use "cat /proc/test_proc", it is found that there are three

"kernel

Quoted 2 lines
Quoted 2 lines

test" messages
appear. Why it happened like this? I expected the message should be

shown

Quoted 3 lines
Quoted 2 lines

once.

#3 lore raw

Hi,

Another thing that you could do is use the seq_file interface for proc-fs. That should do away with the EOF/double-read problem.

seq_file is available in kernel 2.4.15 and later.

~Randy

On Sat, 13 Apr 2002, Anthony Chee wrote:

| After I added *eof =1, that message appears two times. How can I reduce it
| only one?
|
| ----- Original Message -----
| From: "Peter Wächtler" <[email protected]>
| To: "Anthony Chee" <[email protected]>
| Cc: <[email protected]>
| Sent: Saturday, April 13, 2002 9:58 PM
| Subject: Re: read proc entry
|
|
| > Anthony Chee wrote:
| > >
| > > I written the following code in a module
| > >
| > > static struct proc_dir_entry *test_proc;
| > > test_proc = create_proc_read_entry(test_proc, 0444, NULL,
| read_test_proc,
| > > NULL);
| > >
| > > void show_kernel_message() {
| > >     printk("\nkernel test\n");
| > > }
| > >
| > > int read_test_info(char* page, char** start, off_t off, int count, int*
| eof,
| > > void* data) {
| > >     show_kernel_message();
| >
| > I think you have to signal EOF
| >
| > *eof=1;
| >
| > > }
| > >
| > > After I use "cat /proc/test_proc", it is found that there are three
| "kernel
| > > test" messages
| > > appear. Why it happened like this? I expected the message should be
| shown
| > > once.
| > >
| >
| -