← Back to team overview

freenx-team team mailing list archive

Re: Samba shares working?

 

Hi Thilo,

 - I put the patch in the code FreeNX code style and commented.
 - If you try to mount a folder and share a printer, on one of them the fds
will
already be closed, so I moved the code to inside the function. (Am I wrong?)
 - Reduced to 5 the counter of the close loop, FreeNX uses till fd 4.

Can you test the attached patch?

Regards,
Shima

On Tue, Apr 28, 2009 at 1:46 PM, Thilo Uttendorfer <
t.uttendorfer@xxxxxxxxxxxx> wrote:

> Hi Jeremy,
>
> On Monday 27 April 2009, Jeremy Wilkins wrote:
> >  I'm confused as to what this trap and loop accomplish. We can't paste
> code
> > in until we understand the ramifications of the changes.
>
> > > After some more debugging and testing I finally solved the problem.
> When
> > > cmd_node_smbmount (as well as cmd_node_addprinter) is called, the
> > > function gets instantly terminated (at least in my setup/environment)
> > > because it was not properly detached.
> > >
> > > I had to add several things to the cmd_node_smbmount call:
> > > - Use "double fork" (thanks to [1])
> > > - Use trap
> > > - Close all open file handles
>
>
> I try to explain it a bit more detailed:
>
> - The "double fork" is used to make sure the process outlives the current
>  shell. I thought this was necessary to detatch the process, but after
>  running another test, it works without the extra parentheses as well.
>  Updated patch attached.
> - The trap command is used to catch signal 1 (SIGHUP), otherwise the
> process
>  terminates.
> - The loop is used to close all open file handles. freenx uses some exec
> calls
>  like "exec 4>&1" but closes only STDIN, STDOUT and STDERR ( "exec 0<&-",
>  "exec 1>&-", "exec 2>&-" ). Maybe it's too much to close all open file
>  handles up to 255 (probably only a few are used), but it doesn't harm
>  either. Anyway, if you don't close these file handles, the process hangs.
>
>
> Thilo
>
> --
> Thilo Uttendorfer
> Linux Information Systems AG
> Putzbrunner Str. 71, 81739 München
>
> t.uttendorfer@xxxxxxxxxxxx, http://www.linux-ag.com
>
> _______________________________________________
> Mailing list: https://launchpad.net/~freenx-team<https://launchpad.net/%7Efreenx-team>
> Post to     : freenx-team@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~freenx-team<https://launchpad.net/%7Efreenx-team>
> More help   : https://help.launchpad.net/ListHelp
>
>
=== modified file 'nxnode'
--- nxnode	2009-03-01 16:18:34 +0000
+++ nxnode	2009-04-28 17:16:52 +0000
@@ -1430,6 +1430,14 @@
 
 cmd_node_smbmount()
 {
+	# The trap signal 1 (SIGHUP), otherwise the process hangs.
+	trap '' 1
+	# Close all open file handles, otherwise the process hangs.
+	for ((i=3; i<5; i++))
+	do
+		eval "exec $i<&- $i>&-"
+	done
+
 	sessionid=$(getparam_sessionid)
 	port=$(getparam port)
 	username=$(getparam username)
@@ -1461,6 +1469,14 @@
 
 cmd_node_addprinter()
 {
+	# The trap signal 1 (SIGHUP), otherwise the process hangs.
+	trap '' 1
+	# Close all open file handles, otherwise the process hangs.
+	for ((i=3; i<5; i++))
+	do
+		eval "exec $i<&- $i>&-"
+	done
+
 	sessionid=$(getparam_sessionid)
 	type=$(getparam type)
 	port=$(getparam port)


Follow ups

References