crtools: Show command line in log

Submitted by Cyrill Gorcunov on Sept. 28, 2018, 4:33 p.m.

Details

Message ID 20180928163327.30610-1-gorcunov@virtuozzo.com
State New
Series "crtools: Show command line in log"
Headers show

Commit Message

Cyrill Gorcunov Sept. 28, 2018, 4:33 p.m.
From: Cyrill Gorcunov <gorcunov@gmail.com>

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

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

Patch hide | download patch | download mbox

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");