#
# 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
#
#
#
import os
import six
if rc != 0:
return 0
"""SpawnFileAction() -> spawn file action object
Creates a Python object that encapsulates the posix_spawn_file_action_t
type. This is used by the posix_spawn(3C) interface to control actions
on file descriptors in the new process. This object implements the
following methods.
add_close(fd) -- Add the file descriptor fd to the list of fds to be
closed in the new process.
add_open(fd, path, oflag, mode) -- Open the file at path with flags
oflags and mode, assign it to the file descriptor numbered fd in the new
process.
add_dup2(fd, newfd) -- Take the file descriptor in fd and dup2 it to newfd
in the newly created process.
add_close_childfds(fd) -- Add all file descriptors above 2 except fd
(optionally) to list of fds to be closed in the new process.
Information about the underlying C interfaces can be found in the
following man pages:
posix_spawn(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_adddup2(3C)
"""
# The file_actions routines don't set errno, so we have to create
# the exception tuple by hand.
"""Add the file descriptor fd to the list of descriptors to be closed in
the new process."""
raise TypeError("fd must be int type")
"""Open the file at path with flags oflags and mode, assign it to
the file descriptor numbered fd in the new process."""
raise TypeError("fd must be int type")
raise TypeError("path must be a string")
raise TypeError("oflag must be int type")
raise TypeError("path must be int type")
mode)
"""Take the file descriptor in fd and dup2 it to newfd in the newly
created process."""
raise TypeError("fd must be int type")
raise TypeError("newfd must be int type")
"""Add to a SpawnFileAction a series of 'closes' that will close all of
the fds >= startfd in the child process. A single fd may be skipped,
provided that it is given as the optional except argument."""
raise TypeError("start_fd must be int type")
raise TypeError("except_fd must be int type")
# Set up walk_data for fdwalk.
# Perform the walk.
"""Invoke posix_spawnp(3C).
'filename' is the name of the executeable file.
'args' is a sequence of arguments supplied to the newly executed program.
'fileactions' defines what actions will be performed upon the file
descriptors of the spawned executable. If defined, it must be a
SpawnFileAction object.
'env', the enviroment, if provided, it must be a sequence object."""
raise TypeError("filename must be a string")
spawn_args = []
# This essentially does force_bytes in pkg.misc, but importing pkg.misc has
# a circular import issue, so we implement the conversion here.
# Process env, if supplied by caller
spawn_env = []
if env:
# setup file actions, if passed by caller
if fileactions:
raise TypeError("fileact must be a SpawnFileAction object.")
# Now do the actual spawn
return pid[0]