本文整理汇总了C++中WIFEXITED函数的典型用法代码示例。如果您正苦于以下问题:C++ WIFEXITED函数的具体用法?C++ WIFEXITED怎么用?C++ WIFEXITED使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WIFEXITED函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _evalpid
//.........这里部分代码省略.........
}
fprintf(stderr, "\n");
flog("\n");
}
#ifndef HAVE_SILENCE
int i = 0;
while (argv[i] != NULL) {
fprintf(stderr, "%s ", argv[i++]);
}
fprintf(stderr, "\n");
#endif
#endif
switch (pid = fork()) {
case -1: /* error */
perror("fork");
return errno;
case 0: /* child */
/*
* Reset signal handlers set for parent process
*/
for (sig = 0; sig < (_NSIG - 1); sig++)
signal(sig, SIG_DFL);
/*
* Clean up
*/
ioctl(0, TIOCNOTTY, 0);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
setsid();
/*
* We want to check the board if exist UART? , add by honor
* 2003-12-04
*/
if ((fd = open("/dev/console", O_RDWR)) < 0) {
(void)open("/dev/null", O_RDONLY);
(void)open("/dev/null", O_WRONLY);
(void)open("/dev/null", O_WRONLY);
} else {
close(fd);
(void)open("/dev/console", O_RDONLY);
(void)open("/dev/console", O_WRONLY);
(void)open("/dev/console", O_WRONLY);
}
/*
* Redirect stdout to <path>
*/
if (path) {
flags = O_WRONLY | O_CREAT;
if (!strncmp(path, ">>", 2)) {
/*
* append to <path>
*/
flags |= O_APPEND;
path += 2;
} else if (!strncmp(path, ">", 1)) {
/*
* overwrite <path>
*/
flags |= O_TRUNC;
path += 1;
}
if ((fd = open(path, flags, 0644)) < 0)
perror(path);
else {
dup2(fd, STDOUT_FILENO);
close(fd);
}
}
/*
* execute command
*/
// for (i = 0; argv[i]; i++)
// snprintf (buf + strlen (buf), sizeof (buf), "%s ", argv[i]);
// cprintf("cmd=[%s]\n", buf);
setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1);
alarm(timeout);
execvp(argv[0], argv);
perror(argv[0]);
exit(errno);
default: /* parent */
if (ppid) {
*ppid = pid;
return 0;
} else {
waitpid(pid, &status, 0);
if (WIFEXITED(status))
return WEXITSTATUS(status);
else
return status;
}
}
}
示例2: main
int main(int argc, char **argv)
{
pid_t npid, cpid;
int s, ns, cs, fc, cc, scn, scr, i;
if(argc < 3){
return 1;
}
_max = atoi(argv[1]);
if(_max < 0){
return 1;
}
setsid();
for(i = 0; i < sizeof(_sig) / sizeof(int); ++i){
signal(_sig[i], handler);
}
//limit(RLIMIT_NPROC, 64);
if(_max == 0){
limit(RLIMIT_AS, 32 * 1024 * 1024);
}
limit(RLIMIT_CPU, 1);
_pid = fork();
if(_pid < 0){
return 1;
}
if(_pid == 0){
if(_max <= 1){
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
}
execv(argv[2], argv + 2);
}
cc = 1;
fc = 0;
while(cc > 0){
cpid = wait3(&cs, 0, NULL);
if(WIFEXITED(cs)){
--cc;
if(cpid == _pid){
s = cs;
}
continue;
}
if(WIFSIGNALED(cs)){
kill(0, WTERMSIG(cs));
}
if(_max <= 1){
scn = ptrace(PTRACE_PEEKUSER, cpid, SCN, NULL);
if(_bad[scn] == FORK){
scr = ptrace(PTRACE_PEEKUSER, cpid, SCR, NULL);
if(scr > 0){
++cc;
if(!_max){
ptrace(PTRACE_ATTACH, scr, NULL, NULL);
}
ptrace(PTRACE_SYSCALL, cpid, NULL, NULL);
}else if(fc < _max){
++fc;
ptrace(PTRACE_SYSCALL, cpid, NULL, NULL);
}else{
kill(0, SIGKILL);
}
}else if(_bad[scn]){
kill(0, SIGKILL);
}else{
ptrace(PTRACE_SYSCALL, cpid, NULL, NULL);
}
}
}
return WEXITSTATUS(s);
}
示例3: edit_table
//.........这里部分代码省略.........
fclose(in);
fclose(out);
struct stat st;
if (stat(s, &st) != 0) {
fprintf(stderr, "cannot stat temporary file: %s\n", strerror(errno));
goto end;
}
mt = st.st_mtime; // save modification time for detecting its change
// Editor selecting algorithm:
// 1. Check EDITOR environment variable
// 2. Check VISUAL environment variable
// 3. Try to get from configuration
// 4. Check presence of /etc/alternatives/editor
// 5. Use hard-wired editor
e = getenv("EDITOR");
if (e == NULL) {
e = getenv("VISUAL");
if (e == NULL) {
if (!IncronCfg::GetValue("editor", ed))
throw InotifyException("configuration is corrupted", EINVAL);
if (!ed.empty()) {
e = ed.c_str();
}
else {
if (access(INCRON_ALT_EDITOR, X_OK) == 0)
e = INCRON_ALT_EDITOR;
else
e = INCRON_DEFAULT_EDITOR;
}
}
}
// this block is explicite due to gotos' usage simplification
{
pid_t pid = fork();
if (pid == 0) {
if (setgid(gid) != 0 || setuid(uid) != 0) {
fprintf(stderr, "cannot set user '%s': %s\n", rUser.c_str(), strerror(errno));
goto end;
}
execlp(e, e, s, NULL);
_exit(1);
}
else if (pid > 0) {
int status;
if (wait(&status) != pid) {
perror("error while waiting for editor");
goto end;
}
if (!(WIFEXITED(status)) || WEXITSTATUS(status) != 0) {
perror("editor finished with error");
goto end;
}
}
else {
perror("cannot start editor");
goto end;
}
}
if (stat(s, &st) != 0) {
fprintf(stderr, "cannot stat temporary file: %s\n", strerror(errno));
goto end;
}
if (st.st_mtime == mt) {
fprintf(stderr, "table unchanged\n");
ok = true;
goto end;
}
{
IncronTab ict;
if (ict.Load(s) && ict.Save(tp)) {
if (chmod(tp.c_str(), S_IRUSR | S_IWUSR) != 0) {
fprintf(stderr, "cannot change mode of temporary file: %s\n", strerror(errno));
}
}
else {
fprintf(stderr, "cannot move temporary table: %s\n", strerror(errno));
goto end;
}
}
ok = true;
fprintf(stderr, "table updated\n");
end:
unlink(s);
return ok;
}
示例4: runAndGetCexForked
static SolverImpl::SolverRunStatus
runAndGetCexForked(::VC vc, STPBuilder *builder, ::VCExpr q,
const std::vector<const Array *> &objects,
std::vector<std::vector<unsigned char> > &values,
bool &hasSolution, double timeout) {
unsigned char *pos = shared_memory_ptr;
unsigned sum = 0;
for (std::vector<const Array *>::const_iterator it = objects.begin(),
ie = objects.end();
it != ie; ++it)
sum += (*it)->size;
if (sum >= shared_memory_size)
llvm::report_fatal_error("not enough shared memory for counterexample");
fflush(stdout);
fflush(stderr);
int pid = fork();
if (pid == -1) {
klee_warning("fork failed (for STP)");
if (!IgnoreSolverFailures)
exit(1);
return SolverImpl::SOLVER_RUN_STATUS_FORK_FAILED;
}
if (pid == 0) {
if (timeout) {
::alarm(0); /* Turn off alarm so we can safely set signal handler */
::signal(SIGALRM, stpTimeoutHandler);
::alarm(std::max(1, (int)timeout));
}
unsigned res = vc_query(vc, q);
if (!res) {
for (std::vector<const Array *>::const_iterator it = objects.begin(),
ie = objects.end();
it != ie; ++it) {
const Array *array = *it;
for (unsigned offset = 0; offset < array->size; offset++) {
ExprHandle counter =
vc_getCounterExample(vc, builder->getInitialRead(array, offset));
*pos++ = getBVUnsigned(counter);
}
}
}
_exit(res);
} else {
int status;
pid_t res;
do {
res = waitpid(pid, &status, 0);
} while (res < 0 && errno == EINTR);
if (res < 0) {
klee_warning("waitpid() for STP failed");
if (!IgnoreSolverFailures)
exit(1);
return SolverImpl::SOLVER_RUN_STATUS_WAITPID_FAILED;
}
// From timed_run.py: It appears that linux at least will on
// "occasion" return a status when the process was terminated by a
// signal, so test signal first.
if (WIFSIGNALED(status) || !WIFEXITED(status)) {
klee_warning("STP did not return successfully. Most likely you forgot "
"to run 'ulimit -s unlimited'");
if (!IgnoreSolverFailures) {
exit(1);
}
return SolverImpl::SOLVER_RUN_STATUS_INTERRUPTED;
}
int exitcode = WEXITSTATUS(status);
if (exitcode == 0) {
hasSolution = true;
} else if (exitcode == 1) {
hasSolution = false;
} else if (exitcode == 52) {
klee_warning("STP timed out");
// mark that a timeout occurred
return SolverImpl::SOLVER_RUN_STATUS_TIMEOUT;
} else {
klee_warning("STP did not return a recognized code");
if (!IgnoreSolverFailures)
exit(1);
return SolverImpl::SOLVER_RUN_STATUS_UNEXPECTED_EXIT_CODE;
}
if (hasSolution) {
values = std::vector<std::vector<unsigned char> >(objects.size());
unsigned i = 0;
for (std::vector<const Array *>::const_iterator it = objects.begin(),
ie = objects.end();
it != ie; ++it) {
const Array *array = *it;
std::vector<unsigned char> &data = values[i++];
data.insert(data.begin(), pos, pos + array->size);
pos += array->size;
}
}
//.........这里部分代码省略.........
示例5: main
int main()
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
fprintf(stderr, "Unable to mask SIGCHLD");
return 1;
}
signal(SIGCHLD, sig_hand);
int fd[2];
if (pipe(fd) == -1){
fprintf(stderr, "Unable to open pipe ");
return 1;
}
pid_t child = fork();
if (child)
{
// Parent proc
close(fd[1]); // Close unused write end
struct timespec timeout;
timeout.tv_sec = 120;
timeout.tv_nsec = 0;
char buf[2];
read(fd[0], &buf, 1); // wait until child activate timer
close(fd[0]);
// This process waits enough for the child process to complete
if (sigtimedwait(&sigset, NULL, &timeout) < 0)
{
if (errno == EAGAIN)
{
fprintf(stderr, "Timeout, killing child\n");
kill (child, SIGKILL);
return 1;
}
else
{
fprintf(stderr, "Error in sigtimedwait");
return 1;
}
}
int status;
// In case child process is still running the test fails (assuming deadlock occurred)
if (waitpid(child, &status, 0) < 0) {
fprintf(stderr, "Error on waitpid");
return 1;
}
if(WIFEXITED(status) && WEXITSTATUS(status)==0)
{
fprintf(stderr, "Parent - terminate OK\n");
return 0;
}
return 1;
}
else
{
// inside child
close(fd[0]); // Close unused read end
struct sigaction sigact;
struct itimerval itval;
pthread_t tid;
sigact.sa_handler = Handle;
sigact.sa_flags = 0;
sigemptyset(&sigact.sa_mask);
if (sigaction(SIGVTALRM, &sigact, 0) == -1)
{
fprintf(stderr, "Child - Unable to set up handler\n");
return 1;
}
// Create a new thread that calls a system call in a loop
if (pthread_create(&tid, 0, DoSysCallTillSignalsDone, 0) != 0)
{
fprintf(stderr, "Child - Unable to create thread\n");
return 1;
}
// Set timer to create an async signals
itval.it_interval.tv_sec = 0;
itval.it_interval.tv_usec = USLEEP_TIME;
itval.it_value.tv_sec = 0;
itval.it_value.tv_usec = USLEEP_TIME;
if (setitimer(ITIMER_VIRTUAL, &itval, 0) == -1)
{
fprintf(stderr, "Child - Unable to set up timer\n");
return 1;
}
close(fd[1]); // send EOF to signal parent that timer is on
/*
* Call an analysis function in a loop .
*/
//.........这里部分代码省略.........
示例6: jl_process_exited
int jl_process_exited(int status) { return WIFEXITED(status); }
示例7: DS2ASSERT
ErrorCode Process::wait() {
int status, signal;
ProcessInfo info;
ThreadId tid;
// We have at least one thread when we start waiting on a process.
DS2ASSERT(!_threads.empty());
while (!_threads.empty()) {
tid = blocking_waitpid(-1, &status, __WALL);
DS2LOG(Debug, "wait tid=%d status=%#x", tid, status);
if (tid <= 0)
return kErrorProcessNotFound;
auto threadIt = _threads.find(tid);
if (threadIt == _threads.end()) {
// If we don't know about this thread yet, but it has a WIFEXITED() or a
// WIFSIGNALED() status (i.e.: it terminated), it means we already
// cleaned up the thread object (e.g.: in Process::suspend), but we
// hadn't waitpid()'d it yet. Avoid re-creating a Thread object here.
if (WIFEXITED(status) || WIFSIGNALED(status)) {
goto continue_waiting;
}
// A new thread has appeared that we didn't know about. Create the
// Thread object and return.
DS2LOG(Debug, "creating new thread tid=%d", tid);
_currentThread = new Thread(this, tid);
return kSuccess;
} else {
_currentThread = threadIt->second;
}
_currentThread->updateStopInfo(status);
switch (_currentThread->_stopInfo.event) {
case StopInfo::kEventNone:
_currentThread->resume();
goto continue_waiting;
case StopInfo::kEventExit:
case StopInfo::kEventKill:
DS2LOG(Debug, "thread %d is exiting", tid);
//
// Killing the main thread?
//
// Note(sas): This might be buggy; the main thread exiting
// doesn't mean that the process is dying.
//
if (tid == _pid && _threads.size() == 1) {
DS2LOG(Debug, "last thread is exiting");
break;
}
//
// Remove and release the thread associated with this pid.
//
removeThread(tid);
goto continue_waiting;
case StopInfo::kEventStop:
signal = _currentThread->_stopInfo.signal;
DS2LOG(Debug, "stopped tid=%d status=%#x signal=%s", tid, status,
Stringify::Signal(signal));
if (_passthruSignals.find(signal) != _passthruSignals.end()) {
_currentThread->resume(signal);
goto continue_waiting;
} else {
//
// This is a signal that we want to transmit back to the
// debugger.
//
break;
}
}
break;
continue_waiting:
_currentThread = nullptr;
continue;
}
if (!(WIFEXITED(status) || WIFSIGNALED(status)) || tid != _pid) {
//
// Suspend the process, this must be done after updating
// the thread trap info.
//
suspend();
}
if ((WIFEXITED(status) || WIFSIGNALED(status)) && tid == _pid) {
_terminated = true;
}
//.........这里部分代码省略.........
示例8: g_spawn_command_line_sync
gboolean
g_spawn_command_line_sync (const gchar *command_line,
gchar **standard_output,
gchar **standard_error,
gint *exit_status,
GError **error)
{
#ifdef G_OS_WIN32
#else
pid_t pid;
gchar **argv;
gint argc;
int stdout_pipe [2] = { -1, -1 };
int stderr_pipe [2] = { -1, -1 };
int status;
int res;
if (!g_shell_parse_argv (command_line, &argc, &argv, error))
return FALSE;
if (standard_output && !create_pipe (stdout_pipe, error))
return FALSE;
if (standard_error && !create_pipe (stderr_pipe, error)) {
if (standard_output) {
CLOSE_PIPE (stdout_pipe);
}
return FALSE;
}
pid = fork ();
if (pid == 0) {
gint i;
if (standard_output) {
close (stdout_pipe [0]);
dup2 (stdout_pipe [1], STDOUT_FILENO);
}
if (standard_error) {
close (stderr_pipe [0]);
dup2 (stderr_pipe [1], STDERR_FILENO);
}
for (i = g_getdtablesize () - 1; i >= 3; i--)
close (i);
/* G_SPAWN_SEARCH_PATH is always enabled for g_spawn_command_line_sync */
if (!g_path_is_absolute (argv [0])) {
gchar *arg0;
arg0 = g_find_program_in_path (argv [0]);
if (arg0 == NULL) {
exit (1);
}
//g_free (argv [0]);
argv [0] = arg0;
}
execv (argv [0], argv);
exit (1); /* TODO: What now? */
}
g_strfreev (argv);
if (standard_output)
close (stdout_pipe [1]);
if (standard_error)
close (stderr_pipe [1]);
if (standard_output || standard_error) {
res = read_pipes (stdout_pipe [0], standard_output, stderr_pipe [0], standard_error, error);
if (res) {
waitpid (pid, &status, WNOHANG); /* avoid zombie */
return FALSE;
}
}
NO_INTR (res, waitpid (pid, &status, 0));
/* TODO: What if error? */
if (WIFEXITED (status) && exit_status) {
*exit_status = WEXITSTATUS (status);
}
#endif
return TRUE;
}
示例9: do_master_child
static void do_master_child(void)
{
int lc;
int pid;
int status;
if (SETUID(NULL, ltpuser->pw_uid) == -1) {
tst_brkm(TBROK, NULL,
"setuid failed to set the effective uid to %d",
ltpuser->pw_uid);
}
for (lc = 0; TEST_LOOPING(lc); lc++) {
int tst_fd;
tst_count = 0;
TEST(tst_fd = open(testfile, O_RDWR));
if (TEST_RETURN != -1) {
tst_resm(TFAIL, "call succeeded unexpectedly");
close(tst_fd);
}
if (TEST_ERRNO == EACCES) {
tst_resm(TPASS, "open returned errno EACCES");
} else {
tst_resm(TFAIL, "open returned unexpected errno - %d",
TEST_ERRNO);
continue;
}
pid = FORK_OR_VFORK();
if (pid < 0)
tst_brkm(TBROK, NULL, "Fork failed");
if (pid == 0) {
int tst_fd2;
/* Test to open the file in son process */
TEST(tst_fd2 = open(testfile, O_RDWR));
if (TEST_RETURN != -1) {
tst_resm(TFAIL, "call succeeded unexpectedly");
close(tst_fd2);
}
TEST_ERROR_LOG(TEST_ERRNO);
if (TEST_ERRNO == EACCES) {
tst_resm(TPASS, "open returned errno EACCES");
} else {
tst_resm(TFAIL,
"open returned unexpected errno - %d",
TEST_ERRNO);
}
tst_exit();
} else {
/* Wait for son completion */
waitpid(pid, &status, 0);
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
exit(WEXITSTATUS(status));
}
}
tst_exit();
}
示例10: mgt_reap_child
static void
mgt_reap_child(void)
{
int i;
int status = 0xffff;
struct vsb *vsb;
pid_t r = 0;
assert(child_pid != -1);
/*
* Close the CLI connections
* This signals orderly shut down to child
*/
mgt_cli_stop_child();
if (child_cli_out >= 0)
closex(&child_cli_out);
if (child_cli_in >= 0)
closex(&child_cli_in);
/* Stop the poker */
if (ev_poker != NULL) {
vev_del(mgt_evb, ev_poker);
free(ev_poker);
}
ev_poker = NULL;
/* Stop the listener */
if (ev_listen != NULL) {
vev_del(mgt_evb, ev_listen);
free(ev_listen);
ev_listen = NULL;
}
/* Compose obituary */
vsb = VSB_new_auto();
XXXAN(vsb);
/* Wait for child to die */
for (i = 0; i < mgt_param.cli_timeout; i++) {
r = waitpid(child_pid, &status, WNOHANG);
if (r == child_pid)
break;
(void)sleep(1);
}
if (r == 0) {
VSB_printf(vsb, "Child (%jd) not dying, killing", (intmax_t)r);
/* Kick it Jim... */
if (MGT_FEATURE(FEATURE_NO_COREDUMP))
(void)kill(child_pid, SIGKILL);
else
(void)kill(child_pid, SIGQUIT);
r = waitpid(child_pid, &status, 0);
}
if (r != child_pid)
fprintf(stderr, "WAIT 0x%jx\n", (uintmax_t)r);
assert(r == child_pid);
MAC_reopen_sockets(NULL);
VSB_printf(vsb, "Child (%jd) %s", (intmax_t)r,
status ? "died" : "ended");
if (WIFEXITED(status) && WEXITSTATUS(status)) {
VSB_printf(vsb, " status=%d", WEXITSTATUS(status));
exit_status |= 0x20;
if (WEXITSTATUS(status) == 1)
VSC_C_mgt->child_exit = ++static_VSC_C_mgt.child_exit;
else
VSC_C_mgt->child_stop = ++static_VSC_C_mgt.child_stop;
}
if (WIFSIGNALED(status)) {
VSB_printf(vsb, " signal=%d", WTERMSIG(status));
exit_status |= 0x40;
VSC_C_mgt->child_died = ++static_VSC_C_mgt.child_died;
}
#ifdef WCOREDUMP
if (WCOREDUMP(status)) {
VSB_printf(vsb, " (core dumped)");
exit_status |= 0x80;
VSC_C_mgt->child_dump = ++static_VSC_C_mgt.child_dump;
}
#endif
AZ(VSB_finish(vsb));
MGT_complain(status ? C_ERR : C_INFO, "%s", VSB_data(vsb));
VSB_delete(vsb);
/* Dispose of shared memory but evacuate panic messages first */
if (heritage.panic_str[0] != '\0') {
mgt_panic_record(r);
mgt_SHM_Destroy(1);
VSC_C_mgt->child_panic = ++static_VSC_C_mgt.child_panic;
} else {
mgt_SHM_Destroy(MGT_DO_DEBUG(DBG_VSM_KEEP));
}
mgt_SHM_Create();
mgt_SHM_Commit();
if (child_state == CH_RUNNING)
child_state = CH_DIED;
//.........这里部分代码省略.........
示例11: ProcessBreakpoint
//.........这里部分代码省略.........
} else {
dbg_printf( "who the hell interrupted waitpid()?\n" );
}
do_cont = FALSE;
continue;
}
if( ret < 0 )
perror( "waitpid()" );
do_cont = TRUE;
/* record current execution point */
#if defined( MD_x86 )
ptrace( PTRACE_GETREGS, pid, NULL, ®s );
#elif defined( MD_ppc )
regs.eip = ptrace( PTRACE_PEEKUSER, pid, REGSIZE * PT_NIP, NULL );
#endif
if( WIFSTOPPED( status ) ) {
/* If debuggee has dynamic section, try getting the r_debug struct
* every time the child process stops. The r_debug data may not be
* available immediately after the child process first loads.
*/
if( !HaveRdebug && (DbgDyn != NULL) ) {
if( Get_ld_info( pid, DbgDyn, &Rdebug, &DbgRdebug ) ) {
AddLibrary( pid, Rdebug.r_map );
HaveRdebug = TRUE;
/* Set a breakpoint in dynamic linker. That way we can be
* informed on dynamic library load/unload events.
*/
ReadMem( pid, &saved_opcode, Rdebug.r_brk, sizeof( saved_opcode ) );
dbg_printf( "setting ld breakpoint at %p, old opcode was %X\n", Rdebug.r_brk, saved_opcode );
WriteMem( pid, &brk_opcode, Rdebug.r_brk, sizeof( brk_opcode ) );
}
}
sample_continue = FALSE;
switch( (ptrace_sig = WSTOPSIG( status )) ) {
case SIGSEGV:
dbg_printf( "SIGSEGV at %p\n", regs.eip );
sample_continue = TRUE;
break;
case SIGILL:
dbg_printf( "SIGILL at %p\n", regs.eip );
sample_continue = TRUE;
break;
case SIGABRT:
dbg_printf( "SIGABRT at %p\n", regs.eip );
sample_continue = TRUE;
break;
case SIGINT:
dbg_printf( "SIGINT at %p\n", regs.eip );
sample_continue = TRUE;
break;
case SIGTRAP:
dbg_printf( "SIGTRAP at %p\n", regs.eip );
if( ProcessBreakpoint( pid, regs.eip ) ) {
// don't pass on SIGTRAP if we expected this breakpoint
ptrace_sig = 0;
}
sample_continue = TRUE;
break;
case SIGSTOP:
/* presumably we were behind this SIGSTOP */
RecordSample( regs.eip, 1 );
ptrace_sig = 0;
sample_continue = TRUE;
break;
default:
/* all other signals get passed down to the child and we let
* the child handle them (or not handle and die)
*/
sample_continue = TRUE;
break;
}
} else if( WIFEXITED( status ) ) {
dbg_printf( "WIFEXITED pid %d\n", pid );
report();
sample_continue = FALSE;
} else if( WIFSIGNALED( status ) ) {
dbg_printf( "WIFSIGNALED pid %d\n", pid );
report();
sample_continue = FALSE;
}
} while( sample_continue );
}
static int GetExeNameFromPid( pid_t pid, char *buffer, int max_len )
{
char procfile[24];
int len;
sprintf( procfile, "/proc/%d/exe", pid );
len = readlink( procfile, buffer, max_len );
if( len < 0 )
len = 0;
buffer[len] = '\0';
return( len );
}
示例12: seed_rng
void
seed_rng(void)
{
#ifndef OPENSSL_PRNG_ONLY
int devnull;
int p[2];
pid_t pid;
int ret;
unsigned char buf[RANDOM_SEED_SIZE];
mysig_t old_sigchld;
if (RAND_status() == 1) {
debug3("RNG is ready, skipping seeding");
return;
}
debug3("Seeding PRNG from %s", SSH_RAND_HELPER);
if ((devnull = open("/dev/null", O_RDWR)) == -1)
fatal("Couldn't open /dev/null: %s", strerror(errno));
if (pipe(p) == -1)
fatal("pipe: %s", strerror(errno));
old_sigchld = signal(SIGCHLD, SIG_DFL);
if ((pid = fork()) == -1)
fatal("Couldn't fork: %s", strerror(errno));
if (pid == 0) {
dup2(devnull, STDIN_FILENO);
dup2(p[1], STDOUT_FILENO);
/* Keep stderr open for errors */
close(p[0]);
close(p[1]);
close(devnull);
if (original_uid != original_euid &&
( seteuid(getuid()) == -1 ||
setuid(original_uid) == -1) ) {
fprintf(stderr, "(rand child) setuid(%li): %s\n",
(long int)original_uid, strerror(errno));
_exit(1);
}
execl(SSH_RAND_HELPER, "ssh-rand-helper", NULL);
fprintf(stderr, "(rand child) Couldn't exec '%s': %s\n",
SSH_RAND_HELPER, strerror(errno));
_exit(1);
}
close(devnull);
close(p[1]);
memset(buf, '\0', sizeof(buf));
ret = atomicio(read, p[0], buf, sizeof(buf));
if (ret == -1)
fatal("Couldn't read from ssh-rand-helper: %s",
strerror(errno));
if (ret != sizeof(buf))
fatal("ssh-rand-helper child produced insufficient data");
close(p[0]);
if (waitpid(pid, &ret, 0) == -1)
fatal("Couldn't wait for ssh-rand-helper completion: %s",
strerror(errno));
signal(SIGCHLD, old_sigchld);
/* We don't mind if the child exits upon a SIGPIPE */
if (!WIFEXITED(ret) &&
(!WIFSIGNALED(ret) || WTERMSIG(ret) != SIGPIPE))
fatal("ssh-rand-helper terminated abnormally");
if (WEXITSTATUS(ret) != 0)
fatal("ssh-rand-helper exit with exit status %d", ret);
RAND_add(buf, sizeof(buf), sizeof(buf));
memset(buf, '\0', sizeof(buf));
#endif /* OPENSSL_PRNG_ONLY */
if (RAND_status() != 1)
fatal("PRNG is not seeded");
}
示例13: main
int main(int argc, char* argv[]){
long i;
long iterations = DEFAULT_ITERATIONS;
struct sched_param param;
int policy, num_processes, status;
double x, y;
double inCircle = 0.0;
double inSquare = 0.0;
double pCircle = 0.0;
double piCalc = 0.0;
pid_t pid, wpid;
int j = 0;
/* Set default policy if not supplied */
if(argc < 2){
policy = SCHED_OTHER;
}
/* Set default number of processes */
if(argc < 3){
num_processes = LOW;
}
/* Set policy if supplied */
if(argc > 1){
if(!strcmp(argv[1], "SCHED_OTHER")){
policy = SCHED_OTHER;
}
else if(!strcmp(argv[1], "SCHED_FIFO")){
policy = SCHED_FIFO;
}
else if(!strcmp(argv[1], "SCHED_RR")){
policy = SCHED_RR;
}
else {
fprintf(stderr, "Unhandeled scheduling policy\n");
exit(EXIT_FAILURE);
}
}
/* Set # Of Processes */
if(argc > 2){
if(!strcmp(argv[2], "LOW")){
num_processes = LOW;
}
else if(!strcmp(argv[2], "MEDIUM")){
num_processes = MEDIUM;
}
else if(!strcmp(argv[2], "HIGH")){
num_processes = HIGH;
}
else{
fprintf(stderr, "Unhandeled number of processes\n");
exit(EXIT_FAILURE);
}
}
/* Set process to max prioty for given scheduler */
param.sched_priority = sched_get_priority_max(policy);
/* Set new scheduler policy */
fprintf(stdout, "Current Scheduling Policy: %d\n", sched_getscheduler(0));
fprintf(stdout, "Setting Scheduling Policy to: %d\n", policy);
if(sched_setscheduler(0, policy, ¶m)){
perror("Error setting scheduler policy");
exit(EXIT_FAILURE);
}
fprintf(stdout, "New Scheduling Policy: %d\n", sched_getscheduler(0));
/* Fork number of processes specified */
printf("Number of processes to be forked %d \n", num_processes);
for(i = 0; i < num_processes; i++){
if((pid = fork()) == -1){
fprintf(stderr, "Error Forking Child Process");
exit(EXIT_FAILURE);
}
// only if pid is 0, we are in child
if(pid == 0){
for(i=0; i<iterations; i++){
x = (random() % (RADIUS * 2)) - RADIUS;
y = (random() % (RADIUS * 2)) - RADIUS;
if(zeroDist(x,y) < RADIUS){
inCircle++;
}
inSquare++;
}
/* Finish calculation */
pCircle = inCircle/inSquare;
piCalc = pCircle * 4.0;
/* Print result */
fprintf(stdout, "pi = %f\n", piCalc);
exit(0);
}
}
// terminate all children until wpid is 0
while((wpid = wait(&status)) > 0){
if(WIFEXITED(status)){
//.........这里部分代码省略.........
示例14: client_exec_script
//.........这里部分代码省略.........
prev_size = input->used;
buf = buffer_append_space_unsafe(input, IO_BLOCK_SIZE);
/* peek in socket input buffer */
ret = recv(conn->fd, buf, IO_BLOCK_SIZE, MSG_PEEK);
if (ret <= 0) {
buffer_set_used_size(input, prev_size);
if (strchr(str_c(input), '\n') != NULL)
script_verify_version(t_strcut(str_c(input), '\n'));
if (ret < 0)
i_fatal("recv(MSG_PEEK) failed: %m");
i_fatal("recv(MSG_PEEK) failed: disconnected");
}
/* scan for final \n\n */
pos = CONST_PTR_OFFSET(input->data, scanpos);
end = CONST_PTR_OFFSET(input->data, prev_size + ret);
for (; pos < end; pos++) {
if (pos[-1] == '\n' && pos[0] == '\n') {
header_complete = TRUE;
pos++;
break;
}
}
scanpos = pos - (const unsigned char *)input->data;
/* read data for real (up to and including \n\n) */
ret = recv(conn->fd, buf, scanpos-prev_size, 0);
if (prev_size+ret != scanpos) {
if (ret < 0)
i_fatal("recv() failed: %m");
if (ret == 0)
i_fatal("recv() failed: disconnected");
i_fatal("recv() failed: size of definitive recv() differs from peek");
}
buffer_set_used_size(input, scanpos);
}
alarm(0);
/* drop the last two LFs */
buffer_set_used_size(input, scanpos-2);
args = t_strsplit(str_c(input), "\n");
script_verify_version(*args); args++;
if (*args != NULL) {
if (strncmp(*args, "alarm=", 6) == 0) {
unsigned int seconds;
if (str_to_uint(*args + 6, &seconds) < 0)
i_fatal("invalid alarm option");
alarm(seconds);
args++;
}
if (strcmp(*args, "noreply") == 0) {
/* no need to fork and check exit status */
exec_child(conn, args + 1);
i_unreached();
}
if (**args == '\0')
i_fatal("empty options");
args++;
}
if ((pid = fork()) == (pid_t)-1) {
i_error("fork() failed: %m");
return FALSE;
}
if (pid == 0) {
/* child */
exec_child(conn, args);
i_unreached();
}
/* parent */
/* check script exit status */
if (waitpid(pid, &status, 0) < 0) {
i_error("waitpid() failed: %m");
return FALSE;
} else if (WIFEXITED(status)) {
ret = WEXITSTATUS(status);
if (ret != 0) {
i_error("Script terminated abnormally, exit status %d", (int)ret);
return FALSE;
}
} else if (WIFSIGNALED(status)) {
i_error("Script terminated abnormally, signal %d", WTERMSIG(status));
return FALSE;
} else if (WIFSTOPPED(status)) {
i_fatal("Script stopped, signal %d", WSTOPSIG(status));
return FALSE;
} else {
i_fatal("Script terminated abnormally, return status %d", status);
return FALSE;
}
return TRUE;
}
示例15: f_pcntl_wifexited
bool f_pcntl_wifexited(int status) { return WIFEXITED(status);}