Attempting to correct the problem about which I earlier posted - wherein a system() call which apparently succeeds is perceived to have failed by the * process, I changed code in app_system.c so that it would be more discerning... res = system((char *)data); /* if (res < 0) { ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); res = -1; } else if (res == 127) { ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); res = -1; */ if (res == -1) { ast_log(LOG_WARNING, "Fork failed for '%s'\n", (char *)data); res = -1; } else if (WEXITSTATUS(res) != 0) { ast_log(LOG_WARNING, "Error completion for '%s'\n", (char *)data); res = -1; It is now indeed more discerning, but it has reported Fork failed. But the fork most certainly has not failed! The shell command invoked has run, and what's more, completed successfully, producing the expected files. Referring to the system(2) man page (Red Hat 9, stock)... RETURN VALUE The value returned is -1 on error (e.g. fork failed), and the return status of the command otherwise. This latter return status is in the format specified in wait(2). Thus, the exit code of the command will be WEXITSTATUS(status). In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127). ...and noting that "fork failed" is only an example of an error, I'm wondering what *other* condition might cause the -1 return value. Does anyone have any ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20040221/9113f3b1/attachment.htm
andrewg@felinemenace.org
2004-Feb-21 07:13 UTC
[Asterisk-Users] System called seems forked up
On Sat, Feb 21, 2004 at 09:08:02AM -0500, Bill Michaelson wrote:> > Does anyone have any ideas? >Can you check the errno? strerror(errno); should give you a string of why it failed. (Just be careful not to use other stuff which touches errno after the fork() (note, I didn't read over the code, just something that came to mind.)
>It is now indeed more discerning, but it has reported Fork failed. But >the fork most certainly has not failed! The shell command invoked has >run, and what's more, completed successfully, producing the expected files.> Does anyone have any ideas?andrewg@felinemenace.org suggested: Can you check the errno? strerror(errno); should give you a string of why it failed. (Just be careful not to use other stuff which touches errno after the fork() Of course - very good suggestion (embarrassed I didn't think of it)... anyway... it returns 10, which perror tells me is "No child processes". Sooo, I suppose the spawned process is somehow disassociated from the process group prior to execution of the wait() embedded within the system()? Duuh... I'm still stumped, but I guess we are on to something? On the other hand, if a fork does really fail, one might expect errno to be 10 in that case too. I've half a mind to break it out into a fork/exec/wait for myself, but, uh, ugh. I guess I'm lazy. Please, briliant insights, anybody? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20040221/25f319c1/attachment.htm