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

Consolidate process cwd() "null" return value across all platforms #2238

Closed
giampaolo opened this issue Apr 16, 2023 · 1 comment
Closed
Labels

Comments

@giampaolo
Copy link
Owner

giampaolo commented Apr 16, 2023

There are cases where Process.cwd() cannot be determined, but not due a permission error (AccessDenied). Sometimes the kernel simply returns a "null" information and there's nothing we can do about it. Some other times like in #2237 the kernel returns ENOENT because perhaps the directory no longer exists, and again, we're forced to return a "null" value (this time I opted for None).

When such cases occur, psutil sometimes returns None, some other times an empty string. Perhaps even worse, none of this is documented. Such cases should be consolidated (either return None or empty string everywhere) and documented.
Because the native type returned cwd() is a string, I'm more keen on returning an empty string everywhere rather than None.

@giampaolo giampaolo added the bug label Apr 16, 2023
@giampaolo
Copy link
Owner Author

Process.exe() is similar. In case of "null" value, we have a contract test which asserts it's an empty string:

self.assertEqual(ret, '')

giampaolo added a commit that referenced this issue Apr 16, 2023
ddelange added a commit to ddelange/psutil that referenced this issue Apr 21, 2023
* 'master' of https://github.com/giampaolo/psutil: (22 commits)
  use glob.glob() in setup.py
  OSX / refact: get rid of process_info.c (giampaolo#2243)
  OSX C refact: reconstruct _psutil_osx.c to preserve history
  OSX: rename psutil/_psutil_osx.c to arch/osx/proc.c to preserve GIT history
  OSX big C refactoring (giampaolo#2242)
  fix failing users() test; update HISTORY; give CREDITS to @0-wiz-0 for giampaolo#2241
  win C refact: reconstruct _psutil_windows.c trying to preserve history
  rename _psutil_windows.c -> proc.c
  Win, C, refact: move proc funcs into proc.c file
  BSD big refact: move proc funcs in new proc.c file
  Fix build on NetBSD due to missing .h include. (giampaolo#2241)
  Win, C, refact: move boot_time() and users() in new sys.c
  Windows / refact: new sensors.c file
  C refact: remove useless cmdline / cwd / environ layers. Call direct functions
  pre release
  Add CI testing for OpenBSD and NetBSD (giampaolo#2240)
  Fix giampaolo#2239 / proc name(): don't fail with ZombieProcess on cmdline()
  giampaolo#2238: passed wrong value to Py_BuildValue
  fix giampaolo#2238 if cwd() cannot be determined always return "" instead of None
  Fix giampaolo#2237, OpenBSD, cwd(): return None instead of FileNotFoundError
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant