[LTP] [PATCH v2 4/4] syscalls/pidfd_send_signal03
Petr Vorel
pvorel@suse.cz
Wed Jun 12 16:13:22 CEST 2019
> 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
More information about the ltp
mailing list