diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 337d6a208ab61e067fe8c6e1fe3fd97f42521ca6..abd883c73844d3aa65bdb86b0c6cd06329b8a174 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -38,17 +38,8 @@ VIR_LOG_INIT("util.systemd"); -/** - * virSystemdEscapeName: - * - * This function escapes various characters in @name and appends that - * escaped string to @buf, in order to comply with the requirements - * from systemd/machined. Parameter @full_escape decides whether to - * also escape dot as a first character and '-'. - */ static void virSystemdEscapeName(virBufferPtr buf, - const char *name, - bool full_escape) + const char *name) { static const char hextable[16] = "0123456789abcdef"; @@ -66,7 +57,7 @@ static void virSystemdEscapeName(virBufferPtr buf, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ ":-_.\\" - if (full_escape && *name == '.') { + if (*name == '.') { ESCAPE(*name); name++; } @@ -74,7 +65,7 @@ static void virSystemdEscapeName(virBufferPtr buf, while (*name) { if (*name == '/') virBufferAddChar(buf, '-'); - else if ((full_escape && *name == '-') || + else if (*name == '-' || *name == '\\' || !strchr(VALID_CHARS, *name)) ESCAPE(*name); @@ -94,9 +85,9 @@ char *virSystemdMakeScopeName(const char *name, virBuffer buf = VIR_BUFFER_INITIALIZER; virBufferAddLit(&buf, "machine-"); - virSystemdEscapeName(&buf, drivername, true); + virSystemdEscapeName(&buf, drivername); virBufferAddLit(&buf, "\\x2d"); - virSystemdEscapeName(&buf, name, true); + virSystemdEscapeName(&buf, name); virBufferAddLit(&buf, ".scope"); if (virBufferCheckError(&buf) < 0) @@ -113,7 +104,7 @@ char *virSystemdMakeSliceName(const char *partition) if (*partition == '/') partition++; - virSystemdEscapeName(&buf, partition, true); + virSystemdEscapeName(&buf, partition); virBufferAddLit(&buf, ".slice"); if (virBufferCheckError(&buf) < 0) @@ -139,7 +130,7 @@ char *virSystemdMakeMachineName(const char *name, virBufferAsprintf(&buf, "%s-%s-", username, drivername); } - virSystemdEscapeName(&buf, name, false); + virSystemdEscapeName(&buf, name); machinename = virBufferContentAndReset(&buf); cleanup: diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 49d37c2032ecd4c6a3a6f98d8ee7f8ac18e17aea..06fec5495bc2e4aa5937214c7e4402c52eb09ad0 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -517,9 +517,9 @@ mymain(void) } while (0) TEST_MACHINE("demo", "qemu-demo"); - TEST_MACHINE("demo-name", "qemu-demo-name"); + TEST_MACHINE("demo-name", "qemu-demo\\x2dname"); TEST_MACHINE("demo!name", "qemu-demo\\x21name"); - TEST_MACHINE(".demo", "qemu-.demo"); + TEST_MACHINE(".demo", "qemu-\\x2edemo"); TEST_MACHINE("bull\U0001f4a9", "qemu-bull\\xf0\\x9f\\x92\\xa9"); # define TESTS_PM_SUPPORT_HELPER(name, function) \