(root)/
strace-6.5/
tests-m32/
signalfd4.c
       1  /*
       2   * Check decoding of signalfd4 syscall.
       3   *
       4   * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2016-2023 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "scno.h"
      13  
      14  #if defined HAVE_SYS_SIGNALFD_H \
      15   && defined HAVE_SIGNALFD
      16  
      17  # include <signal.h>
      18  # include <stdio.h>
      19  # include <unistd.h>
      20  # include <sys/signalfd.h>
      21  # include "kernel_fcntl.h"
      22  
      23  # ifndef SKIP_IF_PROC_IS_UNAVAILABLE
      24  #  define SKIP_IF_PROC_IS_UNAVAILABLE
      25  # endif
      26  
      27  int
      28  main(void)
      29  {
      30  	SKIP_IF_PROC_IS_UNAVAILABLE;
      31  
      32  	const char *const sigs1 = "USR2";
      33  	const char *const sigs2 = SIGUSR2 < SIGCHLD ? "USR2 CHLD" : "CHLD USR2";
      34  	const unsigned int size = get_sigset_size();
      35  
      36  	sigset_t mask;
      37  	sigemptyset(&mask);
      38  	sigaddset(&mask, SIGUSR2);
      39  
      40  	int fd = signalfd(-1, &mask, SFD_CLOEXEC | SFD_NONBLOCK);
      41  
      42  # ifdef PRINT_SIGNALFD
      43  	if (fd == -1)
      44  		perror_msg_and_skip("signalfd");
      45  # endif
      46  
      47  	printf("signalfd4(-1, [%s], %u, SFD_CLOEXEC|SFD_NONBLOCK) = %s",
      48  	       sigs1, size, sprintrc(fd));
      49  # ifdef PRINT_SIGNALFD
      50  	printf("<signalfd:[%s]>\n", sigs1);
      51  # else
      52  	putchar('\n');
      53  # endif
      54  
      55  	sigaddset(&mask, SIGCHLD);
      56  	fd = signalfd(fd, &mask, 0);
      57  
      58  # ifdef PRINT_SIGNALFD
      59  	printf("signalfd4(%d<signalfd:[%s]>, [%s], %u, 0) = %s<signalfd:[%s]>\n",
      60  	       fd, sigs1, sigs2, size, sprintrc(fd), sigs2);
      61  # else
      62  	printf("signalfd4(%d, [%s], %u, 0) = %s\n", fd, sigs2, size, sprintrc(fd));
      63  # endif
      64  
      65  	puts("+++ exited with 0 +++");
      66  	return 0;
      67  }
      68  
      69  #else
      70  
      71  SKIP_MAIN_UNDEFINED("HAVE_SYS_SIGNALFD_H && HAVE_SIGNALFD")
      72  
      73  #endif