From: chrubis@suse.cz
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH v2] new testcase: kmsg01
Date: Mon, 24 Jun 2013 15:22:49 +0200 [thread overview]
Message-ID: <20130624132249.GC1638@rei> (raw)
In-Reply-To: <016bca5a3f28e308234e5b1028a831e5fa50fda6.1371736603.git.jstancek@redhat.com>
Hi!
> +static int timed_read_kmsg(int fd, int timeout_sec)
> +{
> + int child, status, ret = 0;
> + int pipefd[2];
> + char msg[MAX_MSGSIZE];
> +
> + if (pipe(pipefd) != 0)
> + tst_brkm(TBROK|TERRNO, cleanup, "pipe failed");
> +
> + child = fork();
> + switch (child) {
> + case -1:
> + tst_brkm(TBROK|TERRNO, cleanup, "failed to fork");
> + case 0:
> + /* child does all the reading and keeps writing to
> + * pipe to let parent know that it didn't block */
> + SAFE_CLOSE(NULL, pipefd[0]);
There is a problem with calling the SAFE_ macros from child processes.
The SAFE_ macros use tst_brkm() interface to halt program execution (in
case of failure) which is not supposed to be used from child and may
lead to unexpected results.
> +static void test_seek(void)
> +{
> + int k, j = NUM_READ_RETRY, fd;
> + char msg[MAX_MSGSIZE];
> + unsigned long seqno[2];
> +
> + /* 1. read() after SEEK_SET 0 returns same (first) message */
> + tst_resm(TINFO, "TEST: seek SEEK_SET 0");
> +
> + fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
> + if (fd < 0)
> + tst_brkm(TBROK|TERRNO, cleanup, "failed to open /dev/kmsg");
> +
> + while (j) {
> + for (k = 0; k < 2; k++) {
> + TEST(read(fd, msg, sizeof(msg)));
> + if (TEST_RETURN == -1) {
> + if (errno == EPIPE)
> + break;
> + else
> + tst_brkm(TBROK|TTERRNO, cleanup,
> + "failed to read /dev/kmsg");
> + }
> + if (get_msg_fields(msg, NULL, &seqno[k]) != 0)
> + tst_resm(TFAIL, "failed to parse seqid: %s",
> + msg);
> + if (k == 0)
> + if (lseek(fd, 0, SEEK_SET) == -1)
> + tst_resm(TFAIL|TERRNO,
> + "SEEK_SET 0 failed");
> + }
> +
> + if (TEST_RETURN != -1)
> + break;
> +
> + /* give a second to whoever overwrote first message to finish */
> + sleep(1);
> + j--;
> +
> + /* read returned EPIPE, reopen fd and try again */
> + SAFE_CLOSE(cleanup, fd);
> + fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
> + if (fd < 0)
> + tst_brkm(TBROK|TERRNO, cleanup,
> + "failed to open /dev/kmsg");
I guess that the comment says something different than the code, there
is no read involved here.
Acked with change from SAFE_CLOSE() to close() in the child process.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2013-06-24 13:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-20 14:12 [LTP] [PATCH v2] new testcase: kmsg01 Jan Stancek
2013-06-22 18:17 ` Mike Frysinger
2013-06-24 13:22 ` chrubis [this message]
[not found] ` <2114792229.1514957.1372081597213.JavaMail.root@redhat.com>
2013-06-24 13:54 ` chrubis
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=20130624132249.GC1638@rei \
--to=chrubis@suse.cz \
--cc=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.