public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: src/librc/
Date: Fri, 20 Jun 2014 21:22:03 +0000 (UTC)	[thread overview]
Message-ID: <1403298107.9eb9b28d3e3b6725559fb38101ae869c1e4530ce.williamh@OpenRC> (raw)

commit:     9eb9b28d3e3b6725559fb38101ae869c1e4530ce
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Fri Jun 20 21:01:47 2014 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Fri Jun 20 21:01:47 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=9eb9b28d

librc: filter out container processes on OpenVZ host

Thanks to info and testing done by Daniel Robbins <drobbins <AT> funtoo.org>,
there is now a fix for this. Below is his description of the steps
OpenRC needed to use.

1) See if /proc/<pid>/status exists
2) If it does, see if it has a "envID:" field
3) If it does, see if "envID:" is set to "0"
4) If so, then it's one of the host's processes and should be a
candidate for the list. Otherwise, it is one of the container's
processes and should be ignored.

This should fix the bug and allow start-stop-daemon to work properly on
OpenVZ hosts.

X-Gentoo-Bug: 376817
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=376817

---
 src/librc/librc-daemon.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index e98b02c..a53e6e1 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -90,6 +90,11 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
 {
 	DIR *procdir;
 	struct dirent *entry;
+	FILE *fp;
+	bool container_pid = false;
+	bool openvz_host = false;
+	char *line = NULL;
+	size_t len = 0;
 	pid_t p;
 	char buffer[PATH_MAX];
 	struct stat sb;
@@ -117,6 +122,26 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
 			runscript_pid = 0;
 	}
 
+	/*
+	If /proc/self/status contains EnvID: 0, then we are an OpenVZ host,
+	and we will need to filter out processes that are inside containers
+	from our list of pids.
+	*/
+
+	if (exists("/proc/self/status")) {
+		fp = fopen("/proc/self/status", "r");
+		if (fp) {
+			while(! feof(fp)) {
+				rc_getline(&line, &len, fp);
+				if (strncmp(line, "envID:\t0", 8) == 0) {
+					openvz_host = true;
+					break;
+				}
+			}
+			fclose(fp);
+		}
+	}
+
 	while ((entry = readdir(procdir)) != NULL) {
 		if (sscanf(entry->d_name, "%d", &p) != 1)
 			continue;
@@ -134,6 +159,25 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
 		if (argv &&
 		    !pid_is_argv(p, (const char *const *)argv))
 			continue;
+		/* If this is an OpenVZ host, filter out container processes */
+		if (openvz_host) {
+			snprintf(buffer, sizeof(buffer), "/proc/%d/status", p);
+			if (exists(buffer)) {
+				fp = fopen(buffer, "r");
+				if (! fp)
+					continue;
+				while (! feof(fp)) {
+					rc_getline(&line, &len, fp);
+					if (strncmp(line, "envID:", 6) == 0) {
+						container_pid = ! (strncmp(line, "envID:\t0", 8) == 0);
+						break;
+					}
+				}
+				fclose(fp);
+			}
+		}
+		if (container_pid)
+			continue;
 		if (!pids) {
 			pids = xmalloc(sizeof(*pids));
 			LIST_INIT(pids);
@@ -142,6 +186,8 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
 		pi->pid = p;
 		LIST_INSERT_HEAD(pids, pi, entries);
 	}
+	if (line != NULL)
+		free(line);
 	closedir(procdir);
 	return pids;
 }


             reply	other threads:[~2014-06-20 21:22 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-20 21:22 William Hubbs [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-08-06 22:52 [gentoo-commits] proj/openrc:master commit in: src/librc/ William Hubbs
2018-06-28 18:03 William Hubbs
2018-06-22 20:57 William Hubbs
2018-06-20 22:45 William Hubbs
2018-05-22 22:12 William Hubbs
2018-05-22 22:12 William Hubbs
2017-11-30 19:58 William Hubbs
2017-11-14 19:22 William Hubbs
2017-10-26 18:58 William Hubbs
2017-10-24 15:43 William Hubbs
2016-12-20  0:29 William Hubbs
2016-08-15 18:48 William Hubbs
2016-01-19  6:12 William Hubbs
2016-01-19  6:12 William Hubbs
2016-01-19  6:12 William Hubbs
2016-01-19  6:12 William Hubbs
2015-12-08 18:53 William Hubbs
2015-11-05 18:53 William Hubbs
2015-11-05 18:53 William Hubbs
2015-05-04 15:10 William Hubbs
2015-01-12 16:44 William Hubbs
2014-11-01 22:05 William Hubbs
2014-10-24 15:45 William Hubbs
2014-10-23 19:13 William Hubbs
2014-10-23 17:57 William Hubbs
2014-10-20 20:59 William Hubbs
2014-07-19 18:06 William Hubbs
2013-10-21 19:53 William Hubbs
2013-10-04 19:07 William Hubbs
2013-10-04 19:07 William Hubbs
2013-04-14  3:45 William Hubbs
2012-10-05  3:28 William Hubbs
2012-02-25 21:02 William Hubbs
2012-02-25 16:57 Christian Ruppert
2012-01-30 19:33 William Hubbs
2012-01-24 18:41 Christian Ruppert
2012-01-21  3:41 William Hubbs
2012-01-16 18:16 William Hubbs
2012-01-15  0:05 Christian Ruppert
2011-11-07 15:58 William Hubbs
2011-07-13 19:39 Christian Ruppert
2011-07-09 21:15 Christian Ruppert
2011-06-28 16:47 Christian Ruppert
2011-05-28 16:02 Mike Frysinger
2011-04-28  0:18 William Hubbs
2011-04-28  0:18 William Hubbs
2011-04-09 19:56 William Hubbs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403298107.9eb9b28d3e3b6725559fb38101ae869c1e4530ce.williamh@OpenRC \
    --to=williamh@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox