]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
profile/systemd-osc-context: do not zero-pad pid value
authorRasmus Villemoes <rv@rasmusvillemoes.dk>
Mon, 20 Jul 2026 13:04:21 +0000 (15:04 +0200)
committerRasmus Villemoes <rv@rasmusvillemoes.dk>
Tue, 21 Jul 2026 09:06:30 +0000 (11:06 +0200)
The %.20d specifier was introduced in 2d738a0aee ("profile/systemd-osc-context:
Enforce length limits"). But, for numeric conversions, the precision is not an
upper bound, but rather a lower bound on the output width, padding as necessary
with 0 on the left. So as-is, this does not in fact limit the output to at most
20 characters.

Of course, in practice, pids on linux are never greater than 2^22, and
certainly never larger than what would fit in a 20-digit decimal. On the other
hand, that more or less guarantees that the pid= field is always emitted with
12+ leadings zeroes, which is a bit silly. Moreover, a leading 0 can cause a
parser to treat it as octal.

Since $$ does expand to the PID in decimal, just print that as a string, with the
enforced 20 character limit.

profile.d/80-systemd-osc-context.sh

index 9bbb71285fa30fda6733e1fcd457393f1e736bb5..6e6812ce4db188df4813453ddca3c89aaf002ab5 100644 (file)
@@ -52,7 +52,7 @@ __systemd_osc_context_common() {
     if [ -f /etc/machine-id ]; then
         printf ";machineid=%.36s" "$(</etc/machine-id)"
     fi
-    printf ";user=%.255s;hostname=%.255s;bootid=%.36s;pid=%.20d" "$USER" "$HOSTNAME" "$(</proc/sys/kernel/random/boot_id)" "$$"
+    printf ";user=%.255s;hostname=%.255s;bootid=%.36s;pid=%.20s" "$USER" "$HOSTNAME" "$(</proc/sys/kernel/random/boot_id)" "$$"
 }
 
 __systemd_osc_context_precmdline() {