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

Execute source using /bin/bash not /bin/sh #547

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shinglerb
Copy link

Attempting to execute source in /bin/sh doesn't work if /bin/sh isn't bash

@knet-ci-bot
Copy link

Can one of the admins verify this patch?

@@ -1268,7 +1268,7 @@ def fence_logout(conn, logout_string, sleep=0):
def source_env(env_file):
# POSIX: name shall not contain '=', value doesn't contain '\0'
output = subprocess.check_output("source {} && env -0".format(env_file), shell=True,
executable="/bin/sh")
executable="/bin/bash")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case, the bash´ism should be removed. /bin/bash is not available on all systems.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works fine if you replace "source" with "." (tested with bash, dash and sh on FreeBSD):
output = subprocess.check_output(". {} && env -0".format(env_file), shell=True, executable="/bin/sh")

@knet-jenkins
Copy link

knet-jenkins bot commented Jun 12, 2023

Can one of the admins check and authorise this run please: https://ci.kronosnet.org/job/fence-agents-pipeline/job/PR-547/1/input

@oalbrigt
Copy link
Collaborator

It seems like replacing source with . should fix this issue.

@DEmmons
Copy link

DEmmons commented Aug 12, 2024

I can confirm this still causes issues on Ubuntu 24.04, for what it's worth. I ran into it with the fence_openstack agent. Two good resolutions have been suggested, and it seems that determining which one is better needs to be informed by the intention of compatibility:

  • If the intention is to continue to assume the shell is bash (as the current code does), and not worry about systems that do not have bash available, this PR is just right. while it's not always the default shell, bash is available for most *nix environments that could run these agents, and even things like OSX. Ostensibly this also helps keep the behavior predictable.
  • If the intention is to run in as many POSIX systems as possible with their default shell, the suggestion of using a "." instead of the bash builtin "source" is probably the right call, though this assumes the line will be interpreted the same way in each shell. While that can be understood to be a basic goal of the POSIX standard, here we are, discussing this.
  • if both of these approaches leave out compatibility for an important target environment, handling beyond a one-line change may be needed, but nothing comes to mind

To sum up, unless I've misunderstood project goals, this PR looks like the right solution.

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.

6 participants