public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Prototype jni/DaemonFactory.
@ 2008-05-20 19:20 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-05-20 19:20 UTC (permalink / raw)
  To: frysk-cvs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-05-20 19:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-20 19:20 [SCM] master: Prototype jni/DaemonFactory cagney

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).