I have received a file descriptor for a USB device from an Android app (using getFileDescriptor()), sent it via JNI in native code and received it in a child process (AVRDude) via a Unix socket and tried to use for uploading.
So I'm getting a "Not a typewriter" error. Does it mean that file descriptor was passed incorrectly (it is a positive int and it is not equal to -1 after receiving)? Or can there be another error? Can it be a permissions issue (though permissions to UsbDevice is granted and passing via a socket seems to hold permissions, the device is not rooted)?
The code used (ser_posix.c
in AVRDude 5_11_0 sources):
fprintf(stdout, "Try to set baud = %i for fd = %i", baud, usbfd);
if (!isatty(usbfd)) { // Error here!
fprintf(stderr, "!isatty\n");
return -ENOTTY;
}
Right after receiving from the socket file descriptor is checked to be valid (and I believe it is):
if (!(fcntl(usbfd, F_GETFL) != -1 || errno != EBADF)) {
fprintf(stderr, "Invalid file descriptor %d, - %s", usbfd, strerror(errno));
exit(1);
}
Originally the file descriptor in ser_posix is received like that (and I believe it's working):
fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
In my implementation I use the file descriptor from the Android app instead. Is it what's expected?