[Libburn] Small patch for poll
Warly
warly at mandrakesoft.com
Wed Aug 25 04:58:48 PDT 2004
Not to segfault if the drive to poll is not the 2nd one, and to be able
to switch for one burner to another with CTRL-C if several are present
(not tested).
diff -ur libburn-0.2/test/poll.c libburn-0.2.w/test/poll.c
--- libburn-0.2/test/poll.c 2003-12-15 07:16:51.000000000 +0100
+++ libburn-0.2.w/test/poll.c 2004-08-25 13:49:28.217350727 +0200
@@ -6,10 +6,17 @@
#include <unistd.h>
#include <stdio.h>
+#include <signal.h>
#include <assert.h>
static struct burn_drive_info *drives;
static unsigned int n_drives;
+int NEXT;
+
+static void catch_int ()
+{
+ NEXT = 1;
+}
static void poll_drive(int d)
{
@@ -29,8 +36,8 @@
while ((s = burn_disc_get_status(drives[d].drive))
== BURN_DISC_UNREADY)
usleep(1000);
-
- while (1) {
+
+ while (NEXT == 0) {
sleep(2);
mmc_get_event(drives[d].drive);
}
@@ -39,6 +46,9 @@
int main()
{
+ int i;
+ struct sigaction newact;
+ struct sigaction oldact;
fprintf(stderr, "Initializing library...");
if (burn_initialize())
fprintf(stderr, "Success\n");
@@ -50,8 +60,18 @@
fprintf(stderr, "Scanning for devices...");
while (!burn_drive_scan(&drives, &n_drives)) ;
fprintf(stderr, "Done\n");
+ if (!drives) {
+ printf("No burner found\n");
+ return 1;
+ }
- poll_drive(2);
+ newact.sa_handler = catch_int;
+ sigaction(SIGINT, &newact, &oldact);
+ for (i = 0; i < n_drives; i++) {
+ NEXT=0;
+ poll_drive(i);
+ }
+ sigaction(SIGINT, &oldact, NULL);
burn_drive_info_free(drives);
burn_finish();
return 0;
--
Warly
More information about the libburn
mailing list