diff mbox series

[meta] systemctl: allow instance names starting with numbers

Message ID 20230706232157.3602573-1-lincoln.ramsay@digi.com
State New
Headers show
Series [meta] systemctl: allow instance names starting with numbers | expand

Commit Message

lincoln.ramsay@digi.com July 6, 2023, 11:21 p.m. UTC
From: Lincoln Ramsay <lincoln.ramsay@digi.com>

Templated systemd service files can have an instance starting with
a number, but the poky systemctl replacement for building a rootfs
crafts a regex replacement pattern that uses \1, which is not
terminated, and when combined with the instance name leads to an
invalid expression.

For example, installing myservice@1a.service will cause a call to
re.sub with replacement \11a, which tries to use the 11th match,
while the pattern only has 1 match.

There is a terminated alternative syntax that avoids this issue.
\g<1> achieves the same result but doesn't break when the result
is \g<1>1a.

Signed-off-by: Lincoln Ramsay <lincoln.ramsay@digi.com>
---
 meta/recipes-core/systemd/systemd-systemctl/systemctl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ross Burton July 7, 2023, 10:10 a.m. UTC | #1
On 7 Jul 2023, at 00:21, Ramsay, Lincoln via lists.openembedded.org <Lincoln.Ramsay=digi.com@lists.openembedded.org> wrote:
> -                dependent = re.sub("([^%](%%)*)%i", "\\1{}".format(instance), dependent)
> +                dependent = re.sub("([^%](%%)*)%i", "\\g<1>{}".format(instance), dependent)

Interestingly, Yuta submitted the identical patch last week (queued for master).

Ross
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 514f747fe6..7fe751b397 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -202,7 +202,7 @@  class SystemdUnit():
         try:
             for dependent in config.get('Install', prop):
                 # expand any %i to instance (ignoring escape sequence %%)
-                dependent = re.sub("([^%](%%)*)%i", "\\1{}".format(instance), dependent)
+                dependent = re.sub("([^%](%%)*)%i", "\\g<1>{}".format(instance), dependent)
                 wants = systemdir / "{}.{}".format(dependent, dirstem) / service
                 add_link(wants, target)