summaryrefslogtreecommitdiff
path: root/src/test/test-process-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-11 00:10:02 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-05-05 13:59:23 +0200
commit99009ed0f490b89fa14ca323a9ffb9b963980822 (patch)
treedc1e6b0f6eb506f9bca8225468830268c47146db /src/test/test-process-util.c
parent07468a16e46dba9da8b9c8593e0c2ee5bfec3c69 (diff)
downloadsystemd-99009ed0f490b89fa14ca323a9ffb9b963980822.tar.gz
basic/process-util: add mode where posix shell escape is used for quoting
The new flag is not used, except in tests, so no functional change yet. This way, the command as shown can be copied-and-pasted into the shell in more cases. For simple cases, shell quoting with "" is enough. But $'' is needed when there are control characters in the command.
Diffstat (limited to 'src/test/test-process-util.c')
-rw-r--r--src/test/test-process-util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 957d23ffc5..f79df46d29 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -431,6 +431,7 @@ static void test_get_process_cmdline_harder(void) {
#define CMDLINE1 "foo\0'bar'\0\"bar$\"\0x y z\0!``\0"
#define EXPECT1 "foo \"'bar'\" \"\\\"bar\\$\\\"\" \"x y z\" \"!\\`\\`\" \"\""
+#define EXPECT1p "foo $'\\'bar\\'' $'\"bar$\"' $'x y z' $'!``' \"\""
assert_se(lseek(fd, SEEK_SET, 0) == 0);
assert_se(write(fd, CMDLINE1, sizeof CMDLINE1) == sizeof CMDLINE1);
assert_se(ftruncate(fd, sizeof CMDLINE1) == 0);
@@ -441,8 +442,15 @@ static void test_get_process_cmdline_harder(void) {
assert_se(streq(line, EXPECT1));
line = mfree(line);
+ assert_se(get_process_cmdline(0, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX, &line) >= 0);
+ log_debug("got: ==%s==", line);
+ log_debug("exp: ==%s==", EXPECT1p);
+ assert_se(streq(line, EXPECT1p));
+ line = mfree(line);
+
#define CMDLINE2 "foo\0\1\2\3\0\0"
#define EXPECT2 "foo \"\\001\\002\\003\" \"\" \"\""
+#define EXPECT2p "foo $'\\001\\002\\003' \"\" \"\""
assert_se(lseek(fd, SEEK_SET, 0) == 0);
assert_se(write(fd, CMDLINE2, sizeof CMDLINE2) == sizeof CMDLINE2);
assert_se(ftruncate(fd, sizeof CMDLINE2) == 0);
@@ -453,6 +461,12 @@ static void test_get_process_cmdline_harder(void) {
assert_se(streq(line, EXPECT2));
line = mfree(line);
+ assert_se(get_process_cmdline(0, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX, &line) >= 0);
+ log_debug("got: ==%s==", line);
+ log_debug("exp: ==%s==", EXPECT2p);
+ assert_se(streq(line, EXPECT2p));
+ line = mfree(line);
+
safe_close(fd);
_exit(EXIT_SUCCESS);
}