From aw@old-forest.org  Fri Apr 29 16:50:51 2016
Received: (at submit) by bugs.x2go.org; 29 Apr 2016 14:50:53 +0000
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on
	ymir.das-netzwerkteam.de
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=3.0 tests=BAYES_50,URIBL_BLOCKED
	autolearn=ham version=3.3.2
Received: from localhost (localhost [127.0.0.1])
	by ymir.das-netzwerkteam.de (Postfix) with ESMTP id A60765DA98
	for <submit@bugs.x2go.org>; Fri, 29 Apr 2016 16:50:51 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at ymir.das-netzwerkteam.de
Received: from ymir.das-netzwerkteam.de ([127.0.0.1])
	by localhost (ymir.das-netzwerkteam.de [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id FLPoPbFtextg for <submit@bugs.x2go.org>;
	Fri, 29 Apr 2016 16:50:44 +0200 (CEST)
Received: from apu.snow-crash.org (apu.snow-crash.org [78.47.227.179])
	by ymir.das-netzwerkteam.de (Postfix) with ESMTP id C9DC55DA93
	for <submit@bugs.x2go.org>; Fri, 29 Apr 2016 16:50:44 +0200 (CEST)
Received: from chao.old-forest.org (arne.local [10.99.0.2])
	by apu.snow-crash.org (Postfix) with ESMTP id 8C5B18276A
	for <submit@bugs.x2go.org>; Fri, 29 Apr 2016 16:50:44 +0200 (CEST)
Received: from anhrefn ([192.168.10.23] helo=anhrefn.saar.de)
	by chao.old-forest.org with esmtps (Exim 4.84_2)
	(envelope-from <aw@old-forest.org>)
	id 1aw9ki-00032X-6l
	for submit@bugs.x2go.org; Fri, 29 Apr 2016 16:50:44 +0200
Received: from aw by anhrefn.saar.de with local (Exim 4.87)
	(envelope-from <aw@old-forest.org>)
	id 1aw9ki-00063M-7e
	for submit@bugs.x2go.org; Fri, 29 Apr 2016 16:50:44 +0200
Date: Fri, 29 Apr 2016 16:50:44 +0200
From: Arne Wichmann <aw@anhrefn.saar.de>
To: submit@bugs.x2go.org
Subject: x2gocdmanager failing in a number of corner cases
Message-ID: <20160429145044.GA23150@anhrefn.saar.de>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="AhhlLboLdkugWU4S"
Content-Disposition: inline
User-Agent: Mutt/1.5.23 (2014-03-12)


--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Package: x2gocdmanager
Version: 1.1.0.2-0x2go1+git20150607.485+jessie.main.1
Tags: patch

I found a number of cases where x2gocdmanager was not mounting/unmounting
CDROMs as expected. Namely:
- When CDs were changed quickly, the change of CD was not detected and the
  old CD stayed mounted
- Sometimes the umount failed because some files were still open (and
  similar cases). In that case x2gocdmanager considered the CD umounted and
  all further tries to mount a CD failed.

I append a patch which apart from these problem cases
- creates support for a log file, so problems can be more easily debugged.
  If the log file is not present a warning will be printed, but
  x2gocdmanager will work without logging as it was before
- makes an effort to unmount everything in /media at the start of the
  manager
- includes some basic debug output so that further problems can be
  pinpointed more easily

Indentations are a bit broken in the patch...

cu

AW

--- /usr/sbin/x2gocdmanager.dpkg-dist   2016-04-29 16:01:19.000000000 +0200
+++ /usr/sbin/x2gocdmanager     2016-04-29 16:01:41.000000000 +0200
@@ -46,11 +46,19 @@
=20
        # silence this daemon script completely...
        close(STDIN);
-       close(STDOUT);
-       close(STDERR);
=20
        $SIG{TERM}=3D\&catch_term;
=20
+       # do not die here - file unwritable is a way to silence this
+       open(STDOUT,">>/var/log/x2gocdmanager") || warn "open failed: $!";
+       open(STDERR,">>&STDOUT") || print("open failed: $!");
+       print("Started ",time(),"\n");
+
+       # unmount everything which is mounted in /media
+       for (glob("/media/*")) {
+         system("umount -ff $_") or warn "could not umount $_";
+       }
+
        my @mounted;
        my @idedrives;
=20
@@ -108,7 +116,11 @@
                        }
                        elsif($rez=3D=3D101)=20
                        {
-                               push(@cdarray,@drives[$i]);
+                               # do not push if media change detected
+                               # this will umount the CD. after the next
+                               # iteration the new one will be mounted
+                               $_=3Dioctl(CDROM,0x5325,0);
+                               push(@cdarray,@drives[$i]) unless $_=3D=3D1;
                        }
                        close (CDROM);
                }
