Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I ever have to worry that "no shell will be available" to execute a system command?

Tags:

The manual page "man system" contains the following section:

  • If command is NULL, then a nonzero value if a shell is available, or 0 if no shell is available.

which basically indicates that I can check with if(system(NULL) != 0) {foo;} if a shell is currently available or not.

When do I have to consider to do so? Because I never ever got an error which was related to this specific case.

like image 769
Lavair Avatar asked Nov 04 '18 23:11

Lavair


1 Answers

Also from man system:

[...] even though POSIX.1-2001 requires a conforming implementation to provide a shell, that shell may not be available or executable if the calling program has previously called chroot(2) [...]

So that's a possible case where /bin/sh might not be available. In practice I wouldn't worry too much about it. (But then again, I probably wouldn't use system in real code in the first place.)

like image 177
melpomene Avatar answered Oct 21 '22 10:10

melpomene