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 completions as root hangs the shell #11024

Closed
hazhargaleh opened this issue Aug 26, 2022 · 4 comments
Closed

Bash completions as root hangs the shell #11024

hazhargaleh opened this issue Aug 26, 2022 · 4 comments
Labels
Milestone

Comments

@hazhargaleh
Copy link

My composer.json:

I don't have composer.json because I don't have a project.

Output of composer diagnose:

Checking platform settings: OK
Checking git settings: OK git version 2.34.1
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.5-dev+b6028951b8a2254d4896b4dd13bcbe380a3d51bf
PHP version: 8.1.9
PHP binary path: /usr/bin/php8.1
OpenSSL version: OpenSSL 3.0.2 15 Mar 2022
cURL version: 7.81.0 libz 1.2.11 ssl OpenSSL/3.0.2
zip: extension present, unzip present, 7-Zip not available

When I run this command:

composer upd[TAB][TAB]

Here I can't see the autocompletion for root user and the shell terminal is blocked. I can't cancel with CTRL+C. I must close the terminal window.

I get the following output:

root@php:~# composer upd[TAB][TAB]

And I expected this to happen:

I expected to see autocompleted commands for root user.

I debugged the issue and I found the completion command is:

php /usr/local/bin/composer _complete -sbash -c1 -S2.4.1 -icomposer

and when I execute this command as root, composer ask confirmation because I'm root:

root@php:~# php /usr/local/bin/composer _complete -sbash -c1 -S2.4.1 -icomposer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? 

Possible solutions

Maybe we never autocomplete for root, but it must not block the shell.

Or maybe we always autocomplete for root and we never ask confirmation, like this :

php /usr/local/bin/composer _complete -sbash -c1 -S2.4.1 -icomposer --no-interaction --no-plugins
@Seldaek
Copy link
Member

Seldaek commented Aug 26, 2022

Can you please try to apply symfony/symfony#47394 to your completion file to check it fixes it for you?

@Seldaek Seldaek added the Bug label Aug 26, 2022
@Seldaek Seldaek added this to the 2.4 milestone Aug 26, 2022
@hazhargaleh
Copy link
Author

I tested with the root user and it works without hangs the shell.
Thanks

fabpot added a commit to symfony/symfony that referenced this issue Sep 2, 2022
…eractive mode (Seldaek)

This PR was merged into the 5.4 branch.

Discussion
----------

[Console] [Completion] Make bash completion run in non interactive mode

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Refs composer/composer#11024

Composer does prompt in some contexts, and that blocks/freezes the completion as it runs in an interactive context but is not actually visible. Explicitly setting it to be non interactive seems to be the fix to me.

TODO:

- [ ] A similar fix probably should be applied to other completion types supported in newer versions than 5.4

Commits
-------

cf0b56f Make bash completion run in non interactive mode
@PowerKiKi
Copy link

Should this be closed because it was already solved in symfony ? or do you prefer to wait until it actually is released in composer ?

@Seldaek
Copy link
Member

Seldaek commented Sep 14, 2022

Looked again at fixing symfony/symfony#47394 (comment) and then I took the opportunity to also fix this issue at the same time, even for those without the updated -n completion. So 2.4.2 should work.

emahorvat52 pushed a commit to emahorvat52/composer that referenced this issue Feb 3, 2023
When running without `COMPOSER_ALLOW_SUPERUSER` set so it always happens after prompting, or does not happen if input is non-interactive.

Also fixed support for bash completions hanging when running as root

Fixes composer#11024
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

3 participants