From 7109c0d2d9ee89bc2b8ed057ce18829084b389ce Mon Sep 17 00:00:00 2001 From: WaLyong Cho Date: Tue, 7 Jun 2016 23:26:42 +0900 Subject: [PATCH] activation: set children oom_score_adj to 0 If dbus is running as systemd service, dbus daemon is running with oom_score_adj -900 by OOMScoreAdjust=-900. And children will also have same value with dbus daemon. To avoid this, set the child itself values after fork () to 0. --- dbus/dbus-spawn.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index afdcd68..e810ad5 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -1359,6 +1359,26 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, } else if (grandchild_pid == 0) { +#ifdef __linux__ + int fd = -1; + +#ifdef O_CLOEXEC + fd = open ("/proc/self/oom_score_adj", O_WRONLY | O_CLOEXEC); +#endif + + if (fd < 0) + { + fd = open ("/proc/self/oom_score_adj", O_WRONLY); + _dbus_fd_set_close_on_exec (fd); + } + + if (fd >= 0) + { + if (write (fd, "0", sizeof (char)) < 0) + _dbus_warn ("writing oom_score_adj error: %s\n", strerror (errno)); + _dbus_close (fd, NULL); + } +#endif /* Go back to ignoring SIGPIPE, since it's evil */ signal (SIGPIPE, SIG_IGN); -- 2.5.5