public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] repo/proj/guru:master commit in: app-misc/corectrl/, app-misc/corectrl/files/
@ 2023-11-01 23:27 Haelwenn Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Haelwenn Monnier @ 2023-11-01 23:27 UTC (permalink / raw
  To: gentoo-commits

commit:     b54461e3cb53392165e06d2f84835bc853e7e5a6
Author:     Kostadin Shishmanov <kocelfc <AT> tutanota <DOT> com>
AuthorDate: Wed Nov  1 16:20:17 2023 +0000
Commit:     Haelwenn Monnier <contact <AT> hacktivis <DOT> me>
CommitDate: Wed Nov  1 16:20:17 2023 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=b54461e3

app-misc/corectrl: drop 1.3.6, remove gcc 14 patch

Signed-off-by: Kostadin Shishmanov <kocelfc <AT> tutanota.com>

 app-misc/corectrl/Manifest                    |  1 -
 app-misc/corectrl/corectrl-1.3.6.ebuild       | 58 ---------------------------
 app-misc/corectrl/files/corectrl-gcc-14.patch | 12 ------
 3 files changed, 71 deletions(-)

diff --git a/app-misc/corectrl/Manifest b/app-misc/corectrl/Manifest
index ad85c4d9b5..090a88c96f 100644
--- a/app-misc/corectrl/Manifest
+++ b/app-misc/corectrl/Manifest
@@ -1,2 +1 @@
-DIST corectrl-v1.3.6.tar.bz2 570738 BLAKE2B 8ff9255c67836e6826ea76663d1dcc8b39b024d806a75279ab5065550b1c9b1b54ed33acbf255a6c41f603df3146988c82df0c4c3f12e9e1f345c0eba432f361 SHA512 7f7718176a566c3f8d3b236c41a283d0b61f83c0dcc5954845214bb7b174bdff775e05d563c02b3fe17f2224541b0defc7900bbab6b0498d4bb02babfe4c8ce3
 DIST corectrl-v1.3.7.tar.bz2 570815 BLAKE2B fe8231ba71948d17b1e5d598bf19cde0e51ec13a20849b7bb12fa4cc8401d671123a5de00705cddd141e1ed68c097a315d676df060e704c5f0c0cf18c3383963 SHA512 f0c8ddc8180cb20935f58e0d473fc5436a430313f939adb6f1c41b0d278e689aaf6dd9d12b02ff81144dba494e713ccb4008bd3131bf8aa0769e13ac4de563be

diff --git a/app-misc/corectrl/corectrl-1.3.6.ebuild b/app-misc/corectrl/corectrl-1.3.6.ebuild
deleted file mode 100644
index 57104c21ab..0000000000
--- a/app-misc/corectrl/corectrl-1.3.6.ebuild
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright 1999-2023 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI=8
-
-inherit ecm
-
-DESCRIPTION="Core control application"
-HOMEPAGE="https://gitlab.com/corectrl/corectrl"
-
-if [[ ${PV} == 9999 ]]; then
-	inherit git-r3
-	EGIT_REPO_URI="https://gitlab.com/corectrl/corectrl.git"
-else
-	SRC_URI="https://gitlab.com/corectrl/corectrl/-/archive/v${PV}/corectrl-v${PV}.tar.bz2"
-	KEYWORDS="~amd64"
-	S="${WORKDIR}/${PN}-v${PV}"
-fi
-
-LICENSE="GPL-3"
-SLOT="0"
-
-IUSE="test"
-RESTRICT="!test? ( test )"
-
-DEPEND="
-	dev-qt/qtdbus:5
-	dev-qt/qtdeclarative:5
-	dev-qt/qtcharts:5[qml]
-	dev-qt/qtsvg:5
-	dev-qt/linguist-tools:5
-	dev-qt/qtquickcontrols2:5
-	dev-libs/quazip
-	dev-libs/botan:2
-	sys-auth/polkit
-	x11-libs/libdrm[video_cards_amdgpu]
-	dev-libs/libfmt
-	dev-libs/pugixml
-	dev-cpp/easyloggingpp
-	dev-cpp/units
-	test? (
-		~dev-cpp/catch-2.13.8
-		dev-cpp/trompeloeil
-	)
-"
-
-BDEPEND="${DEPEND}"
-
-PATCHES=(
-	"${FILESDIR}"/${PN}-gcc-14.patch
-)
-
-src_configure() {
-	local mycmakeargs+=(
-		-DBUILD_TESTING=$(usex test ON OFF)
-	)
-	cmake_src_configure
-}

diff --git a/app-misc/corectrl/files/corectrl-gcc-14.patch b/app-misc/corectrl/files/corectrl-gcc-14.patch
deleted file mode 100644
index 6392db7402..0000000000
--- a/app-misc/corectrl/files/corectrl-gcc-14.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/src/core/components/controls/controlgroupxmlparser.cpp b/src/core/components/controls/controlgroupxmlparser.cpp
-index c83a187..c580fc3 100644
---- a/src/core/components/controls/controlgroupxmlparser.cpp
-+++ b/src/core/components/controls/controlgroupxmlparser.cpp
-@@ -5,6 +5,7 @@
- 
- #include <pugixml.hpp>
- #include <utility>
-+#include <algorithm>
- 
- class ControlGroupXMLParser::Factory final
- : public ProfilePartXMLParser::Factory


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] repo/proj/guru:master commit in: app-misc/corectrl/, app-misc/corectrl/files/
@ 2023-11-06 14:18 David Roman
  0 siblings, 0 replies; 3+ messages in thread
