/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include "pkglib.h"
#include "pkglocale.h"
#include "pkglibmsgs.h"
#ifndef _STDARG_H
#include "stdarg.h"
#endif
/*
* Private definitions
*/
/* Maximum number of arguments to pkg_ExecCmdList */
/* Size of buffer increments when reading from pipe */
/*
* Public Methods
*/
void
rpterr(void)
{
int c;
if (errfile[0]) {
}
errfile[0] = '\0';
}
}
void
ecleanup(void)
{
if (errfile[0]) {
}
}
int
{
char *perrfile;
int status = 0;
pkg_gt("unable to create temp error file, errno=%d"),
errno);
return (-1);
}
/* flush standard i/o before creating new process */
/*
* create new process to execute command in;
* vfork() is being used to avoid duplicating the parents
* memory space - this means that the child process may
* not modify any of the parents memory including the
* standard i/o descriptors - all the child can do is
* adjust interrupts and open files as a prelude to a
* call to exec().
*/
if (pid == 0) {
/*
* this is the child process
*/
int i;
/* reset any signals to default */
for (i = 0; i < NSIG; i++) {
}
if (ifd > 0) {
}
}
if (i >= 0) {
(void) dup2(i, STDERR_FILENO);
}
/* Close all open files except standard i/o */
closefrom(3);
/* execute target executable */
_exit(99);
} else if (pid < 0) {
/* fork failed! */
return (-1);
}
/*
* this is the parent process
*/
if (pid < 0) {
return (-1); /* probably interrupted */
}
switch (status & 0177) {
case 0:
case 0177:
/*FALLTHROUGH*/
default:
/* terminated by a signal */
}
if (status == 0) {
ecleanup();
}
return (status);
}
FILE *
{
if (errfile[0]) {
/* cleanup previous errfile */
}
pkg_gt("unable to create temp error file, errno=%d"),
errno);
return ((FILE *)0);
}
return ((FILE *)0);
}
return ((FILE *)0);
}
} else {
}
return ((FILE *)0);
}
return (pp);
}
int
{
int n;
if (n == 0)
ecleanup();
return (n);
}
/*
* Name: e_ExecCmdArray
* Synopsis: Execute Unix command and return results
* Description: Execute a Unix command and return results and status
* Arguments:
* r_status - [RO, *RW] - (int *)
* Return (exit) status from Unix command:
* == -1 : child terminated with a signal
* != -1 : lower 8-bit value child passed to exit()
* r_results - [RO, *RW] - (char **)
* Any output generated by the Unix command to stdout
* and to stderr
* == (char *)NULL if no output generated
* a_inputFile - [RO, *RO] - (char *)
* Pointer to character string representing file to be
* used as "standard input" for the command.
* a_cmd - [RO, *RO] - (char *)
* Pointer to character string representing the full path
* of the Unix command to execute
* char **a_args - [RO, *RO] - (char **)
* List of character strings representing the arguments
* to be passed to the Unix command. The list must be
* terminated with an element that is (char *)NULL
* Returns: int
* == 0 - Command executed
* Look at r_status for results of Unix command
* != 0 - problems executing command
* r_status and r_results have no meaning;
* r_status will be -1
* r_results will be NULL
* NOTE: Any results returned is placed in new storage for the
* calling method. The caller must use 'free' to dispose
* of the storage once the results are no longer needed.
* NOTE: If 0 is returned, 'r_status' must be queried to
* determine the results of the Unix command.
* NOTE: The system "errno" value from immediately after waitpid() call
* is preserved for the calling method to use to determine
* the system reason why the operation failed.
*/
int
{
char *buffer;
int bufferIndex;
int bufferSize;
int status;
int lerrno;
/* reset return results buffer pointer */
}
*r_status = -1;
/*
* See if command exists
*/
return (-1);
}
/*
* See if input file exists
*/
if (a_inputFile != (char *)NULL) {
} else {
}
if (stdinfile < 0) {
return (-1);
}
/*
* Create a pipe to be used to capture the command output
*/
return (-1);
}
bufferIndex = 0;
return (-1);
}
/* flush standard i/o before creating new process */
/*
* create new process to execute command in;
* vfork() is being used to avoid duplicating the parents
* memory space - this means that the child process may
* not modify any of the parents memory including the
* standard i/o descriptors - all the child can do is
* adjust interrupts and open files as a prelude to a
* call to exec().
*/
if (pid == 0) {
/*
* This is the forked (child) process ======================
*/
int i;
/* reset any signals to default */
for (i = 0; i < NSIG; i++) {
}
/* assign stdin, stdout, stderr as appropriate */
/* Close all open files except standard i/o */
closefrom(3);
/* execute target executable */
_exit(0x00FE);
}
/*
* This is the forking (parent) process ====================
*/
/*
* Spin reading data from the child into the buffer - when the read eofs
* the child has exited
*/
for (;;) {
/* read as much child data as there is available buffer space */
/* break out of read loop if end-of-file encountered */
if (bytesRead == 0) {
break;
}
/* if error, continue if recoverable, else break out of loop */
if (bytesRead == -1) {
/* try again: EAGAIN - insufficient resources */
continue;
}
/* try again: EINTR - interrupted system call */
continue;
}
/* break out of loop - error not recoverable */
break;
}
/* at least 1 byte read: expand buffer if at end */
bufferIndex += bytesRead;
if (bufferIndex >= bufferSize) {
}
}
/* Get subprocess exit status */
for (;;) {
/* break loop if child process status reaped */
if (resultPid != -1) {
break;
}
/* break loop if not interrupted out of waitpid */
break;
}
}
/*
* If the child process terminated due to a call to exit(), then
* set results equal to the 8-bit exit status of the child process;
* otherwise, set the exit status to "-1" indicating that the child
* exited via a signal.
*/
/* return appropriate output */
if (!*buffer) {
/* No contents in output buffer - discard */
/* Not requested to return results - discard */
} else {
/* have output and request to return: pass to calling method */
}
}
/*
* Name: e_ExecCmdList
* Synopsis: Execute Unix command and return results
* Description: Execute a Unix command and return results and status
* Arguments:
* r_status - [RO, *RW] - (int *)
* Return (exit) status from Unix command
* r_results - [RO, *RW] - (char **)
* Any output generated by the Unix command to stdout
* and to stderr
* == (char *)NULL if no output generated
* a_inputFile - [RO, *RO] - (char *)
* Pointer to character string representing file to be
* used as "standard input" for the command.
* a_cmd - [RO, *RO] - (char *)
* Pointer to character string representing the full path
* of the Unix command to execute
* ... - [RO] (?)
* Zero or more arguments to the Unix command
* The argument list must be ended with (void *)NULL
* Returns: int
* == 0 - Command executed
* Look at r_status for results of Unix command
* != 0 - problems executing command
* r_status and r_results have no meaning
* NOTE: Any results returned is placed in new storage for the
* calling method. The caller must use 'free' to dispose
* of the storage once the results are no longer needed.
* NOTE: If LU_SUCCESS is returned, 'r_status' must be queried to
* determine the results of the Unix command.
*/
int
char *a_inputFile, char *a_cmd, ...)
{
int argno = 0;
/*
* Create argument array for exec system call
*/
break;
}
}
}