summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-02-06 16:50:50 +0100
committerThomas Haller <thaller@redhat.com>2023-02-08 10:11:17 +0100
commit4cf94f30c72bce47c5079e8534dda7f9b3c49869 (patch)
tree32362ea4fdd3eff3c1783319dc613861118b809b
parent4b2ded7a4aacc00107f216e577d46b8eaa7cf424 (diff)
downloadNetworkManager-4cf94f30c72bce47c5079e8534dda7f9b3c49869.tar.gz
nmcli: add nmc_print()/nmc_printerr() macros
These will replace the direct calls to g_print()/g_printerr() in nmcli. There are two purposes. 1) the new macros embody the concept of "printing something from nmcli". It means, we can `git grep` for those functions, and find all the relevant places, without hitting the irrelevant ones (e.g. tests that also use g_print()). 2) by having one place, we can trivially change it. That is useful for printf debugging. For example, "test-client.py" runs nmcli and captures and compares the output. With libnm we can set LIBNM_CLIENT_DEBUG and LIBNM_CLIENT_DEBUG_FILE to print libnm debug messages to a file. But we cannot trivially synchronize the messages from nmcli with that output (also because they are consumed by the test and not immediately accessible). This would be easy, if we temporarily could patch nmc_print*() to also log to nm_utils_print(). The new macros will allow doing that at one place. For example, patch the "#if 0" and run: $ LIBNM_CLIENT_DEBUG=trace \ LIBNM_CLIENT_DEBUG_FILE='xxx.%p' \ NMTST_USE_VALGRIND=1 \ LIBTOOL="/bin/sh ./libtool" ./src/tests/client/test-client.sh -- -k monitor
-rw-r--r--src/nmcli/utils.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/nmcli/utils.h b/src/nmcli/utils.h
index 3897cd2b87..5d9449f54b 100644
--- a/src/nmcli/utils.h
+++ b/src/nmcli/utils.h
@@ -369,4 +369,34 @@ gboolean nmc_print_table(const NmcConfig *nmc_config,
/*****************************************************************************/
+#if 0
+/* For manual testing to sync output with LIBNM_CLIENT_DEBUG/LIBNM_CLIENT_DEBUG_FILE */
+#define nmc_print(...) \
+ G_STMT_START \
+ { \
+ gs_free char *_ss = g_strdup_printf(__VA_ARGS__); \
+ gs_free char *_ss1 = g_strdup_printf("nmcli[out]: %s", _ss); \
+ \
+ nm_utils_print(0, _ss1); \
+ nm_utils_print(1, _ss); \
+ } \
+ G_STMT_END
+
+#define nmc_printerr(...) \
+ G_STMT_START \
+ { \
+ gs_free char *_ss = g_strdup_printf(__VA_ARGS__); \
+ gs_free char *_ss1 = g_strdup_printf("nmcli[err]: %s", _ss); \
+ \
+ nm_utils_print(0, _ss1); \
+ nm_utils_print(2, _ss); \
+ } \
+ G_STMT_END
+#else
+#define nmc_print(...) g_print(__VA_ARGS__)
+#define nmc_printerr(...) g_printerr(__VA_ARGS__)
+#endif
+
+/*****************************************************************************/
+
#endif /* NMC_UTILS_H */