/*
* 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) 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 */
/*
* This is the "argument array" definition that is returned by e_new_args and is
* used by e_add_args, e_free_args, etc.
*/
struct _argArray_t {
};
/*
* Private Methods
*/
/*PRINTFLIKE2*/
/*
* 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) {
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;
}
}
}
/*
* Name: e_new_args
* Description: create a new argument array for use in exec() calls
* Arguments: initialCount - [RO, *RO] - (int)
* Initial number of elements to populate the
* argument array with - use best guess
* Returns: argArray_t *
* Pointer to argument array that can be used in other
* functions that accept it as an argument
* == (argArray_t *)NULL - error
* NOTE: you must call e_free_args() when the returned argument array is
* no longer needed so that all storage used can be freed up.
*/
{
/* allocate new argument array structure */
"<argArray_t>");
return ((argArray_t *)NULL);
}
/* allocate initial argument array */
return ((argArray_t *)NULL);
}
/* initialize argument indexes */
aa->_aaNumArgs = 0;
return (aa);
}
/*
* Name: e_add_arg
* Description: add new argument to argument array for use in exec() calls
* Arguments: a_args - [RO, *RW] - (argArray_t *)
* Pointer to argument array (previously allocated via
* a call to e_new_args) to add the argument to
* a_format - [RO, *RO] - (char *)
* Pointer to "printf" style format argument
* ... - [RO, *RO] - (varies)
* Arguments as appropriate for format statement
* Returns: boolean_t
* B_TRUE - success
* B_FALSE - failure
* Examples:
* - to add an argument that specifies a file descriptor:
* int fd;
* - to add a flag or other known text:
* e_add_arg(aa, "-s")
* - to add random text:
* char *random_text;
* e_add_arg(aa, "%s", random_text);
*/
/*PRINTFLIKE2*/
{
/*
* double argument array if array is full
*/
int newMax;
char **newArgs;
(newMax+1) * sizeof (char *));
return (B_FALSE);
}
}
/* determine size of argument to add to list */
/* if it fit in the built in buffer, use that */
/* dup text already generated in bfr */
"<char *>");
return (B_FALSE);
}
} else {
/* allocate space for argument to add */
"<char *>");
return (B_FALSE);
}
/* generate argument to add */
}
/* add argument to the end of the argument array */
return (B_TRUE);
}
/*
* Name: e_get_argv
* Description: return (char **)argv pointer from argument array
* Arguments: a_args - [RO, *RW] - (argArray_t *)
* Pointer to argument array (previously allocated via
* a call to e_new_args) to return argv pointer for
* Returns: char **
* Pointer to (char **)argv pointer suitable for use
* in an exec*() call
* NOTE: the actual character array is always terminated with a (char *)NULL
*/
char **
{
}
/*
* Name: e_get_argc
* Description: return (int) argc count from argument array
* Arguments: a_args - [RO, *RW] - (argArray_t *)
* Pointer to argument array (previously allocated via
* a call to e_new_args) to return argc count for
* Returns: int
* Count of the number of arguments in the argument array
* suitable for use in an exec*() call
*/
int
{
return (a_args->_aaNumArgs);
}
/*
* Name: e_free_args
* Description: free all storage contained in an argument array previously
* allocated by a call to e_new_args
* Arguments: a_args - [RO, *RW] - (argArray_t *)
* Pointer to argument array (previously allocated via
* a call to e_new_args) to free
* Returns: void
* NOTE: preserves errno (usually called right after e_execCmd*())
*/
void
{
int i;
/* free all arguments in the argument array */
}
/* free argument array */
/* free argument array structure */
/* restore errno */
}