Skip to content

pidstat: Escape special characters in JSON output - #454

Open
prownd wants to merge 1 commit into
sysstat:masterfrom
prownd:pidstat-Escape-special-characters-in-JSON-output-s01
Open

prownd wants to merge 1 commit into
sysstat:masterfrom
prownd:pidstat-Escape-special-characters-in-JSON-output-s01

Conversation

@prownd

@prownd prownd commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Command names and command lines are displayed as is in the JSON output of pidstat. A double quote, a backslash or a control character in them (which is common in command lines, e.g. sh -c 'echo "foo"') results in an invalid JSON document:

$ sh -c 'sleep 3; echo "a\b"' &
$ pidstat -o JSON -l -p $! 1 1 | python3 -m json.tool Expecting ',' delimiter: line 14 column 151 (char 444)

Add a function to print a string with these characters escaped and use it to display the command name, the command line, and the user name.

Command names and command lines are displayed as is in the JSON output
of pidstat. A double quote, a backslash or a control character in them
(which is common in command lines, e.g. sh -c 'echo "foo"') results in
an invalid JSON document:

$ sh -c 'sleep 3; echo "a\b"' &
$ pidstat -o JSON -l -p $! 1 1 | python3 -m json.tool
Expecting ',' delimiter: line 14 column 151 (char 444)

Add a function to print a string with these characters escaped and use
it to display the command name, the command line, and the user name.
@natoscott

natoscott commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

@sysstat the github workflow tests aren't running by default (need manual approval - possibly a first-time contributor?) - I think there's a repo setting to adjust this if you want it to happen automatically.

sysstat added a commit that referenced this pull request Oct 4, 2026
Command names and command lines are displayed as is in the JSON
output of pidstat. A double quote, a backslash or a control
character in them (which is common in command lines,
e.g. sh -c 'echo "foo"') results in an invalid JSON document:

$ sh -c 'sleep 3; echo "a\b"' &
$ pidstat -o JSON -l -p $! 1 1 | python3 -m json.tool
Expecting ',' delimiter: line 14 column 151 (char 444)

Add a function to print a string with these characters escaped and
use it to display the command name, the command line, and the user
name.

Reported-by: hanjinpeng <[email protected]>
Signed-off-by: Sebastien GODARD <[email protected]>
@sysstat

sysstat commented Oct 4, 2026

Copy link
Copy Markdown
Owner

@prownd Thanks for this PR.
I didn't merge it because I updated the code so that the function that escapes forbidden characters can also be used by sadf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants