/*
* 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 (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 "stdiom.h"
#include "mse.h"
#include "libc.h"
#define RDR 0
extern const char **_environ;
typedef struct node {
int fd;
} node_t;
extern int __close(int);
/*
* 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 p[2];
int myside;
int yourside;
int fd;
const char *shpath;
int stdio;
int error;
/* quick check to see if fdopen() would fail */
switch (*mode) {
case 'r':
case 'w':
break;
default:
return (NULL);
}
return (NULL);
return (NULL);
}
(void) posix_spawnattr_destroy(&attr);
return (NULL);
}
/*
* Protect the pipe() file descriptors from other calls to popen().
*/
if (pipe(p) < 0) {
(void) posix_spawnattr_destroy(&attr);
(void) posix_spawn_file_actions_destroy(&fact);
return (NULL);
}
/* myside and yourside reverse roles in child */
/* in the child, close all pipes from other popen's */
/*
* These conditions may apply 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.
*/
}
if (error == 0)
if (error == 0)
if (error == 0)
yourside);
}
/*
* non-portable posix_spawn() attributes are being used.
*/
if (error == 0)
if (error) {
(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) {
return (NULL);
}
/*
* This goes here because we cannot call fdopen()
* while holding a lock acquired with lmutex_lock().
* If this fails, we are in trouble because the child
* process has already been spawned. Hopefully
* the child will die due to receiving SIGPIPE.
*/
return (NULL);
}
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);
}