public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Prototype jni/DaemonFactory. Date: Tue, 20 May 2008 19:20:00 -0000 [thread overview] Message-ID: <20080520192044.1408.qmail@sourceware.org> (raw) The branch, master has been updated via 24a1e128332990b4e3927543f6f314fb568b331c (commit) from c578532603748f8d4b4de3f5b6ada6daeaba5f03 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 24a1e128332990b4e3927543f6f314fb568b331c Author: Andrew Cagney <cagney@redhat.com> Date: Tue May 20 15:20:04 2008 -0400 Prototype jni/DaemonFactory. frysk-sys/frysk/sys/ChangeLog 2008-05-20 Andrew Cagney <cagney@redhat.com> * jni/DaemonFactory.cxx: Implement. ----------------------------------------------------------------------- Summary of changes: frysk-sys/frysk/sys/ChangeLog | 4 ++ frysk-sys/frysk/sys/jni/DaemonFactory.cxx | 63 ++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletions(-) First 500 lines of diff: diff --git a/frysk-sys/frysk/sys/ChangeLog b/frysk-sys/frysk/sys/ChangeLog index f8c40c3..efde63d 100644 --- a/frysk-sys/frysk/sys/ChangeLog +++ b/frysk-sys/frysk/sys/ChangeLog @@ -1,3 +1,7 @@ +2008-05-20 Andrew Cagney <cagney@redhat.com> + + * jni/DaemonFactory.cxx: Implement. + 2008-05-17 Andrew Cagney <cagney@redhat.com> * jni/SignalSet.hxx (getRawSet): Add env parameter. diff --git a/frysk-sys/frysk/sys/jni/DaemonFactory.cxx b/frysk-sys/frysk/sys/jni/DaemonFactory.cxx index b358932..bfa72cb 100644 --- a/frysk-sys/frysk/sys/jni/DaemonFactory.cxx +++ b/frysk-sys/frysk/sys/jni/DaemonFactory.cxx @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2008, Red Hat Inc. +// Copyright 2007, 2008, Red Hat Inc. // // FRYSK is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by @@ -37,4 +37,65 @@ // version and license this file solely under the GPL without // exception. +#include <stdio.h> +#include <alloca.h> +#include <errno.h> +#include <unistd.h> +#include <sys/ptrace.h> +#include <sys/types.h> +#include <sys/wait.h> + #include "jni.hxx" + +#include "jnixx/exceptions.hxx" + +using namespace java::lang; +using namespace frysk::sys; + +ProcessIdentifier +DaemonFactory::daemon(jnixx::env env, Redirect redirect, Execute exec) { + volatile int pid = -1; + + // This is executed by the child with the parent blocked, the final + // process id ends up in PID. + errno = 0; + register int v = vfork (); + switch (v) { + case -1: + errnoException(env, errno, "vfork"); + case 0: + // vforked child + // ::fprintf (stderr, "%d is vfork child\n", getpid ()); + pid = fork (); + switch (pid) { + case -1: + // error handled by parent; look for pid<0. + _exit (0); + case 0: + // ::fprintf (stderr, "%d child calls redirect\n", getpid ()); + redirect.reopen(env); + // ::fprintf (stderr, "%d child calls execute\n", getpid ()); + exec.execute(env); + _exit (0); + default: + _exit (0); + } + default: + // Reach here after the vfork child - or middle player - exits. + // Save the fork's error status. + int fork_errno = errno; + // Consume the middle players wait. + errno = 0; + pid_t wpid = ::waitpid (v, NULL, 0); + int wait_errno = errno; + // Did the fork succeed? If not throw its status. + if (pid < 0) + errnoException(env, fork_errno, "fork"); + // Did the wait succeed? If not throw its status. + if (wpid < 0) + errnoException(env, wait_errno, "waitpid", "process %d", v); + // printf ("v %d pid %d\n", v, pid); + redirect.close(env); + return ProcessIdentifierFactory::create(env, pid); + } +} hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-05-20 19:20 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080520192044.1408.qmail@sourceware.org \ --to=cagney@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).