[LTP] [PATCH v2] Refactor pidns30 test using new LTP API
Cyril Hrubis
chrubis@suse.cz
Mon Aug 15 17:07:41 CEST 2022
Hi!
> +static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LTP_ATTRIBUTE_UNUSED void *unused)
> {
> - char buf[256];
> - struct mq_attr attr;
> -
> - if (si->si_signo != SIGUSR1) {
> - printf("received signal = %d unexpectedly\n", si->si_signo);
> + if (si->si_signo != SIGUSR1 || si->si_code != SI_MESGQ || si->si_pid != 0)
> return;
> - }
>
> - if (si->si_code != SI_MESGQ) {
> - printf("expected signal code SI_MESGQ; got %d instead\n",
> - si->si_code);
> - return;
> - }
> -
> - if (si->si_pid) {
> - printf("expected signal originator PID = 0; got %d instead\n",
> - si->si_pid);
> - return;
> - } else {
> - printf("signal originator PID = 0\n");
> - result = TPASS;
> - }
> -
> - /*
> - * Now read the message - Be silent on errors since this is not the
> - * test purpose.
> - */
> - rc = mq_getattr(si->si_int, &attr);
> - if (rc != -1)
> - mq_receive(si->si_int, buf, attr.mq_msgsize, NULL);
> + received++;
I do not like that much that we lost most of the information about the
failure here. Can we store at least the si_signo and si_pid so that they
can be printed in the case of the failure?
> -int main(void)
> +static void run(void)
> {
> - int status;
> - char buf[5];
> - pid_t cpid;
> -
> - setup();
> -
> - if (pipe(child_to_father) == -1 || pipe(father_to_child) == -1) {
> - tst_brkm(TBROK | TERRNO, cleanup, "pipe failed");
> - }
> + int ret;
>
> - tst_syscall(__NR_mq_unlink, mqname);
> + remove_mqueue(mqd);
>
> - /* container creation on PID namespace */
> - cpid = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
> - if (cpid == -1)
> - tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
> + ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, NULL);
> + if (ret < 0)
> + tst_brk(TBROK | TERRNO, "clone failed");
>
> - mqd =
> - tst_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
> - NULL);
> + mqd = mq_open(MQNAME, O_RDWR | O_CREAT | O_EXCL, 0777, 0);
> if (mqd == -1)
> - tst_brkm(TBROK | TERRNO, cleanup, "mq_open failed");
> - else
> - tst_resm(TINFO, "successfully created posix mqueue");
> + tst_brk(TBROK | TERRNO, "mq_open failed");
We allready have SAFE_MQ_OPEN() I guess that we may add the rest of the
SAFE_MQ_* calls as well and use them here.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list