From xors@sendmail.ru  Thu Feb  8 23:03:40 2007
Return-Path: <xors@sendmail.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id A724E16A405
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  8 Feb 2007 23:03:40 +0000 (UTC)
	(envelope-from xors@sendmail.ru)
Received: from softel.ru (mail.softel.ru [217.25.84.28])
	by mx1.freebsd.org (Postfix) with ESMTP id CCBF713C442
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  8 Feb 2007 23:03:39 +0000 (UTC)
	(envelope-from xors@sendmail.ru)
Received: from pg.org ([217.25.92.202])
	by softel.ru (8.12.10/8.12.10/check_local-5) with ESMTP id l18MDipR000953
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 9 Feb 2007 01:13:44 +0300
Received: from xors.pg.org (localhost.pg.org [127.0.0.1])
	by pg.org (8.13.8/8.13.8) with ESMTP id l18MJpcm021037
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 9 Feb 2007 01:19:51 +0300 (MSK)
	(envelope-from xors@xors.pg.org)
Received: (from xors@localhost)
	by xors.pg.org (8.13.8/8.13.8/Submit) id l18MJpBe021036;
	Fri, 9 Feb 2007 01:19:51 +0300 (MSK)
	(envelope-from xors)
Message-Id: <200702082219.l18MJpBe021036@xors.pg.org>
Date: Fri, 9 Feb 2007 01:19:51 +0300 (MSK)
From: Maxim Samsonov <xors@sendmail.ru>
Reply-To: Maxim Samsonov <xors@sendmail.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH]: x11/kdebase3 [kioslave/media] media ejecting, various HAL backend problems
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         108949
>Category:       ports
>Synopsis:       [PATCH]: x11/kdebase3 [kioslave/media] media ejecting, various HAL backend problems
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kde
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 08 23:10:22 GMT 2007
>Closed-Date:    Sat Feb 10 03:51:16 GMT 2007
>Last-Modified:  Sat Feb 10 03:51:16 GMT 2007
>Originator:     Maxim Samsonov
>Release:        FreeBSD 6.2-STABLE i386
>Organization:
>Environment:
>Description:
This patch tries to solve the problems in
kioslave/media which are listed below:
1. Correct ejecting of mounted volumes (unmount before eject).
2. Mounting of removable media drives (such as CD-ROM drives) 
   listed in /etc/fstab (removes checking linux's "user" mount option).
3. Polling floppy drives over the mount state (FreeBSD HAL doesn't do this).
4. Informing the fileview when HAL notifies that
   mounting is completed.
5. Mounting cdrom volume in locale charset.
>How-To-Repeat:
>Fix:
--- kdebase3.diff begins here ---
diff -ubdBrN kdebase3.orig/Makefile kdebase3/Makefile
--- kdebase3.orig/Makefile	Mon Jan  8 13:35:52 2007
+++ kdebase3/Makefile	Thu Feb  8 23:51:24 2007
@@ -71,7 +71,8 @@
 .endif
 
 .if defined(WITH_HAL) && ${OSVERSION} > 500035
-EXTRA_PATCHES=	${FILESDIR}/extrapatch-kioslave_media_mediamanager-halbackend.cpp
+EXTRA_PATCHES=	${FILESDIR}/extrapatch-kioslave_media_mediamanager-halbackend.cpp \
+		${FILESDIR}/extrapatch-kioslave_media_mediamanager-halbackend.h
 LIB_DEPENDS+=	dbus-qt-1.1:${PORTSDIR}/devel/dbus-qt3 \
 		hal.1:${PORTSDIR}/sysutils/hal
 PLIST_SUB+=	MEDIA=""
diff -ubdBrN kdebase3.orig/files/extrapatch-kioslave_media_mediamanager-halbackend.cpp kdebase3/files/extrapatch-kioslave_media_mediamanager-halbackend.cpp
--- kdebase3.orig/files/extrapatch-kioslave_media_mediamanager-halbackend.cpp	Wed Dec 20 23:42:54 2006
+++ kdebase3/files/extrapatch-kioslave_media_mediamanager-halbackend.cpp	Thu Feb  8 23:38:29 2007
@@ -1,14 +1,43 @@
---- kioslave/media/mediamanager/halbackend.cpp.orig	Sun Oct  1 19:31:54 2006
-+++ kioslave/media/mediamanager/halbackend.cpp	Wed Dec 20 20:22:28 2006
-@@ -17,7 +17,6 @@
+--- kioslave/media/mediamanager/halbackend.cpp.orig	Sun Oct  1 21:31:54 2006
++++ kioslave/media/mediamanager/halbackend.cpp	Tue Feb  6 02:14:55 2007
+@@ -17,9 +17,13 @@
  */
  
  #include "halbackend.h"
 -#include "linuxcdpolling.h"
  
  #include <stdlib.h>
++#ifdef Q_OS_FREEBSD
++#include <sys/param.h>
++#include <sys/ucred.h>
++#include <sys/mount.h>
++#endif
  
-@@ -242,11 +241,11 @@
+ #include <qfile.h>
+ #include <klocale.h>
+@@ -66,6 +70,10 @@
+     /* Close HAL connection */
+     if (m_halContext)
+     {
++#ifdef Q_OS_FREEBSD
++        m_pollTimer.stop();
++        m_pollMediaList.clear();
++#endif
+         const QPtrList<Medium> medlist = m_mediaList.list();
+         QPtrListIterator<Medium> it (medlist);
+         for ( const Medium *current_medium = it.current(); current_medium; current_medium = ++it)
+@@ -185,6 +193,10 @@
+ 
+     libhal_free_string_array( halDeviceList );
+ 
++#ifdef Q_OS_FREEBSD
++    connect(&m_pollTimer, SIGNAL(timeout()),
++        this, SLOT(pollMediaList()));
++#endif
+     return true;
+ }
+ 
+@@ -242,11 +254,11 @@
          Medium* medium = new Medium(udi, "");
  
          QMap<QString,QString> options = MediaManagerUtils::splitOptions(mountoptions(udi));
@@ -22,7 +51,44 @@
          }
          setVolumeProperties(medium);
          m_mediaList.addMedium(medium, allowNotification);
-@@ -326,7 +325,7 @@
+@@ -264,6 +276,11 @@
+             Medium* medium = new Medium(udi, "");
+             setFloppyProperties(medium);
+             m_mediaList.addMedium(medium, allowNotification);
++#ifdef Q_OS_FREEBSD
++            m_pollTimer.stop();
++            m_pollMediaList.append(medium);
++            m_pollTimer.start(250);
++#endif
+             return;
+         }
+ 
+@@ -285,12 +302,23 @@
+ 
+ void HALBackend::RemoveDevice(const char *udi)
+ {
++#ifdef Q_OS_FREEBSD
++    m_pollMediaList.remove(m_mediaList.findById(udi));
++    if (m_pollMediaList.isEmpty())
++        m_pollTimer.stop();
++#endif
+     m_mediaList.removeMedium(udi, true);
+ }
+ 
+ void HALBackend::ModifyDevice(const char *udi, const char* key)
+ {
+-    Q_UNUSED(key);
++    if (
++        !( strcmp(key, "info.hal_mount.created_mount_point")
++        && strcmp(key, "info.hal_mount.mounted_by_uid")
++        && strcmp(key, "volume.mount_point")
++        && strcmp(key, "volume.is_mounted_read_only")))
++        return;
++
+     const char* mediumUdi = findMediumUdiFromUdi(udi);
+     if (!mediumUdi)
+         return;
+@@ -326,7 +354,7 @@
      }
  
      const char* mediumUdi = findMediumUdiFromUdi(udi);
