Skip to content

Commit

Permalink
fix: filter out non-printable characters in process line
Browse files Browse the repository at this point in the history
Otherwise the output might be distorted by characters like `\n`.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
(cherry picked from commit 8166a58)
  • Loading branch information
smira committed Sep 21, 2024
1 parent 70d3c91 commit c8dedbe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/talosctl/cmd/talos/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ var cpu = func(p1, p2 *machineapi.ProcessInfo) bool {
return p1.CpuTime > p2.CpuTime
}

//nolint:gocyclo
func processesOutput(ctx context.Context, c *client.Client) (output string, err error) {
var remotePeer peer.Peer

Expand Down Expand Up @@ -214,6 +215,15 @@ func processesOutput(ctx context.Context, c *client.Client) (output string, err
args = p.Args
}

// filter out non-printable characters
args = strings.Map(func(r rune) rune {
if r < 32 || r > 126 {
return ' '
}

return r
}, args)

node := defaultNode

if msg.Metadata != nil {
Expand Down
11 changes: 11 additions & 0 deletions internal/pkg/dashboard/components/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func NewProcessTable() *ProcessTable {
}

// OnAPIDataChange implements the APIDataListener interface.
//
//nolint:gocyclo
func (widget *ProcessTable) OnAPIDataChange(node string, data *apidata.Data) {
nodeData := data.Nodes[node]

Expand Down Expand Up @@ -97,6 +99,15 @@ func (widget *ProcessTable) OnAPIDataChange(node string, data *apidata.Data) {
args = proc.Args
}

// filter out non-printable characters
args = strings.Map(func(r rune) rune {
if r < 32 || r > 126 {
return ' '
}

return r
}, args)

line := fmt.Sprintf("%7d %s %6.1f %6.1f %8s %8s %10s %4d %s",
proc.GetPid(),
proc.State,
Expand Down

0 comments on commit c8dedbe

Please sign in to comment.