public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Implement jni/AuditLibs, jni/StatelessFile, and jni/Uname. Date: Thu, 22 May 2008 15:25:00 -0000 [thread overview] Message-ID: <20080522152556.19831.qmail@sourceware.org> (raw) The branch, master has been updated via 05dbb548a7214062166c1cd7eb447c3ef7ca88d1 (commit) from 6b1edf3fd6d721ae29fd96c54c70bde00920430c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 05dbb548a7214062166c1cd7eb447c3ef7ca88d1 Author: Andrew Cagney <cagney@redhat.com> Date: Thu May 22 11:23:47 2008 -0400 Implement jni/AuditLibs, jni/StatelessFile, and jni/Uname. frysk-sys/ChangeLog 2008-05-22 Andrew Cagney <cagney@redhat.com> * Makefile.am (JniRunner): Add TestStatelessFile and TestPseudoTerminal. frysk-sys/frysk/sys/ChangeLog 2008-05-22 Andrew Cagney <cagney@redhat.com> * jni/Poll.cxx: Implement. * jni/AuditLibs.cxx: Implement. * jni/StatelessFile.cxx: Implement. * jni/Uname.cxx: Implement. frysk-sys/jnixx/ChangeLog 2008-05-22 Andrew Cagney <cagney@redhat.com> * exceptions.cxx (errnoException): Use vasprintf, not snprintf. (runtimeException): Simplify exception checks; throw RuntimeException. * print.cxx (vajprintf): Ditto. ----------------------------------------------------------------------- Summary of changes: frysk-sys/ChangeLog | 5 ++ frysk-sys/Makefile.am | 2 + frysk-sys/frysk/sys/ChangeLog | 7 +++ frysk-sys/frysk/sys/jni/AuditLibs.cxx | 27 ++++++++++- frysk-sys/frysk/sys/jni/StatelessFile.cxx | 75 +++++++++++++++++++++++++++- frysk-sys/frysk/sys/jni/Uname.cxx | 27 ++++++++++- frysk-sys/jnixx/ChangeLog | 6 ++ frysk-sys/jnixx/exceptions.cxx | 47 +++++++++++------- frysk-sys/jnixx/print.cxx | 7 ++- 9 files changed, 179 insertions(+), 24 deletions(-) First 500 lines of diff: diff --git a/frysk-sys/ChangeLog b/frysk-sys/ChangeLog index f2e5e9a..814a8e1 100644 --- a/frysk-sys/ChangeLog +++ b/frysk-sys/ChangeLog @@ -1,3 +1,8 @@ +2008-05-22 Andrew Cagney <cagney@redhat.com> + + * Makefile.am (JniRunner): Add TestStatelessFile and + TestPseudoTerminal. + 2008-05-21 Andrew Cagney <cagney@redhat.com> * Makefile.am (JniRunner): Add frysk.sys.termios. diff --git a/frysk-sys/Makefile.am b/frysk-sys/Makefile.am index d444764..e8ae3e6 100644 --- a/frysk-sys/Makefile.am +++ b/frysk-sys/Makefile.am @@ -100,8 +100,10 @@ JniRunner: | frysk-sys.jar libfrysk-sys-jni.so echo " frysk.sys.proc \\" >> $@.tmp echo " frysk.sys.termios \\" >> $@.tmp echo " frysk.sys.TestProcessIdentifier \\" >> $@.tmp + echo " frysk.sys.TestPseudoTerminal \\" >> $@.tmp echo " frysk.sys.TestSignal \\" >> $@.tmp echo " frysk.sys.TestSignalSet \\" >> $@.tmp + echo " frysk.sys.TestStatelessFile \\" >> $@.tmp echo " inua \\" >> $@.tmp echo " jnixx \\" >> $@.tmp echo " lib.stdcpp \\" >> $@.tmp diff --git a/frysk-sys/frysk/sys/ChangeLog b/frysk-sys/frysk/sys/ChangeLog index 2f3a67b..8bd46c2 100644 --- a/frysk-sys/frysk/sys/ChangeLog +++ b/frysk-sys/frysk/sys/ChangeLog @@ -1,3 +1,10 @@ +2008-05-22 Andrew Cagney <cagney@redhat.com> + + * jni/Poll.cxx: Implement. + * jni/AuditLibs.cxx: Implement. + * jni/StatelessFile.cxx: Implement. + * jni/Uname.cxx: Implement. + 2008-05-21 Andrew Cagney <cagney@redhat.com> * jni/Pipe.cxx: Implement. diff --git a/frysk-sys/frysk/sys/jni/AuditLibs.cxx b/frysk-sys/frysk/sys/jni/AuditLibs.cxx index b358932..9614942 100644 --- a/frysk-sys/frysk/sys/jni/AuditLibs.cxx +++ b/frysk-sys/frysk/sys/jni/AuditLibs.cxx @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2008, Red Hat Inc. +// Copyright 2005, 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,29 @@ // version and license this file solely under the GPL without // exception. +#include <stdlib.h> +#include <libaudit.h> +#include <malloc.h> + #include "jni.hxx" + +#include "jnixx/elements.hxx" + +using namespace java::lang; + +String +frysk::sys::AuditLibs::syscallToName(jnixx::env env, jint syscall, + jint machine) { + const char* syscall_name = audit_syscall_to_name(syscall, machine); + if(syscall_name == NULL){ + return String(env, NULL); + } + return String::NewStringUTF(env, syscall_name); +} + +jint +frysk::sys::AuditLibs::nameToSyscall(jnixx::env env, String name, + jint machine) { + StringChars syscall_name = StringChars(env, name); + return audit_name_to_syscall(syscall_name.elements(), machine); +} diff --git a/frysk-sys/frysk/sys/jni/StatelessFile.cxx b/frysk-sys/frysk/sys/jni/StatelessFile.cxx index b358932..6f49760 100644 --- a/frysk-sys/frysk/sys/jni/StatelessFile.cxx +++ b/frysk-sys/frysk/sys/jni/StatelessFile.cxx @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2008, Red Hat Inc. +// Copyright 2005, 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 @@ -10,11 +10,11 @@ // 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 FRYSK; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -// +// // In addition, as a special exception, Red Hat, Inc. gives You the // additional right to link the code of FRYSK with code not covered // under the GNU General Public License ("Non-GPL Code") and to @@ -37,4 +37,73 @@ // version and license this file solely under the GPL without // exception. +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + #include "jni.hxx" + +#include "jnixx/bounds.hxx" +#include "jnixx/exceptions.hxx" +#include "jnixx/elements.hxx" + +using namespace java::lang; + +jint +frysk::sys::StatelessFile::pread(jnixx::env env, jlong fileOffset, + jnixx::byteArray bytes, + jint start, jint length) { + verifyBounds(env, bytes, start, length); + + ArrayBytes unixPath = ArrayBytes(env, GetUnixPath(env)); + int fd = ::open((const char *)unixPath.elements(), O_RDONLY); + if (fd < 0) + errnoException(env, errno, "open", "filename %s", + (const char *)unixPath.elements()); + unixPath.release(); + + // XXX: 64-bit? + ArrayBytes buffer = ArrayBytes(env, bytes); + ssize_t rc = ::pread64 (fd, start + buffer.elements(), length, fileOffset); + if (rc < 0) { + int savedErrno = errno; + ::close (fd); + errnoException(env, savedErrno, "pread", "fd %d, count %d, offset %ld", + fd, (int) length, (long)fileOffset); + } + buffer.release(); + + ::close (fd); + return rc; +} + +jint +frysk::sys::StatelessFile::pwrite(jnixx::env env, jlong fileOffset, + jnixx::byteArray bytes, + jint start, jint length) { + verifyBounds (env, bytes, start, length); + + ArrayBytes unixPath = ArrayBytes(env, GetUnixPath(env)); + int fd = ::open((const char *)unixPath.elements(), O_WRONLY); + if (fd < 0) + errnoException(env, errno, "open", "filename %s", + (const char *)unixPath.elements()); + unixPath.release(); + + // XXX: 64-bit? + ArrayBytes buffer = ArrayBytes(env, bytes); + ssize_t rc = ::pwrite64 (fd, start + buffer.elements(), length, fileOffset); + if (rc < 0) { + int savedErrno = errno; + ::close (fd); + errnoException(env, savedErrno, "pwrite", "fd %d, count %d, offset %ld", + fd, (int) length, (long)fileOffset); + } + buffer.release(); + + ::close (fd); + return rc; +} diff --git a/frysk-sys/frysk/sys/jni/Uname.cxx b/frysk-sys/frysk/sys/jni/Uname.cxx index b358932..e1a4f3f 100644 --- a/frysk-sys/frysk/sys/jni/Uname.cxx +++ b/frysk-sys/frysk/sys/jni/Uname.cxx @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2008, Red Hat Inc. +// Copyright 2006, 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,29 @@ // version and license this file solely under the GPL without // exception. +#include <string.h> +#include <sys/utsname.h> + #include "jni.hxx" + +using namespace java::lang; + +frysk::sys::Uname +frysk::sys::Uname::get(jnixx::env env) { + struct utsname names; + Uname retval = Uname::New(env); + + (void)::uname(&names); + + retval.SetSysname(env, String::NewStringUTF(env, names.sysname)); + retval.SetNodename(env, String::NewStringUTF(env, names.nodename)); + retval.SetRelease(env, String::NewStringUTF(env, names.release)); + retval.SetVersion(env, String::NewStringUTF(env, names.version)); + retval.SetMachine(env, String::NewStringUTF(env, names.machine)); +#ifdef _GNU_SOURCE + retval.SetDomainname(env, String::NewStringUTF(env, names.domainname)); +#else + retval.SetDomainname(env, NULL); +#endif + return retval; +} diff --git a/frysk-sys/jnixx/ChangeLog b/frysk-sys/jnixx/ChangeLog index 3ae3c54..d94d3ed 100644 --- a/frysk-sys/jnixx/ChangeLog +++ b/frysk-sys/jnixx/ChangeLog @@ -1,3 +1,9 @@ +2008-05-22 Andrew Cagney <cagney@redhat.com> + + * exceptions.cxx (errnoException): Use vasprintf, not snprintf. + (runtimeException): Simplify exception checks; throw RuntimeException. + * print.cxx (vajprintf): Ditto. + 2008-05-21 Andrew Cagney <cagney@redhat.com> * JniBindings.java: Add == for Object. diff --git a/frysk-sys/jnixx/exceptions.cxx b/frysk-sys/jnixx/exceptions.cxx index 2531868..f02d8f9 100644 --- a/frysk-sys/jnixx/exceptions.cxx +++ b/frysk-sys/jnixx/exceptions.cxx @@ -48,6 +48,8 @@ #include "jnixx/exceptions.hxx" #include "jnixx/print.hxx" +using namespace java::lang; + static void throwErrno(::jnixx::env& env, int error, const char *fmt, ...) __attribute__((noreturn)); void @@ -55,6 +57,7 @@ throwErrno(::jnixx::env& env, int error, const char *fmt, ...) { va_list ap; va_start(ap, fmt); java::lang::String message = vajprintf(env, fmt, ap); + va_end(ap); switch (error) { #ifdef EBADF case EBADF: @@ -95,47 +98,55 @@ throwErrno(::jnixx::env& env, int error, const char *fmt, ...) { default: frysk::sys::Errno::New(env, error, message).Throw(env); } - va_end(ap); } void errnoException(::jnixx::env& env, int error, const char *prefix) { - // Hack; for moment just throw something. throwErrno(env, errno, "%s: %s", prefix, strerror(error)); } void errnoException(::jnixx::env& env, int error, const char *prefix, const char *fmt, ...) { + // Allocate a copy of the message. va_list ap; va_start(ap, fmt); - char message[256]; - if (::snprintf(message, sizeof(message), fmt, ap) < 0) { - errnoException(env, errno, "malloc"); + char *message = NULL; + if (::vasprintf(&message, fmt, ap) < 0) { + // If this fails things are pretty much stuffed. + int err = errno; + fprintf(stderr, "warning: vasprintf in errnoException failed (%s)\n", + ::strerror(err)); + RuntimeException::ThrowNew(env, "vasprintf in errnoException failed"); } - throwErrno(env, errno, "%s: %s (%s)", prefix, strerror(error), message); va_end(ap); + try { + throwErrno(env, errno, "%s: %s (%s)", prefix, strerror(error), message); + } catch (java::lang::Throwable e) { + // always executed. + ::free(message); + throw e; + } } void runtimeException(::jnixx::env& env, const char *fmt, ...) { - jclass cls = env.FindClass("java/lang/RuntimeException"); va_list ap; va_start(ap, fmt); - char *msg = NULL; - int status = ::vasprintf(&msg, fmt, ap); - va_end(ap); - if (status < 0) { - fprintf(stderr, "runtimeException: vasprintf failed: %s", - ::strerror(errno)); - env.ThrowNew(cls, "runtimeException: vasprintf failed"); + char *message = NULL; + if (::vasprintf(&message, fmt, ap) < 0) { + // If this fails things are pretty much stuffed. + int err = errno; + fprintf(stderr, "warning: vasprintf in runtimeException failed: %s", + ::strerror(err)); + RuntimeException::ThrowNew(env, "vasprintf in runtimeException failed"); } + va_end(ap); try { - env.ThrowNew(cls, msg); + RuntimeException::ThrowNew(env, message); } catch (java::lang::Throwable e) { - // XXX: Work around lack of finally by catchching, then - // re-throwing, the exception - ::free(msg); + // Always executed. + ::free(message); throw e; } } diff --git a/frysk-sys/jnixx/print.cxx b/frysk-sys/jnixx/print.cxx index b3e4f3b..7653f97 100644 --- a/frysk-sys/jnixx/print.cxx +++ b/frysk-sys/jnixx/print.cxx @@ -39,6 +39,7 @@ #include <stdlib.h> #include <errno.h> +#include <string.h> #include "jni.hxx" #include "jnixx/print.hxx" @@ -66,7 +67,11 @@ String vajprintf(::jnixx::env& env, const char *fmt, va_list ap) { char* message = NULL; if (::vasprintf(&message, fmt, ap) < 0) { - errnoException(env, errno, "vasprintf"); + // If this fails things are pretty much stuffed. + int err = errno; + fprintf(stderr, "warning: vasprintf in vajprintf failed (%s)\n", + ::strerror(err)); + RuntimeException::ThrowNew(env, "vasprintf in vajprintf failed"); } try { return String::NewStringUTF(env, message); hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-05-22 15:25 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=20080522152556.19831.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).