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

BASH 4.3.42 Errors - error importing fucntion definition for BASH_FUNC_module Fedora 23 (F23) #2065

Closed
taz77 opened this issue Mar 13, 2016 · 36 comments
Assignees
Labels

Comments

@taz77
Copy link

taz77 commented Mar 13, 2016

I have been trying to resolve this but I haven't been able to on my own. Hoping someone else here has some insight. Running the latest Drush (via Composer global install) I get errors in bash on Fedora 23 which is using Bash version 4.3.42.

This error:

sh: scl: line 1: syntax error: unexpected end of file
sh: error importing function definition for `BASH_FUNC_scl'

and:

sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for `BASH_FUNC_module'

Repeats itself eight times per drush call. Drush still runs without a problem. Just blasts your terminal with loads of text.

I have axed the .drush/ folder and re-run drush init. That does not change the problem. Googling the error gets a lot of hits for many other issues.

Ideas?

@weitzman
Copy link
Member

No idea.

Try Drupal Answers.

@taz77
Copy link
Author

taz77 commented Mar 20, 2016

The problem is with Drush and the latest version of Bash shell. That is why I posted this here.

@mtift
Copy link

mtift commented Apr 25, 2016

I have also experienced this problem on Fedora. It's not clear to me where to put the unset module command.

@taz77
Copy link
Author

taz77 commented Apr 26, 2016

Agreed. It's a compatibility issue that will grow once the newer versions of bash are more mainstream. They just don't realize it here yet. The maintainers are quick to close rather than diagnose.

@greg-1-anderson
Copy link
Member

Not sure this is caused by new versions of bash; this apparently was a problem for some folks in 2011. See: http://gridengine.org/pipermail/users/2011-November/002019.html

I suspect that this problem is Fedora-specific. It would be helpful if a Fedora user could provide more diagnostic information on some of the suggested workarounds.

@mtift
Copy link

mtift commented May 5, 2016

Hey, Greg! I run Debian on most of my machines, and I've never encountered this problem before. Previously, my workflow was to check out the drush git repo and then switch branches when I switched back and forth between Drupal 7 and Drupal 8 projects. I only encountered this on a newer laptop that seems to do (other tasks) better with Fedora (but not this), so I think you might be correct that this Fedora-specific. The errors I encountered looked exactly like the ones mentioned in the first comment of this issue.

However, apparently git branch switching is (no longer?) necessary. So for me the solution was simply to follow the install instructions on http://docs.drush.org/en/master/install/ and all seems to work, and I happily switch back and forth from D7 to D8. That might not work for others, but it suits my needs.

@taz77
Copy link
Author

taz77 commented May 7, 2016

@greg-1-anderson All the probing and google searching I did came back to the shell script being executed. I spent a lot of time on it before I posted the issue here because my research had come to the conclusion that the problem is with the shell script.

The bash shell in Fedora is pretty far ahead of most distro's. My Mac only has v3.2.57 running Yosemite.

@taz77
Copy link
Author

taz77 commented May 7, 2016

Here is an example of one of the things I found and it was mentioned on other pages that the issue was with semi-colons in the bash shell scripts. That all the lines needed to have semi-colons at the end.

https://stackoverflow.com/questions/10496758/unexpected-end-of-file-and-error-importing-function-definition-error-running

@taz77
Copy link
Author

taz77 commented May 7, 2016

Here is another good blog post pertaining to the export function.
https://kb.brightcomputing.com/faq/index.php?action=artikel&cat=2&id=239&artlang=en

I will make a note to myself to spin up some other machines and see if I can replicate this in another distro.

@iamorangehat
Copy link

It appears the call to pcntl_exec is causing the message(s).
Not a drupal admin but our drupal admin asked me to take a look at it. He had me test using "drush8 core-status" as a test. To fix(?) I set $use_pcntl_exec = FALSE (below function_exists near line 326) to use proc_open instead of pcntl_exec in /includes/startup.inc and that eliminated the error. He still needs to do testing after this change to see if broke anything doing that change.
This a work-around as it is probably a bash or perhaps pcntl_exec problem. I'm still looking at it.