@@ -31,7 +97,7 @@
      if (!mediumUdi)
          return;
  
-@@ -384,7 +383,7 @@
+@@ -384,7 +412,7 @@
          {
              Medium m( *cmedium );
              if ( setFstabProperties( &m ) ) {
@@ -40,7 +106,15 @@
                  m_mediaList.changeMediumState(m, false);
              }
              return;
-@@ -469,28 +468,23 @@
+@@ -399,6 +427,7 @@
+         setFloppyProperties(m);
+     if (libhal_device_query_capability(m_halContext, mediumUdi, "camera", NULL))
+         setCameraProperties(m);
++    m->setHalMounted(libhal_device_get_property_string(m_halContext, mediumUdi, "info.hal_mount.created_mount_point", NULL));
+ 
+     m_mediaList.changeMediumState(*m, false);
+ 
+@@ -469,28 +498,23 @@
              else
                  mimeType = "media/dvd" + MOUNT_SUFFIX;
  
@@ -80,7 +154,7 @@
      }
      else
      {
-@@ -575,7 +569,7 @@
+@@ -575,7 +599,7 @@
              }
          }
  
@@ -89,7 +163,7 @@
          QString fstype = medium->fsType();
          if ( fstype.isNull() )
              fstype = "auto";
-@@ -762,7 +756,7 @@
+@@ -762,7 +786,7 @@
          if (t.endsWith("="))
              t = t.left(t.length() - 1);
          valids[t] = true;
