[PATCH v2] Add an option for raising Strauss awareness

Eugene Syromyatnikov evgsyr at gmail.com
Mon Apr 1 18:55:00 UTC 2019


As Der Strauss is the strace mascot and also an endangered species,
it is now strace's responsibility to raise awareness about it.

* straus.c: New file.
* straus.h: New header.
* Makefile.am (strace_SOURCES): Add them.
* strace.c: Include "straus.h".
(version_verbosity): New static variable.
(print_version): Add verbosity argument, call print_straus.
(increase_version_verbosity): New function.
(init) <case 'V'>: Call increase_version_verbosity.
(init): Call print_version and exit if version_verbosity is non-zero.
* tests/straus_body.exp: New file.
* tests/straus_head.exp: Likewise.
* tests/Makefile.am (EXTRA_DIST): Add them.
* tests/strace-V.test: Update expected output, add checks.
* strace.1.in: Document it.
* NEWS: Mention it.
---
 Makefile.am           |  2 ++
 NEWS                  |  3 +++
 strace.1.in           |  2 ++
 strace.c              | 23 +++++++++++++---
 straus.c              | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 straus.h              | 19 +++++++++++++
 tests/Makefile.am     |  2 ++
 tests/strace-V.test   | 37 +++++++++++++++++++-------
 tests/straus_body.exp | 26 ++++++++++++++++++
 tests/straus_head.exp | 11 ++++++++
 10 files changed, 186 insertions(+), 13 deletions(-)
 create mode 100644 straus.c
 create mode 100644 straus.h
 create mode 100644 tests/straus_body.exp
 create mode 100644 tests/straus_head.exp

diff --git a/Makefile.am b/Makefile.am
index 56987ae..c052bc7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -309,6 +309,8 @@ strace_SOURCES =	\
 	statx.c		\
 	statx.h		\
 	strace.c	\
+	straus.c	\
+	straus.h	\
 	string_to_uint.c \
 	string_to_uint.h \
 	swapon.c	\
diff --git a/NEWS b/NEWS
index cf63dea..be43c2d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,9 @@
 Noteworthy changes in release ?.? (????-??-??)
 ==============================================
 
+* Improvements
+  * Added an ability to raise Strauss awareness.
+
 * Bug fixes
   * Fixed decoding of last two arguments of clone syscall on riscv.
 
diff --git a/strace.1.in b/strace.1.in
index 76a7411..adcc942 100644
--- a/strace.1.in
+++ b/strace.1.in
@@ -914,6 +914,8 @@ Print the help summary.
 .B \-V
 Print the version number of
 .BR strace .
+Multiple instances of the option beyond specific threshold tend to increase
+Strauss awareness.
 .SH DIAGNOSTICS
 When
 .I command
diff --git a/strace.c b/strace.c
index ca8d558..7078b09 100644
--- a/strace.c
+++ b/strace.c
@@ -37,6 +37,7 @@
 #include "ptrace_syscall_info.h"
 #include "scno.h"
 #include "printsiginfo.h"
+#include "straus.h"
 #include "trace_event.h"
 #include "xstring.h"
 #include "delay.h"
@@ -79,6 +80,8 @@ static unsigned int tflag;
 static bool rflag;
 static bool print_pid_pfx;
 
+static unsigned int version_verbosity;
+
 /* -I n */
 enum {
 	INTR_NOT_SET        = 0,
@@ -196,7 +199,7 @@ strerror(int err_no)
 #endif /* HAVE_STERRROR */
 
 static void
-print_version(void)
+print_version(unsigned int verbosity)
 {
 	static const char features[] =
 #ifdef ENABLE_STACKTRACE
@@ -228,6 +231,9 @@ print_version(void)
 	       PACKAGE_NAME, PACKAGE_VERSION, COPYRIGHT_YEAR, PACKAGE_URL);
 	printf("\nOptional features enabled:%s\n",
 	       features[0] ? features : " (none)");
+
+	/* Raise straus awareness */
+	print_straus(verbosity);
 }
 
 static void
