]> git.proxmox.com Git - qemu-server.git/blobdiff - qmeventd/qmeventd.h
qmeventd: further improve getting VMID from PID
[qemu-server.git] / qmeventd / qmeventd.h
index 30aea988cce8c7b83391745cc7fe62e1ecf6aa3d..9afc9351a0a09bb84b89c0d549c587954151fbc5 100644 (file)
@@ -1,27 +1,22 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
 /*
-
-    Copyright (C) 2018 Proxmox Server Solutions GmbH
-
-    Copyright: qemumonitor is under GNU GPL, the GNU General Public License.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; version 2 dated June, 1991.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-    02111-1307, USA.
+    Copyright (C) 2018 - 2021 Proxmox Server Solutions GmbH
 
     Author: Dominik Csapak <d.csapak@proxmox.com>
+    Author: Stefan Reiter <s.reiter@proxmox.com>
 */
 
-#define VERBOSE_PRINT(...) do { if (verbose) { printf(__VA_ARGS__); } } while (0)
+#include <sys/syscall.h>
+#include <time.h>
+
+#ifndef __NR_pidfd_open
+#define __NR_pidfd_open 434
+#endif
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal 424
+#endif
+
+#define VERBOSE_PRINT(...) do { if (verbose) { printf(__VA_ARGS__); fflush(stdout); } } while (0)
 
 static inline void log_neg(int errval, const char *msg)
 {
@@ -38,6 +33,18 @@ static inline void bail_neg(int errval, const char *msg)
     }
 }
 
+static inline int
+pidfd_open(pid_t pid, unsigned int flags)
+{
+    return syscall(__NR_pidfd_open, pid, flags);
+}
+
+static inline int
+pidfd_send_signal(int pidfd, int sig, siginfo_t *info, unsigned int flags)
+{
+    return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
+}
+
 typedef enum {
     CLIENT_NONE,
     CLIENT_QEMU,
@@ -57,6 +64,8 @@ struct Client {
 
     int fd;
     pid_t pid;
+    int pidfd;
+    time_t timeout;
 
     ClientType type;
     ClientState state;