@@ -98,7 +172,17 @@
      }
      libhal_free_string_array(array);
      QStringList result;
-@@ -887,7 +881,7 @@
+@@ -882,12 +906,17 @@
+             result << "journaling=ordered";
+     }
+ 
++    if (valids.contains("-C"))
++    {
++        result << QString("charset=%1").arg(KGlobal::locale()->encoding());
++    }
++
+     return result;
+ }
  
  bool HALBackend::setMountoptions(const QString &name, const QStringList &options )
  {
@@ -107,7 +191,7 @@
  
      KConfig config("mediamanagerrc");
      config.setGroup(name);
-@@ -927,7 +921,7 @@
+@@ -927,7 +956,7 @@
      if (!(dmesg = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
                                                  "org.freedesktop.Hal.Device.Volume",
                                                  "Mount"))) {
@@ -116,7 +200,7 @@
          return i18n("Internal Error");
      }
  
-@@ -935,7 +929,7 @@
+@@ -935,7 +964,7 @@
                                     DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &poptions, noptions,
                                     DBUS_TYPE_INVALID))
      {
@@ -125,7 +209,7 @@
          dbus_message_unref (dmesg);
          return i18n("Internal Error");
      }
-@@ -963,7 +957,7 @@
+@@ -963,7 +992,7 @@
          return qerror;
      }
  
@@ -134,7 +218,7 @@
  
      dbus_message_unref (dmesg);
      dbus_message_unref (reply);