From: David Roman @ 2023-11-06 14:18 UTC (permalink / raw
  To: gentoo-commits

commit:     a0663d155645cebe7966941220eed0a487b44e16
Author:     Kostadin Shishmanov <kocelfc <AT> tutanota <DOT> com>
AuthorDate: Sat Nov  4 21:14:58 2023 +0000
Commit:     David Roman <davidroman96 <AT> gmail <DOT> com>
CommitDate: Sat Nov  4 21:14:58 2023 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=a0663d15

app-misc/corectrl-1.3.7: fix building with linux-headers 6.6

Signed-off-by: Kostadin Shishmanov <kocelfc <AT> tutanota.com>

 app-misc/corectrl/corectrl-1.3.7.ebuild            |   3 +
 .../files/corectrl-1.3.7-headers-6.6.patch         | 540 +++++++++++++++++++++
 2 files changed, 543 insertions(+)

diff --git a/app-misc/corectrl/corectrl-1.3.7.ebuild b/app-misc/corectrl/corectrl-1.3.7.ebuild
index e56edefc64..26596dd7fe 100644
--- a/app-misc/corectrl/corectrl-1.3.7.ebuild
+++ b/app-misc/corectrl/corectrl-1.3.7.ebuild
@@ -46,6 +46,9 @@ DEPEND="
 
 BDEPEND="${DEPEND}"
 
+PATCHES=(
+	"${FILESDIR}"/${P}-headers-6.6.patch
+)
 src_configure() {
 	local mycmakeargs+=(
 		-DBUILD_TESTING=$(usex test ON OFF)

diff --git a/app-misc/corectrl/files/corectrl-1.3.7-headers-6.6.patch b/app-misc/corectrl/files/corectrl-1.3.7-headers-6.6.patch
new file mode 100644
index 0000000000..cb9f429b79
--- /dev/null
+++ b/app-misc/corectrl/files/corectrl-1.3.7-headers-6.6.patch
@@ -0,0 +1,540 @@
+From 8cb2d9038a5e92212f79904353a05ba7d9f8aa5f Mon Sep 17 00:00:00 2001
+From: Kostadin Shishmanov <kocelfc@tutanota.com>
+Date: Sat, 4 Nov 2023 23:00:14 +0200
+Subject: [PATCH] Fix compilation with Linux 6.6 API headers
+
+Due to some changes in cn_proc.h in Linux 6.6 headers, including and using it
+mixed with C++ code is no longer posible without specifying that the code is C
+code and must be compiled with a C compiler.
+
+Isolate all process connector related code into its own C file, which is now
+compiled using a C compiler, and adapt it to adhere to the new changes.
+
+---
+ CMakeLists.txt                          |   4 +-
+ src/helper/CMakeLists.txt               |   1 +
+ src/helper/pmon/nlprocexecsocket.cpp    | 204 +++---------------------
+ src/helper/pmon/nlprocexecsocket.h      |   6 -
+ src/helper/pmon/processeventconnector.c | 193 ++++++++++++++++++++++
+ src/helper/pmon/processeventconnector.h |  27 ++++
+ 6 files changed, 244 insertions(+), 191 deletions(-)
+ create mode 100644 src/helper/pmon/processeventconnector.c
+ create mode 100644 src/helper/pmon/processeventconnector.h
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 38ab229..275f48b 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1,7 +1,7 @@
+ cmake_minimum_required(VERSION 3.3)
+ 
+-project(CoreCtrl LANGUAGES CXX)
+-set(PROJECT_HOMEPAGE_URL "https://gitlab.com/corectrl/corectrl")
++project(CoreCtrl
++        HOMEPAGE_URL "https://gitlab.com/corectrl/corectrl")
+ set(PROJECT_FQDN "org.corectrl.corectrl")
+ set(PROJECT_VERSION 1.3.7)
+ 
+diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt
+index 2bc779f..13bdcbf 100644
+--- a/src/helper/CMakeLists.txt
++++ b/src/helper/CMakeLists.txt
+@@ -47,6 +47,7 @@ list(APPEND PROCESS_MONITOR_SRC
+   pmon/processregistry.cpp
+   pmon/appregistry.cpp
+   pmon/msgdispatcher.cpp
++  pmon/processeventconnector.c
+ )
+ 
+ list(APPEND SYSTEM_CONTROL_SRC
+diff --git a/src/helper/pmon/nlprocexecsocket.cpp b/src/helper/pmon/nlprocexecsocket.cpp
+index 947ea38..e09c5e7 100644
+--- a/src/helper/pmon/nlprocexecsocket.cpp
++++ b/src/helper/pmon/nlprocexecsocket.cpp
+@@ -4,213 +4,51 @@
+ #include "nlprocexecsocket.h"
+ 
+ #include "processevent.h"
+-#include <cstdint>
+-#include <linux/bpf_common.h>
+-#include <linux/cn_proc.h>
+-#include <linux/connector.h>
+-#include <linux/filter.h>
+-#include <linux/netlink.h>
+-#include <netinet/in.h>
+-#include <stddef.h>
+-#include <string.h>
+-#include <sys/socket.h>
+-#include <sys/time.h>
+-#include <unistd.h>
++
++extern "C" {
++#include "processeventconnector.h"
++}
+ 
+ NLProcExecSocket::FDHandle::~FDHandle()
+ {
+-  if (fd >= 0)
+-    close(fd);
++  process_event_connector_close(fd);
+ }
+ 
+ NLProcExecSocket::NLProcExecSocket()
+ {
+-  sockFd_.fd = createSocket();
++  sockFd_.fd = process_event_connector_new();
+   if (sockFd_.fd < 0)
+     throw std::runtime_error("Cannot create netlink socket");
+ 
+-  if (setTimeout(5) < 0)
++  if (process_event_connector_set_timeout(sockFd_.fd, 5) < 0)
+     throw std::runtime_error("Cannot set socket timeout");
+ 
+-  if (installSocketFilter() < 0)
++  if (process_event_connector_install_filter(sockFd_.fd) < 0)
+     throw std::runtime_error("Cannot install socket filters");
+ 
+-  if (bindToSocket() < 0)
++  if (process_event_connector_bind(sockFd_.fd) < 0)
+     throw BindError("Cannot bind to socket");
+ 
+-  if (subscribeToProcEvents(true) < 0)
++  if (process_event_connector_subscribe(sockFd_.fd, true) < 0)
+     throw std::runtime_error("Cannot subscribe to proc events");
+ }
+ 
+ NLProcExecSocket::~NLProcExecSocket()
+ {
+-  subscribeToProcEvents(false);
++  process_event_connector_subscribe(sockFd_.fd, false);
+ }
+ 
+ ProcessEvent NLProcExecSocket::waitForEvent() const
+ {
+-  struct nlcn_msg_t
+-  {
+-    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
+-    struct cn_msg cn_msg;
+-  };
+-
+-  auto const msg_size =
+-      NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(struct proc_event));
+-  std::uint8_t msg_buffer[msg_size] = {0};
+-  auto msg = (struct nlcn_msg_t *)msg_buffer;
+-
+-  ssize_t const rc = recv(sockFd_.fd, msg, msg_size, 0);
+-  if (rc > 0) {
+-    auto const event = ((struct proc_event *)msg->cn_msg.data);
+-    switch (event->what) {
+-      case proc_event::PROC_EVENT_EXEC:
+-        return ProcessEvent{ProcessEvent::Type::EXEC,
+-                            event->event_data.exec.process_pid};
+-
+-      case proc_event::PROC_EVENT_EXIT:
+-        return ProcessEvent{ProcessEvent::Type::EXIT,
+-                            event->event_data.exit.process_pid};
+-      default:
+-        return ProcessEvent{ProcessEvent::Type::IGNORE, -1};
+-    }
++  auto event = process_event_connector_read_event(sockFd_.fd);
++  switch (event.type) {
++    case process_event_type::PROCESS_EVENT_EXEC:
++      return ProcessEvent{ProcessEvent::Type::EXEC, event.pid};
++      break;
++    case process_event_type::PROCESS_EVENT_EXIT:
++      return ProcessEvent{ProcessEvent::Type::EXIT, event.pid};
++      break;
++    default:
++      return ProcessEvent{ProcessEvent::Type::IGNORE, -1};
+   }
+-
+-  return ProcessEvent{ProcessEvent::Type::IGNORE, -1};
+-}
+-
+-inline int NLProcExecSocket::createSocket() const
+-{
+-  return socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
+-}
+-
+-int NLProcExecSocket::setTimeout(unsigned int seconds) const
+-{
+-  struct timeval duration;
+-  duration.tv_sec = seconds;
+-  duration.tv_usec = 0;
+-
+-  return setsockopt(sockFd_.fd, SOL_SOCKET, SO_RCVTIMEO, &duration,
+-                    sizeof(duration));
+-}
+-
+-int NLProcExecSocket::bindToSocket() const
+-{
+-  struct sockaddr_nl sa_nl;
+-  sa_nl.nl_family = AF_NETLINK;
+-  sa_nl.nl_groups = CN_IDX_PROC;
+-  sa_nl.nl_pid = 0; // 0 = lets the kernel to handle nl_pid
+-
+-  return bind(sockFd_.fd, reinterpret_cast<struct sockaddr *>(&sa_nl),
+-              sizeof(sa_nl));
+-}
+-
+-int NLProcExecSocket::installSocketFilter() const
+-{
+-  struct sock_filter filter[] = {
+-      // clang-format off
+-
+-      // check message from kernel
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_pid)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
+-      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
+-
+-      // check message type NLMSG_DONE
+-      BPF_STMT(BPF_LD | BPF_H | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_type)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(NLMSG_DONE), 1, 0),
+-      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
+-
+-      // check proc connector event CN_IDX_PROC
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, id) +
+-                                         offsetof(struct cb_id, idx)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_IDX_PROC), 1, 0),
+-      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
+-
+-      // check proc connector event CN_VAL_PROC
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, id) +
+-                                         offsetof(struct cb_id, val)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_VAL_PROC), 1, 0),
+-      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
+-
+-      // accept exec messages from processes
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, data) +
+-                                         offsetof(struct proc_event, what)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(proc_event::PROC_EVENT_EXEC), 0, 6),
+-
+-      // processes have process_pid == process_tgid (thread group leaders)
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, data) +
+-                                         offsetof(struct proc_event, event_data.exec.process_pid)),
+-      BPF_STMT(BPF_ST, 0),
+-      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, data) +
+-                                         offsetof(struct proc_event, event_data.exec.process_tgid)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
+-      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
+-
+-      // accept exit messages from processes
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, data) +
+-                                         offsetof(struct proc_event, what)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(proc_event::PROC_EVENT_EXIT), 0, 6),
+-
+-      // processes have process_pid == process_tgid
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, data) +
+-                                         offsetof(struct proc_event, event_data.exit.process_pid)),
+-      BPF_STMT(BPF_ST, 0),
+-      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
+-      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
+-                                         offsetof(struct cn_msg, data) +
+-                                         offsetof(struct proc_event, event_data.exit.process_tgid)),
+-      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
+-      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
+-
+-      // drop any other messages
+-      BPF_STMT(BPF_RET | BPF_K, 0x0),
+-
+-      // clang-format on
+-  };
+-
+-  struct sock_fprog fprog;
+-  memset(&fprog, 0, sizeof(fprog));
+-  fprog.filter = filter;
+-  fprog.len = sizeof(filter) / sizeof(*filter);
+-
+-  return setsockopt(sockFd_.fd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog,
+-                    sizeof(fprog));
+-}
+-
+-int NLProcExecSocket::subscribeToProcEvents(bool subscribe) const
+-{
+-  struct nlcn_msg_t
+-  {
+-    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
+-    struct cn_msg cn_msg;
+-  };
+-
+-  auto const msg_size =
+-      NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(enum proc_cn_mcast_op));
+-  std::uint8_t msg_buffer[msg_size] = {0};
+-  auto msg = (struct nlcn_msg_t *)msg_buffer;
+-
+-  msg->nl_hdr.nlmsg_len = msg_size;
+-  msg->nl_hdr.nlmsg_pid = 0;
+-  msg->nl_hdr.nlmsg_type = NLMSG_DONE;
+-
+-  msg->cn_msg.id.idx = CN_IDX_PROC;
+-  msg->cn_msg.id.val = CN_VAL_PROC;
+-  msg->cn_msg.len = sizeof(enum proc_cn_mcast_op);
+-
+-  auto mcast = (enum proc_cn_mcast_op *)msg->cn_msg.data;
+-  *mcast = subscribe ? PROC_CN_MCAST_LISTEN : PROC_CN_MCAST_IGNORE;
+-
+-  if (send(sockFd_.fd, msg, msg_size, 0) < 0)
+-    return -1;
+-
+-  return 0;
+ }
+diff --git a/src/helper/pmon/nlprocexecsocket.h b/src/helper/pmon/nlprocexecsocket.h
+index 902e20e..be119e0 100644
+--- a/src/helper/pmon/nlprocexecsocket.h
++++ b/src/helper/pmon/nlprocexecsocket.h
+@@ -22,12 +22,6 @@ class NLProcExecSocket final
+   ProcessEvent waitForEvent() const;
+ 
+  private:
+-  inline int createSocket() const;
+-  int setTimeout(unsigned int seconds) const;
+-  int bindToSocket() const;
+-  int installSocketFilter() const;
+-  int subscribeToProcEvents(bool subscribe) const;
+-
+   struct FDHandle
+   {
+     int fd{-1};
+diff --git a/src/helper/pmon/processeventconnector.c b/src/helper/pmon/processeventconnector.c
+new file mode 100644
+index 0000000..a18070e
+--- /dev/null
++++ b/src/helper/pmon/processeventconnector.c
+@@ -0,0 +1,193 @@
++// SPDX-License-Identifier: GPL-3.0-or-later
++// Copyright 2023 Juan Palacios <jpalaciosdev@gmail.com>
++
++#include "processeventconnector.h"
++
++#include <linux/bpf_common.h>
++#include <linux/cn_proc.h>
++#include <linux/connector.h>
++#include <linux/filter.h>
++#include <linux/netlink.h>
++#include <linux/version.h>
++#include <netinet/in.h>
++#include <string.h>
++#include <sys/socket.h>
++#include <sys/time.h>
++#include <unistd.h>
++
++#define SUBSCRIBE_MSG_SIZE                                                     \
++  NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(enum proc_cn_mcast_op))
++#define READ_EVENT_MSG_SIZE                                                    \
++  NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(struct proc_event))
++
++int process_event_connector_new()
++{
++  return socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
++}
++
++int process_event_connector_close(int socket_fd)
++{
++  if (socket_fd >= 0)
++    return close(socket_fd);
++
++  return 0;
++}
++
++int process_event_connector_set_timeout(int socket_fd, unsigned int seconds)
++{
++  struct timeval duration;
++  duration.tv_sec = seconds;
++  duration.tv_usec = 0;
++
++  return setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, &duration,
++                    sizeof(duration));
++}
++
++int process_event_connector_bind(int socket_fd)
++{
++  struct sockaddr_nl sa_nl;
++  sa_nl.nl_family = AF_NETLINK;
++  sa_nl.nl_groups = CN_IDX_PROC;
++  sa_nl.nl_pid = 0; // 0 = lets the kernel to handle nl_pid
++
++  return bind(socket_fd, (struct sockaddr *)(&sa_nl), sizeof(sa_nl));
++}
++
++int process_event_connector_subscribe(int socket_fd, bool subscribe)
++{
++  typedef struct nlcn_msg_t
++  {
++    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
++    struct cn_msg cn_msg;
++  } nlcn_msg;
++
++  char msg_buffer[SUBSCRIBE_MSG_SIZE] = {0};
++  nlcn_msg *msg = (nlcn_msg *)msg_buffer;
++
++  msg->nl_hdr.nlmsg_len = SUBSCRIBE_MSG_SIZE;
++  msg->nl_hdr.nlmsg_pid = 0;
++  msg->nl_hdr.nlmsg_type = NLMSG_DONE;
++
++  msg->cn_msg.id.idx = CN_IDX_PROC;
++  msg->cn_msg.id.val = CN_VAL_PROC;
++  msg->cn_msg.len = sizeof(enum proc_cn_mcast_op);
++
++  enum proc_cn_mcast_op *mcast = (enum proc_cn_mcast_op *)msg->cn_msg.data;
++  *mcast = subscribe ? PROC_CN_MCAST_LISTEN : PROC_CN_MCAST_IGNORE;
++
++  if (send(socket_fd, msg, SUBSCRIBE_MSG_SIZE, 0) < 0)
++    return -1;
++
++  return 0;
++}
++
++int process_event_connector_install_filter(int socket_fd)
++{
++  struct sock_filter filter[] = {
++      // clang-format off
++
++      // check message from kernel
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_pid)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
++      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
++
++      // check message type NLMSG_DONE
++      BPF_STMT(BPF_LD | BPF_H | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_type)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(NLMSG_DONE), 1, 0),
++      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
++
++      // check proc connector event CN_IDX_PROC
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, id) +
++                                         offsetof(struct cb_id, idx)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_IDX_PROC), 1, 0),
++      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
++
++      // check proc connector event CN_VAL_PROC
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, id) +
++                                         offsetof(struct cb_id, val)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_VAL_PROC), 1, 0),
++      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
++
++      // accept exec messages from processes
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, data) +
++                                         offsetof(struct proc_event, what)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(PROC_EVENT_EXEC), 0, 6),
++
++      // processes have process_pid == process_tgid (thread group leaders)
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, data) +
++                                         offsetof(struct proc_event, event_data.exec.process_pid)),
++      BPF_STMT(BPF_ST, 0),
++      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, data) +
++                                         offsetof(struct proc_event, event_data.exec.process_tgid)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
++      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
++
++      // accept exit messages from processes
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, data) +
++                                         offsetof(struct proc_event, what)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(PROC_EVENT_EXIT), 0, 6),
++
++      // processes have process_pid == process_tgid
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, data) +
++                                         offsetof(struct proc_event, event_data.exit.process_pid)),
++      BPF_STMT(BPF_ST, 0),
++      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
++      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
++                                         offsetof(struct cn_msg, data) +
++                                         offsetof(struct proc_event, event_data.exit.process_tgid)),
++      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
++      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
++
++      // drop any other messages
++      BPF_STMT(BPF_RET | BPF_K, 0x0),
++
++      // clang-format on
++  };
++
++  struct sock_fprog fprog;
++  memset(&fprog, 0, sizeof(fprog));
++  fprog.filter = filter;
++  fprog.len = sizeof(filter) / sizeof(*filter);
++
++  return setsockopt(socket_fd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog,
++                    sizeof(fprog));
++}
++
++process_event process_event_connector_read_event(int socket_fd)
++{
++  typedef struct nlcn_msg_t
++  {
++    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
++    struct cn_msg cn_msg;
++  } nlcn_msg;
++
++  char msg_buffer[READ_EVENT_MSG_SIZE] = {0};
++  nlcn_msg *msg = (nlcn_msg *)msg_buffer;
++
++  ssize_t const rc = recv(socket_fd, msg, READ_EVENT_MSG_SIZE, 0);
++  if (rc > 0) {
++    struct proc_event *event = ((struct proc_event *)msg->cn_msg.data);
++    switch (event->what) {
++      case PROC_EVENT_EXEC:
++        return (process_event){.type = PROCESS_EVENT_EXEC,
++                               .pid = event->event_data.exec.process_pid};
++
++      case PROC_EVENT_EXIT:
++        return (process_event){.type = PROCESS_EVENT_EXIT,
++                               .pid = event->event_data.exit.process_pid};
++
++      default:
++        return (process_event){.type = PROCESS_EVENT_OTHER, .pid = -1};
++    }
++  }
++
++  return (process_event){.type = PROCESS_EVENT_OTHER, .pid = -1};
++}
+diff --git a/src/helper/pmon/processeventconnector.h b/src/helper/pmon/processeventconnector.h
+new file mode 100644
+index 0000000..35c4b5b
+--- /dev/null
++++ b/src/helper/pmon/processeventconnector.h
+@@ -0,0 +1,27 @@
++// SPDX-License-Identifier: GPL-3.0-or-later
++// Copyright 2023 Juan Palacios <jpalaciosdev@gmail.com>
++
++#pragma once
++
++#include <stdbool.h>
++#include <stddef.h>
++
++typedef enum process_event_type_t {
++  PROCESS_EVENT_EXEC,
++  PROCESS_EVENT_EXIT,
++  PROCESS_EVENT_OTHER,
++} process_event_type;
++
++typedef struct process_event_t
++{
++  process_event_type type;
++  int pid;
++} process_event;
++
++int process_event_connector_new();
++int process_event_connector_close(int socket_fd);
++int process_event_connector_set_timeout(int socket_fd, unsigned int seconds);
++int process_event_connector_bind(int socket_fd);
++int process_event_connector_subscribe(int socket_fd, bool subscribe);
++int process_event_connector_install_filter(int socket_fd);
++process_event process_event_connector_read_event(int socket_fd);
+-- 
+2.42.1
+


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] repo/proj/guru:master commit in: app-misc/corectrl/, app-misc/corectrl/files/
@ 2024-01-09 12:03 David Roman
  0 siblings, 0 replies; 3+ messages in thread
