Closing file descriptor for sshd that spawns remote threads
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Closing file descriptor for sshd that spawns remote threads
Greetings
I have a script that executes a remote secure shell to a server and runs a few startup scripts to launch in-house software. The scripts spawn various procs/threads so subsequently they inherit the shell's file descriptors...so the ssh session will hang as sshd is waiting for a close() it will never receive.
I can narrow down the PPID of the open fd's quite easily: lsof -a -p `ps -ef|grep "\[priv\]" | grep -v grep | awk '{print $2}'` -d0,1,2
Unfortunately, I tried to redefine the fd inside the script and then close those before reassigning fd0,1,2 again, but it still hangs...I can always grep and | awk '{print $2}' for a string to get the PID to kill of the sshd but this could possibly return the wrong session should another sshd be open for the same grep string (which is slightly possible on the system)
Anyway, is there a good or standard way to close the fd for such an event? namely, an ssh to re remote server that executes a startup of various procs...or is there a good way to redefine the fd inside the script.
It is similar, if not identical, to Bug52 in bugzilla, namely try the following:
From a host ssh to a client
Run any command that forks a process in the backgroun
Logout of client, ssh hangs
Similarly, shopt -s nohuponexit is one solution, however it doesn't work for me here. I also tried to export a PROMPT_COMMAND for "disown -a -h" but still no go. Finally, the only solution that works, which is a hack at best, is to kill -9 on the sshd that executes, but I wanted a more graceful way to get around this. Also, upgrading to a newer version of OpenSSH isn't a solution either (CM system).
I know there has been a lot of chatter on the web on these issues, but alas, no one had a solution, so figured I would give it a whirl here...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.