Anybody know what is __supposed__ to happen with lseek()
on /proc/kmsg. Right now, it does nothing, always returns
0. Given that, how am I supposed to clear the kmsg buffer
since it's not a terminal??
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
Hi,
> how am I supposed to clear the kmsg buffer since it's not a terminal??
fd = open("/proc/kmsg", O_RDONLY | O_NONBLOCK);
while(read(fd, buf, sizeof(buf)) > 0);
if(errno == EAGAIN) { printf("Clear!\n"); }
This is language (spoken-wise) neutral :p
Jan Engelhardt
--
On Tue, 22 Mar 2005, Jan Engelhardt wrote:
> Hi,
>
>> how am I supposed to clear the kmsg buffer since it's not a terminal??
>
> fd = open("/proc/kmsg", O_RDONLY | O_NONBLOCK);
> while(read(fd, buf, sizeof(buf)) > 0);
> if(errno == EAGAIN) { printf("Clear!\n"); }
>
> This is language (spoken-wise) neutral :p
>
Gawd, you are a hacker. I already have to suck on pipes
because I can't seek them. Now, I can't even seek a
file-system???!!
>
>
> Jan Engelhardt
> --
>
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
> Gawd, you are a hacker. I already have to suck on pipes
> because I can't seek them. Now, I can't even seek a
> file-system???!!
Here goodie goodie...
diff -pdru linux-2.6.11.4/fs/proc/kmsg.c linux-2.6.11-AS9/fs/proc/kmsg.c
--- linux-2.6.11.4/fs/proc/kmsg.c 2005-03-21 20:14:58.000000000 +0100
+++ linux-2.6.11-AS9/fs/proc/kmsg.c 2005-03-22 21:28:40.000000000 +0100
@@ -46,10 +46,15 @@ static unsigned int kmsg_poll(struct fil
return 0;
}
+static loff_t kmsg_seek(struct file *filp, loff_t offset, int origin) {
+ if(origin != 2 /* SEEK_END */ || offset < 0) { return -ESPIPE; }
+ return do_syslog(5, NULL, 0);
+}
struct file_operations proc_kmsg_operations = {
.read = kmsg_read,
.poll = kmsg_poll,
.open = kmsg_open,
.release = kmsg_release,
+ .llseek = kmsg_seek,
};
Works so far that do_syslog is called with the correct parameters --
however, that does not work. (Did I discover a bug?)
# rcsyslog stop; # so that kmsg is not slurped by someone else
# perl -le 'open X,"</proc/kmsg";seek X,0,2;print read X,$b,3'
the perl command should block, because with the seek(), we've just emptied the
syslog ring buffer. Obviously, it does not, and read() succeeds - prints 3.
Any hints on what's wrong here?
Jan Engelhardt
--
On Tue, 22 Mar 2005, Jan Engelhardt wrote:
>> Gawd, you are a hacker. I already have to suck on pipes
>> because I can't seek them. Now, I can't even seek a
>> file-system???!!
>
> Here goodie goodie...
>
> diff -pdru linux-2.6.11.4/fs/proc/kmsg.c linux-2.6.11-AS9/fs/proc/kmsg.c
> --- linux-2.6.11.4/fs/proc/kmsg.c 2005-03-21 20:14:58.000000000 +0100
> +++ linux-2.6.11-AS9/fs/proc/kmsg.c 2005-03-22 21:28:40.000000000 +0100
> @@ -46,10 +46,15 @@ static unsigned int kmsg_poll(struct fil
> return 0;
> }
>
> +static loff_t kmsg_seek(struct file *filp, loff_t offset, int origin) {
> + if(origin != 2 /* SEEK_END */ || offset < 0) { return -ESPIPE; }
> + return do_syslog(5, NULL, 0);
> +}
>
> struct file_operations proc_kmsg_operations = {
> .read = kmsg_read,
> .poll = kmsg_poll,
> .open = kmsg_open,
> .release = kmsg_release,
> + .llseek = kmsg_seek,
> };
>
>
> Works so far that do_syslog is called with the correct parameters --
> however, that does not work. (Did I discover a bug?)
>
> # rcsyslog stop; # so that kmsg is not slurped by someone else
> # perl -le 'open X,"</proc/kmsg";seek X,0,2;print read X,$b,3'
>
> the perl command should block, because with the seek(), we've just emptied the
> syslog ring buffer. Obviously, it does not, and read() succeeds - prints 3.
> Any hints on what's wrong here?
>
Sure, read() needs to be modified to respect the file-position
set by kmsg_seek(). I don't think you can get away with the
call back into do_syslog.
In other words we shouldn't move a user-mode hack into the
kernel.
>
> Jan Engelhardt
> --
>
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
linux-os wrote:
> On Tue, 22 Mar 2005, Jan Engelhardt wrote:
>
>> Hi,
>>
>>> how am I supposed to clear the kmsg buffer since it's not a terminal??
>>
>>
>> fd = open("/proc/kmsg", O_RDONLY | O_NONBLOCK);
>> while(read(fd, buf, sizeof(buf)) > 0);
>> if(errno == EAGAIN) { printf("Clear!\n"); }
>>
>> This is language (spoken-wise) neutral :p
>>
>
> Gawd, you are a hacker. I already have to suck on pipes
> because I can't seek them. Now, I can't even seek a
> file-system???!!
I'm not sure that seek makes any sense on that, since it is more like a
pipe than a normal file..
--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/
Jan Engelhardt <[email protected]> wrote:
> +static loff_t kmsg_seek(struct file *filp, loff_t offset, int origin) {
> + if(origin != 2 /* SEEK_END */ || offset < 0) { return -ESPIPE; }
^^^
"Allow" seeking past the end of the buffer?
1> Sure, read() needs to be modified to respect the file-position
1> set by kmsg_seek(). I don't think you can get away with the
1> call back into do_syslog.
2>I'm not sure that seek makes any sense on that, since it is more like a
2>pipe than a normal file..
Well, seek(fd, 0, SEEK_END) could be used to flush a pipe's buffers.
0>> +static loff_t kmsg_seek(struct file *filp, loff_t offset, int origin) {
0>> + if(origin != 2 /* SEEK_END */ || offset < 0) { return -ESPIPE; }
3> "Allow" seeking past the end of the buffer?
Well, what does lseek(fd, >0, SEEK_END) do on normal files?
Jan Engelhardt
--
Followup to: <[email protected]>
By author: Jan Engelhardt <[email protected]>
In newsgroup: linux.dev.kernel
>
> Well, what does lseek(fd, >0, SEEK_END) do on normal files?
>
Sets the file pointer beyond the end of the file (a write() there will
extend the file.)
-hpa
On Wed, 23 Mar 2005, Jan Engelhardt wrote:
>
> 1> Sure, read() needs to be modified to respect the file-position
> 1> set by kmsg_seek(). I don't think you can get away with the
> 1> call back into do_syslog.
>
> 2>I'm not sure that seek makes any sense on that, since it is more like a
> 2>pipe than a normal file..
>
> Well, seek(fd, 0, SEEK_END) could be used to flush a pipe's buffers.
>
Yep. That's what I tried to do. Just returns 0 and continues to
contain all the cached data.
> 0>> +static loff_t kmsg_seek(struct file *filp, loff_t offset, int origin) {
> 0>> + if(origin != 2 /* SEEK_END */ || offset < 0) { return -ESPIPE; }
> 3> "Allow" seeking past the end of the buffer?
>
> Well, what does lseek(fd, >0, SEEK_END) do on normal files?
>
Goes to the end plus offset. A subsequent read returns EOF
or 0 depending upon your read mechanism. This is what I wanted
to do but with no offset.
Currently, I do this crap:
for(;;)
{
pfd.fd = ifd;
pfd.events = POLLIN;
pfd.revents = 0;
if(poll(&pfd, 1, 0) <= 0)
break;
(void)read(ifd, ibuf, BUF_LEN);
}
I should be able to just lseek(ifd, 0 SEEK_END);
> --
>
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.