Skip to contentSkip to conversation

RFC: Inconsistent short read behaviour in __do_proc_dointvec vs _proc_do_string

DISCUSSION Earl Chew 1 participant 1 message Dec 21, 2011

lore
Share & tools
lore

Earl Chew

author
#0 lore raw

Should repeated short reads in __do_proc_dointvec behave consistently with _proc_do_string ?

Consider:

Quoted 11 lines
    char c[1];
    int n;

    while (1)
    {
        n = read(0, c, 1);

        if (n <= 0) break;

        write (1, c, 1);
    }

Running this program on /proc/self/stat emits the expected output.

Running this program on /proc/sys/kernel/random/poolsize does not :-(

The issue is that __do_proc_dointvec does not accommodate non-zero file positions when reading:

Quoted 4 lines
        if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
               *lenp = 0;
               return 0;
        }

OTOH _proc_do_string seems quite willing to accommodate it:

Quoted 11 lines
        if (write) {
           ...
        } else {
           len = strlen(data);
           if (len > maxlen)
                    len = maxlen;

           if (*ppos > len) {
                    *lenp = 0;
                    return 0;
           }

Should __do_proc_intvec behave more like _proc_do_string, or vice-versa ?

Earl