public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 4/4] syscalls/pidfd_send_signal03
Date: Wed, 12 Jun 2019 16:13:22 +0200	[thread overview]
Message-ID: <20190612141322.GB15090@x230> (raw)
In-Reply-To: <20190604114702.28255-3-camann@suse.com>

> Add testcase to check if the syscall will send a signal
> to a process with the same PID as the targeted process.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

LGTM, thanks for your patch!

> +++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
...
> +#define _GNU_SOURCE
I guess this is not needed.
> +
> +#include <signal.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include "pidfd_send_signal.h"
> +#include "tst_safe_pthread.h"
> +//#include "tst_safe_file_ops.h"
Reviewer should remove this comment.

> +
> +#define PIDTRIES	3
> +
> +static char *last_pid_file;
> +static int pidfd, new_pidfd;
> +static int old_inode, new_inode;
> +
> +static int get_inode_number(int fd)
> +{
> +	struct stat file_stat;
> +
> +	SAFE_FSTAT(fd, &file_stat);
> +	return file_stat.st_ino;
> +}
> +
> +static void verify_pidfd_send_signal(void)
> +{
> +	pid_t pid, new_pid;
> +	char pid_filename[32];
> +	char pid_str[16];
> +	int i, fail;
> +
> +	fail = 1;
> +	for (i = 0; i < PIDTRIES; i++) {
> +		pid = SAFE_FORK();
> +		if (pid == 0) {
> +			TST_CHECKPOINT_WAIT(0);
> +			return;
> +		}
> +
> +		sprintf(pid_filename, "/proc/%d", pid);
> +		pidfd = SAFE_OPEN(pid_filename, O_DIRECTORY | O_CLOEXEC);
> +		old_inode = get_inode_number(pidfd);
> +
> +		TST_CHECKPOINT_WAKE(0);
> +		tst_reap_children();
> +
> +		/* Manipulate PID for next process */
> +		sprintf(pid_str, "%d", pid - 1);
> +		SAFE_FILE_PRINTF(last_pid_file, pid_str);
> +
> +		new_pid = SAFE_FORK();
> +		if (new_pid == 0) {
> +			TST_CHECKPOINT_WAIT(0);
> +			return;
> +		}
> +
> +		if (new_pid == pid) {
> +			new_pidfd = SAFE_OPEN(pid_filename,
> +					O_DIRECTORY | O_CLOEXEC);
> +			new_inode = get_inode_number(new_pidfd);
> +			SAFE_CLOSE(new_pidfd);
> +			fail = 0;
> +			break;
> +		}
> +
> +		if (i < PIDTRIES) {
> +			tst_res(TINFO,
> +				"Failed to set correct PID, trying again...");
> +		}
> +		SAFE_CLOSE(pidfd);
> +		TST_CHECKPOINT_WAKE(0);
> +		tst_reap_children();
> +	}
> +	if (fail) {
> +		tst_brk(TBROK,
> +			"Could not set new child to same PID as the old one!");
> +	}
> +	if (old_inode == new_inode) {
> +		tst_res(TWARN,
> +			"File descriptor of new process points to the inode "
> +			"of the old process!");
I'd join this string on a single line. Also not sure if this is not TFAIL,
but probably not.

> +	}
> +
> +	TEST(pidfd_send_signal(pidfd, SIGUSR1, NULL, 0));
> +	if (TST_RET == -1 && TST_ERR == ESRCH) {
> +		tst_res(TPASS,
> +			"Did not send signal to wrong process with same PID!");
> +	} else {
> +		tst_res(TFAIL | TTERRNO,
> +			"pidf_send_signal() ended unexpectedly - return value: %ld, error",
> +			TST_RET);
> +	}
> +	TST_CHECKPOINT_WAKE(0);
> +	tst_reap_children();
> +
> +	SAFE_CLOSE(pidfd);
A bit repeating yourself, but not important.

Kind regards,
Petr

  reply	other threads:[~2019-06-12 14:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 11:47 [LTP] [PATCH v2 2/4] syscalls/pidfd_send_signal01 Christian Amann
2019-06-04 11:47 ` [LTP] [PATCH v2 3/4] syscalls/pidfd_send_signal02 Christian Amann
2019-06-12 13:54   ` Petr Vorel
2019-06-04 11:47 ` [LTP] [PATCH v2 4/4] syscalls/pidfd_send_signal03 Christian Amann
2019-06-12 14:13   ` Petr Vorel [this message]
2019-06-06 13:10 ` [LTP] [PATCH v2 2/4] syscalls/pidfd_send_signal01 Cyril Hrubis
2019-06-11 11:12   ` Christian Amann
2019-06-12 13:41 ` Petr Vorel

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=20190612141322.GB15090@x230 \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /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