popen.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 1988, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A/* Copyright (c) 1988 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * Cancellation cleanup handler. 2N/A * If we were cancelled in waitpid(), create a daemon thread to 2N/A * reap our abandoned child. No other thread can do this for us. 2N/A * We have been cancelled. There is no need to restore 2N/A * the original sigmask after blocking all signals because 2N/A * pthread_exit() will block all signals while we exit. 2N/A /* quick check to see if fdopen() would fail */ 2N/A shpath =
"";
/* force child to fail immediately */ 2N/A * Protect the pipe() file descriptors from other calls to popen(). 2N/A /* myside and yourside reverse roles in child */ 2N/A /* in the child, close all pipes from other popen's */ 2N/A * These conditions may apply if a previous iob returned 2N/A * by popen() was closed with fclose() rather than pclose(), 2N/A * or if close(fileno(iob)) was called. Don't let these 2N/A * programming errors cause us to malfunction here. 2N/A * non-portable posix_spawn() attributes are being used. 2N/A * This goes here because we cannot call fdopen() 2N/A * while holding a lock acquired with lmutex_lock(). 2N/A * If this fails, we are in trouble because the child 2N/A * process has already been spawned. Hopefully 2N/A * the child will die due to receiving SIGPIPE. 2N/A * pclose() is a cancellation point. 2N/A /* mark this pipe closed */ 2N/A * waitpid() is a cancellation point. 2N/A * This causes pclose() to be a cancellation point. 2N/A * If we have already been cancelled (pclose() was called from 2N/A * a cancellation cleanup handler), attempt to reap the process 2N/A * w/o waiting, and if that fails just call cleanup(pid). 2N/A /* waitpid(..., WNOHANG) is not a cancellation point */ 2N/A * curr->fd can equal fd if a previous iob returned by 2N/A * popen() was closed with fclose() rather than pclose(), 2N/A * or if close(fileno(iob)) was called. Don't let these 2N/A * programming errors cause us to malfunction here. 2N/A /* make a lame attempt to reap the forgotten child */ 2N/A * _insert() and _delete() are used by p2open() in libgen.