On Tue, Sep 22, 2009 at 03:49:40PM +0200, Corin wrote:
> The 'read' command seems to only read the first character and not the whole 
> line.
> 
> Example / comparison with bash:
> 
> # /bin/dash
> # read MAX </proc/sys/net/netfilter/nf_conntrack_max
> # echo $MAX
> 2
> 
> # /bin/bash
> # read MAX </proc/sys/net/netfilter/nf_conntrack_max
> # echo $MAX
> 262144

Hi, this doesn't look like a bug in dash, but in the kernel's
implementation of the /proc/sys/net/ hierarchy.  If you copy the file to
/tmp/, it works just fine.

cat <<EOT >t.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char **argv) {
        char c;
        int fd = open(argv[1], O_RDONLY);
        if (fd == -1) return 1;
        for (;;) {
                int i = read(fd, &c, 1);
                if (i == 0) break;
                if (i == -1) return 2;
                if (write(1, &c, 1) == -1) return 3;
        }
        write(1, "\n", 1);
        return 0;
}
EOT
gcc t.c
./a.out /proc/sys/net/unix/max_dgram_qlen
cat /proc/sys/net/unix/max_dgram_qlen
cp /proc/sys/net/unix/max_dgram_qlen /tmp/
./a.out /tmp/max_dgram_qlen

Regards, Gerrit.



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to