# HG changeset patch # User Mahlon E. Smith # Date 1230194146 0 # Node ID e908d309e7ec1a36b00d8d19126733291e01d2fb # Parent b1426511fb64f58e035a70845883bc8fe46cac2c * It compiles! * Removed additional leftover link parser stuff. * Removed unused memory allocate/free stuff until I discuss with my cohort. It may be back... it may be left over from linkparser too. ;) * list() works, but cores. Not sure why yet. Really, list() should be renamed to something sensible, and return instantiated BSD::Jail objects to attach() to or get additional info on. * Ruby C bindings are way, way fun. Reminds me how little C I can remember with one project a year :) diff -r b1426511fb64 -r e908d309e7ec ext/bsdjail.c --- a/ext/bsdjail.c Thu Dec 25 07:33:20 2008 +0000 +++ b/ext/bsdjail.c Thu Dec 25 08:35:46 2008 +0000 @@ -1,6 +1,9 @@ /* + * * bsdjail.c - Ruby jparallel * $Id$ + * + * vim: set nosta noet ts=4 sw=4: * * Authors: * * Michael Granger @@ -15,15 +18,7 @@ * */ -#include -#include - -#include -#include -#include -#include -#include - +#include "bsdjail.h" VALUE rbjail_mBSD; VALUE rbjail_cBSDJail; @@ -38,93 +33,6 @@ }; */ -/* - * Allocation function - */ -static jail * -rbjail_jail_alloc() -{ - jail *ptr = ALLOC( jail ); - - ptr->version = 0; - ptr->path = NULL; - ptr->hostname = NULL; - ptr->ip_number = 0; - - debugMsg(( "Initialized a jail pointer <%p>", ptr )); - return ptr; -} - - -/* - * GC Free function - */ -static void -rbjail_jail_gc_free( ptr ) - jail *ptr; -{ - if ( ptr ) { - ptr->path = NULL; - ptr->hostname = NULL; - xfree( ptr ); - } - - else { - debugMsg(( "Not freeing an uninitialized rlink_SENTENCE" )); - } -} - - -/* - * Object validity checker. Returns the data pointer. - */ -static rlink_SENTENCE * -check_sentence( self ) - VALUE self; -{ - debugMsg(( "Checking a LinkParser::Sentence object (%d).", self )); - Check_Type( self, T_DATA ); - - if ( !IsSentence(self) ) { - rb_raise( rb_eTypeError, "wrong argument type %s (expected LinkParser::Sentence)", - rb_class2name(CLASS_OF( self )) ); - } - - return DATA_PTR( self ); -} - - -/* - * Fetch the data pointer and check it for sanity. - */ -static rlink_SENTENCE * -get_sentence( self ) - VALUE self; -{ - rlink_SENTENCE *ptr = check_sentence( self ); - - debugMsg(( "Fetching a Sentence (%p).", ptr )); - if ( !ptr ) - rb_raise( rb_eRuntimeError, "uninitialized Sentence" ); - - return ptr; -} - - -/* - * Publicly-usable sentence-fetcher - */ -rlink_SENTENCE * -rlink_get_sentence( self ) - VALUE self; -{ - return get_sentence( self ); -} - - - - - static void rbjail_do_jail_attach( int jid ) @@ -137,12 +45,12 @@ static VALUE rbjail_attach_block( int jid ) { - int pid; + int pid; - rb_secure(2); + rb_secure(2); - fflush(stdout); - fflush(stderr); + fflush(stdout); + fflush(stderr); switch ( pid = fork() ) { case 0: @@ -170,65 +78,65 @@ { VALUE jidnum, rval; int jid; - + rb_scan_args( argc, argv, "1", &jidnum ); jid = NUM2INT( jidnum ); if ( rb_block_given_p() ) { rval = rbjail_attach_block( jid ); } - + else { rbjail_do_jail_attach( jid ); rval = Qtrue; } - + return rval; } static VALUE - rbjail_list( VALUE self ) +rbjail_list( VALUE self ) { - struct kinfo_prison *sxp, *xp; + struct xprison *xp; struct in_addr in; size_t i, len; - if (sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1) - rb_sys_fail("sysctlbyname(): jail.list"); - - xp = ALLOCA_N( kinfo_prison, 1 ); + /* Get the size of the xprison and allocate memory to it. */ + if ( sysctlbyname("security.jail.list", NULL, &len, NULL, 0) == -1 ) + rb_sys_fail("sysctlbyname(): security.jail.list"); + xp = ALLOCA_N( struct xprison, 1 ); - if (sysctlbyname("jail.list", xp, &len, NULL, 0) == -1) { - rb_sys_fail("sysctlbyname(): jail.list"); + /* Get and sanity check the current prison list */ + if ( sysctlbyname("security.jail.list", xp, &len, NULL, 0) == -1 ) { + rb_sys_fail("sysctlbyname(): security.jail.list"); } - - if (len < sizeof(*xp) || len % sizeof(*xp) || - xp->pr_version != KINFO_PRISON_VERSION) + if ( len < sizeof(*xp) || len % sizeof(*xp) || + xp->pr_version != XPRISON_VERSION ) rb_fatal("Kernel and userland out of sync"); len /= sizeof(*xp); printf(" JID IP Address Hostname Path\n"); - for (i = 0; i < len; i++) { - in.s_addr = ntohl(xp->pr_ip); + for ( i = 0; i < len; i++ ) { + in.s_addr = ntohl( xp->pr_ip ); printf("%6d %-15.15s %-29.29s %.74s\n", - xp->pr_id, inet_ntoa(in), xp->pr_host, xp->pr_path); + xp->pr_id, inet_ntoa(in), xp->pr_host, xp->pr_path); xp++; } - free(sxp); - exit(0); - + return self; } void Init_bsdjail( void ) { rbjail_mBSD = rb_define_module( "BSD" ); - rbjail_cBSDJail = rb_define_class_under( rbjail_mBSD, "Jail" ); + rbjail_cBSDJail = rb_define_class_under( rbjail_mBSD, "Jail", rb_cObject ); rb_define_singleton_method( rbjail_cBSDJail, "list", rbjail_list, 0 ); - rb_define_alloc_function( rbjail_cBSDJail, ) - + + /* + rb_define_alloc_function( rbjail_cBSDJail, ); + rb_define_method( rbjail_cBSDJail, "attach", rbjail_attach, -1 ); - + */ } diff -r b1426511fb64 -r e908d309e7ec ext/bsdjail.h --- a/ext/bsdjail.h Thu Dec 25 07:33:20 2008 +0000 +++ b/ext/bsdjail.h Thu Dec 25 08:35:46 2008 +0000 @@ -1,5 +1,8 @@ /* * bsdjail.h - Header for the bsdjail extension + * + * vim: set nosta noet ts=4 sw=4: + * * $Id$ * * Authors: @@ -39,15 +42,17 @@ #ifndef _BSDJAIL_H_ #define _BSDJAIL_H_ +#include +#include /* For rb_dbl2big() */ #include #include #include #include #include - -#include -#include /* For rb_dbl2big() */ +#include +#include +#include /* Debugging functions/macros */