Consider the following code:
if (login_tty(channel_data->pty_slave) != 0) // new terminal session
exit(1); // fail
execl("/bin/sh", "sh", mode, command, NULL); // replace process image
It should better be
exit(EXIT_FAILURE) or some other (non 0) exit code, and I recommend calling
perror just before that
exit. As explained by PSKocick there are good reasons to call
_exit (but his arguments could be reversed, one would want to run
atexit and standard fflushs by using
In your case, failure is unlikely, but imagine however if some other process has removed
/bin/sh (e.g. the sysadmin making the stupid mistake of running
/bin/rm -rf . in the root directory, or in
/bin/, perhaps in some other terminal window).
execve could also fail when system resources are (temporarily) exhausted, e.g for
ENOMEMInsufficient kernel memory was available.
And (in rare cases) this could even happen for
exec usage would probably fail (with
E2BIG) if (by mistake)
command was a string of a million of non-null bytes.
As a general coding rule, all important system calls should be checked against failure.