[PATCH v7 4/4] tests: check status qualifier

Dmitry V. Levin ldv at altlinux.org
Mon Jul 8 12:16:49 UTC 2019


On Sat, Jul 06, 2019 at 09:20:15AM +0200, Paul Chaignon wrote:
> diff --git a/tests/status-none.c b/tests/status-none.c
> new file mode 100644
> index 00000000..226532c2
> --- /dev/null
> +++ b/tests/status-none.c
> @@ -0,0 +1,65 @@
> +/*
> + * Check status filtering when a non-leader thread invokes execve.
> + *
> + * Copyright (c) 2019 Paul Chaignon <paul.chaignon at gmail.com>
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "tests.h"
> +#include <asm/unistd.h>
> +#include <errno.h>
> +#include <pthread.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +static pid_t leader;
> +static pid_t tid;
> +
> +static pid_t
> +k_gettid(void)
> +{
> +	return syscall(__NR_gettid);
> +}
> +
> +static void *
> +thread(void *arg)
> +{
> +	tid = k_gettid();
> +
> +	struct timespec ts = { .tv_nsec = 100000000 };
> +	(void) clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
> +
> +	printf("%-5d +++ superseded by execve in pid %u +++\n",
> +	       leader, tid);
> +
> +	ts.tv_nsec = 12345;
> +	(void) nanosleep(&ts, NULL);
> +
> +	char *argv[] = {((char **) arg)[0], (char *) "0", NULL};
> +	execve(argv[0], argv, NULL);
> +	perror_msg_and_fail("execve");
> +}
> +
> +int
> +main(int ac, char **av)
> +{
> +	setvbuf(stdout, NULL, _IONBF, 0);
> +	leader = getpid();
> +
> +	if (ac > 1) {
> +		printf("%-5d +++ exited with 0 +++\n", leader);
> +		return 0;
> +	}
> +
> +	pthread_t t;
> +	errno = pthread_create(&t, NULL, thread, av);
> +	if (errno)
> +		perror_msg_and_fail("pthread_create");
> +
> +	struct timespec ts = { .tv_sec = 123 };
> +	(void) nanosleep(&ts, 0);
> +
> +	return 1;
> +}

btw, why do you need two different kinds of sleep in the child,
and why do you need two nanosleep invocations in the child at all?

This is -e status=none test, strace doesn't print any of these syscalls,
all you need is to let the parent enough time to fall into deep sleep
before invoking execve.

Similar question applies to status-unfinished.c test.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20190708/ea2ba797/attachment.bin>


More information about the Strace-devel mailing list