@taz77
Copy link
Author

taz77 commented May 10, 2016

@iamorangehat I will give this a test too. Maybe post a patch for others to use in testing.

@iamorangehat
Copy link

iamorangehat commented May 10, 2016

After finding the command I felt was causing the issue, I noticed that if the function_exists returns a FALSE (if pcntl_exec function is not available) so it falls through to use proc_open. I added a line to force it to FALSE. We could have probably added pcntl to the disable_functions in php.ini and did the same thing without changing the startup.inc though not sure what parm in disable_functions, i.e. pcntl or pcntl_exec

@greg-1-anderson
Copy link
Member

If function_exists('pcntl_exec') is returning FALSE, why did you need to force it to false? Was that a typo?

@iamorangehat
Copy link

iamorangehat commented May 10, 2016

No, I was getting TRUE on my system so I forced it to false so it fell through to proc_open. Sorry for the confusion.

@bperet
Copy link

bperet commented Jun 5, 2016

I just installed Drush globally via composer on CentOS 6.8 and am getting the same error:

# drush status
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for `BASH_FUNC_module'
 PHP executable         :  /usr/bin/php
 PHP configuration      :  /etc/php.ini
 PHP OS                 :  Linux
 Drush script           :  /opt/drush-8.x/vendor/drush/drush/drush.php
 Drush version          :  8.1.2
 Drush temp directory   :  /tmp
 Drush configuration    :
 Drush alias files      :

If I "unset module" from BASH then it seems to work OK.

@taz77
Copy link
Author

taz77 commented Jun 19, 2016

Fedora updates and Drush updates. This still spams the hell of out my screen every time I run drush.

drush cc all sh: module: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_module'
sh: scl: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_scl' sh: scl: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_scl'
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_module' sh: scl: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_scl'
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_module' sh: scl: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_scl'
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_module' sh: scl: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_scl'
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_module' sh: scl: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_scl'
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_module' sh: scl: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_scl'
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_module' sh: scl: line 1: syntax error: unexpected end of file sh: error importing function definition forBASH_FUNC_scl'
sh: module: line 1: syntax error: unexpected end of file
sh: error importing function definition for BASH_FUNC_module' [notice] 'all' cache was cleared.

@iamorangehat
Copy link

Try this:
in /etc/php.ini
disable_functions = pcntl_exec

@taz77
Copy link
Author

taz77 commented Jul 16, 2016

The above works!

@bke-daniel
Copy link

Same here on CentOS 6.x and 7. Installed via Composer.
Solution provided by @iamorangehat works, thanks lad!

@artforlife
Copy link

@iamorangehat Thanks, it worked on Amazon CentOS!

@nvaken
Copy link
Contributor

nvaken commented Jun 2, 2017

How would you go about changing that value on a shared hosting solution? In that situation I'm - ofcourse - unable to edit the php.ini.

@iamorangehat
Copy link

@nvaken , Then you need alter drush so it doesn't use pcntl_exec by editing the code.
in directory: drush9/vendor/drush/drush/includes (or drush8 or whatever)
vi startup.inc
Find the lines below (usually somewhere near line 330)
// Always use pcntl_exec if it exists.
$use_pcntl_exec = function_exists("pcntl_exec");
And under those lines add:
$use_pcntl_exec = FALSE;
That should fix it.

@grayside
Copy link
Contributor

grayside commented Jun 6, 2017

This thread points to the function_exists() being an unpredictable indicator of function availability. Near the bottom of the thread is this idea:

strpos( ini_get( 'disable_functions' ), 'posix_getpwuid' )

So maybe we need to have two levels of checks for availability of pcntl_exec?

@febbraro
Copy link

febbraro commented Jun 6, 2017

This is exactly the problem I'm having. The function is disabled in php.ini, but function_exists is returning true.

[root@671d6f2970b3 /]# php -i | grep disable_functions
disable_functions => pcntl_exec => pcntl_exec
[root@671d6f2970b3 /]# php -r "print ini_get('disable_functions');"
pcntl_exec
[root@671d6f2970b3 /]# php -r "print function_exists('pcntl_exec') ? 'yes' : 'no';"
yes
[root@671d6f2970b3 /]# php -r "print strpos(ini_get('disable_functions'), 'pcntl_exec') === false ? 'no' : 'yes';"
yes

@whitingjr
Copy link

I came across the same compile error building Netty using Fedora. I installed the package libtool.x86_64. The installation provided the missing function definitions. Allowing my build to complete successfully.

@weitzman
Copy link
Member

Fixed, AFAICT.

@manavk
Copy link

manavk commented Jan 15, 2018

Solution provided by @iamorangehat works for me, thanks..!

@nerdoc
Copy link

nerdoc commented Sep 2, 2018

I just downloaded Drush 8 via composer (for D7) on CentOS7 (host on uberspace.de), and it is not fixed there - is this just fixed in Drush9?

@iamorangehat
Copy link

You will probably need to still do this:
in /etc/php.ini
disable_functions = pcntl_exec

@nerdoc
Copy link

nerdoc commented Sep 6, 2018

@iamorangehat Thanks, works perfectly.

@cristian100
Copy link

Wooonderful!! @iamorangehat it worked for me on CentOs 7 Thanks!

@greg-1-anderson
Copy link
Member

It would be more helpful to focus on the solution by @whitingjr. Disabling pcntl_exec is an inferior solution that may have undesirable side effects on Drush 8, and probably makes Drush 9.6.0 nonfunctional.

@dexp-io
Copy link

dexp-io commented Jan 9, 2019

Add the command below to ~/.bash_profile or ~/.bashrc file then logout/login again.

unset module

Or simple run quick command:

echo "unset module" >> ~/.bash_profile && source ~/.bash_profile

@dirkd
Copy link

dirkd commented Feb 13, 2020

Fwiw the core issue is how Drush8 is retrieving the system's shell environment. The code at

if (empty($env)) {
exec('printenv', $env_items);
foreach ($env_items as $item) {
// Each $item is 'key=value' or just 'key'.
// If $item has no value, then explode will return
// a single array, [0 => 'key']. We add a default
// value of [1 => 'value'] to cover this case. If
// explode returns two items, the default value is ignored.
list($key, $value) = explode('=', $item, 2) + array(1 => '');
$env[$key] = $value;
}
}

operates under the assumption that every environment variable printed by printenv occupies exactly one line. On Fedora-based systems (e.g. Fedora, CentOS, RHEL) this assumption does not always hold. On those systems the following environment variable is defined when the package environment-modules installed:

BASH_FUNC_module()=() {  eval `/usr/bin/modulecmd bash $*`
}

The origin of this envvar with a newline character is that the function containing a semicolon is exported into the environment via export -f in /usr/share/Modules/init/bash.

This is parsed into the the $env-Array by drush as:

array(
    [BASH_FUNC_module()] => () {  eval `/usr/bin/modulecmd bash $*`
    [}] =>
)

As this is passed into pctnl_exec() further down the line (

$error = pcntl_exec($found_script, $arguments, $env);
) this causes the executing shell to emit the syntax error. Since $env is not used when executing via proc_open the error is only showing when using pctnl_exec().

So possible mitigations are indeed unsetting the env variable module in the calling environment - if you don't need its functionality - or populating $_ENV by adding E to the variables_order to skip the printenv-parsing.

To ultimately fix this the environment retrieval should probably be adjusted to cope with multiline environment variables.

@Peneheals
Copy link

It is still a problem, just got the above error in an RHEL 7.8 system. I agree with @dirkd : "To ultimately fix this the environment retrieval should probably be adjusted to cope with multiline environment variables."

It also worth to mention that the above mentioned disable_functions = pcntl_exec in the /etc/php.ini can temporarily fix the error.

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

No branches or pull requests