From: Richard Palethorpe <rpalethorpe@suse.de>
To: zhanglianjie <zhanglianjie@uniontech.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 2/5] syscalls/clone03: Convert to new API
Date: Fri, 24 Sep 2021 10:19:40 +0100 [thread overview]
Message-ID: <87bl4il49f.fsf@suse.de> (raw)
In-Reply-To: <20210923085224.868-2-zhanglianjie@uniontech.com>
Hello,
This is a big improvement. However there are some things from the old
test which can be improved.
> +static void verify_clone(void)
> +{
> + int child_pid;
>
> - /* Close read end from parent */
> - if ((close(pfd[0])) == -1)
> - tst_resm(TWARN | TERRNO, "close(pfd[0]) failed");
> + TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, child_fn, NULL, CHILD_STACK_SIZE,
> + child_stack));
tst_clone is the new API.
>
> - /* Get child's pid from pid string */
> - child_pid = atoi(buff);
> + if (!TST_PASS)
> + return;
>
> - if (TEST_RETURN == child_pid)
> - tst_resm(TPASS, "Test passed");
> - else
> - tst_resm(TFAIL, "Test failed");
> + tst_reap_children();
>
> - if ((wait(&status)) == -1)
> - tst_brkm(TBROK | TERRNO, cleanup,
> - "wait failed, status: %d", status);
> - }
> + child_pid = atoi(channel);
atoi is deprecated (see the man page).
>
> - free(child_stack);
> -
> - cleanup();
> - tst_exit();
> + TST_EXP_PASS(!(TST_RET == child_pid), "pid(%d)", child_pid);
> }
>
> static void setup(void)
> {
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> - TEST_PAUSE;
> + child_stack = SAFE_MALLOC(CHILD_STACK_SIZE);
> + channel = SAFE_MMAP(NULL, 10, PROT_READ | PROT_WRITE,
> + MAP_SHARED | MAP_ANONYMOUS, -1, 0);
You could mmap a region needed for pid_t and just read and write it like
a normal variable.
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2021-09-24 9:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-23 8:52 [LTP] [PATCH v3 1/5] syscalls/clone02: Convert to new API zhanglianjie
2021-09-23 8:52 ` [LTP] [PATCH v3 2/5] syscalls/clone03: " zhanglianjie
2021-09-24 9:19 ` Richard Palethorpe [this message]
2021-10-11 15:02 ` Cyril Hrubis
2021-09-23 8:52 ` [LTP] [PATCH v3 3/5] syscalls/clone05: " zhanglianjie
2021-10-11 15:59 ` Cyril Hrubis
2021-09-23 8:52 ` [LTP] [PATCH v3 4/5] syscalls/clone06: " zhanglianjie
2021-10-12 9:21 ` Cyril Hrubis
2021-10-13 2:49 ` zhanglianjie
2021-09-23 8:52 ` [LTP] [PATCH v3 5/5] syscalls/clone07: " zhanglianjie
2021-10-12 9:37 ` Cyril Hrubis
2021-10-13 5:14 ` zhanglianjie
2021-10-13 10:00 ` Cyril Hrubis
2021-10-11 15:40 ` [LTP] [PATCH v3 1/5] syscalls/clone02: " Cyril Hrubis
2021-10-12 6:39 ` zhanglianjie
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=87bl4il49f.fsf@suse.de \
--to=rpalethorpe@suse.de \
--cc=ltp@lists.linux.it \
--cc=zhanglianjie@uniontech.com \
/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