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

Restore sudoedit filetype detection #104

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ferki
Copy link

@ferki ferki commented Apr 20, 2023

This PR is a proposal to fix #31 by using the proc filesystem to determine the original filenames from the command line of the parent process when using sudoedit or sudo -e to edit files.

Main details of this approach:

  • get the PID of the parent process from the PPid: line of /proc/self/status
  • get the command line of the parent process from /proc/<ppid>/cmdline which holds a list of arguments separated by null bytes
  • checking for sudoedit or sudo -e at the beginning of the parent command line, and setting an offset to file arguments starting index

It is a follow-up on previous discussions on #31 and #79, and in response to

not ruling out pursuing a more robust solution

in this comment.

While I’m lacking the exact criteria for a solution to be considered “robust” for vim-eunuch purposes, this approach does address the known concerns from previous attempts:

  • it doesn’t use system calls
  • filename detection is more portable
  • works with filenames containing spaces

I tested this on successfully on:

  • Linux in the past few days (Gentoo with kernel 6.1.12; please test more)
  • FreeBSD 13.2 briefly in a VM (I'm not a BSD user though, and had to manually mount procfs first; please test more)

I'm also not a Mac OS X user, but it does not seem to have a procfs out-of-the-box that we could use in a similar manner. There are apparently third-party solutions like kimtopley/ProcFS which sounds like a weird dependency, or we may opt for a system() based approach via ps commands (with the remark that on previous attempts this was discouraged).

Anyone testing should be aware that this seems to conflict with current latest version of vim-polyglot, so best to disable that before trying this patch.

I’m opening it as a draft pull request only at first in order to learn more and gather further feedback.

My main questions at this stage:

  • Would this first draft be an acceptable direction? Shall I keep investing effort in it?
  • This is my first contribution attempt with vimscript. Are there better ways to obtain and process this info from procfs?
  • Is it OK to have it only on Linux and optionally on BSD?
  • What else we may attempt on Mac OS X to obtain parent process ID, and/or parent process command line (command + arguments)?

Please review, and let me know how to improve it further. I'm also happy to reorganize commits into a different history if desired.

Determine the original filename by inspecting the command line of the
parent process in the proc filesystem.
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.

SudoEdit filetype detection doesn't work with >= sudo-1.8.13
1 participant