@@ -1547,6 +1553,13 @@ set_sighandler(int signo, void (*sighandler)(int), struct sigaction *oldact)
 	sigaction(signo, &sa, oldact);
 }
 
+static void
+increase_version_verbosity(void)
+{
+	if (version_verbosity < (STRAUS_START_VERBOSITY + straus_lines))
+		version_verbosity++;
+}
+
 /*
  * Initialization part of main() was eating much stack (~0.5k),
  * which was unused after init.
@@ -1691,8 +1704,7 @@ init(int argc, char *argv[])
 			qualify("abbrev=none");
 			break;
 		case 'V':
-			print_version();
-			exit(0);
+			increase_version_verbosity();
 			break;
 		case 'w':
 			count_wallclock = 1;
@@ -1722,6 +1734,11 @@ init(int argc, char *argv[])
 		}
 	}
 
+	if (version_verbosity) {
+		print_version(version_verbosity);
+		exit(0);
+	}
+
 	argv += optind;
 	argc -= optind;
 
diff --git a/straus.c b/straus.c
new file mode 100644
index 0000000..93fa6bc
--- /dev/null
+++ b/straus.c
@@ -0,0 +1,74 @@
+/*
+ * Strauss awareness implementation.
+ *
+ * Copyright (c) 2018-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "defs.h"
+
+#include "straus.h"
+
+static const char *straus[] = {
+	"                         ",
+	"     ____                ",
+	"    /    \\               ",
+	"   |-. .-.|              ",
+	"   (_@)(_@)              ",
+	"   .---_  \\              ",
+	"  /..   \\_/              ",
+	"  |__.-^ /               ",
+	"      }  |               ",
+	"     |   [               ",
+	"     [  ]                ",
+	"    ]   |                ",
+	"    |   [                ",
+	"    [  ]                 ",
+	"   /   |        __       ",
+	"  \\|   |/     _/ /_      ",
+	" \\ |   |//___/__/__/_    ",
+	"\\\\  \\ /  //    -____/_   ",
+	"//   \"   \\\\      \\___.-  ",
+	" //     \\\\  __.----._/_  ",
+	"/ //|||\\\\ .-         __> ",
+	"[        /         __.-  ",
+	"[        [           }   ",
+	"\\        \\          /    ",
+	" \"-._____ \\.____.--\"     ",
+	"    |  | |  |            ",
+	"    |  | |  |            ",
+	"    |  | |  |            ",
+	"    |  | |  |            ",
+	"    {  } {  }            ",
+	"    |  | |  |            ",
+	"    |  | |  |            ",
+	"    |  | |  |            ",
+	"    /  { |  |            ",
+	" .-\"   / [   -._         ",
+	"/___/ /   \\ \\___\"-.      ",
+	"    -\"     \"-            ",
+	"                         ",
+	"                         ",
+	"                         ",
+	"There's nothing more here, really.",
+	"                         ",
+	"                         ",
+	"                         ",
+	"...so far.               ",
+	};
+
+const size_t straus_lines = ARRAY_SIZE(straus);
+
+void
+print_straus(size_t verbosity)
+{
+	if (verbosity < STRAUS_START_VERBOSITY)
+		return;
+
+	verbosity = MIN(verbosity - STRAUS_START_VERBOSITY, straus_lines);
+
+	for (size_t i = 0; i < verbosity; i++)
+		puts(straus[i]);
+}
diff --git a/straus.h b/straus.h
new file mode 100644
index 0000000..04864b5
--- /dev/null
+++ b/straus.h
@@ -0,0 +1,19 @@
+/*
+ * Strauss awareness interface declarations.
+ *
+ * Copyright (c) 2018-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef STRACE_STRAUS_H
+#define STRACE_STRAUS_H
+
+enum { STRAUS_START_VERBOSITY = 5 };
+
+extern const size_t straus_lines;
+
+extern void print_straus(size_t verbosity);
+
+#endif /* STRACE_STRAUS_H */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9e99aff..cbba044 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -432,6 +432,8 @@ EXTRA_DIST = \
 	strace-k.test \
 	strace-r.expected \
 	strace.supp \
+	straus_body.exp \
+	straus_head.exp \
 	sun_path.expected \
 	syntax.sh \
 	trace_fstat.in \
diff --git a/tests/strace-V.test b/tests/strace-V.test
index a0274c2..92f1770 100755
--- a/tests/strace-V.test
+++ b/tests/strace-V.test
@@ -6,8 +6,6 @@
 run_prog_skip_if_failed date +%Y > /dev/null
 year="$(date +%Y)"
 
-run_strace -V > "$LOG"
-
 getstr()
 {
 	sed -r -n 's/#define[[:space:]]*'"$1"'[[:space:]]*"([^"]*)".*/\1/p' \
@@ -57,13 +55,32 @@ esac
 features="${option_unwind}${option_demangle}${option_m32}${option_mx32}"
 [ -n "$features" ] || features=" (none)"
 
-cat > "$EXP" << __EOF__
-$(getstr PACKAGE_NAME) -- version $(getstr PACKAGE_VERSION)
-Copyright (c) 1991-${config_year} The strace developers <$(getstr PACKAGE_URL)>.
-This is free software; see the source for copying conditions.  There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+for i in $(seq 4); do
+	case "$i" in
+		1) opt="-V";;
+		2) opt="-V -V -V -V";;
+		3) opt="-VVVV -VVVV -VVVV -VVVV";;
+		4) opt="-VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV";;
+	esac
+
+	run_strace ${opt} > "${LOG}.${opt}"
+
+	cat > "${EXP}.${opt}" <<-__EOF__
+		$(getstr PACKAGE_NAME) -- version $(getstr PACKAGE_VERSION)
+		Copyright (c) 1991-${config_year} The strace developers <$(getstr PACKAGE_URL)>.
+		This is free software; see the source for copying conditions.  There is NO
+		warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+		Optional features enabled:${features}
+	__EOF__
 
-Optional features enabled:${features}
-__EOF__
+	if [ 3 -le "$i" ]; then
+		cat ../straus_head.exp >> "${EXP}.${opt}"
+	fi
+
+	if [ 4 -le "$i" ]; then
+		cat ../straus_body.exp >> "${EXP}.${opt}"
+	fi
 
-match_diff "$LOG" "$EXP"
+	match_diff "${LOG}.${opt}" "${EXP}.${opt}"
+done
diff --git a/tests/straus_body.exp b/tests/straus_body.exp
new file mode 100644
index 0000000..a771bfa
--- /dev/null
+++ b/tests/straus_body.exp
@@ -0,0 +1,26 @@
+    ]   |                
+    |   [                
+    [  ]                 
+   /   |        __       
+  \|   |/     _/ /_      
+ \ |   |//___/__/__/_    
+\\  \ /  //    -____/_   
+//   "   \\      \___.-  
+ //     \\  __.----._/_  
+/ //|||\\ .-         __> 
+[        /         __.-  
+[        [           }   
+\        \          /    
+ "-._____ \.____.--"     
+    |  | |  |            
+    |  | |  |            
+    |  | |  |            
+    |  | |  |            
+    {  } {  }            
+    |  | |  |            
+    |  | |  |            
+    |  | |  |            
+    /  { |  |            
+ .-"   / [   -._         
+/___/ /   \ \___"-.      
+    -"     "-            
diff --git a/tests/straus_head.exp b/tests/straus_head.exp
new file mode 100644
index 0000000..70bd04b
--- /dev/null
+++ b/tests/straus_head.exp
@@ -0,0 +1,11 @@
+                         
+     ____                
+    /    \               
+   |-. .-.|              
+   (_@)(_@)              
+   .---_  \              
+  /..   \_/              
+  |__.-^ /               
+      }  |               
+     |   [               
+     [  ]                
-- 
2.1.4



More information about the Strace-devel mailing list