Got errors when using sudo with ps

Open
#1,043 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
cli, devtools

Research direction

Start at watchers.Responder.submit and follow runner.Runner.handle_output, _handle_output, respond, and write_proc_stdin. Reproduce the sudo ps axww command on Debian and inspect the response triggered by the process-list output. Done means the output no longer causes a password write after the Paramiko channel closes or an OSError: Socket is closed ThreadException.

Written by the indexing model from the issue text.

Description

Hi,

This is not exactly an issue, more of a warning for people having this kind of issues. It is both related to the invoke and the paramiko library

I am using fabric (which is based on paramiko and invoke) in order to retrieve a list of running processus on a Debian server with ps axww -o pid=,ppid=,etimes=,command=. At that time, I used the sudo function to run it.

From time to time, I got a ThreadException, and it came out that it was coming from the invoke library: when doing the ps command, I got the following output:

3432669       1       0 /lib/systemd/systemd --user
3432670 3432669       0 (sd-pam)
3432716       2       0 [kworker/9:1]
3432730 3432625       0 sshd: xxx@notty
3432731 3432730       0 sudo -S -p [sudo] password:  ps axww -o pid=,ppid=,etimes=,command=
3432732 3432731       0 ps axww -o pid=,ppid=,etimes=,command=

As the -p [sudo] password: option appears in the command output, the watchers.Responder.submit function returns matches, and triggers the runner.Runner.handle_output -> _handle_output -> respond -> write_proc_stdin function, thinking it should send the password.

As the paramiko channel get closed once the command output is printed, the write_proc_stdin sometimes tries to write the password after the channel closure, which triggers a ThreadException OSError: Socket is closed

(Sorry if I am not using the correct terminology, I am not a developer)

Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.