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

Run script permission denied #2374

Closed
GladOSkar opened this issue Oct 19, 2019 · 10 comments
Closed

Run script permission denied #2374

GladOSkar opened this issue Oct 19, 2019 · 10 comments

Comments

@GladOSkar
Copy link

GladOSkar commented Oct 19, 2019

The "run" build commands don't work on my system.

the opened term said the run script was not executable.

Running the script manually (via sh as implemented in build.c) yields

oskar@torres ~ % /bin/sh -c /tmp/geany_run_script_HVQX9Z.sh
/bin/sh: /tmp/geany_run_script_HVQX9Z.sh: Permission denied

Which makes sense since the file is not marked as executable:

oskar@torres ~ % ls -l /tmp/geany_run_script_HVQX9Z.sh
.rw-rw-r-- 256 oskar 19 Oct 19:23 /tmp/geany_run_script_HVQX9Z.sh

As can be seen in build.c, executable permissions are only set on apple platforms:

geany/src/build.c

Lines 1170 to 1186 in 75def8a

success = FALSE;
g_free(str);
#ifdef __APPLE__
if (success && g_chmod(fname, 0777) != 0)
{
if (error)
{
gint errsv = errno;
g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errsv),
"Failed to make file executable: %s", g_strerror(errsv));
}
success = FALSE;
}
#endif
if (!success)

I changed this in my PR #2372 which solves the problem for me. I'm not sure if i'm missing something here.

I don't think passing the script through sh circumvents the need for execution rights but i'm not an expert on unix permissions so maybe someone else knows why this was expected to work and/or works for other people?

Thanks!

@elextr
Copy link
Member

elextr commented Oct 19, 2019

Well, since you havn't told us what "your system" is how can we help you?

@GladOSkar
Copy link
Author

GladOSkar commented Oct 19, 2019

Oh sorry it's Solus 4. I also tested on Debian 10 and got the same result.

My default shell is zsh but I don't think that makes a difference here. sh is in /bin/sh and executable.

I'm mostly just wondering how and under what conditions this does work

@elextr
Copy link
Member

elextr commented Oct 19, 2019

Ahh, bleeding edge distros, maybe something changed, although I'd expect a report from Arch first :)

Clearly it works for most people since this is the first report. I know several devs use debian but I don't know if they have upgraded to 10 yet, lets see what they say.

Note that here on Mint 19.1 Geany execute works, but /bin/sh -c script in the command line gets permission denied if the script does not have execute permission. I would have said thats actually correct, its running as a command (thats what -c says) not reading it as a script. Running /bin/sh script works without execute permission since its reading it as a script not executing it, subtle but important difference.

But why Geany works I don't know, but would speculate its to do with which of the 16 trillion[1] modes of bash gets used, non-interactive, non-login, run as sh etc etc.

[1] rough estimate

@elextr
Copy link
Member

elextr commented Oct 20, 2019

My default shell is zsh but I don't think that makes a difference here. sh is in /bin/sh and executable.

Actually its possibly the problem if sh is just an alias for zsh, which says it emulates sh if started by that name, but how well that emulation is done I don't know. Can you check what sh actually runs?

@elextr
Copy link
Member

elextr commented Oct 20, 2019

And its possible that the reason Apple needs execute is because it uses zsh, @techee ??

@GladOSkar
Copy link
Author

Can you check what sh actually runs?

Just checked, on Solus sh is symlinked to bash, on Debian 10 to dash...

You're right in that not using -c works for both. No idea what a true sh's behavior would be

@techee
Copy link
Member

techee commented Oct 20, 2019

@GladOSkar Where did you get the -c flag from? Geany should run the script without -c. When you go to Edit->Preferences->Tools, what does the "Terminal" command say? The default is

xterm -e \"/bin/sh %c\"

without -c.

And its possible that the reason Apple needs execute is because it uses zsh, @techee ??

I think this ifdef can be removed now. I believe that in the past we really used to have the run script executable and run it using /bin/sh -c run_script.sh but we changed it because on some systems we weren't allowed to run an executable file from /tmp because of security settings.

@GladOSkar
Copy link
Author

GladOSkar commented Oct 20, 2019

When you go to Edit->Preferences->Tools, what does the "Terminal" command say?

It's kitty "%c", which explains what went wrong. Thanks!

kitty /bin/sh %c works, but not when the command is quoted. But that's probably a kitty issue.

Probably removed that at some point ages ago. I used to always use the VTE without run script which is why i didn't notice.

Thanks a lot you two! Great work on geany btw, i love it :)

@elextr
Copy link
Member

elextr commented Oct 21, 2019

I think this ifdef can be removed now. I believe that in the past we really used to have the run script executable and run it using /bin/sh -c run_script.sh but we changed it because on some systems we weren't allowed to run an executable file from /tmp because of security settings.

Ok, I hadn't noticed it was changed, neat.

@techee
Copy link
Member

techee commented Oct 21, 2019

Ah, no, I take it back, we need it executable on Apple. The terminal is run using the open command like

open -a terminal %c

and %c has to be a file, not a command, and it has to be executable in order to be launched this way.

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

No branches or pull requests

3 participants