-@@ -974,7 +968,7 @@
+@@ -974,15 +1003,33 @@
  
  void HALBackend::slotResult(KIO::Job *job)
  {
@@ -143,7 +227,34 @@
      if (job->error())
      {
          KMessageBox::error(0, job->errorText());
-@@ -992,7 +986,7 @@
+     }
+-    ResetProperties( mount_jobs[job].latin1() );
+     mount_jobs.remove(job);
+ }
+ 
++#ifdef Q_OS_FREEBSD
++void HALBackend::pollMediaList()
++{
++    struct statfs *mntBuf;
++    int mntNum = getmntinfo(&mntBuf, MNT_NOWAIT);
++    QPtrList<Medium>::iterator it = m_pollMediaList.begin();
++    QPtrList<Medium>::iterator end = m_pollMediaList.end();
++    for (; it!=end; ++it)
++    {
++        bool mounted = false;
++        const char *dev = (*it)->deviceNode().ascii();
++        for (int n = mntNum-1; n >= 0 && !mounted; n--) 
++            mounted = !strcmp(dev, mntBuf[n].f_mntfromname);
++        if ((*it)->isMounted() != mounted)
++            ResetProperties((*it)->id().latin1());
++    }
++}
++#endif
++
+ QString HALBackend::isInFstab(const Medium *medium)
+ {
+     KMountPoint::List fstab = KMountPoint::possibleMountPoints(KMountPoint::NeedMountOptions|KMountPoint::NeedRealDeviceName);
+@@ -992,11 +1039,13 @@
  
      for (; it!=end; ++it)
      {
@@ -151,8 +262,14 @@
 +        kdDebug(1219) << "isInFstab -" << medium->deviceNode() << "- -" << (*it)->realDeviceName() << "- -" << (*it)->mountedFrom() << endl;
          if ((*it)->mountedFrom() == medium->deviceNode() || ( !medium->deviceNode().isEmpty() && (*it)->realDeviceName() == medium->deviceNode() ) )
  	{
++#ifndef Q_OS_FREEBSD
              QStringList opts = (*it)->mountOptions();
-@@ -1012,7 +1006,7 @@
+             if (opts.contains("user") || opts.contains("users"))
++#endif
+                 return (*it)->mountPoint();
+         }
+     }
+@@ -1012,7 +1061,7 @@
      QString mountPoint = isInFstab(medium);
      if (!mountPoint.isNull())
      {
@@ -161,7 +278,7 @@
          KIO::Job *job = KIO::mount( false, 0, medium->deviceNode(), mountPoint );
          connect(job, SIGNAL( result (KIO::Job *)),
                  SLOT( slotResult( KIO::Job *)));
-@@ -1023,7 +1017,7 @@
+@@ -1023,7 +1072,7 @@
  
      QStringList soptions;
  
@@ -170,7 +287,7 @@
  
      QMap<QString,QString> valids = MediaManagerUtils::splitOptions(mountoptions(medium->id()));
      if (valids["flush"] == "true")
-@@ -1036,10 +1030,10 @@
+@@ -1036,10 +1085,10 @@
  
      if (valids["ro"] == "true")
          soptions << "ro";
@@ -183,7 +300,29 @@
      if (valids["quiet"] == "true")
          soptions << "quiet";
  
-@@ -1121,7 +1115,7 @@
+@@ -1069,6 +1118,11 @@
+             soptions << QString("data=ordered");
+     }
+ 
++    if (valids.contains("charset"))
++    {
++        soptions << QString("-C=%1").arg(valids["charset"]);
++    }
++
+     const char **options = new const char*[soptions.size() + 1];
+     uint noptions = 0;
+     for (QStringList::ConstIterator it = soptions.begin(); it != soptions.end(); ++it, ++noptions)
+@@ -1081,9 +1135,6 @@
+         return qerror;
+     }
+ 
+-    medium->setHalMounted(true);
+-    ResetProperties(medium->id().latin1());
+-
+     return QString();
+ }
+ 
+@@ -1121,7 +1172,7 @@
      QString mountPoint = isInFstab(medium);
      if (!mountPoint.isNull())
      {
@@ -192,7 +331,7 @@
          KIO::Job *job = KIO::unmount( medium->mountPoint(), false );
          connect(job, SIGNAL( result (KIO::Job *)),
                  SLOT( slotResult( KIO::Job *)));
-@@ -1134,7 +1128,7 @@
+@@ -1134,7 +1185,7 @@
      const char *options[2];
  
      const char *udi = medium->id().latin1();
@@ -201,7 +340,7 @@
  
      dbus_error_init(&error);
      DBusConnection *dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
-@@ -1147,7 +1141,7 @@
+@@ -1147,7 +1198,7 @@
      if (!(dmesg = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
                                                  "org.freedesktop.Hal.Device.Volume",
                                                  "Unmount"))) {
@@ -210,7 +349,7 @@
          return i18n("Internal Error");
      }
  
-@@ -1157,7 +1151,7 @@
+@@ -1157,7 +1208,7 @@
      if (!dbus_message_append_args (dmesg, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, 0,
                                     DBUS_TYPE_INVALID))
      {
@@ -219,7 +358,7 @@
          dbus_message_unref (dmesg);
          return i18n("Internal Error");
      }
-@@ -1165,7 +1159,7 @@
+@@ -1165,7 +1216,7 @@
      dbus_error_init (&error);
      if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, dmesg, -1, &error)))
      {
@@ -228,7 +367,7 @@
          QString qerror = error.message;
          if (!strcmp(error.name, "org.freedesktop.Hal.Device.Volume.Busy")) {
              qerror = QString("<qt>") + i18n("Device is Busy:");
-@@ -1201,7 +1195,7 @@
+@@ -1201,13 +1252,10 @@
          return qerror;
      }
  
@@ -237,3 +376,9 @@
  
      dbus_message_unref (dmesg);
      dbus_message_unref (reply);
+-
+-    medium->setHalMounted(false);
+-    ResetProperties(udi);
+ 
+     return QString();
+ }
diff -ubdBrN kdebase3.orig/files/extrapatch-kioslave_media_mediamanager-halbackend.h kdebase3/files/extrapatch-kioslave_media_mediamanager-halbackend.h
--- kdebase3.orig/files/extrapatch-kioslave_media_mediamanager-halbackend.h	Thu Jan  1 03:00:00 1970
+++ kdebase3/files/extrapatch-kioslave_media_mediamanager-halbackend.h	Thu Feb  8 23:38:41 2007
@@ -0,0 +1,33 @@
+--- kioslave/media/mediamanager/halbackend.h.orig	Sun Jan 28 23:58:13 2007
++++ kioslave/media/mediamanager/halbackend.h	Thu Feb  1 02:51:48 2007
+@@ -34,6 +34,9 @@
+ #include <qobject.h>
+ #include <qstringlist.h>
+ #include <qstring.h>
++#ifdef Q_OS_FREEBSD
++#include <qtimer.h>
++#endif
+ 
+ #include <config.h>
+ 
+@@ -154,6 +157,9 @@
+ 
+ private slots:
+ 	void slotResult(KIO::Job *job);
++#ifdef Q_OS_FREEBSD
++	void pollMediaList();
++#endif
+ 
+ /* Hal call-backs -- from gvm*/
+ public:
+@@ -217,6 +223,10 @@
+ 	DBusConnection *dbus_connection;
+ 
+ 	QMap<KIO::Job *, QString> mount_jobs;
++#ifdef Q_OS_FREEBSD
++	QTimer m_pollTimer;
++	QPtrList<Medium> m_pollMediaList;
++#endif
+ };
+ 
+ #endif /* _HALBACKEND_H_ */
diff -ubdBrN kdebase3.orig/files/patch-kioslave_media_mounthelper-kio_media_mounthelper.cpp kdebase3/files/patch-kioslave_media_mounthelper-kio_media_mounthelper.cpp
--- kdebase3.orig/files/patch-kioslave_media_mounthelper-kio_media_mounthelper.cpp	Thu Jan  1 03:00:00 1970
+++ kdebase3/files/patch-kioslave_media_mounthelper-kio_media_mounthelper.cpp	Thu Feb  8 23:43:59 2007
@@ -0,0 +1,32 @@
+--- kioslave/media/mounthelper/kio_media_mounthelper.cpp.orig	Sat Jan 27 01:58:24 2007
++++ kioslave/media/mounthelper/kio_media_mounthelper.cpp	Sat Jan 27 02:35:28 2007
+@@ -77,7 +77,9 @@
+ 	m_isCdrom = medium.mimeType().find("dvd")!=-1
+ 	         || medium.mimeType().find("cd")!=-1;
+ 
+-	if (args->isSet("u"))
++	bool do_eject = args->isSet("s") || args->isSet("e");
++
++	if (args->isSet("u") || do_eject)
+ 	{
+ 	  DCOPRef mediamanager("kded", "mediamanager");
+ 	  DCOPReply reply = mediamanager.call( "unmount", medium.id());
+@@ -85,13 +87,14 @@
+ 	    reply.get(m_errorStr);
+ 	  kdDebug() << "medium unmount " << m_errorStr << endl;
+ 	  if (m_errorStr.isNull())
++	  {
++	    if( do_eject )
++	      invokeEject(device, true);
++	    else
+ 	    ::exit(0);
++	  }
+ 	  else
+ 	    error();
+-	}
+-	else if (args->isSet("s") || args->isSet("e"))
+-	{
+-		invokeEject(device, true);
+ 	}
+ 	else
+ 	{
--- kdebase3.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->kde 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Feb 8 23:10:36 UTC 2007 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=108949 

From: Michael Nottebrock <lofi@freebsd.org>
To: bug-followup@freebsd.org, xors@sendmail.ru
Cc:  
Subject: Re: ports/108949: [PATCH]: x11/kdebase3 [kioslave/media] media ejecting, various HAL backend problems
Date: Fri, 9 Feb 2007 07:15:30 +0100

 Thanks for your continued work on this!
 
 There is a problem with the charset mount option however: KDE/Qt's names for 
 encodings don't always match FreeBSD's. For instance with 
 LANG=de_DE.ISO8859-15, KGlobal::locale()->encoding() yields "ISO 8859-15", 
 but mount_cd9660 only understands ISO8859-15, ISO-8859-15 or ISO_8859-15. Do 
 you want to work on that some more or should I go ahead and commit the patch 
 without the charset conversion?

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/108949: commit references a PR
Date: Sat, 10 Feb 2007 03:32:57 +0000 (UTC)

 lofi        2007-02-10 03:32:52 UTC
 
   FreeBSD ports repository
 
   Modified files:
     x11/kdebase3         Makefile 
     x11/kdebase3/files   
                          extrapatch-kioslave_media_mediamanager-halbackend.cpp 
   Added files:
     x11/kdebase3/files   
                          extrapatch-kioslave_media_mediamanager-halbackend.h 
                          patch-kioslave_media_mediamanager-fstabbackend.cpp 
                          patch-kioslave_media_mounthelper-kio_media_mounthelper.cpp 
   Log:
   Fix various problems in the media kioslave:
   
   - Correct ejecting of mounted volumes (unmount before eject).
   - Mounting of removable media drives (such as CD-ROM drives)
     listed in /etc/fstab (removes checking linux's "user" mount option).
   - Polling floppy drives over the mount state (FreeBSD HAL doesn't do this).
   - Informing the fileview when HAL notifies that mounting is completed.
   - Mounting cdrom volume in locale charset. Note: Requires cd9660_iconv!
   
   PR:             ports/108949
   Submitted by:   Maxim Samsonov <xors@sendmail.ru>
   
   - Disable polling of nfs shares in the fstabbackend. Mounting/Unmounting
     is broken and the polling can cause DBus aborts that take kded with
     them.
   
   Revision  Changes    Path
   1.190     +3 -2      ports/x11/kdebase3/Makefile
   1.3       +175 -24   ports/x11/kdebase3/files/extrapatch-kioslave_media_mediamanager-halbackend.cpp
   1.1       +33 -0     ports/x11/kdebase3/files/extrapatch-kioslave_media_mediamanager-halbackend.h (new)
   1.6       +10 -0     ports/x11/kdebase3/files/patch-kioslave_media_mediamanager-fstabbackend.cpp (new)
   1.1       +32 -0     ports/x11/kdebase3/files/patch-kioslave_media_mounthelper-kio_media_mounthelper.cpp (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: lofi 
State-Changed-When: Sat Feb 10 03:50:57 UTC 2007 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=108949 
>Unformatted:
