Magellan Linux

Contents of /trunk/cdparanoia/patches/cdparanoia-3.9.8-sgio-O_EXCL.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (show annotations) (download)
Tue May 8 20:06:05 2007 UTC (17 years ago) by niro
File size: 5057 byte(s)
-import

1 --- cdparanoia-III-alpha9.8/interface/scan_devices.c.O_EXCL 2001-03-26 00:44:01.000000000 -0500
2 +++ cdparanoia-III-alpha9.8/interface/scan_devices.c 2003-05-20 14:33:16.000000000 -0400
3 @@ -148,7 +148,7 @@
4
5 cdrom_drive *d=NULL;
6 struct stat st;
7 - int fd=-1;
8 + int fd=-1, i;
9 int type;
10 char *description=NULL;
11 char *device;
12 @@ -180,7 +180,12 @@
13 /* Yay, ATAPI... */
14 /* Ping for CDROM-ness */
15
16 - fd=open(device,O_RDONLY|O_NONBLOCK);
17 + fd=open(device,O_RDONLY|O_NONBLOCK|O_EXCL);
18 + for (i = 0; (i<10) && (fd == -1); i++) {
19 + fprintf(stderr, "Error trying to open %s exclusively (%s). retrying in 1 second.\n", device, strerror(errno));
20 + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
21 + fd = open(device,O_RDONLY|O_NONBLOCK|O_EXCL);
22 + }
23 if(fd==-1){
24 idperror(messagedest,messages,"\t\tUnable to open %s",device);
25 free(device);
26 @@ -250,14 +255,6 @@
27 return(NULL);
28 }
29
30 - if(fd==-1)fd=open(device,O_RDONLY|O_NONBLOCK);
31 - if(fd==-1){
32 - idperror(messagedest,messages,"\t\tUnable to open %s",device);
33 - free(device);
34 - if(description)free(description);
35 - return(NULL);
36 - }
37 -
38 /* Minimum init */
39
40 d=calloc(1,sizeof(cdrom_drive));
41 @@ -311,12 +308,19 @@
42 char *devfs_test,
43 char *devfs_other,
44 char *prompt,int messagedest,char **messages){
45 - int dev=open(device,O_RDONLY|O_NONBLOCK);
46 + int dev=-1;
47 scsiid a,b;
48
49 int i,j;
50 char buffer[200];
51
52 + dev=open(device,O_RDONLY|O_NONBLOCK|O_EXCL);
53 + for (i = 0; (i<10) && (dev == -1); i++) {
54 + fprintf(stderr, "Error trying to open %s exclusively (%s). retrying in 1 second.\n", device, strerror(errno));
55 + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
56 + dev = open(device,O_RDONLY|O_NONBLOCK|O_EXCL);
57 + }
58 +
59 /* if we're running under /devfs, build the device name from the
60 device we already have */
61 if(!strncmp(device,devfs_test,strlen(devfs_test))){
62 @@ -327,6 +331,11 @@
63 int matchf;
64 sprintf(pos,"/%s",devfs_other);
65 matchf=open(buffer,O_RDONLY|O_NONBLOCK);
66 + for (i = 0; (i<10) && (matchf==-1); i++) {
67 + fprintf(stderr, "Error trying to open %s exclusively (%s). retrying in 1 seconds.\n", buffer, strerror(errno));
68 + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
69 + matchf = open(buffer,O_RDONLY|O_NONBLOCK);
70 + }
71 if(matchf!=-1){
72 close(matchf);
73 close(dev);
74 @@ -353,7 +362,7 @@
75 for(i=0;i<25;i++){
76 for(j=0;j<2;j++){
77 int pattern=0;
78 - int matchf;
79 + int matchf, k;
80
81 while(prefixes[pattern]!=NULL){
82 switch(j){
83 @@ -368,6 +377,12 @@
84 }
85
86 matchf=open(buffer,O_RDONLY|O_NONBLOCK);
87 + for (k = 0; (k<10) && (matchf==-1); k++) {
88 + fprintf(stderr, "Error trying to open %s exclusively (%s). retrying in 1 second.\n", buffer, strerror(errno));
89 + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
90 + matchf=open(buffer,O_RDONLY|O_NONBLOCK);
91 + }
92 +
93 if(matchf!=-1){
94 if(get_scsi_id(matchf,&b)==0){
95 if(a.bus==b.bus && a.id==b.id && a.lun==b.lun){
96 @@ -438,7 +453,7 @@
97 cdrom_drive *d=NULL;
98 struct stat i_st;
99 struct stat g_st;
100 - int i_fd=-1;
101 + int i_fd=-1, i;
102 int g_fd=-1;
103 int version;
104 int type;
105 @@ -534,8 +549,20 @@
106 goto cdda_identify_scsi_fail;
107 }
108
109 - if(ioctl_device)i_fd=open(ioctl_device,O_RDONLY|O_NONBLOCK);
110 - g_fd=open(generic_device,O_RDWR);
111 + if(ioctl_device) {
112 + i_fd=open(ioctl_device,O_RDONLY|O_NONBLOCK|O_EXCL);
113 + for(i=0; (i<10) && (i_fd==-1); i++) {
114 + fprintf(stderr, "Error trying to open %s exclusively (%s). retrying in 1 second.\n", ioctl_device, strerror(errno));
115 + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
116 + i_fd=open(ioctl_device,O_RDONLY|O_NONBLOCK|O_EXCL);
117 + }
118 + }
119 + g_fd=open(generic_device,O_RDWR|O_EXCL);
120 + for(i=0; (i<10) && (g_fd==-1); i++) {
121 + fprintf(stderr, "Error trying to open %s exclusively (%s). retrying in 1 second.\n", generic_device, strerror(errno));
122 + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
123 + g_fd=open(generic_device,O_RDWR|O_EXCL);
124 + }
125
126 if(ioctl_device && i_fd==-1)
127 idperror(messagedest,messages,"\t\tCould not open SCSI cdrom device "
128 @@ -661,7 +688,7 @@
129
130 cdrom_drive *d=NULL;
131 struct stat st;
132 - int fd=-1;
133 + int fd=-1,i;
134
135 idmessage(messagedest,messages,"\tTesting %s for file/test interface",
136 filename);
137 @@ -678,7 +705,17 @@
138 return(NULL);
139 }
140
141 - fd=open(filename,O_RDONLY);
142 + /* I'm not certain this one nees O_EXCL, but it can't hurt */
143 + fd=open(filename,O_RDONLY|O_EXCL);
144 + for(i=0; (i<10) && (fd==-1); i++) {
145 + fprintf(stderr, "Error trying to open %s exclusively (%s). retrying in 1 second.\n", filename, strerror(errno));
146 + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0));
147 + fd=open(filename,O_RDONLY|O_EXCL);
148 + }
149 +
150 + if(ioctl_device && i_fd==-1)
151 + idperror(messagedest,messages,"\t\tCould not open SCSI cdrom device "
152 + "%s (continuing)",ioctl_device);
153
154 if(fd==-1){
155 idperror(messagedest,messages,"\t\tCould not open file %s",filename);