eject: close file description after usage

Also reindent the switch statement. CID 702040.
This commit is contained in:
Philippe Saint-Pierre
2015-07-02 16:12:34 -04:00
parent e2a8ef11f6
commit 39ceaa9c28
+15 -6
View File
@@ -151,17 +151,17 @@ static int do_eject(char operation, char *device)
return 1;
}
switch (operation) {
case 'h':
return usage("eject");
case 'e':
if (ioctl(fd, B_EJECT_DEVICE, NULL, 0) < 0) {
perror(device);
close(fd);
return 1;
}
break;
case 'l':
if (ioctl(fd, B_LOAD_MEDIA, NULL, 0) < 0) {
perror(device);
close(fd);
return 1;
}
break;
@@ -169,6 +169,7 @@ static int do_eject(char operation, char *device)
bval = true;
if (ioctl(fd, B_SCSI_PREVENT_ALLOW, &bval, sizeof(bval)) < 0) {
perror(device);
close(fd);
return 1;
}
break;
@@ -176,12 +177,15 @@ static int do_eject(char operation, char *device)
bval = false;
if (ioctl(fd, B_SCSI_PREVENT_ALLOW, &bval, sizeof(bval)) < 0) {
perror(device);
close(fd);
return 1;
}
break;
case 'q':
if (ioctl(fd, B_GET_MEDIA_STATUS, &devstatus, sizeof(devstatus)) < 0) {
if (ioctl(fd, B_GET_MEDIA_STATUS, &devstatus, sizeof(devstatus))
< 0) {
perror(device);
close(fd);
return 1;
}
switch (devstatus) {
@@ -193,8 +197,10 @@ static int do_eject(char operation, char *device)
}
break;
case 's':
if (ioctl(fd, B_GET_MEDIA_STATUS, &devstatus, sizeof(devstatus)) < 0) {
if (ioctl(fd, B_GET_MEDIA_STATUS, &devstatus, sizeof(devstatus))
< 0) {
perror(device);
close(fd);
return 1;
}
switch (devstatus) {
@@ -202,12 +208,14 @@ static int do_eject(char operation, char *device)
case B_DEV_NO_MEDIA:
if (ioctl(fd, B_EJECT_DEVICE, NULL, 0) < 0) {
perror(device);
close(fd);
return 1;
}
break;
case B_DEV_DOOR_OPEN:
if (ioctl(fd, B_LOAD_MEDIA, NULL, 0) < 0) {
perror(device);
close(fd);
return 1;
}
break;
@@ -215,9 +223,10 @@ static int do_eject(char operation, char *device)
perror(device);
}
break;
case 'h':
default:
usage("eject");
return 1;
close(fd);
return usage("eject");
}
close(fd);
return 0;