@@ -129,33 +141,35 @@
                                open (D,">",expand_filename("~x2gothinclien=
t/export/$name.unexport"));
                                print D "unexport=3D/media/$name\n";
                                close(D);
-                               system("umount -ff /media/$name");
-
+                               print("umounting $name\n");
+                               if (system("umount -ff /media/$name")=3D=3D=
0) {
                                system("killall x2goejectcd");
                                splice(@mounted,$i,1);
                        }
                }
+               }
=20
                # enumerate all available CD/DVD devices
                for my $i (0..$#cdarray)
                {
                        # mount the CD/DVD device if not yet mounted...
                        my @arr=3Dgrep { "$_" eq "@cdarray[$i]" } @mounted;
-                       if (@arr =3D=3D 0)
-                       {
+                 if (@arr =3D=3D 0) {
                                my @name=3Dsplit("/","@cdarray[$i]");
                                my $name=3D"CDROM-@name[2]";
                                mkdir("/media");
                                mkdir("/media/$name");
+                   print("mounting @cdarray[$i]\n");
                                {
                                        open (D,">",expand_filename("~x2got=
hinclient/export/$name"));
                                        print D "export=3D/media/$name\n";
                                        close(D);
+                     print("mount worked: @cdarray[$i]\n");
                                        push (@mounted,@cdarray[$i]);
                                        system("killall x2goejectcd");
                                        system("DISPLAY=3D:0 x2goejectcd&");
-                               }
+                   } else { warn("mount failed: $?"); }
                        }
                }
        }



--=20
[...] If you don't want to be restricted, don't agree to it. If you are
coerced, comply as much as you must to protect yourself, just don't support
it. Noone can free you but yourself. (crag, on Debian Planet)
Arne Wichmann (aw@saar.de)

--AhhlLboLdkugWU4S
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCAAGBQJXI3TDAAoJEENYfBy4DUs+7E4QAJrdEzJFH6e6hvUyHfiq1t8J
kHGrXv55YU7KHo5FicpZTHfkB60B5i7SVBzYrkEl3znZ98ih+60VT/Irpd4dJS0j
qFewL4nj5Gdb08TVj4rVLtUjU3wD+HwzWu3WLIqg9ZXRNZDHpf/7BXRucLbm4UyH
eOV+jpy2cXUM2uIrd0moAwYE2QwN4o6e2+SjGsK+ifjkNqDAfUcmJ8z7AtZC43Ew
armDOXwxM+W6CZgFyNTxtDG/Dad38JV55KyqyV2I6nGWaAiXoQLnRUYpnetGJESx
pVf7C9HDk9Y/j+Sw77k70gCB2r11eYw7JaLyZ7dI0pjNvNQYUVAiMrqHAvdugW4b
5YMBnCiUwiY8K43AyxUP+WAzWu0QLcW7FVGGhf1mxu387cupxk4koT0DOq4dJcw+
nWH4wSuzAZEHZCWhFTwRgzIvOfe8sQxlhnZtOi/E3uVUz0g5i9Z6qkYHiAJlsFnQ
kW1mTSMbSC4Q0pfcWL1qkTbMRKkBI8GoSF+Zjg0wFis8eJ2iNlkWdwQdK6AnBVrL
Nca+gfYHw1mDXp9SAP0RAOV0CQcuB9kbiA0OyY2fK5iTT9rWwJb6huNimG9PNVWb
ozjL8P6gAFczz/TDP8bFz7MN15t8DhcRYvNxreMZ6DX2DwwqGjLlBCd/v3jsIXjC
ew9sCtsv2KPeVS8cxAve
=sfQ5
-----END PGP SIGNATURE-----

--AhhlLboLdkugWU4S--

