Skip to content

Add doas support#19

Open
chambln wants to merge 2 commits into
barneygale:masterfrom
chambln:doas
Open

Add doas support#19
chambln wants to merge 2 commits into
barneygale:masterfrom
chambln:doas

Conversation

@chambln
Copy link
Copy Markdown

@chambln chambln commented Nov 6, 2022

Based on #18 by @wxllow.

I'm not aware of the intent behind or args[0] == "sudo" in the section reproduced below, so I may have broken something if that was important. All I know is that removing it prevented a raise that terminated the program before it could try doas instead of sudo.

def elevate(show_console=True, graphical=True):
    ...
    for args in commands:
        try:
            os.execlp(args[0], *args)
        except OSError as e:
            if e.errno != errno.ENOENT or args[0] == "sudo":
                raise

Another solution I had (shown below) was to catch the FileNotFoundError that is raised when sudo is not found on PATH.

def elevate(show_console=True, graphical=True):
    ...
    for args in commands:
        try:
            os.execlp(args[0], *args)
        except FileNotFoundError:
            raise               # sudo or doas not found 
        except OSError as e:
            if e.errno != errno.ENOENT or args[0] == "sudo":
                raise

This needs to be tested on a system which has only sudo (no doas) before being merged, so I've marked this PR as a draft.

@wxllow
Copy link
Copy Markdown

wxllow commented Jul 12, 2023

I am SOO late but i believe the purpose of args[0] == "sudo" is that since sudo was the last command being checked if it's not found then that means there are no available commands, so an exception is thrown. In my pull request, I made the mistake of adding commands.append(["doas"] + args) after commands.append(["sudo"] + args)

However, I think keeping the args[0] == "sudo" exactly as is and just moving the doas line to be before the sudo line would be the best solution. doas before sudo makes more sense because 99% of the people who have doas installed would prefer using it than sudo (otherwise they just wouldn't have installed doas)

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.

2 participants