chiark / gitweb /
Merge pull request #15 from elogind/dev_v229
[elogind.git] / src / basic / process-util.c
index 94ca0401d097e0e22970b8957d39df081936efef..550419d5ed608082bca14c7f7ae5e538a0f90f7b 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
+#include <linux/oom.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/personality.h>
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <syslog.h>
 #include <unistd.h>
+#ifdef HAVE_VALGRIND_VALGRIND_H
+#include <valgrind/valgrind.h>
+#endif
 
 #include "alloc-util.h"
 #include "escape.h"
 #include "fs-util.h"
 //#include "ioprio.h"
 #include "log.h"
+#include "macro.h"
+#include "missing.h"
 #include "process-util.h"
 #include "signal-util.h"
+//#include "stat-util.h"
 #include "string-table.h"
 #include "string-util.h"
 #include "user-util.h"
@@ -185,8 +194,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 void rename_process(const char name[8]) {
         assert(name);
 
@@ -251,8 +259,7 @@ int is_kernel_thread(pid_t pid) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 int get_process_capeff(pid_t pid, char **capeff) {
         const char *p;
         int r;
@@ -304,8 +311,7 @@ int get_process_exe(pid_t pid, char **name) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
         _cleanup_fclose_ FILE *f = NULL;
         char line[LINE_MAX];
@@ -537,8 +543,7 @@ void sigkill_wait(pid_t *pid) {
                 (void) wait_for_terminate(*pid, NULL);
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 int kill_and_sigcont(pid_t pid, int sig) {
         int r;
 
@@ -641,6 +646,19 @@ bool pid_is_alive(pid_t pid) {
         return true;
 }
 
+#if 0 /// UNNEEDED by elogind
+int pid_from_same_root_fs(pid_t pid) {
+        const char *root;
+
+        if (pid < 0)
+                return 0;
+
+        root = procfs_file_alloca(pid, "root");
+
+        return files_same(root, "/proc/1/root");
+}
+#endif // 0
+
 bool is_main_thread(void) {
         static thread_local int cached = 0;
 
@@ -650,8 +668,7 @@ bool is_main_thread(void) {
         return cached > 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 noreturn void freeze(void) {
 
         /* Make sure nobody waits for us on a socket anymore */
@@ -739,6 +756,23 @@ const char* personality_to_string(unsigned long p) {
         return NULL;
 }
 
+void valgrind_summary_hack(void) {
+#ifdef HAVE_VALGRIND_VALGRIND_H
+        if (getpid() == 1 && RUNNING_ON_VALGRIND) {
+                pid_t pid;
+                pid = raw_clone(SIGCHLD, NULL);
+                if (pid < 0)
+                        log_emergency_errno(errno, "Failed to fork off valgrind helper: %m");
+                else if (pid == 0)
+                        exit(EXIT_SUCCESS);
+                else {
+                        log_info("Spawned valgrind helper as PID "PID_FMT".", pid);
+                        (void) wait_for_terminate(pid, NULL);
+                }
+        }
+#endif
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",