procfs-problem with linux 2.4.24

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I have a problem regarding a procfs entry.

I created one and added a read_func. If I do a
"cat /proc/.../my_entry", debug-printk's show me, that my read function is
called 3 times. It returns 21,19 and 21 bytes.

A "strace cat /proc/.../my_entry" has the following output

...
open("/proc/.../my_entry")		= 3
...
read(3,"21 bytes output ...",4096)	= 21
write(1,"21 bytes output ...")		= 21
read(3,"",4096)				= 0
...
close(3)


I have no clue what happens. My module shows me 3 calls of the read function,
but strace shows only 2 (and a return value which is never returned from the
read function). Can anyone explain me what happens here?

The read function 

int read_alarm (char *page, char** start, off_t off, int count, int *eof, void *data) {

        int diff, ret = 0, len = 0;
        unsigned long flags;
        MOD_INC_USE_COUNT;

        struct netshaper *ns = (struct netshaper*) data;
        printk("read_alarm: sem_getcount(1) == %d\n",sem_getcount(&ns->sema_buffer_read));
        if (down_interruptible(&ns->sema_buffer_read) == -EINTR) {
                printk("read_alarm interrupted\n");
                ret = 0;
                *eof=1; /* no more data */
                goto out;
        }

        /* operations on the alarm_buffer */
        spin_lock_irqsave(ns->alarm_buffer_lock,flags);


        char* s = &ns->alarm_buffer[ns->read_index*ALARM_SIZE];
	if (strlen(s) > count) {
		len = count;
	else {
		len = strlen(s);
	}

        /* write out ns->alarm_buffer[ns->read_index*ALARM_SIZE] */
        ret = snprintf(page+off,len,"%s",s);
        ns->read_index = (ns->read_index+1) % ALARM_BUFFER_LINES;
        diff = ns->write_index - ns->read_index;
        printk("read_alarm: sem_getcount(2) == %d\n", sem_getcount(&ns->sema_buffer_read));
        printk("read_alarm: read_index_new = %d\n",ns->read_index);

        spin_unlock_irqrestore(ns->alarm_buffer_lock,flags);

        /* check if there are more elements in the buffer */
        printk("read_alarm: diff = %d\n",diff);
        if (diff != 0) {
                /* still some left  */
                printk ("read_alarm: up(&ns->sema_buffer_read)\n");
                up(&ns->sema_buffer_read);
        }
        *eof=0;
out:
        printk("read_alarm: ret = %d\n",ret);
        MOD_DEC_USE_COUNT;
        return ret;
}


Jörg

-- 
 Da fehlt aber noch die Fehlerbehandlung. Wenn wir die jetzt einbauen,
 wird es richtig häßlich. Deshalb ist die Standardfehlerbehandlung in C
 meistens der Segmentation Fault."  -- Christian Becker 

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux