This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

with-open-file problem of sbcl

13 posts · 11256 views

(with-open-file (in  #P"/sys/class/net/eth0/statistics/rx_bytes" :direction :input)
  (read in))
This code can work with clisp but sbcl fail.

I copy file sys/class/net/eth0/statistics/rx_bytes to my home folder, and with-open-file works.

I don't know why? Is this sbcl's bug?

Re: with-open-file problem of sbcl

Hmm... good question. When I try it, SBCL just hangs. I can interrupt it with C-c in a term window, but it never returns. A simple "cat /sys/class/net/eth0/statistics/rx_bytes" works just fine. This is with SBCL 1.0.17 on Fedora 8 (2.6.25.11 kernel).
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: with-open-file problem of sbcl

findinglisp wrote:Hmm... good question. When I try it, SBCL just hangs. I can interrupt it with C-c in a term window, but it never returns. A simple "cat /sys/class/net/eth0/statistics/rx_bytes" works just fine. This is with SBCL 1.0.17 on Fedora 8 (2.6.25.11 kernel).
SBCL 1.0.18 1.0.19 on Debian sid (2.6.26-1-686) suck too.

Re: with-open-file problem of sbcl

I would post it to the SBCL developer's mailing list and see what they have to say.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Re: with-open-file problem of sbcl

A simpler test case:
(let
    ((f (open #P"/sys/class/net/eth0/statistics/rx_bytes" :direction :input)))
  (read-char f))
This hangs for me, which shows that the bug isn't tied specifically to (with-open-file) or (read).

Re: with-open-file problem of sbcl

findinglisp wrote:I would post it to the SBCL developer's mailing list and see what they have to say.
Have you posted it to sbcl mailing list. I haven't see at gmane.lisp.steel-bank.devel.

Re: with-open-file problem of sbcl

Does it happen with other weird 'virtual' mounted files - i.e. in /dev, /proc?

Re: with-open-file problem of sbcl

Exolon wrote:Does it happen with other weird 'virtual' mounted files - i.e. in /dev, /proc?
I test"/proc/stat" for read read-line with sbcl 1.0.20, it works.

"/sys/class/net/eth0/statistics/rx_bytes" still hang. :?

Re: with-open-file problem of sbcl

I think this is a bug, and a known issue for the sbcl people. In fact, I have a recollection of reading something about this and sbcl-devel a few months ago. I have searched throught the archives and found this,

http://sourceforge.net/mailarchive/mess ... hacker.com

So maybe snoop around that thread.

If you really need to access that data, you might go through the shell. Using trivial shell, something like this would work:
(read-from-string
   (trivial-shell:shell-command
      "cat /sys/class/net/eth0/statistics/rx_bytes" ))
But, really this is a kludge at best.


Zach

Re: with-open-file problem of sbcl

Thank you very very much!
smithzv wrote:I think this is a bug, and a known issue for the sbcl people. In fact, I have a recollection of reading something about this and sbcl-devel a few months ago. I have searched throught the archives and found this,

http://sourceforge.net/mailarchive/mess ... hacker.com

So maybe snoop around that thread.

If you really need to access that data, you might go through the shell. Using trivial shell, something like this would work:
(read-from-string
   (trivial-shell:shell-command
      "cat /sys/class/net/eth0/statistics/rx_bytes" ))
But, really this is a kludge at best.


Zach

Re: with-open-file problem of sbcl

deftsp wrote:
findinglisp wrote:I would post it to the SBCL developer's mailing list and see what they have to say.
Have you posted it to sbcl mailing list. I haven't see at gmane.lisp.steel-bank.devel.
deftsp: findinglisp meant "If I were you I would post...", i.e. he meant that you should post to the SBCL developers' mailing list.

Re: with-open-file problem of sbcl

While the code below is undoubtedly an ugly vile hack, this is what I came up with on the spur of the moment. One things that makes me a bit unhappy aside from the fixed length buffer and the sloppy error handling* is that I'm not completely comfortable with read in this context. I'm not sure it's a great idea to assume that any of the file contents parse nicely as lisp data.
(defun read-from-kernel-pseudo-file (file-name
                                     &optional (max-read 256))
  (with-open-file (in file-name)
    (let ((buf (make-array max-read
                           :element-type '(unsigned-byte 8))))
      (let ((actual (sb-unix:unix-read (sb-sys:fd-stream-fd in)
                                       (sb-sys:vector-sap buf)
                                       max-read)))
        (if (null actual)
            (error "Bad Unix read()")
            (read-from-string
              (sb-ext:octets-to-string (subseq buf 0 actual))))))))
* Remedy left as an exercise for the reader.

Re: with-open-file problem of sbcl

Wodin wrote:
deftsp wrote:
findinglisp wrote:I would post it to the SBCL developer's mailing list and see what they have to say.
Have you posted it to sbcl mailing list. I haven't see at gmane.lisp.steel-bank.devel.
deftsp: findinglisp meant "If I were you I would post...", i.e. he meant that you should post to the SBCL developers' mailing list.
Oh,sorry. That's my fault.