mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Herbert Rosmanith <kernel@wildsau.enemy.org>
To: linux-kernel@vger.kernel.org
Cc: Herbert Rosmanith <kernel@wildsau.enemy.org>
Subject: procfs uglyness caused by "cat"
Date: Tue, 14 Mar 2006 11:43:46 +0100 (MET)	[thread overview]
Message-ID: <200603141043.k2EAhlTV016354@wildsau.enemy.org> (raw)


hello list,

when doing "cat /proc/uptime" or similar files, the
routine which prepares the buffer gets called twice.

this is because "cat" reads two times from the file,
as a system-call-trace shows:

    # strace -f cat /proc/uptime
    ...
    read(3, "5241.09 5082.74\n", 1024)      = 16
    ...
    read(3, "", 1024)                       = 0
    ...

this leads to uptime_read_proc() being called two times,
the second time with parameter off=16, but since this
is ignored, the work is done twice: clock_...gettime(),
cputime_to_timespec(), sprintf(), proc_calc_metrics()
and so on.

insert a printk-statement if you don't beleive this.

btw, there's no wrong information produced because of this,
because *page points to the same location both calls.

a simple way to get rid of this:

static int uptime_read_proc(char *page, char **start, off_t off,
                                 int count, int *eof, void *data)
{
        struct timespec uptime;
        struct timespec idle;
        int len;
        cputime_t idletime;

+	if (off)
+		return 0;

        cputime_add(init_task.utime, init_task.stime);
        do_posix_clock_monotonic_gettime(&uptime);
        cputime_to_timespec(idletime, &idle);
        len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
...
and so on.

this affects possibly all /proc files which ignore the offset parameter
and are evaluated(?) with "cat".

regards,
h.rosmanith



             reply	other threads:[~2006-03-14 10:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-14 10:43 Herbert Rosmanith [this message]
2006-03-14 15:57 ` Paul Jackson
     [not found] <5Qfgo-3At-15@gated-at.bofh.it>
2006-03-14 14:35 ` Robert Hancock
2006-03-14 15:33   ` Paul Rolland
2006-03-14 17:59     ` Paul Jackson
2006-03-14 18:45       ` Paul Rolland
2006-03-15  8:06   ` Herbert Rosmanith
2006-03-15  8:23   ` Herbert Rosmanith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200603141043.k2EAhlTV016354@wildsau.enemy.org \
    --to=kernel@wildsau.enemy.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®