Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Add support to spawn the process #18

Closed
jviotti opened this issue Apr 26, 2016 · 2 comments
Closed

Add support to spawn the process #18

jviotti opened this issue Apr 26, 2016 · 2 comments

Comments

@jviotti
Copy link
Contributor

jviotti commented Apr 26, 2016

Hey there,

How hard would it be to allow the child process to be spawned instead of executed on this module? I didn't take a look myself, but I suspect it's just a matter of spawning the final command built by this module in Attempt().

The use case is that we've figured out how to call the process that needs the elevation in Etcher, instead of the full application, but we need to consume its stdout and stderr while it runs in order to get state information.

In my mind, the sudoPrompt.spawn() function should just return the spawn object for the client to handle.

What do you think about this addition? Happy to collaborate on it.

@jorangreef
Copy link
Owner

It is possible but would be a fair amount of work. Would be great if you could tackle it.

The Attempt() call is just the tip of the iceberg. That's there to try and run the command if a sudo session already exists, and if it does then that could be just a straight-forward spawn() instance passed back to the user.

But otherwise, the user command is run by a bash subshell which is called by the applet after acquiring administrator privileges. So we would essentially be trying to create a fake spawn() instance with all the same properties as a normal Node.js spawn() instance, but which wraps a bash subshell.

To understand how this works:

  1. Add a console.log() statement to print out instance.path just after MacCommand() runs (https://github.com/jorangreef/sudo-prompt/blob/master/index.js#L196). This is the path to the temporary app created by sudo-prompt.
  2. Before granting privileges, take a look at the logged path and then open it in Finder and make a copy of the temp app. The app will otherwise be deleted as soon as privileges are granted.
  3. Open the app with Script Editor to view the Apple Script source, and then take a look in the MacOS directory within the app to see the bash scripts which are there.

If we can do this properly that would be great, but some aspects of the spawn() instance might be difficult to copy perfectly. Alternatively, it might be easier to write out your script's stdout and stderr streams to a file and tail those.

@jviotti
Copy link
Contributor Author

jviotti commented May 3, 2016

Hi @jorangreef

I see :/ I certainly underestimated the amount of work needed. I'll take the tail approach as you suggested and see how far I can get with it.

I'll re-open this issue if needed, thanks a lot!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants