Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[console] Exit code should not be capped, but masked #13996

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

Closed
jaytaph opened this issue Mar 20, 2015 · 9 comments
Closed

[console] Exit code should not be capped, but masked #13996

jaytaph opened this issue Mar 20, 2015 · 9 comments

Comments

@jaytaph
Copy link
Contributor

jaytaph commented Mar 20, 2015

Inside the console Application.php, an exit code is capped to 255 if it is larger than 255. This is in agreement with Linux where exit codes are only valid in the 0-255 range.

However, Linux by default (including most applications, like bash), do not cap, but mask the exit code with & 255 instead. Accordingly, an application that exits with status code 300 will receive the exit code 44. In a symfony console application, this would be 255.

Maybe this is something that might be changed as well in the application.php?

@Tobion
Copy link
Contributor

Tobion commented Mar 23, 2015

Ref #8202

http://www.php.net/manual/en/function.exit.php

Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

So in php terms we would need to mask with 254 which would also not be consistent with linux.

@kingcrunch
Copy link
Contributor

@Tobion It's been a while I found a practical use for bit-operations, but if I remember correctly masking with 254 would mean, that you only can set even numbers, because the lowest bit is missing (011 & 010 = 010)

@jaytaph
Copy link
Contributor Author

jaytaph commented Mar 26, 2015

It seems that a simple php script:

  php -r 'exit(300);' ; echo $?

actually outputs 44 as well (strace shows exit_group(300), so php does not cap either).

Maybe it would even be better to not handle these situations after all, and remove the cap all together without replacing it with a mask?

@fabpot
Copy link
Member

fabpot commented Mar 27, 2015

@jaytaph If PHP is doing the right thing for us, let's remove the logic on our side.

@jaytaph
Copy link
Contributor Author

jaytaph commented Apr 9, 2015

@fabpot I think that is a good idea.. however, I do not know what will happen on windows machines. Maybe somebody should verify if this behaviour is the same?

@Tobion
Copy link
Contributor

Tobion commented Apr 9, 2015

@jaytaph on windows it's not masked. The code below returns 300. So I guess the masking is done by the linux console and not by php because in mingw your example also outputs 44.

php -r "exit(300);"
echo %ERRORLEVEL%

@jaytaph
Copy link
Contributor Author

jaytaph commented Apr 9, 2015

@Tobion The cap is actually done by the linux exit_group system call: http://lxr.free-electrons.com/source/kernel/exit.c#L842 Here is the exit code masked with 0xFF (and shifted, because the lower bits have different meanings, like core dumped,stopped, continued etc).

Same exit result (44) works on Darwin too.

It seems that under windows, exit codes are 32-bit signed integers (http://en.wikipedia.org/wiki/Exit_status#Windows), so here no filtering should take place anyway (an exit(300) seems valid).

Maybe we should thus get rid of the cap, and not even replace it with a mask? As every supported OS seems to handle this fine, and PHP doesn't really care either way (exit codes are passed directly to the OS), even the 255 reserved code seems to cause no issues (a quick scan through the php core doesn't even seem to suggest 255 should be considered reserved, maybe this is a remnant from past versions).

@stof
Copy link
Member

stof commented Jan 28, 2016

Not capping has a severe issue: exit(256) will then become a 0 exit code on Linux, which is a success one. This is bad (especially as we can use the exception code as exit code)

@javiereguiluz
Copy link
Member

Closing it for the reasons given by @stof in the previous comment and @Tobion in #17591 (comment).

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

No branches or pull requests

6 participants