From: Karel Zak <kzak@redhat.com>
To: Austen Dicken <cvpcsm@gmail.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 1/1] dmesg: adds the ability to "follow" the klog ring buffer
Date: Tue, 3 May 2011 14:53:22 +0200 [thread overview]
Message-ID: <20110503125322.GK29492@nb.net.home> (raw)
In-Reply-To: <BANLkTin=y5oaEU0913dOnjWhosiyXe3Zwg@mail.gmail.com>
On Fri, Apr 29, 2011 at 11:42:00AM -0500, Austen Dicken wrote:
> adds the "-f" option to dmesg, which allows an underpriviledged
> user to "follow" the kernel ring buffer, outputting new messages as they
I like the "follow the kernel ring buffer" idea, but ...
> appear. this is done non-destructively so that the current buffer remains
> after execution.
>
> this also changes the log output to be by-line instead of by-character,
> and saves the last line printed on each read of the buffer. if looping,
> it will then read the buffer again, but not output until it finds the last
> line that it printed.
... this seems like a problem to me.
[...]
> - for (i = 0; i < n; i++) {
> - if (!raw && (i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
> - i++;
> - while (isdigit(buf[i]))
> - i++;
> - if (buf[i] == '>')
> + this_line = xmalloc(n * sizeof(char));
> + for (i = 0, j = 0; i < n; i++) {
> + if (!raw && (i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
> i++;
> + while (isdigit(buf[i]))
> + i++;
> + if (buf[i] == '>')
> + i++;
> + }
> + this_line[j] = buf[i];
> +
> + if (this_line[j] == '\n') {
> + this_line[j] = '\0';
> + if (last_line) {
> + if (!strcmp(last_line, this_line)) {
> + free(last_line);
> + last_line = NULL;
> + }
> + } else
> + printf("%s\n", this_line);
It expects that the kernel log does not contain duplicate messages.
Is it correct? I don't think so, I see:
ata1.00: configured for UDMA/100
ata1.00: configured for UDMA/100
You have to compile kernel with CONFIG_PRINTK_TIME, otherwise your
heuristic will not work properly.
> + usleep(200);
> +
> + } while (follow_loop);
Hmm... sleep() in code usually means a poor design or API.
What about to support -f (follow) for privileged users only?
Then you can use klogctl(2, ...). It waits until the kernel log buffer
is non-empty, so the last_line and usleep() will be unnecessary, and
the implementation will be pretty simple.
> + if (prev_sighandler)
> + signal(SIGINT, prev_sighandler);
> + else
> + signal(SIGINT, SIG_DFL);
Why do you need to restore the handler before return (exit)? It seems
unnecessary.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2011-05-03 12:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-29 16:42 [PATCH 1/1] dmesg: adds the ability to "follow" the klog ring buffer Austen Dicken
2011-05-03 12:53 ` Karel Zak [this message]
2011-05-03 14:14 ` Austen Dicken
2011-05-04 12:43 ` Karel Zak
2011-05-20 14:20 ` Austen Dicken
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=20110503125322.GK29492@nb.net.home \
--to=kzak@redhat.com \
--cc=cvpcsm@gmail.com \
--cc=util-linux@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