From: Kang Kai <Kai.Kang@windriver.com>
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net,
Zhenfeng Zhao <Zhenfeng.Zhao@windriver.com>
Subject: Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
Date: Tue, 4 Sep 2012 17:44:08 +0800 [thread overview]
Message-ID: <5045CD68.6050303@windriver.com> (raw)
In-Reply-To: <1083211279.14961355.1346740544417.JavaMail.root@redhat.com>
On 2012年09月04日 14:35, Jan Stancek wrote:
>
> ----- Original Message -----
>> From: "Kang Kai"<Kai.Kang@windriver.com>
>> To: "Kang Kai"<kai.kang@windriver.com>
>> Cc: ltp-list@lists.sourceforge.net, "Zhenfeng Zhao"<Zhenfeng.Zhao@windriver.com>
>> Sent: Monday, 3 September, 2012 10:45:58 AM
>> Subject: Re: [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info
>>
>> On 2012年08月09日 18:30, Kang Kai wrote:
>>
>> Hi Wanlong,
>>
>>> In this test case, it uses a variable to share data between child
>>> and
>>> parent processes. But after fork there is a copy of the variable in
>>> child process and modify it will not affect the variable in the
>>> parent
>>> process. Then when the child process call mq_open() before parent
>>> process,
>>> the case will fail.
>>>
>>> Use tmp file to replace the variable. Any modification in child
>>> process
>>> can be seen in parent process.
>> Any comment for this patch?
> I had one question, see here:
> http://article.gmane.org/gmane.linux.ltp/16611
>
> Regards,
> Jan
>
>> Thanks,
>> Kai
>>
>>> Signed-off-by: Kang Kai<kai.kang@windriver.com>
>>> ---
>>> .../conformance/interfaces/mq_open/16-1.c | 38
>>> +++++++++++++++++--
>>> 1 files changed, 34 insertions(+), 4 deletions(-)
>>>
>>> diff --git
>>> a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>>> b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>>> index b9a3215..ebd697b 100644
>>> ---
>>> a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>>> +++
>>> b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
>>> @@ -20,9 +20,11 @@
>>> * this is fine (will have some false positives, but no false
>>> negatives).
>>> */
>>>
>>> +#include<sys/mman.h>
>>> #include<sys/stat.h>
>>> #include<sys/types.h>
>>> #include<sys/wait.h>
>>> +#include<errno.h>
>>> #include<fcntl.h>
>>> #include<mqueue.h>
>>> #include<signal.h>
>>> @@ -32,11 +34,15 @@
>>> #include "posixtest.h"
>>>
>>> #define NAMESIZE 50
>>> +#define TNAME "mq_open/16-1.c"
>>>
>>> int main()
>>> {
>>> char qname[NAMESIZE];
>>> + char fname[NAMESIZE];
>>> int pid, succeeded=0;
>>> + int fd;
>>> + void *pa = NULL;
>>> mqd_t childqueue, queue;
>>>
>>> /*
>>> @@ -47,6 +53,26 @@ int main()
>>>
>>> sprintf(qname, "/mq_open_16-1_%d", getpid());
>>>
>>> + sprintf(fname, "/tmp/pts_mq_open_16_1_%d", getpid());
>>> + unlink(fname);
>>> + fd = open(fname, O_CREAT | O_RDWR | O_EXCL,
>>> + S_IRUSR | S_IWUSR);
>>> + if (fd == -1) {
>>> + printf(TNAME " Error at open(): %s\n", strerror(errno));
>>> + exit(PTS_UNRESOLVED);
>>> + }
Hi Jan,
Copy your comment here
>>> + /* file is empty now, will cause "Bus error" */
>>> + write(fd, "\0", 1);
| Isn't there a risk of SIGBUS, when the file length is just 1 byte
| and it's mapped to sizeof(int)?
|
| SIGBUS Attempted access to a portion of the buffer that does not correspond to the file (for example, beyond
| the end of the file, including the case where another process has truncated the file).
I think why it doen't fail:
mmap implemented on linux willl map one page size if length pass to mmap less than one page size. So we can use the memory in this one page size.
But empty file is special case cause SIGBUS.
>>> + unlink(fname);
>>> +
>>> + pa = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED,
>>> fd, 0);
>>> + if (pa == MAP_FAILED) {
>>> + printf(TNAME " Error at mmap: %s\n", strerror(errno));
>>> + close(fd);
>>> + exit(PTS_FAIL);
>>> + }
I add test code here:
>>> + *(int *)pa = 0;
>>> +
int *pi = (int *)pa;
++pi;
*pi = 4;
It still doesn't fail.
So that may implement dependent. I will update the patch to write a int
to the file.
Regards,
Kai
>>> if ((pid = fork()) == 0) {
>>> sigset_t mask;
>>> int sig;
>>> @@ -62,7 +88,7 @@ int main()
>>> childqueue = mq_open(qname, O_CREAT|O_EXCL|O_RDWR,
>>> S_IRUSR | S_IWUSR, NULL);
>>> if (childqueue != (mqd_t)-1) {
>>> - succeeded++;
>>> + ++*(int *)pa;
>>> #ifdef DEBUG
>>> printf("mq_open() in child succeeded\n");
>>> } else {
>>> @@ -79,7 +105,7 @@ int main()
>>> queue = mq_open(qname, O_CREAT | O_EXCL |O_RDWR,
>>> S_IRUSR | S_IWUSR, NULL);
>>> if (queue != (mqd_t)-1) {
>>> - succeeded++;
>>> + ++*(int *)pa;
>>> #ifdef DEBUG
>>> printf("mq_open() in parent succeeded\n");
>>> } else {
>>> @@ -93,13 +119,15 @@ int main()
>>> mq_close(queue);
>>> mq_close(childqueue);
>>> mq_unlink(qname);
>>> + close(fd);
>>> + munmap(pa, sizeof(int));
>>> return PTS_UNRESOLVED;
>>> }
>>>
>>> mq_close(queue);
>>> mq_close(childqueue);
>>> mq_unlink(qname);
>>> -
>>> + succeeded = *(int *)pa;
>>> if (succeeded==0) {
>>> printf("Test FAILED - mq_open() never succeeded\n");
>>> return PTS_FAIL;
>>> @@ -111,8 +139,10 @@ int main()
>>> }
>>>
>>> printf("Test PASSED\n");
>>> + close(fd);
>>> + munmap(pa, sizeof(int));
>>> return PTS_PASS;
>>> }
>>>
>>> return PTS_UNRESOLVED;
>>> -}
>>> \ No newline at end of file
>>> +}
>>
>> ------------------------------------------------------------------------------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond.
>> Discussions
>> will include endpoint security, mobile security and the latest in
>> malware
>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> Ltp-list mailing list
>> Ltp-list@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/ltp-list
>>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2012-09-04 9:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-09 10:30 [LTP] Patches for posix test cases Kang Kai
2012-08-09 10:30 ` [LTP] [PATCH 1/3] pthread_cond_signal/1-1: use sched_yield to sync threads Kang Kai
2012-08-10 10:22 ` Jan Stancek
2012-08-13 2:50 ` Kang Kai
2012-08-23 1:57 ` Wanlong Gao
2012-08-09 10:30 ` [LTP] [PATCH 2/3] mq_open/16-1: use tmp file to share info Kang Kai
2012-08-10 9:31 ` Jan Stancek
2012-09-03 8:45 ` Kang Kai
2012-09-04 6:35 ` Jan Stancek
2012-09-04 9:44 ` Kang Kai [this message]
2012-09-04 5:33 ` Wanlong Gao
2012-09-04 7:40 ` Kang Kai
2012-09-04 8:27 ` Kang Kai
2012-09-04 8:41 ` Wanlong Gao
2012-09-04 8:45 ` Kang Kai
2012-08-09 10:30 ` [LTP] [PATCH 3/3] timer_settime/5-3: fix test hung Kang Kai
2012-08-10 9:16 ` Jan Stancek
2012-08-21 4:01 ` Wanlong Gao
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=5045CD68.6050303@windriver.com \
--to=kai.kang@windriver.com \
--cc=Zhenfeng.Zhao@windriver.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox