On couple of RHEL 5.8, I am facing problem with execve calls. The execve is not failing however, getting the following error:
/bin/bash: h: No such file or directory
I am using it the following way in C++ code:
::fork();
.
.
.
char achWritePipeDescriptor[8], achReadPipeDescriptor[8];
snprintf(achWritePipeDescriptor, sizeof(achWritePipeDescriptor), "%d", fWritePipeDescriptor);
snprintf(achReadPipeDescriptor, sizeof(achReadPipeDescriptor), "%d", fReadPipeDescriptor);
// fWritePipeDescriptor and fReadPipeDescriptor are integers
::execl("/bin/sh", "/bin/sh", "Launcher.sh", achWritePipeDescriptor, achReadPipeDescriptor, (char*)0);
switch(errno)
{
default:
printf("\n Failed to launch Launcher.sh\n");
break;
}
The exec call here is not failing, but I was getting above error when trying to interact with the above script.sh. The strace output for this process looks like following:
execve("/bin/bash", ["/bin/bash", "h", "10", "6"], [/* 36 vars */]) = 0
.
.
.
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
fstat(2, 0x7fff23708910) = -1 EBADF (Bad file descriptor)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b9d1c785000
write(2, "/bin/bash: h: No such file or di"..., 40) = -1 EBADF (Bad file descriptor)
exit_group(127) = ?
Process 13030 detached
There is no file "h" being referenced here, but the last character of the script name is "h". Also, the script that I am trying to exec does exist at expected location and is having sufficient permissions.
I have no clue from where the "h" is coming.
I changed my execve call to following:
::execl("Launcher.sh", "Launcher.sh", achWritePipeDescriptor, achReadPipeDescriptor,(char*)0);
With this, it worked properly, but down the code below, I am seeing similar error for another execl call. The difference in the second exec is that the binary is different, but the error remains the same.
I am not sure, if this is server specific issue.
Any clues, any troubleshooting steps would be of great help.
My Bad, I should have mentioned it earlier itself, the <script.sh>
is a placeholder. I tried to indicate that a shell script is what I am trying to exec.
Also, writefd
and readfd
are char*
here. It can be clearly seen in the strace output I have pasted here. Again, the exec is not failing here as i am not seeing the "Failed to launch Launcher.sh" message.