[Pommed-commits] r302 - in trunk: . pommed

Julien Blache jblache at alioth.debian.org
Sat Apr 14 17:13:45 UTC 2007


Author: jblache
Date: 2007-04-14 17:13:45 +0000 (Sat, 14 Apr 2007)
New Revision: 302

Modified:
   trunk/ChangeLog
   trunk/pommed/cd_eject.c
   trunk/pommed/cd_eject.h
Log:
Rewrite the CD ejection routine.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-04-14 17:11:52 UTC (rev 301)
+++ trunk/ChangeLog	2007-04-14 17:13:45 UTC (rev 302)
@@ -5,6 +5,8 @@
 	- gpomme: added configuration GUI, courtesy of Daniel G. SIEGEL.
 	- gpomme: added elegant-bright and elegant-dark themes, courtesy
 	of Natanael Arndt <arndtn at gmx.de>.
+	- pommed: rewrote CD ejection routine; no longer depends on eject,
+	sends the dbus notification before ejecting the CD.
 
 version 1.2:
 	- pommed: PowerBook5,5 has an ADB keyboard, not a USB keyboard.

Modified: trunk/pommed/cd_eject.c
===================================================================
--- trunk/pommed/cd_eject.c	2007-04-14 17:11:52 UTC (rev 301)
+++ trunk/pommed/cd_eject.c	2007-04-14 17:13:45 UTC (rev 302)
@@ -21,12 +21,17 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include <syslog.h>
 
+#include <sys/ioctl.h>
+#include <linux/cdrom.h>
+
 #include "pommed.h"
 #include "conffile.h"
 #include "cd_eject.h"
@@ -36,27 +41,52 @@
 void
 cd_eject(void)
 {
-  char cmd[128];
+  int fd;
   int ret;
 
   if (!eject_cfg.enabled)
     return;
 
-  strcpy(cmd, CD_EJECT_CMD " ");
-  strncat(cmd, eject_cfg.device, sizeof(cmd) - 1);
+  fd = open(eject_cfg.device, O_RDONLY | O_NONBLOCK);
+  if (fd < 0)
+    {
+      logmsg(LOG_ERR, "Could not open CD/DVD device");
 
-  ret = system(cmd);
+      return;
+    }
 
-  if (WEXITSTATUS(ret) != 0)
+  /* Check drive status */
+  ret = ioctl(fd, CDROM_DRIVE_STATUS);
+  switch (ret)
     {
-      /* 127 means "shell not available" */
-      if (WEXITSTATUS(ret) != 127)
-	logmsg(LOG_WARNING, "CD ejection failed, eject returned %d", WEXITSTATUS(ret));
+      case CDS_NO_INFO: /* fall through */
+	logmsg(LOG_INFO, "Driver does not support CDROM_DRIVE_STATUS, trying to eject anyway");
 
-      return;
+      case CDS_DISC_OK:
+	mbpdbus_send_cd_eject();
+
+	ret = ioctl(fd, CDROMEJECT);
+	if (ret != 0)
+	  logmsg(LOG_ERR, "Eject command failed");
+	break;
+
+      case CDS_NO_DISC:
+	logmsg(LOG_INFO, "No disc in CD/DVD drive");
+	break;
+
+      case CDS_DRIVE_NOT_READY:
+	logmsg(LOG_INFO, "Drive not ready, please retry later");
+	break;
+
+      case CDS_TRAY_OPEN:
+	logmsg(LOG_INFO, "Drive tray already open");
+	break;
+
+      default:
+	logmsg(LOG_INFO, "CDROM_DRIVE_STATUS returned %d", ret);
     }
 
-  mbpdbus_send_cd_eject();
+  close(fd);
 }
 
 
@@ -68,13 +98,4 @@
       eject_cfg.enabled = 0;
       return;
     }
-
-  if (strlen(eject_cfg.device) > 100)
-    {
-      eject_cfg.enabled = 0;
-
-      logmsg(LOG_INFO, "CD/DVD device path too long, CD ejection disabled");
-
-      return;
-    }
 }

Modified: trunk/pommed/cd_eject.h
===================================================================
--- trunk/pommed/cd_eject.h	2007-04-14 17:11:52 UTC (rev 301)
+++ trunk/pommed/cd_eject.h	2007-04-14 17:13:45 UTC (rev 302)
@@ -6,9 +6,6 @@
 #define __CD_EJECT_H__
 
 
-#define CD_EJECT_CMD            "/usr/bin/eject"
-
-
 void
 cd_eject(void);
 




More information about the Pommed-commits mailing list