[CRIU] [PATCH] crtools: Show command line in log

Cyrill Gorcunov gorcunov at gmail.com
Fri Sep 28 19:33:27 MSK 2018


From: Cyrill Gorcunov <gorcunov at gmail.com>

For easier debug lets show unmodified command line
on debug log level.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/crtools.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/criu/crtools.c b/criu/crtools.c
index 1697e9592..70efb0b53 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -229,6 +229,25 @@ static void rlimit_unlimit_nofile_self(void)
 		pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n");
 }
 
+/*
+ * Hopefully 16K of memory gonna be enough
+ * to keep all arguments
+ */
+#define ARGV_COPY_LEN	((16 << 10) - 1)
+static char argv_copy[ARGV_COPY_LEN + 1];
+
+static void argv_init(int argc, char *argv[])
+{
+	size_t pos, i;
+
+	for (pos = i = 0; pos < ARGV_COPY_LEN && i < argc; i++) {
+		char *p = strncpy(&argv_copy[pos], argv[i], ARGV_COPY_LEN - pos);
+		pos += strlen(p);
+		if (pos < ARGV_COPY_LEN)
+			argv_copy[pos++] = ' ';
+	}
+}
+
 static int early_init(void)
 {
 	/*
@@ -369,6 +388,7 @@ int main(int argc, char *argv[], char *envp[])
 	if (argc < 2)
 		goto usage;
 
+	argv_init(argc, argv);
 	init_opts();
 
 	if (!strcmp(argv[1], "swrk")) {
@@ -751,6 +771,12 @@ int main(int argc, char *argv[], char *envp[])
 	if (log_init(opts.output))
 		return 1;
 
+	/*
+	 * Show the complete untouched
+	 * command line for debug sake.
+	 */
+	pr_debug("%s\n", argv_copy);
+
 	if (opts.deprecated_ok)
 		pr_debug("DEPRECATED ON\n");
 
-- 
2.17.1



More information about the CRIU mailing list