Reputation: 21
Is there a way to detect if a CD is inserted in C on Linux?
I tried it with an SIGIO Signal:
fd = open("/dev/cdrom", O_RDWR | O_NONBLOCK );
struct sigaction saio;
saio.sa_handler = signal_handler_IO;
saio.sa_flags = 0;
saio.sa_restorer = NULL;
sigaction(SIGIO,&saio,NULL);
fcntl(fd, F_SETFL, FNDELAY);
fcntl(fd, F_SETOWN, getpid());
fcntl(fd, F_SETFL, O_ASYNC );
But the function "signal_handler_IO" is never called.
Is there a possibility doing it this way?
Upvotes: 2
Views: 100
Reputation: 75
did you try to use poll()
or any similar functions? (epoll/epoll_wait/select/...)
https://man7.org/linux/man-pages/man2/poll.2.html
Upvotes: 1