From: David Roman @ 2024-01-09 12:03 UTC (permalink / raw
  To: gentoo-commits

commit:     8d3019c77f36e51d7c1c95a081578b310a1b9c7e
Author:     Kostadin Shishmanov <kocelfc <AT> tutanota <DOT> com>
AuthorDate: Mon Jan  8 20:02:39 2024 +0000
Commit:     David Roman <davidroman96 <AT> gmail <DOT> com>
CommitDate: Mon Jan  8 20:05:14 2024 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=8d3019c7

app-misc/corectrl: add 1.3.8, remove 1.3.7, tweak ebuild a bit and remove unneeded patch

Signed-off-by: Kostadin Shishmanov <kocelfc <AT> tutanota.com>

 app-misc/corectrl/Manifest                         |   2 +-
 ...corectrl-1.3.7.ebuild => corectrl-1.3.8.ebuild} |   9 +-
 app-misc/corectrl/corectrl-9999.ebuild             |   6 +-
 .../files/corectrl-1.3.7-headers-6.6.patch         | 540 ---------------------
 4 files changed, 7 insertions(+), 550 deletions(-)

diff --git a/app-misc/corectrl/Manifest b/app-misc/corectrl/Manifest
index 090a88c96f..2a35052580 100644
--- a/app-misc/corectrl/Manifest
+++ b/app-misc/corectrl/Manifest
@@ -1 +1 @@
-DIST corectrl-v1.3.7.tar.bz2 570815 BLAKE2B fe8231ba71948d17b1e5d598bf19cde0e51ec13a20849b7bb12fa4cc8401d671123a5de00705cddd141e1ed68c097a315d676df060e704c5f0c0cf18c3383963 SHA512 f0c8ddc8180cb20935f58e0d473fc5436a430313f939adb6f1c41b0d278e689aaf6dd9d12b02ff81144dba494e713ccb4008bd3131bf8aa0769e13ac4de563be
+DIST corectrl-v1.3.8.tar.bz2 571563 BLAKE2B 65a768589ab5b60092888ae9d50d3350a02642508b3c05b15a2bc69874e20e9f133c58c29eb9cb61127c393029636dd3914b48ea10d01f51b469e27c00e0d1e6 SHA512 099f13afd246ecbadfbe1b8e2e61dfd9a5fbecfd7dda09bbc1e28415d3729fe46b1bff11651672b13cbc5d3d8b2610ac78b367afa8f681499fe45bb7dded2588

