/*
SSSD
Common helper functions to be used in child processes
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2009 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fcntl.h>
#include <tevent.h>
#include <errno.h>
#include "util/find_uid.h"
#include "util/child_common.h"
struct sss_sigchild_ctx {
int options;
};
struct sss_child_ctx {
void *pvt;
};
struct tevent_signal *se,
int signum,
int count,
void *siginfo,
void *private_data);
struct tevent_context *ev,
struct sss_sigchild_ctx **child_ctx)
{
if (!sigchld_ctx) {
"fatal error initializing sss_sigchild_ctx\n");
return ENOMEM;
}
"fatal error initializing children hash table: [%s]\n",
return ret;
}
BlockSignals(false, SIGCHLD);
return EIO;
}
*child_ctx = sigchld_ctx;
return EOK;
}
{
int error;
"failed to delete child_ctx from hash table [%d]: %s\n",
}
return 0;
}
struct sss_sigchild_ctx *sigchld_ctx,
void *pvt,
struct sss_child_ctx **child_ctx)
{
int error;
return ENOMEM;
}
if (error != HASH_SUCCESS) {
return ENOMEM;
}
return EOK;
}
struct sss_child_cb_pvt {
int wait_status;
};
struct tevent_immediate *imm,
void *pvt)
{
int error;
"failed to delete child_ctx from hash table [%d]: %s\n",
}
}
}
struct tevent_signal *se,
int signum,
int count,
void *siginfo,
void *private_data)
{
int error;
int wait_status;
do {
do {
errno = 0;
if (pid == -1) {
return;
} else if (pid == 0) continue;
if (error == HASH_SUCCESS) {
"Out of memory invoking SIGCHLD callback\n");
return;
}
if (invoke_pvt == NULL) {
"out of memory invoking SIGCHLD callback\n");
return;
}
} else if (error == HASH_ERROR_KEY_NOT_FOUND) {
"BUG: waitpid() returned [%d] but it was not in the table. "
"This could be due to a linked library creating processes "
"without registering them with the sigchld handler\n",
pid);
/* We will simply ignore this and return to the loop
* This will prevent a zombie, but may cause unexpected
* behavior in the code that was trying to handle this
* pid.
*/
} else {
"SIGCHLD hash table error [%d]: %s\n",
/* This is bad, but we should try to check for other
* children anyway, to avoid potential zombies.
*/
}
} while (pid != 0);
}
struct sss_child_ctx_old {
int child_status;
void *pvt;
};
struct sss_child_ctx_old **_child_ctx)
{
"Setting up signal handler up for pid [%d]\n", pid);
return ENOMEM;
}
/* Error setting up signal handler */
return ENOMEM;
}
if (_child_ctx != NULL) {
*_child_ctx = child_ctx;
}
return EOK;
}
{
/* We still want to wait for the child to finish, but the caller is not
* interested in the result anymore (e.g. timeout was reached). */
if (ret == -1) {
}
}
/* Async communication with the child process via a pipe */
struct write_pipe_state {
int fd;
};
struct tevent_context *ev,
{
goto fail;
}
return req;
fail:
return NULL;
}
{
struct write_pipe_state);
if (flags & TEVENT_FD_READ) {
"write_pipe_done called with TEVENT_FD_READ,"
" this should not happen.\n");
return;
}
errno = 0;
return;
}
return;
}
return;
}
{
return EOK;
}
struct read_pipe_state {
int fd;
};
{
goto fail;
}
return req;
fail:
return NULL;
}
{
struct read_pipe_state);
if (flags & TEVENT_FD_WRITE) {
" this should not happen.\n");
return;
}
buf,
if (size == -1) {
return;
} else if (size > 0) {
return;
}
return;
} else if (size == 0) {
return;
} else {
"unexpected return value of read [%zd].\n", size);
return;
}
}
{
return EOK;
}
struct tevent_immediate *imm,
void *pvt);
{
if (count <= 0) {
"SIGCHLD handler called with invalid child count\n");
return;
}
errno = 0;
if (ret == -1) {
} else if (ret == 0) {
"waitpid did not found a child with changed status.\n");
} else {
"child [%d] failed with status [%d].\n", ret,
} else {
"child [%d] finished successfully.\n", ret);
}
"child [%d] was terminated by signal [%d].\n", ret,
} else {
"child [%d] was stopped by signal [%d].\n", ret,
}
"child [%d] was resumed by delivery of SIGCONT.\n",
ret);
}
return;
}
/* Invoke the callback in a tevent_immediate handler
* so that it is safe to free the tevent_signal *
*/
"Out of memory invoking sig handler callback\n");
return;
}
}
return;
}
struct tevent_immediate *imm,
void *pvt)
{
}
/* Stop monitoring for this child */
}
int child_debug_fd,
const char *binary,
const char *extra_argv[],
bool extra_args_only,
char ***_argv)
{
/*
* program name, debug_level, debug_timestamps,
* debug_microseconds and NULL
*/
size_t i;
if (extra_args_only) {
}
/* Save the current state in case an interrupt changes it */
if (!extra_args_only) {
if (child_debug_to_file) argc++;
if (child_debug_stderr) argc++;
}
if (extra_argv) {
for (i = 0; extra_argv[i]; i++) argc++;
}
/*
* program name, debug_level, debug_to_file, debug_timestamps,
* debug_microseconds and NULL
*/
return ENOMEM;
}
/* Add extra_attrs first */
if (extra_argv) {
for (i = 0; extra_argv[i]; i++) {
goto fail;
}
}
}
if (!extra_args_only) {
goto fail;
}
if (child_debug_stderr) {
goto fail;
}
}
if (child_debug_to_file) {
goto fail;
}
}
goto fail;
}
goto fail;
}
}
goto fail;
}
if (argc != 0) {
goto fail;
}
return EOK;
fail:
return ret;
}
int *pipefd_to_child, int *pipefd_from_child,
const char *extra_argv[], bool extra_args_only,
int child_in_fd, int child_out_fd)
{
int ret;
char **argv;
if (ret == -1) {
}
close(pipefd_from_child[0]);
if (ret == -1) {
}
&argv);
}
}
int *pipefd_to_child, int *pipefd_from_child,
{
}
{
int ret;
}
}
}
}
return EOK;
}
{
int ret;
return EOK;
}
return ret;
}
if (*debug_fd == -1) {
return ret;
}
}
return EOK;
}