Debugging open() command call with truss

564 views Asked by At

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

There are 1 answers

0
ICantNameMe On BEST ANSWER

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.