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

Julien Blache jblache at alioth.debian.org
Sat May 12 15:39:28 UTC 2007


Author: jblache
Date: 2007-05-12 15:39:27 +0000 (Sat, 12 May 2007)
New Revision: 329

Modified:
   trunk/ChangeLog
   trunk/INSTALL
   trunk/pommed/cd_eject.c
Log:
Back to using eject(1) for CD ejection.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-05-12 13:00:12 UTC (rev 328)
+++ trunk/ChangeLog	2007-05-12 15:39:27 UTC (rev 329)
@@ -2,7 +2,7 @@
 --------------------
 
 version 1.5:
-	- pommed: added umount support to the CD ejection code.
+	- pommed: back to using eject(1) for CD ejection.
 
 version 1.4:
 	- pommed: add proper support for the PowerBook5,8 and PowerBook5,9

Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL	2007-05-12 13:00:12 UTC (rev 328)
+++ trunk/INSTALL	2007-05-12 15:39:27 UTC (rev 329)
@@ -17,6 +17,7 @@
  - libdbus
  - libasound
  - libofapi (aka oflib); see below
+ - eject
 
 gpomme requires:
  - libdbus

Modified: trunk/pommed/cd_eject.c
===================================================================
--- trunk/pommed/cd_eject.c	2007-05-12 13:00:12 UTC (rev 328)
+++ trunk/pommed/cd_eject.c	2007-05-12 15:39:27 UTC (rev 329)
@@ -41,96 +41,6 @@
 #include "dbus.h"
 
 
-static char *
-check_mount(char *device)
-{
-  char line[1024];
-  char dev[512];
-  char mpoint[512];
-
-  int ret;
-  FILE *fp;
-
-  fp = fopen("/proc/mounts", "r");
-  if (fp == NULL)
-    {
-      logmsg(LOG_ERR, "Could not open mount table for reading: %s\n", strerror(errno));
-      return NULL;
-    }
-
-  while (fgets(line, sizeof(line), fp) != 0)
-    {
-      ret = sscanf(line, "%511s %511s", dev, mpoint);
-      if (ret < 2)
-	continue;
-
-      if (strcmp(dev, device) == 0)
-	{
-	  fclose(fp);
-	  return strdup(mpoint);
-	}
-    }
-
-  fclose(fp);
-
-  return NULL;
-}
-
-static int
-try_to_unmount(char *device)
-{
-  char *rdev;
-  char *mpoint;
-  int ret;
-
-  /* passing NULL is a GNU extension, recommended by POSIX */
-  rdev = realpath(device, NULL);
-  if (rdev == NULL)
-    return -1;
-
-  mpoint = check_mount(rdev);
-  if (mpoint == NULL)
-    {
-      free(rdev);
-      return 0;
-    }
-
-  logdebug("%s (%s) mounted on %s; attempting to unmount\n", device, rdev, mpoint);
-
-  ret = fork();
-  if (ret == 0) /* exec umount */
-    {
-      /* We need to call umount because mount/umount maintain /etc/mtab ... */
-      execl("/bin/umount", "umount", mpoint, NULL);
-
-      logmsg(LOG_ERR, "Could not execute umount: %s", strerror(errno));
-      exit(1);
-    }
-  else if (ret == -1)
-    {
-      logmsg(LOG_ERR, "Could not fork: %s\n", strerror(errno));
-      free(rdev);
-      free(mpoint);
-      return -1;
-    }
-  else
-    {
-      waitpid(ret, &ret, 0);
-      if ((WIFEXITED(ret) == 0) || (WEXITSTATUS(ret) != 0))
-	{
-	  logmsg(LOG_INFO, "umount failed");
-	  free(rdev);
-	  free(mpoint);
-	  return -1;
-	}
-    }
-
-  free(rdev);
-  free(mpoint);
-  return 0;
-}
-
-
 void
 cd_eject(void)
 {
@@ -177,27 +87,30 @@
 	return;
     }
 
-  ret = try_to_unmount(eject_cfg.device);
-  if (ret < 0)
+  ret = fork();
+  if (ret == 0) /* exec eject */
     {
-      logmsg(LOG_ERR, "Could not unmount device");
-      return;
-    }
+      execl("/usr/bin/eject", "eject", eject_cfg.device, NULL);
 
-  mbpdbus_send_cd_eject();
-
-  fd = open(eject_cfg.device, O_RDONLY | O_NONBLOCK);
-  if (fd < 0)
+      logmsg(LOG_ERR, "Could not execute eject: %s", strerror(errno));
+      exit(1);
+    }
+  else if (ret == -1)
     {
-      logmsg(LOG_ERR, "Could not open CD/DVD device: %s", strerror(errno));
+      logmsg(LOG_ERR, "Could not fork: %s\n", strerror(errno));
       return;
     }
+  else
+    {
+      mbpdbus_send_cd_eject();
 
-  ret = ioctl(fd, CDROMEJECT);
-  if (ret != 0)
-    logmsg(LOG_ERR, "Eject command failed: %s", strerror(errno));
-
-  close(fd);
+      waitpid(ret, &ret, 0);
+      if ((WIFEXITED(ret) == 0) || (WEXITSTATUS(ret) != 0))
+	{
+	  logmsg(LOG_INFO, "eject failed");
+	  return;
+	}
+    }
 }
 
 




More information about the Pommed-commits mailing list