[OE-core] [PATCH 1/1] pseudo: add prefix for log and make log consistent

Robert Yang liezhi.yang at windriver.com
Wed Sep 28 06:22:24 UTC 2016


The log messages might not be consistent when the same error happens,
part of the log messages go to terminial, and part of them go to
pseudo.log, and these code use multiprocesses, which makes it very hard
to understand, for example:
$ kill -9 `ps aux | grep /usr/bin/pseud | awk '{print $2}'`
$ /path/to/usr/bin/pseudo & /path/to/usr/bin/pseudo

Messages printed to terminal:
  Child process exit status 4: lock_held
Messages printed to pseudo.log:
  pseudo: lock already held by existing pid 34028.
  pseudo: Couldn't obtain lock: Resource temporarily unavailable.

They are messages for one error, so that they should be consistent, this
patch fixes the problem, they will go into pseudo.log now.

This patch also adds log prefix "pseudo: " for the message to show where
they are from.

Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
---
 ...er.c-add-prefix-for-log-and-make-log-cons.patch | 83 ++++++++++++++++++++++
 meta/recipes-devtools/pseudo/pseudo_1.8.1.bb       |  1 +
 2 files changed, 84 insertions(+)
 create mode 100644 meta/recipes-devtools/pseudo/files/0001-pseudo_server.c-add-prefix-for-log-and-make-log-cons.patch

diff --git a/meta/recipes-devtools/pseudo/files/0001-pseudo_server.c-add-prefix-for-log-and-make-log-cons.patch b/meta/recipes-devtools/pseudo/files/0001-pseudo_server.c-add-prefix-for-log-and-make-log-cons.patch
new file mode 100644
index 0000000..e9cf3ba
--- /dev/null
+++ b/meta/recipes-devtools/pseudo/files/0001-pseudo_server.c-add-prefix-for-log-and-make-log-cons.patch
@@ -0,0 +1,83 @@
+From 505ea70ff63da3645243a7f3e4359432b11c3dd9 Mon Sep 17 00:00:00 2001
+From: Robert Yang <liezhi.yang at windriver.com>
+Date: Tue, 27 Sep 2016 19:39:03 -0700
+Subject: [PATCH] pseudo_server.c: add prefix for log and make log consistent
+
+The log messages might not be consistent when the same error happens,
+part of the log messages go to terminial, and part of them go to
+pseudo.log, and these code use multiprocesses, which makes it very hard
+to understand, for example:
+$ kill -9 `ps aux | grep /usr/bin/pseud | awk '{print $2}'`
+$ /path/to/usr/bin/pseudo & /path/to/usr/bin/pseudo
+
+Messages printed to terminal:
+  Child process exit status 4: lock_held
+Messages printed to pseudo.log:
+  pseudo: lock already held by existing pid 34028.
+  pseudo: Couldn't obtain lock: Resource temporarily unavailable.
+
+They are messages for one error, so that they should be consistent, this
+patch fixes the problem, they will go into pseudo.log now.
+
+This patch also adds log prefix "pseudo: " for the message to show where
+they are from.
+
+Upstream-Status: Pending
+
+Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
+---
+ pseudo_server.c | 9 ++++++---
+ pseudo_util.c   | 3 +++
+ 2 files changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/pseudo_server.c b/pseudo_server.c
+index 8731d20..31e7b0a 100644
+--- a/pseudo_server.c
++++ b/pseudo_server.c
+@@ -168,6 +168,12 @@ pseudo_server_start(int daemonize) {
+ 				strerror(errno));
+ 			exit(PSEUDO_EXIT_FORK_FAILED);
+ 		}
++
++		/* log messages will go into pseudo.log from here */
++		fclose(stdin);
++		fclose(stdout);
++		pseudo_debug_logfile(PSEUDO_LOGFILE, 2);
++
+ 		if (child) {
+ 			int status;
+ 			int rc;
+@@ -229,9 +235,6 @@ pseudo_server_start(int daemonize) {
+ 		} else {
+ 			/* detach from parent session */
+ 			setsid();
+-			fclose(stdin);
+-			fclose(stdout);
+-			pseudo_debug_logfile(PSEUDO_LOGFILE, 2);
+ 			/* and then just execute the server code normally.  */
+ 			/* Any logging will presumably go to logfile, but
+ 			 * exit status will make it back to the parent for
+diff --git a/pseudo_util.c b/pseudo_util.c
+index 0c156cf..3948c93 100644
+--- a/pseudo_util.c
++++ b/pseudo_util.c
+@@ -494,6 +494,8 @@ pseudo_diag(char *fmt, ...) {
+ 	va_list ap;
+ 	char debuff[8192];
+ 	int len;
++	/* log prefix */
++	char *pseudo_log_prefix = "pseudo: ";
+ 	/* gcc on Ubuntu 8.10 requires that you examine the return from
+ 	 * write(), and won't let you cast it to void.  Of course, if you
+ 	 * can't print error messages, there's nothing to do.
+@@ -507,6 +509,7 @@ pseudo_diag(char *fmt, ...) {
+ 	if (len > 8192)
+ 		len = 8192;
+ 
++	wrote += write(pseudo_util_debug_fd, pseudo_log_prefix, strlen(pseudo_log_prefix));
+ 	if (debugged_newline && (pseudo_util_debug_flags & PDBGF_PID)) {
+ 		wrote += write(pseudo_util_debug_fd, pid_text, pid_len);
+ 	}
+-- 
+2.9.0
+
diff --git a/meta/recipes-devtools/pseudo/pseudo_1.8.1.bb b/meta/recipes-devtools/pseudo/pseudo_1.8.1.bb
index cec2149..fa614cd 100644
--- a/meta/recipes-devtools/pseudo/pseudo_1.8.1.bb
+++ b/meta/recipes-devtools/pseudo/pseudo_1.8.1.bb
@@ -7,6 +7,7 @@ SRC_URI = "http://downloads.yoctoproject.org/releases/pseudo/${BPN}-${PV}.tar.bz
            file://moreretries.patch \
            file://Fix-xattr-performance.patch \
            file://0001-Don-t-send-SIGUSR1-to-init.patch \
+           file://0001-pseudo_server.c-add-prefix-for-log-and-make-log-cons.patch \
            "
 
 SRC_URI[md5sum] = "ee38e4fb62ff88ad067b1a5a3825bac7"
-- 
2.9.0




More information about the Openembedded-core mailing list