* lseek on /proc/kmsg
@ 2005-03-22 18:23 linux-os
2005-03-22 19:25 ` Jan Engelhardt
0 siblings, 1 reply; 10+ messages in thread
From: linux-os @ 2005-03-22 18:23 UTC (permalink / raw)
To: Linux kernel
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
2005-03-22 18:23 lseek on /proc/kmsg linux-os
@ 2005-03-22 19:25 ` Jan Engelhardt
2005-03-22 19:26 ` linux-os
0 siblings, 1 reply; 10+ messages in thread
From: Jan Engelhardt @ 2005-03-22 19:25 UTC (permalink / raw)
To: linux-os; +Cc: Linux kernel
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
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
2005-03-22 19:25 ` Jan Engelhardt
@ 2005-03-22 19:26 ` linux-os
2005-03-22 21:21 ` Jan Engelhardt
0 siblings, 1 reply; 10+ messages in thread
From: linux-os @ 2005-03-22 19:26 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Linux kernel
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
2005-03-22 19:26 ` linux-os
@ 2005-03-22 21:21 ` Jan Engelhardt
2005-03-22 21:39 ` linux-os
0 siblings, 1 reply; 10+ messages in thread
From: Jan Engelhardt @ 2005-03-22 21:21 UTC (permalink / raw)
To: linux-os; +Cc: Linux kernel
> 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
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
2005-03-22 21:21 ` Jan Engelhardt
@ 2005-03-22 21:39 ` linux-os
2005-03-23 7:13 ` Jan Engelhardt
0 siblings, 1 reply; 10+ messages in thread
From: linux-os @ 2005-03-22 21:39 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Linux kernel
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
[not found] ` <3KXou-8ft-3@gated-at.bofh.it>
@ 2005-03-22 23:57 ` Robert Hancock
0 siblings, 0 replies; 10+ messages in thread
From: Robert Hancock @ 2005-03-22 23:57 UTC (permalink / raw)
To: linux-kernel
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 hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
[not found] ` <fa.j3anmof.1b06cjp@ifi.uio.no>
@ 2005-03-23 2:22 ` Bodo Eggert
0 siblings, 0 replies; 10+ messages in thread
From: Bodo Eggert @ 2005-03-23 2:22 UTC (permalink / raw)
To: Jan Engelhardt, linux-os, Linux kernel
Jan Engelhardt <jengelh@linux01.gwdg.de> 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?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
2005-03-22 21:39 ` linux-os
@ 2005-03-23 7:13 ` Jan Engelhardt
2005-03-23 10:25 ` H. Peter Anvin
2005-03-23 12:11 ` linux-os
0 siblings, 2 replies; 10+ messages in thread
From: Jan Engelhardt @ 2005-03-23 7:13 UTC (permalink / raw)
To: linux-os; +Cc: Linux kernel
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
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
2005-03-23 7:13 ` Jan Engelhardt
@ 2005-03-23 10:25 ` H. Peter Anvin
2005-03-23 12:11 ` linux-os
1 sibling, 0 replies; 10+ messages in thread
From: H. Peter Anvin @ 2005-03-23 10:25 UTC (permalink / raw)
To: linux-kernel
Followup to: <Pine.LNX.4.61.0503230811020.21578@yvahk01.tjqt.qr>
By author: Jan Engelhardt <jengelh@linux01.gwdg.de>
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: lseek on /proc/kmsg
2005-03-23 7:13 ` Jan Engelhardt
2005-03-23 10:25 ` H. Peter Anvin
@ 2005-03-23 12:11 ` linux-os
1 sibling, 0 replies; 10+ messages in thread
From: linux-os @ 2005-03-23 12:11 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Linux kernel
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2005-03-23 12:16 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-22 18:23 lseek on /proc/kmsg linux-os
2005-03-22 19:25 ` Jan Engelhardt
2005-03-22 19:26 ` linux-os
2005-03-22 21:21 ` Jan Engelhardt
2005-03-22 21:39 ` linux-os
2005-03-23 7:13 ` Jan Engelhardt
2005-03-23 10:25 ` H. Peter Anvin
2005-03-23 12:11 ` linux-os
[not found] <3KWsu-7dO-13@gated-at.bofh.it>
[not found] ` <3KXeQ-83A-7@gated-at.bofh.it>
[not found] ` <3KXou-8ft-3@gated-at.bofh.it>
2005-03-22 23:57 ` Robert Hancock
[not found] <fa.k09kbma.1kkmjhe@ifi.uio.no>
[not found] ` <fa.j3anmof.1b06cjp@ifi.uio.no>
2005-03-23 2:22 ` Bodo Eggert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox