From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1504 invoked by alias); 24 Oct 2012 15:10:52 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30745 Received: (qmail 5601 invoked from network); 24 Oct 2012 15:10:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at mac.com designates 17.158.236.118 as permitted sender) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855,1.0.431,0.0.0000 definitions=2012-10-24_05:2012-10-24,2012-10-24,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1210240136 Subject: Re: Commands run from functions don't exit cleanly on terminal close (SIGHUP)? From: Alan Pinstein In-reply-to: <2B813FB0-0877-42BA-974C-1A142EF09BCE@mac.com> Date: Wed, 24 Oct 2012 10:10:42 -0400 Message-id: <909858C7-4B5A-4679-90B3-6BF5398BA9FC@mac.com> References: <2B813FB0-0877-42BA-974C-1A142EF09BCE@mac.com> To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.1283) I need to make one clarification; the PPID ends up as 1 (orphaned) if no traps are installed; if the HUP trap is installed, the PPID remains correct, but it still doesn't exit. Alan On Oct 24, 2012, at 10:03 AM, Alan Pinstein wrote: > I am having issues with ssh sessions not exiting when I closed the terminal window containing them. > > I originally noticed this bug while using screen; I believe this bug/problem affects anyone that uses ssh/autossh/tmux/mxrvt/etc from inside a function. It causes screen to hang due to multiple concurrent connections that are orphaned on the client side. > > I have reduced the problem down to whether or not the ssh command is executed directly in the shell, or from inside a function. > > I isolated the issue from ssh as well; it seems that any command run from inside of a function doesn't cleanly exit when it receives a SIGHUP. > > I managed to at least receive the signal before the child exits via TRAPS_ASYNC, but I can't figure out how to make the command die when the trap runs. I've tried "exit" and "return". > > The function below reproduces the scenario easily. > > willnotdie() { > echo 'try closing the terminal window while this runs (lasts 10s), notice that the php command is orphaned and does not die' > echo 'ps ax -o time,ppid,command | grep -v grep| grep "PPID\|php"' > echo 'if you run the PHP code in this script directly on the CLI, then it exists cleanly on terminal close' > > setopt LOCAL_TRAPS LOCAL_OPTIONS TRAPS_ASYNC > echo -n "" > ./sig > (date && echo START) >> ./sig > trap '(date && echo HUP && exit 1) >> ./sig' HUP > trap '(date && echo INT) >> ./sig' INT > php -r '$i = time() + 10; while (true) { if (time() > $i) break; }' > (date && echo DONE) >> ./sig > } > > # monitor the progress with this > while (true) do > ps ax -o time,ppid,command | grep -v grep| grep "PPID\|php" > sleep 1 > done > > I would appreciate any help. > > Thanks in advance. > > Alan