Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when run on macOS outside a tty/pty #35

Open
ids1024 opened this issue Sep 30, 2020 · 7 comments
Open

Fails when run on macOS outside a tty/pty #35

ids1024 opened this issue Sep 30, 2020 · 7 comments

Comments

@ids1024
Copy link
Contributor

ids1024 commented Sep 30, 2020

I noticed this on Github Actions. I haven't reproduced it locally since I don't have a Mac, and it doesn't seem to occur on Linux.

ps normally lists processes on the same tty. It seems on Linux when run outside a tty, it just lists processes regardless of the connected terminal. But based on what I saw on Github actions, it seems this instead lists no processes.

Probably can be fixed with an appropriate argument to ps, though some care may be required to avoid breaking anything else and to be compatible with all ps implementations.

@uranusjr
Copy link
Member

How can I set up a reproduction to investigate this?

@ids1024
Copy link
Contributor Author

ids1024 commented Sep 30, 2020

I've opened a PR (#36) with a Github actions workflow testing this. Which is failing on macOS but passing on Linux.

Edit: https://github.com/ids1024/shellingham/actions/runs/280891996

@ids1024
Copy link
Contributor Author

ids1024 commented Sep 30, 2020

Or, or I guess on Linux, ps not run in a terminal lists all processes that aren't in a terminal, so this is failing for me as well, since I don't have any shells that aren't connected to a tty:

import os
import fcntl
import termios
import subprocess
import shellingham

fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
fcntl.ioctl(fd, termios.TIOCNOTTY, '')
os.close(fd)

subprocess.call(["ps"])
print(shellingham.detect_shell())
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    print(shellingham.detect_shell())
  File "/home/ian/src/shellingham/shellingham/__init__.py", line 25, in detect_shell
    raise ShellDetectionFailure()
shellingham._core.ShellDetectionFailure

@uranusjr
Copy link
Member

uranusjr commented Oct 9, 2020

on Linux, ps not run in a terminal lists all processes that aren't in a terminal

Hmm. I wonder why that’d work on GitHub Actions though? Shellingham tests the shell is in the current process’s parent chain, so maybe it’s detecting the login shell in this case? If so, this arguably be attributed to a Linux quirk and unfixable in shellingham.

@uranusjr
Copy link
Member

uranusjr commented Oct 9, 2020

Nope, there is legistimately a shell detected, persuambly the one used to run the commands you specify in run. But why does not the macOS worker have the same thing? I guess GitHub Actions is just implemented differently for different platforms, and there’s no real solution here.

@ids1024
Copy link
Contributor Author

ids1024 commented Oct 9, 2020

It's a pain to debug with actually having a Mac to try things on locally, but it seemed when I just ran ps on a macOS GitHub action runner, it produced no output. So it seems the behavior of ps on macOS is different when there's not a connected tty.

Using something like ps -e to list all processes would probably fix it. If that's portable. Glancing at the ps(1) man page on Linux, it seems there's a fair bit of variation between different implementations and standards.

@JeppeKlitgaard
Copy link
Contributor

JeppeKlitgaard commented Apr 10, 2021

For whatever reason this is fixed by #49

Edit: I just realised this is because #49 changes the GitHub actions to instead run the tests using pytest.

Moomboh added a commit to Moomboh/shellingham that referenced this issue May 13, 2023
@Moomboh Moomboh mentioned this issue May 13, 2023
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

No branches or pull requests

3 participants