Debugging open() command call with truss

拟墨画扇 提交于 2019-12-12 04:49:50

问题


Using truss -t'open' $(program_call) I get:

open("command.txt", O_RDONLY|O_NONBLOCK)      = 5
response FIFO file descriptor = -1
// Open call was literally sandwiched between print commands, but its not here?
response FIFO file descriptor = 9
open("response.txt", O_WRONLY|O_NONBLOCK)     Err#6 ENXIO
response.txt: No such device or address

The thing is, I initialized the file descriptor to -1, so I KNOW that the open call must have succeeded because it changed the value of the variable. The file descriptor is literally initialized to -1, then somehow gets changed to 9 in the open command call (otherwise the program would end there) but yet the open call does NOT show up in the truss call, and the computer does not recognize it as being open.

Some code:

if ((outfd = open(CMD_FIFO_NAME, O_WRONLY | O_NONBLOCK)) == -1) {
    fprintf(stderr, "Client: Failed to open %s FIFO.\n", CMD_FIFO_NAME);
    exit(1);
}
printf("RESP_FIFO FILE DESCRIPTOR: %d\n", infd);
/* Open the response FIFO for non-blocking reads. */
if ((infd = open(RESP_FIFO_NAME, O_RDONLY | O_NONBLOCK)) == -1) {
    fprintf(stderr, "Client: Failed to open %s FIFO.\n", RESP_FIFO_NAME);
    exit(1);
}
else printf("RESP_FIFO FILE DESCRIPTOR: %d\n", infd);

回答1:


truss -f -t'open,close,read,write' run.sh was useful enough to find my errors, where run.sh was a bash file containing the proper execution of my program.



来源:https://stackoverflow.com/questions/16398377/debugging-open-command-call-with-truss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!