[oe-commits] [openembedded-core] 107/116: pseudo: Add additional logging to the pseudo client

git at git.openembedded.org git at git.openembedded.org
Sun Feb 28 11:30:33 UTC 2016


rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 7d9cc50717464d86063bc1cea2d4da883e37299d
Author: Mark Hatle <mark.hatle at windriver.com>
AuthorDate: Tue Feb 16 16:44:29 2016 -0600

    pseudo: Add additional logging to the pseudo client
    
    [YOCTO #9112]
    
    Add logging to the client, in the case of an abort during setup it should dump
    the abort message to the log in the workdir.
    
    Signed-off-by: Mark Hatle <mark.hatle at windriver.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/conf/bitbake.conf                             |   1 +
 .../pseudo/files/pseudo-client-diagnostics.patch   |  66 +++++++++++
 .../pseudo/files/pseudo-fix-client-logging.patch   | 124 +++++++++++++++++++++
 meta/recipes-devtools/pseudo/pseudo_1.7.5.bb       |   2 +
 4 files changed, 193 insertions(+)

diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 1c43d73..dde3bfb 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -633,6 +633,7 @@ export PSEUDO_DISABLED = "1"
 FAKEROOTBASEENV = "PSEUDO_BINDIR=${STAGING_BINDIR_NATIVE} PSEUDO_LIBDIR=${STAGING_BINDIR_NATIVE}/../lib/pseudo/lib PSEUDO_PREFIX=${STAGING_BINDIR_NATIVE}/../../ PSEUDO_DISABLED=1"
 FAKEROOTCMD = "${STAGING_BINDIR_NATIVE}/pseudo"
 FAKEROOTENV = "PSEUDO_PREFIX=${STAGING_DIR_NATIVE}${prefix_native} PSEUDO_LOCALSTATEDIR=${PSEUDO_LOCALSTATEDIR} PSEUDO_PASSWD=${PSEUDO_PASSWD} PSEUDO_NOSYMLINKEXP=1 PSEUDO_DISABLED=0"
+FAKEROOTENV += "PSEUDO_DEBUG_FILE=${PSEUDO_LOCALSTATEDIR}/pseudo.log"
 FAKEROOTNOENV = "PSEUDO_UNLOAD=1"
 FAKEROOTDIRS = "${PSEUDO_LOCALSTATEDIR}"
 PREFERRED_PROVIDER_virtual/fakeroot-native ?= "pseudo-native"
diff --git a/meta/recipes-devtools/pseudo/files/pseudo-client-diagnostics.patch b/meta/recipes-devtools/pseudo/files/pseudo-client-diagnostics.patch
new file mode 100644
index 0000000..5663d3e
--- /dev/null
+++ b/meta/recipes-devtools/pseudo/files/pseudo-client-diagnostics.patch
@@ -0,0 +1,66 @@
+From 732790277cd0af97179c2781a2208c016b07b04f Mon Sep 17 00:00:00 2001
+From: Seebs <seebs at seebs.net>
+Date: Tue, 16 Feb 2016 13:14:39 -0600
+Subject: [PATCH 1/2] diagnostics for testing
+
+Signed-off-by: Mark Hatle <mark.hatle at windriver.com>
+---
+ ChangeLog.txt   | 1 +
+ pseudo_client.c | 9 +++++++++
+ 2 files changed, 10 insertions(+)
+
+diff --git a/ChangeLog.txt b/ChangeLog.txt
+index eb72127..21db528 100644
+--- a/ChangeLog.txt
++++ b/ChangeLog.txt
+@@ -1,5 +1,6 @@
+ 2016-02-09:
+         * (seebs) 1.7.5 release
++	* (seebs) attempt at diagnostics for client failures
+ 
+ 2016-02-08:
+         * (seebs) require -S to shutdown server when running a command.
+diff --git a/pseudo_client.c b/pseudo_client.c
+index b02657f..da5e376 100644
+--- a/pseudo_client.c
++++ b/pseudo_client.c
+@@ -1215,6 +1215,8 @@ pseudo_client_setup(void) {
+ }
+ 
+ #define PSEUDO_RETRIES 50
++static char *fail_reasons[PSEUDO_RETRIES];
++
+ static pseudo_msg_t *
+ pseudo_client_request(pseudo_msg_t *msg, size_t len, const char *path) {
+ 	pseudo_msg_t *response = 0;
+@@ -1246,6 +1248,9 @@ pseudo_client_request(pseudo_msg_t *msg, size_t len, const char *path) {
+ 				int ms = (getpid() % 5) + 3 + tries;
+ 				struct timespec delay = { .tv_sec = 0, .tv_nsec = ms * 1000000 };
+ 				nanosleep(&delay, NULL);
++				fail_reasons[tries] = "client setup failed";
++			} else {
++				fail_reasons[tries] = "client thinks it started server";
+ 			}
+ 			continue;
+ 		}
+@@ -1257,6 +1262,7 @@ pseudo_client_request(pseudo_msg_t *msg, size_t len, const char *path) {
+ 			response = pseudo_msg_receive(connect_fd);
+ 			if (!response) {
+ 				pseudo_debug(PDBGF_CLIENT, "expected response did not occur; retrying\n");
++				fail_reasons[tries] = "no response from server";
+ 			} else {
+ 				if (response->type != PSEUDO_MSG_ACK) {
+ 					pseudo_debug(PDBGF_CLIENT, "got non-ack response %d\n", response->type);
+@@ -1271,6 +1277,9 @@ pseudo_client_request(pseudo_msg_t *msg, size_t len, const char *path) {
+ 		}
+ 	}
+ 	pseudo_diag("pseudo: server connection persistently failed, aborting.\n");
++	for (tries = 0; tries < PSEUDO_RETRIES; ++tries) {
++		pseudo_diag("  try %2d: %s\n", tries, fail_reasons[tries] ? fail_reasons[tries] : "not recorded");
++	}
+ 	abort();
+ 	return 0;
+ }
+-- 
+2.5.0
+
diff --git a/meta/recipes-devtools/pseudo/files/pseudo-fix-client-logging.patch b/meta/recipes-devtools/pseudo/files/pseudo-fix-client-logging.patch
new file mode 100644
index 0000000..29eb967
--- /dev/null
+++ b/meta/recipes-devtools/pseudo/files/pseudo-fix-client-logging.patch
@@ -0,0 +1,124 @@
+From 7ddd686f09c1af388b16cdaf892ab90cb3ed24be Mon Sep 17 00:00:00 2001
+From: Seebs <seebs at seebs.net>
+Date: Tue, 16 Feb 2016 17:40:01 -0600
+Subject: [PATCH 2/2] fixup for client moving pseudo debug fd to 2 even if fd 2
+ was in use
+
+Signed-off-by: Mark Hatle <mark.hatle at windriver.com>
+---
+ ChangeLog.txt     |  7 ++++++-
+ pseudo.h          |  2 +-
+ pseudo_server.c   | 10 +++++++++-
+ pseudo_util.c     | 13 +++++++------
+ pseudo_wrappers.c |  2 +-
+ 5 files changed, 24 insertions(+), 10 deletions(-)
+
+diff --git a/ChangeLog.txt b/ChangeLog.txt
+index 21db528..40e9235 100644
+--- a/ChangeLog.txt
++++ b/ChangeLog.txt
+@@ -1,6 +1,11 @@
++2016-02-16:
++	* (seebs) attempt at diagnostics for client failures
++	* (seebs) don't try to force pseudo's debug fd to fd 2 in clients.
++	  Also, don't allow server to end up with a client on fd 2, whether
++	  or not fd 2 is already in use.
++
+ 2016-02-09:
+         * (seebs) 1.7.5 release
+-	* (seebs) attempt at diagnostics for client failures
+ 
+ 2016-02-08:
+         * (seebs) require -S to shutdown server when running a command.
+diff --git a/pseudo.h b/pseudo.h
+index 81db201..eb8d3da 100644
+--- a/pseudo.h
++++ b/pseudo.h
+@@ -82,7 +82,7 @@ extern char *pseudo_get_prefix(char *);
+ extern char *pseudo_get_bindir(void);
+ extern char *pseudo_get_libdir(void);
+ extern char *pseudo_get_localstatedir(void);
+-extern int pseudo_logfile(char *defname);
++extern int pseudo_logfile(char *defname, int prefer_fd);
+ extern ssize_t pseudo_sys_path_max(void);
+ extern ssize_t pseudo_path_max(void);
+ #define PSEUDO_PWD_MAX 4096
+diff --git a/pseudo_server.c b/pseudo_server.c
+index 4ceaa47..7127082 100644
+--- a/pseudo_server.c
++++ b/pseudo_server.c
+@@ -165,7 +165,7 @@ pseudo_server_start(int daemonize) {
+ 		pseudo_new_pid();
+ 		fclose(stdin);
+ 		fclose(stdout);
+-		pseudo_logfile(PSEUDO_LOGFILE);
++		pseudo_logfile(PSEUDO_LOGFILE, 2);
+ 	} else {
+ 		/* Write the pid if we don't daemonize */
+ 		pseudo_server_write_pid(getpid());
+@@ -480,6 +480,14 @@ pseudo_server_loop(void) {
+ 			     FD_ISSET(clients[0].fd, &reads))) {
+ 				len = sizeof(client);
+ 				if ((fd = accept(listen_fd, (struct sockaddr *) &client, &len)) != -1) {
++					/* Don't allow clients to end up on fd 2, because glibc's
++					 * malloc debug uses that fd unconditionally.
++					 */
++					if (fd == 2) {
++						int newfd = fcntl(fd, F_DUPFD, 3);
++						close(fd);
++						fd = newfd;
++					}
+ 					pseudo_debug(PDBGF_SERVER, "new client fd %d\n", fd);
+ 					open_client(fd);
+                                         /* A new client implicitly cancels any
+diff --git a/pseudo_util.c b/pseudo_util.c
+index c81df5a..9d24362 100644
+--- a/pseudo_util.c
++++ b/pseudo_util.c
+@@ -1313,7 +1313,7 @@ pseudo_etc_file(const char *file, char *realname, int flags, const char **search
+ 
+ /* set up a log file */
+ int
+-pseudo_logfile(char *defname) {
++pseudo_logfile(char *defname, int prefer_fd) {
+ 	char *pseudo_path;
+ 	char *filename = pseudo_get_value("PSEUDO_DEBUG_FILE");
+ 	char *s;
+@@ -1401,15 +1401,16 @@ pseudo_logfile(char *defname) {
+ 	if (fd == -1) {
+ 		pseudo_diag("help: can't open log file %s: %s\n", pseudo_path, strerror(errno));
+ 	} else {
+-		/* try to force fd to 2.  We do this because glibc's malloc
++		/* try to force fd to prefer_fd.  We do this because glibc's malloc
+ 		 * debug unconditionally writes to fd 2, and we don't want
+ 		 * a client process ending op on fd 2, or server debugging
+-		 * becomes a nightmare.
++		 * becomes a nightmare. So, server sets prefer_fd to 2. Client
++		 * leaves it at -1.
+ 		 */
+-		if (fd != 2) {
++		if (prefer_fd >= 0 && fd != prefer_fd) {
+ 			int newfd;
+-			close(2);
+-			newfd = dup2(fd, 2);
++			close(prefer_fd);
++			newfd = dup2(fd, prefer_fd);
+ 			if (newfd != -1) {
+ 				fd = newfd;
+ 			}
+diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c
+index 34d7f23..ba8b52d 100644
+--- a/pseudo_wrappers.c
++++ b/pseudo_wrappers.c
+@@ -182,7 +182,7 @@ pseudo_init_wrappers(void) {
+ 	/* Once the wrappers are setup, we can now use open... so
+ 	 * setup the logfile, if necessary...
+ 	 */
+-	pseudo_logfile(NULL);
++	pseudo_logfile(NULL, -1);
+ 
+ 	pseudo_magic();
+ 	pseudo_droplock();
+-- 
+2.5.0
+
diff --git a/meta/recipes-devtools/pseudo/pseudo_1.7.5.bb b/meta/recipes-devtools/pseudo/pseudo_1.7.5.bb
index 88bd1f5..071fc71 100644
--- a/meta/recipes-devtools/pseudo/pseudo_1.7.5.bb
+++ b/meta/recipes-devtools/pseudo/pseudo_1.7.5.bb
@@ -5,6 +5,8 @@ SRC_URI = " \
     file://0001-configure-Prune-PIE-flags.patch \
     file://fallback-passwd \
     file://fallback-group \
+    file://pseudo-client-diagnostics.patch \
+    file://pseudo-fix-client-logging.patch \
 "
 
 SRC_URI[md5sum] = "c10209938f03128d0c193f041ff3596d"

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list