chdir to / before execing program.

This commit is contained in:
hjp 2002-01-24 11:00:02 +00:00
parent efe5d8b4a1
commit 22489c6971
1 changed files with 4 additions and 1 deletions

View File

@ -7,7 +7,8 @@ char obwrap_c_rcsid[] =
* from such a script (e.g., oracle) will have open file descriptors * from such a script (e.g., oracle) will have open file descriptors
* on /var/opt/omni, which is a bad thing. * on /var/opt/omni, which is a bad thing.
* This program closes all file descriptors except stdin and stdout, * This program closes all file descriptors except stdin and stdout,
* changes uid (if -u is given) and executes the specified program. * changes uid (if -u is given), chdirs to the root directory and
* executes the specified program.
*/ */
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
@ -84,6 +85,8 @@ int main(int argc, char **argv) {
dup2(1, 2); dup2(1, 2);
chdir("/");
execv(argv[optind], argv + optind + 1); execv(argv[optind], argv + optind + 1);
fprintf(nonstderr, "%s: could not exec %s: %s\n", fprintf(nonstderr, "%s: could not exec %s: %s\n",
cmnd, argv[optind], strerror(errno)); cmnd, argv[optind], strerror(errno));