diff --git a/app-misc/corectrl/corectrl-1.3.7.ebuild b/app-misc/corectrl/corectrl-1.3.8.ebuild
similarity index 87%
rename from app-misc/corectrl/corectrl-1.3.7.ebuild
rename to app-misc/corectrl/corectrl-1.3.8.ebuild
index 26596dd7fe..d99dc875b7 100644
--- a/app-misc/corectrl/corectrl-1.3.7.ebuild
+++ b/app-misc/corectrl/corectrl-1.3.8.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
@@ -46,12 +46,9 @@ DEPEND="
 
 BDEPEND="${DEPEND}"
 
-PATCHES=(
-	"${FILESDIR}"/${P}-headers-6.6.patch
-)
 src_configure() {
-	local mycmakeargs+=(
+	local mycmakeargs=(
 		-DBUILD_TESTING=$(usex test ON OFF)
 	)
-	cmake_src_configure
+	ecm_src_configure
 }

diff --git a/app-misc/corectrl/corectrl-9999.ebuild b/app-misc/corectrl/corectrl-9999.ebuild
index 7b4ca92f3e..7f4910f5ec 100644
--- a/app-misc/corectrl/corectrl-9999.ebuild
+++ b/app-misc/corectrl/corectrl-9999.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
@@ -47,8 +47,8 @@ DEPEND="
 BDEPEND="${DEPEND}"
 
 src_configure() {
-	local mycmakeargs+=(
+	local mycmakeargs=(
 		-DBUILD_TESTING=$(usex test ON OFF)
 	)
-	cmake_src_configure
+	ecm_src_configure
 }

diff --git a/app-misc/corectrl/files/corectrl-1.3.7-headers-6.6.patch b/app-misc/corectrl/files/corectrl-1.3.7-headers-6.6.patch
deleted file mode 100644
index cb9f429b79..0000000000
--- a/app-misc/corectrl/files/corectrl-1.3.7-headers-6.6.patch
+++ /dev/null
@@ -1,540 +0,0 @@
-From 8cb2d9038a5e92212f79904353a05ba7d9f8aa5f Mon Sep 17 00:00:00 2001
-From: Kostadin Shishmanov <kocelfc@tutanota.com>
-Date: Sat, 4 Nov 2023 23:00:14 +0200
-Subject: [PATCH] Fix compilation with Linux 6.6 API headers
-
-Due to some changes in cn_proc.h in Linux 6.6 headers, including and using it
-mixed with C++ code is no longer posible without specifying that the code is C
-code and must be compiled with a C compiler.
-
-Isolate all process connector related code into its own C file, which is now
-compiled using a C compiler, and adapt it to adhere to the new changes.
-
----
- CMakeLists.txt                          |   4 +-
- src/helper/CMakeLists.txt               |   1 +
- src/helper/pmon/nlprocexecsocket.cpp    | 204 +++---------------------
- src/helper/pmon/nlprocexecsocket.h      |   6 -
- src/helper/pmon/processeventconnector.c | 193 ++++++++++++++++++++++
- src/helper/pmon/processeventconnector.h |  27 ++++
- 6 files changed, 244 insertions(+), 191 deletions(-)
- create mode 100644 src/helper/pmon/processeventconnector.c
- create mode 100644 src/helper/pmon/processeventconnector.h
-
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 38ab229..275f48b 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -1,7 +1,7 @@
- cmake_minimum_required(VERSION 3.3)
- 
--project(CoreCtrl LANGUAGES CXX)
--set(PROJECT_HOMEPAGE_URL "https://gitlab.com/corectrl/corectrl")
-+project(CoreCtrl
-+        HOMEPAGE_URL "https://gitlab.com/corectrl/corectrl")
- set(PROJECT_FQDN "org.corectrl.corectrl")
- set(PROJECT_VERSION 1.3.7)
- 
-diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt
-index 2bc779f..13bdcbf 100644
---- a/src/helper/CMakeLists.txt
-+++ b/src/helper/CMakeLists.txt
-@@ -47,6 +47,7 @@ list(APPEND PROCESS_MONITOR_SRC
-   pmon/processregistry.cpp
-   pmon/appregistry.cpp
-   pmon/msgdispatcher.cpp
-+  pmon/processeventconnector.c
- )
- 
- list(APPEND SYSTEM_CONTROL_SRC
-diff --git a/src/helper/pmon/nlprocexecsocket.cpp b/src/helper/pmon/nlprocexecsocket.cpp
-index 947ea38..e09c5e7 100644
---- a/src/helper/pmon/nlprocexecsocket.cpp
-+++ b/src/helper/pmon/nlprocexecsocket.cpp
-@@ -4,213 +4,51 @@
- #include "nlprocexecsocket.h"
- 
- #include "processevent.h"
--#include <cstdint>
--#include <linux/bpf_common.h>
--#include <linux/cn_proc.h>
--#include <linux/connector.h>
--#include <linux/filter.h>
--#include <linux/netlink.h>
--#include <netinet/in.h>
--#include <stddef.h>
--#include <string.h>
--#include <sys/socket.h>
--#include <sys/time.h>
--#include <unistd.h>
-+
-+extern "C" {
-+#include "processeventconnector.h"
-+}
- 
- NLProcExecSocket::FDHandle::~FDHandle()
- {
--  if (fd >= 0)
--    close(fd);
-+  process_event_connector_close(fd);
- }
- 
- NLProcExecSocket::NLProcExecSocket()
- {
--  sockFd_.fd = createSocket();
-+  sockFd_.fd = process_event_connector_new();
-   if (sockFd_.fd < 0)
-     throw std::runtime_error("Cannot create netlink socket");
- 
--  if (setTimeout(5) < 0)
-+  if (process_event_connector_set_timeout(sockFd_.fd, 5) < 0)
-     throw std::runtime_error("Cannot set socket timeout");
- 
--  if (installSocketFilter() < 0)
-+  if (process_event_connector_install_filter(sockFd_.fd) < 0)
-     throw std::runtime_error("Cannot install socket filters");
- 
--  if (bindToSocket() < 0)
-+  if (process_event_connector_bind(sockFd_.fd) < 0)
-     throw BindError("Cannot bind to socket");
- 
--  if (subscribeToProcEvents(true) < 0)
-+  if (process_event_connector_subscribe(sockFd_.fd, true) < 0)
-     throw std::runtime_error("Cannot subscribe to proc events");
- }
- 
- NLProcExecSocket::~NLProcExecSocket()
- {
--  subscribeToProcEvents(false);
-+  process_event_connector_subscribe(sockFd_.fd, false);
- }
- 
- ProcessEvent NLProcExecSocket::waitForEvent() const
- {
--  struct nlcn_msg_t
--  {
--    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
--    struct cn_msg cn_msg;
--  };
--
--  auto const msg_size =
--      NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(struct proc_event));
--  std::uint8_t msg_buffer[msg_size] = {0};
--  auto msg = (struct nlcn_msg_t *)msg_buffer;
--
--  ssize_t const rc = recv(sockFd_.fd, msg, msg_size, 0);
--  if (rc > 0) {
--    auto const event = ((struct proc_event *)msg->cn_msg.data);
--    switch (event->what) {
--      case proc_event::PROC_EVENT_EXEC:
--        return ProcessEvent{ProcessEvent::Type::EXEC,
--                            event->event_data.exec.process_pid};
--
--      case proc_event::PROC_EVENT_EXIT:
--        return ProcessEvent{ProcessEvent::Type::EXIT,
--                            event->event_data.exit.process_pid};
--      default:
--        return ProcessEvent{ProcessEvent::Type::IGNORE, -1};
--    }
-+  auto event = process_event_connector_read_event(sockFd_.fd);
-+  switch (event.type) {
-+    case process_event_type::PROCESS_EVENT_EXEC:
-+      return ProcessEvent{ProcessEvent::Type::EXEC, event.pid};
-+      break;
-+    case process_event_type::PROCESS_EVENT_EXIT:
-+      return ProcessEvent{ProcessEvent::Type::EXIT, event.pid};
-+      break;
-+    default:
-+      return ProcessEvent{ProcessEvent::Type::IGNORE, -1};
-   }
--
--  return ProcessEvent{ProcessEvent::Type::IGNORE, -1};
--}
--
--inline int NLProcExecSocket::createSocket() const
--{
--  return socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
--}
--
--int NLProcExecSocket::setTimeout(unsigned int seconds) const
--{
--  struct timeval duration;
--  duration.tv_sec = seconds;
--  duration.tv_usec = 0;
--
--  return setsockopt(sockFd_.fd, SOL_SOCKET, SO_RCVTIMEO, &duration,
--                    sizeof(duration));
--}
--
--int NLProcExecSocket::bindToSocket() const
--{
--  struct sockaddr_nl sa_nl;
--  sa_nl.nl_family = AF_NETLINK;
--  sa_nl.nl_groups = CN_IDX_PROC;
--  sa_nl.nl_pid = 0; // 0 = lets the kernel to handle nl_pid
--
--  return bind(sockFd_.fd, reinterpret_cast<struct sockaddr *>(&sa_nl),
--              sizeof(sa_nl));
--}
--
--int NLProcExecSocket::installSocketFilter() const
--{
--  struct sock_filter filter[] = {
--      // clang-format off
--
--      // check message from kernel
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_pid)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
--      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
--
--      // check message type NLMSG_DONE
--      BPF_STMT(BPF_LD | BPF_H | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_type)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(NLMSG_DONE), 1, 0),
--      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
--
--      // check proc connector event CN_IDX_PROC
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, id) +
--                                         offsetof(struct cb_id, idx)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_IDX_PROC), 1, 0),
--      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
--
--      // check proc connector event CN_VAL_PROC
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, id) +
--                                         offsetof(struct cb_id, val)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_VAL_PROC), 1, 0),
--      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
--
--      // accept exec messages from processes
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, data) +
--                                         offsetof(struct proc_event, what)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(proc_event::PROC_EVENT_EXEC), 0, 6),
--
--      // processes have process_pid == process_tgid (thread group leaders)
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, data) +
--                                         offsetof(struct proc_event, event_data.exec.process_pid)),
--      BPF_STMT(BPF_ST, 0),
--      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, data) +
--                                         offsetof(struct proc_event, event_data.exec.process_tgid)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
--      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
--
--      // accept exit messages from processes
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, data) +
--                                         offsetof(struct proc_event, what)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(proc_event::PROC_EVENT_EXIT), 0, 6),
--
--      // processes have process_pid == process_tgid
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, data) +
--                                         offsetof(struct proc_event, event_data.exit.process_pid)),
--      BPF_STMT(BPF_ST, 0),
--      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
--      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
--                                         offsetof(struct cn_msg, data) +
--                                         offsetof(struct proc_event, event_data.exit.process_tgid)),
--      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
--      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
--
--      // drop any other messages
--      BPF_STMT(BPF_RET | BPF_K, 0x0),
--
--      // clang-format on
--  };
--
--  struct sock_fprog fprog;
--  memset(&fprog, 0, sizeof(fprog));
--  fprog.filter = filter;
--  fprog.len = sizeof(filter) / sizeof(*filter);
--
--  return setsockopt(sockFd_.fd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog,
--                    sizeof(fprog));
--}
--
--int NLProcExecSocket::subscribeToProcEvents(bool subscribe) const
--{
--  struct nlcn_msg_t
--  {
--    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
--    struct cn_msg cn_msg;
--  };
--
--  auto const msg_size =
--      NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(enum proc_cn_mcast_op));
--  std::uint8_t msg_buffer[msg_size] = {0};
--  auto msg = (struct nlcn_msg_t *)msg_buffer;
--
--  msg->nl_hdr.nlmsg_len = msg_size;
--  msg->nl_hdr.nlmsg_pid = 0;
--  msg->nl_hdr.nlmsg_type = NLMSG_DONE;
--
--  msg->cn_msg.id.idx = CN_IDX_PROC;
--  msg->cn_msg.id.val = CN_VAL_PROC;
--  msg->cn_msg.len = sizeof(enum proc_cn_mcast_op);
--
--  auto mcast = (enum proc_cn_mcast_op *)msg->cn_msg.data;
--  *mcast = subscribe ? PROC_CN_MCAST_LISTEN : PROC_CN_MCAST_IGNORE;
--
--  if (send(sockFd_.fd, msg, msg_size, 0) < 0)
--    return -1;
--
--  return 0;
- }
-diff --git a/src/helper/pmon/nlprocexecsocket.h b/src/helper/pmon/nlprocexecsocket.h
-index 902e20e..be119e0 100644
---- a/src/helper/pmon/nlprocexecsocket.h
-+++ b/src/helper/pmon/nlprocexecsocket.h
-@@ -22,12 +22,6 @@ class NLProcExecSocket final
-   ProcessEvent waitForEvent() const;
- 
-  private:
--  inline int createSocket() const;
--  int setTimeout(unsigned int seconds) const;
--  int bindToSocket() const;
--  int installSocketFilter() const;
--  int subscribeToProcEvents(bool subscribe) const;
--
-   struct FDHandle
-   {
-     int fd{-1};
-diff --git a/src/helper/pmon/processeventconnector.c b/src/helper/pmon/processeventconnector.c
-new file mode 100644
-index 0000000..a18070e
---- /dev/null
-+++ b/src/helper/pmon/processeventconnector.c
-@@ -0,0 +1,193 @@
-+// SPDX-License-Identifier: GPL-3.0-or-later
-+// Copyright 2023 Juan Palacios <jpalaciosdev@gmail.com>
-+
-+#include "processeventconnector.h"
-+
-+#include <linux/bpf_common.h>
-+#include <linux/cn_proc.h>
-+#include <linux/connector.h>
-+#include <linux/filter.h>
-+#include <linux/netlink.h>
-+#include <linux/version.h>
-+#include <netinet/in.h>
-+#include <string.h>
-+#include <sys/socket.h>
-+#include <sys/time.h>
-+#include <unistd.h>
-+
-+#define SUBSCRIBE_MSG_SIZE                                                     \
-+  NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(enum proc_cn_mcast_op))
-+#define READ_EVENT_MSG_SIZE                                                    \
-+  NLMSG_LENGTH(sizeof(struct cn_msg) + sizeof(struct proc_event))
-+
-+int process_event_connector_new()
-+{
-+  return socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
-+}
-+
-+int process_event_connector_close(int socket_fd)
-+{
-+  if (socket_fd >= 0)
-+    return close(socket_fd);
-+
-+  return 0;
-+}
-+
-+int process_event_connector_set_timeout(int socket_fd, unsigned int seconds)
-+{
-+  struct timeval duration;
-+  duration.tv_sec = seconds;
-+  duration.tv_usec = 0;
-+
-+  return setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, &duration,
-+                    sizeof(duration));
-+}
-+
-+int process_event_connector_bind(int socket_fd)
-+{
-+  struct sockaddr_nl sa_nl;
-+  sa_nl.nl_family = AF_NETLINK;
-+  sa_nl.nl_groups = CN_IDX_PROC;
-+  sa_nl.nl_pid = 0; // 0 = lets the kernel to handle nl_pid
-+
-+  return bind(socket_fd, (struct sockaddr *)(&sa_nl), sizeof(sa_nl));
-+}
-+
-+int process_event_connector_subscribe(int socket_fd, bool subscribe)
-+{
-+  typedef struct nlcn_msg_t
-+  {
-+    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
-+    struct cn_msg cn_msg;
-+  } nlcn_msg;
-+
-+  char msg_buffer[SUBSCRIBE_MSG_SIZE] = {0};
-+  nlcn_msg *msg = (nlcn_msg *)msg_buffer;
-+
-+  msg->nl_hdr.nlmsg_len = SUBSCRIBE_MSG_SIZE;
-+  msg->nl_hdr.nlmsg_pid = 0;
-+  msg->nl_hdr.nlmsg_type = NLMSG_DONE;
-+
-+  msg->cn_msg.id.idx = CN_IDX_PROC;
-+  msg->cn_msg.id.val = CN_VAL_PROC;
-+  msg->cn_msg.len = sizeof(enum proc_cn_mcast_op);
-+
-+  enum proc_cn_mcast_op *mcast = (enum proc_cn_mcast_op *)msg->cn_msg.data;
-+  *mcast = subscribe ? PROC_CN_MCAST_LISTEN : PROC_CN_MCAST_IGNORE;
-+
-+  if (send(socket_fd, msg, SUBSCRIBE_MSG_SIZE, 0) < 0)
-+    return -1;
-+
-+  return 0;
-+}
-+
-+int process_event_connector_install_filter(int socket_fd)
-+{
-+  struct sock_filter filter[] = {
-+      // clang-format off
-+
-+      // check message from kernel
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_pid)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
-+      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
-+
-+      // check message type NLMSG_DONE
-+      BPF_STMT(BPF_LD | BPF_H | BPF_ABS, offsetof(struct nlmsghdr, nlmsg_type)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(NLMSG_DONE), 1, 0),
-+      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
-+
-+      // check proc connector event CN_IDX_PROC
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, id) +
-+                                         offsetof(struct cb_id, idx)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_IDX_PROC), 1, 0),
-+      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
-+
-+      // check proc connector event CN_VAL_PROC
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, id) +
-+                                         offsetof(struct cb_id, val)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(CN_VAL_PROC), 1, 0),
-+      BPF_STMT(BPF_RET | BPF_K, 0x0), // drop message
-+
-+      // accept exec messages from processes
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, data) +
-+                                         offsetof(struct proc_event, what)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(PROC_EVENT_EXEC), 0, 6),
-+
-+      // processes have process_pid == process_tgid (thread group leaders)
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, data) +
-+                                         offsetof(struct proc_event, event_data.exec.process_pid)),
-+      BPF_STMT(BPF_ST, 0),
-+      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, data) +
-+                                         offsetof(struct proc_event, event_data.exec.process_tgid)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
-+      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
-+
-+      // accept exit messages from processes
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, data) +
-+                                         offsetof(struct proc_event, what)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(PROC_EVENT_EXIT), 0, 6),
-+
-+      // processes have process_pid == process_tgid
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, data) +
-+                                         offsetof(struct proc_event, event_data.exit.process_pid)),
-+      BPF_STMT(BPF_ST, 0),
-+      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
-+      BPF_STMT(BPF_LD | BPF_W | BPF_ABS, NLMSG_LENGTH(0) +
-+                                         offsetof(struct cn_msg, data) +
-+                                         offsetof(struct proc_event, event_data.exit.process_tgid)),
-+      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 1),
-+      BPF_STMT(BPF_RET | BPF_K, 0xffffffff),
-+
-+      // drop any other messages
-+      BPF_STMT(BPF_RET | BPF_K, 0x0),
-+
-+      // clang-format on
-+  };
-+
-+  struct sock_fprog fprog;
-+  memset(&fprog, 0, sizeof(fprog));
-+  fprog.filter = filter;
-+  fprog.len = sizeof(filter) / sizeof(*filter);
-+
-+  return setsockopt(socket_fd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog,
-+                    sizeof(fprog));
-+}
-+
-+process_event process_event_connector_read_event(int socket_fd)
-+{
-+  typedef struct nlcn_msg_t
-+  {
-+    struct nlmsghdr nl_hdr __attribute__((aligned(NLMSG_ALIGNTO)));
-+    struct cn_msg cn_msg;
-+  } nlcn_msg;
-+
-+  char msg_buffer[READ_EVENT_MSG_SIZE] = {0};
-+  nlcn_msg *msg = (nlcn_msg *)msg_buffer;
-+
-+  ssize_t const rc = recv(socket_fd, msg, READ_EVENT_MSG_SIZE, 0);
-+  if (rc > 0) {
-+    struct proc_event *event = ((struct proc_event *)msg->cn_msg.data);
-+    switch (event->what) {
-+      case PROC_EVENT_EXEC:
-+        return (process_event){.type = PROCESS_EVENT_EXEC,
-+                               .pid = event->event_data.exec.process_pid};
-+
-+      case PROC_EVENT_EXIT:
-+        return (process_event){.type = PROCESS_EVENT_EXIT,
-+                               .pid = event->event_data.exit.process_pid};
-+
-+      default:
-+        return (process_event){.type = PROCESS_EVENT_OTHER, .pid = -1};
-+    }
-+  }
-+
-+  return (process_event){.type = PROCESS_EVENT_OTHER, .pid = -1};
-+}
-diff --git a/src/helper/pmon/processeventconnector.h b/src/helper/pmon/processeventconnector.h
-new file mode 100644
-index 0000000..35c4b5b
---- /dev/null
-+++ b/src/helper/pmon/processeventconnector.h
-@@ -0,0 +1,27 @@
-+// SPDX-License-Identifier: GPL-3.0-or-later
-+// Copyright 2023 Juan Palacios <jpalaciosdev@gmail.com>
-+
-+#pragma once
-+
-+#include <stdbool.h>
-+#include <stddef.h>
-+
-+typedef enum process_event_type_t {
-+  PROCESS_EVENT_EXEC,
-+  PROCESS_EVENT_EXIT,
-+  PROCESS_EVENT_OTHER,
-+} process_event_type;
-+
-+typedef struct process_event_t
-+{
-+  process_event_type type;
-+  int pid;
-+} process_event;
-+
-+int process_event_connector_new();
-+int process_event_connector_close(int socket_fd);
-+int process_event_connector_set_timeout(int socket_fd, unsigned int seconds);
-+int process_event_connector_bind(int socket_fd);
-+int process_event_connector_subscribe(int socket_fd, bool subscribe);
-+int process_event_connector_install_filter(int socket_fd);
-+process_event process_event_connector_read_event(int socket_fd);
--- 
-2.42.1
-


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-09 12:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-01 23:27 [gentoo-commits] repo/proj/guru:master commit in: app-misc/corectrl/, app-misc/corectrl/files/ Haelwenn Monnier
  -- strict thread matches above, loose matches on Subject: below --
2023-11-06 14:18 David Roman
2024-01-09 12:03 David Roman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox