/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2011 by Delphix. All rights reserved.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#include "lint.h"
#include "mtlib.h"
#include "file64.h"
#include <stdio.h>
#include <stdlib.h>
#include <wait.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <thread.h>
#include <pthread.h>
#include <synch.h>
#include <spawn.h>
#include <paths.h>
#include "stdiom.h"
#include "mse.h"
#include "libc.h"
typedef struct node {
int fd;
} node_t;
/*
* Cancellation cleanup handler.
* If we were cancelled in waitpid(), create a daemon thread to
* reap our abandoned child. No other thread can do this for us.
*/
static void
{
/*
* We have been cancelled. There is no need to restore
* the original sigmask after blocking all signals because
* pthread_exit() will block all signals while we exit.
*/
}
FILE *
{
int error;
return (NULL);
return (NULL);
}
(void) posix_spawnattr_destroy(&attr);
return (NULL);
}
/*
* fdopen() can fail (if the fd is too high or we are out of memory),
* but we don't want to have any way to fail after creating the child
* process. So we fdopen() a dummy fd (myfd), and once we get the real
* fd from posix_spawn_pipe_np(), we dup2() the real fd onto the dummy.
*/
if (myfd == -1) {
(void) posix_spawnattr_destroy(&attr);
(void) posix_spawn_file_actions_destroy(&fact);
return (NULL);
}
(void) posix_spawnattr_destroy(&attr);
(void) posix_spawn_file_actions_destroy(&fact);
return (NULL);
}
/* in the child, close all pipes from other popen's */
/*
* The fd may no longer be open if an iob previously returned
* by popen() was closed with fclose() rather than pclose(),
* or if close(fileno(iob)) was called. Use fcntl() to check
* if the fd is still open, so that these programming errors
* won't cause us to malfunction here.
*/
}
}
/*
* non-portable posix_spawn() attributes are being used.
*/
if (error == 0) {
}
if (error != 0) {
(void) posix_spawnattr_destroy(&attr);
(void) posix_spawn_file_actions_destroy(&fact);
return (NULL);
}
(void) posix_spawnattr_destroy(&attr);
(void) posix_spawn_file_actions_destroy(&fact);
if (error != 0) {
return (NULL);
}
/*
* myfd is the one that we fdopen()'ed; make it refer to the
* pipe to the child.
*/
return (iop);
}
/*
* pclose() is a cancellation point.
*/
int
{
int status;
/* mark this pipe closed */
if (pid <= 0) {
return (-1);
}
/*
* waitpid() is a cancellation point.
* This causes pclose() to be a cancellation point.
*
* If we have already been cancelled (pclose() was called from
* a cancellation cleanup handler), attempt to reap the process
* w/o waiting, and if that fails just call cleanup(pid).
*/
if (_thrp_cancelled()) {
/* waitpid(..., WNOHANG) is not a cancellation point */
return (status);
return (-1);
}
status = -1;
break;
}
}
return (status);
}
static void
{
/*
* curr->fd can equal fd if a previous iob returned by
* popen() was closed with fclose() rather than pclose(),
* or if close(fileno(iob)) was called. Don't let these
* programming errors cause us to malfunction here.
*/
/* make a lame attempt to reap the forgotten child */
return;
}
}
else
}
/*
* _insert() and _delete() are used by p2open() in libgen.
*/
int
{
return (-1);
return (0);
}
{
else
return (pid);
}
}
return (-1);
}