[LTP] [PATCH v3 2/5] syscalls/clone03: Convert to new API
Richard Palethorpe
rpalethorpe@suse.de
Fri Sep 24 11:19:40 CEST 2021
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.
More information about the ltp
mailing list