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

General simplification #1566

Merged
merged 4 commits into from
Jan 15, 2023
Merged

General simplification #1566

merged 4 commits into from
Jan 15, 2023

Conversation

KlzXS
Copy link
Collaborator

@KlzXS KlzXS commented Jan 14, 2023

get_output():

  • The function now uses UTIL_SH_EXEC to execute the command.
  • The command writes directly to a tmp file where applicable.
  • Got rid of parameter multi as it's no longer needed.
  • A bad use case is now blocked.
  • Got rid of cmd and fd as they are no longer needed. Correct me if I'm wrong, but fd wasn't ever used and there is a path to call free(cmd) while it's NULL (multi == FALSE and pipe() failing).
  • The comment above wasn't accurate, now it is.
  • g_buf is now clobbered only in some cases. Not that it would matter much, I imagine.

@jarun I still need to look into using UTIL_SH_EXEC for running GUI apps as plugins as you suggested, but I thought I should share this regardless.

I only tried the simple case of setting NNN_HELP and opening the help screen. I might do more extensive testing later, or if someone wants to give it a shot as well that would be great.

@jarun
Copy link
Owner

jarun commented Jan 15, 2023

I see the following issue with nnn -i (to show file info):

Constant message in the info bar: Usage: file [-bcCdEhikLlNnprsSvzZ0] [--apple] [--extension] [--mime-encoding]

@jarun
Copy link
Owner

jarun commented Jan 15, 2023

I think all internal flows that invoke get_output() are failing e.g. listing a zip file results in:

atool: no command specified
Try `atool --help' for more information.

src/nnn.c Outdated Show resolved Hide resolved
Co-authored-by: KlzXS <klzx+github@klzx.cf>
Co-authored-by: Arun Prakash Jana <engineerarun@gmail.com>
@jarun jarun merged commit f9281c8 into jarun:master Jan 15, 2023
@jarun
Copy link
Owner

jarun commented Jan 15, 2023

Thanks @KlzXS!

@jarun
Copy link
Owner

jarun commented Jan 15, 2023

@KlzXS I reverted this change and the changes I made on top of it. It appears concatenating the arguments don't work when the filename has spaces in it due to the usual shell quirks.

@jarun
Copy link
Owner

jarun commented Jan 15, 2023

Please re-raise if you find a way around it.

@KlzXS
Copy link
Collaborator Author

KlzXS commented Jan 15, 2023

I guess it's best to forego using UTIL_SH_EXEC and go the good old way it was while using the rest of the simplification.

I also had thoughts of implementing a new variant of spawn() that would allow us to pass in file descriptors to be mapped to stdin, stdout and stderr. I think a few places in the code might benefit from that. Say we pipe the output directly into nnn instead of writing to a file and reading from it. What do you think?

@jarun
Copy link
Owner

jarun commented Jan 15, 2023

I guess it's best to forego using UTIL_SH_EXEC and go the good old way it was while using the rest of the simplification.

I agree!

I also had thoughts of implementing a new variant of spawn() that would...

We had problems and breaks with such experiments earlier. I think spawn() is good for now.

@KlzXS
Copy link
Collaborator Author

KlzXS commented Jan 15, 2023

I think spawn() is good for now.

Sure. I'll do it the old way. I might submit my experiment at a later date. Might.

@jarun
Copy link
Owner

jarun commented Jan 16, 2023

👍

@N-R-K
Copy link
Collaborator

N-R-K commented Jan 16, 2023

I also had thoughts of implementing a new variant of spawn() that would allow us to pass in file descriptors to be mapped to stdin, stdout and stderr. I think a few places in the code might benefit from that. Say we pipe the output directly into nnn instead of writing to a file and reading from it. What do you think?

@KlzXS You may want to take a look at posix_spawn - it's much faster than fork + dup + exec and I think it should be capable of doing what you want. You can take a look at nsxiv for some reference (the error handling is quite ugly, but otherwise it works quite well): util.c#L251-L294

@KlzXS KlzXS mentioned this pull request Jan 25, 2023
jarun added a commit that referenced this pull request Jan 28, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants