(root)/
strace-6.5/
tests/
netlink_audit.c
       1  /*
       2   * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
       3   * Copyright (c) 2017-2021 The strace developers.
       4   * All rights reserved.
       5   *
       6   * SPDX-License-Identifier: GPL-2.0-or-later
       7   */
       8  
       9  #include "tests.h"
      10  #include "pidns.h"
      11  #include <stdio.h>
      12  #include <string.h>
      13  #include <unistd.h>
      14  #include <sys/socket.h>
      15  #include <linux/audit.h>
      16  #include "netlink.h"
      17  
      18  static void
      19  test_nlmsg_type(const int fd)
      20  {
      21  	PIDNS_TEST_INIT;
      22  
      23  	long rc;
      24  	struct nlmsghdr nlh = {
      25  		.nlmsg_len = sizeof(nlh),
      26  		.nlmsg_type = AUDIT_GET,
      27  		.nlmsg_flags = NLM_F_REQUEST,
      28  		.nlmsg_pid = getpid(),
      29  	};
      30  
      31  	rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
      32  	pidns_print_leader();
      33  	printf("sendto(%d, {nlmsg_len=%u, nlmsg_type=AUDIT_GET"
      34  	       ", nlmsg_flags=NLM_F_REQUEST, nlmsg_seq=0, nlmsg_pid=%d%s}"
      35  	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
      36  	       fd, nlh.nlmsg_len, nlh.nlmsg_pid, pidns_pid2str(PT_TGID),
      37  	       (unsigned) sizeof(nlh), sprintrc(rc));
      38  }
      39  
      40  int main(void)
      41  {
      42  	skip_if_unavailable("/proc/self/fd/");
      43  
      44  	int fd = create_nl_socket(NETLINK_AUDIT);
      45  
      46  	test_nlmsg_type(fd);
      47  
      48  	pidns_print_leader();
      49  	printf("+++ exited with 0 +++\n");
      50  
      51  	return 0;
      52  }