Patch for ldm hanging at logout

Alkis Georgopoulos <[email protected]> Thu, 07 May 2009 12:13:30 +0300
Newsgroups gmane.linux.terminal-server.devel
Message-ID <1241687610.6940.14.camel@alkis>
Hi all,

My TCs had a problem of ldm hanging at logout, waiting for an
already-finished process (the ssh connection) to finish.

The problem was in sshutils.c:
> ldm_wait(pid);
> read(ldm.sshfd, buf, sizeof buf);       /* clear any exit message so
ssh can exit cleanly */
> ldm_wait(ldm.sshpid);

where in my slow terminals half of the time "sshpid" finished before
"pid", so ldm_wait got mixed up and waited 2 times for "sshpid".

In ldm.c I changed
-        res = waitid (P_ALL, 0, &info, WEXITED | WSTOPPED);
+        res = waitid (P_PID, pid, &info, WEXITED | WSTOPPED);
so that ldm_wait ONLY WAITS for the specified child, and not for ANY
child.

I also had to do the following changes in sshutils.c:
+ fcntl(ldm.sshfd, F_SETFL, O_NONBLOCK);
to make the following clean-up call non-blocking:
read(ldm.sshfd, buf, sizeof buf);

Even though I didn't experience any problems with it, I also changed the
"read" above to a "while" so that it flushes sshfd even for size >
sizeof buf.

A last note, in ldm_wait I don't think the "while" is needed anymore,
because it waits for the specific child it was called for. I tried it
without the "while" and it works fine, but I'm not sending it to keep
the proposed changes to a minimum. Of course I can send it if you like.

Kind regards,
Alkis Georgopoulos

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com

_____________________________________________________________________
Ltsp-developer mailing list.   To un-subscribe, or change prefs, goto:
      https://lists.sourceforge.net/lists/listinfo/ltsp-developer
For additional LTSP help,   try #ltsp channel on irc.freenode.net
fix_ldm_hang.patch (text/x-patch, 1.1 KB)
=== modified file 'src/ldm.c'
--- src/ldm.c	2009-04-08 06:58:05 +0000
+++ src/ldm.c	2009-05-06 08:29:51 +0000
@@ -202,9 +202,10 @@
 ldm_wait(GPid pid)
 {
     siginfo_t info;
     do {
         int res;
-        res = waitid (P_ALL, 0, &info, WEXITED | WSTOPPED);
+        res = waitid (P_PID, pid, &info, WEXITED | WSTOPPED);
         if (res == -1) {
             int temp;
             temp = errno;

=== modified file 'src/sshutils.c'
--- src/sshutils.c	2009-03-11 14:52:53 +0000
+++ src/sshutils.c	2009-05-05 19:42:39 +0000
@@ -281,10 +281,15 @@
             ldm.nomadpid = 0;
         }
         loginfo(_("Shutting down ssh session: %s"), command);
+/* Make the read() below non-blocking */
+         fcntl(ldm.sshfd, F_SETFL, O_NONBLOCK);
         pid = ldm_spawn(command, NULL, NULL, NULL);
         ldm_wait(pid);
-        read(ldm.sshfd, buf, sizeof buf);       /* clear any exit message so ssh can exit cleanly */
+        while (read(ldm.sshfd, buf, sizeof buf) > 0) 
+            ;       /* clear any exit message so ssh can exit cleanly */
         ldm_wait(ldm.sshpid);
         ldm.sshpid = 0;
         g_free(command);
     }