ext/bsdjail.c
author Michael Granger <ged@FaerieMUD.org>
Thu, 16 Oct 2008 02:43:08 +0000
changeset 2 0c24586f579a
parent 0 92d00ff32c56
child 5 41a1542b3b10
permissions -rw-r--r--
Checkpoint commit.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     1
/*
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     2
 *  dict.c - Ruby LinkParser - Dict Class
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     3
 *  $Id$
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     4
 *  
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     5
 *  Authors:
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     6
 *    * Michael Granger <ged@FaerieMUD.org>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     7
 *  
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     8
 *  Copyright (c) 2006 The FaerieMUD Consortium.
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
     9
 *  
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    10
 *  This work is licensed under the Creative Commons Attribution License. To
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    11
 *  view a copy of this license, visit
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    12
 *  http://creativecommons.org/licenses/by/1.0 or send a letter to Creative
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    13
 *  Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    14
 *  
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    15
 */
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    16
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    17
#include <ruby.h>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    18
#include <intern.h>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    19
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    20
#include <stdio.h>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    21
#include <sys/param.h>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    22
#include <sys/jail.h>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    23
#include <sys/types.h>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    24
#include <unistd.h>
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    25
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    26
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    27
VALUE rbjail_mBSD;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    28
VALUE rbjail_cBSDJail;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    29
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    30
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    31
/*
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    32
 *  Debug logging function
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    33
 */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    34
void
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    35
#ifdef HAVE_STDARG_PROTOTYPES
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    36
rlink_debug(const char *fmt, ...)
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    37
#else
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    38
rlink_debug( const char *fmt, va_dcl )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    39
#endif
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    40
{
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    41
	char buf[BUFSIZ], buf2[BUFSIZ];
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    42
	va_list	args;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    43
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    44
	if ( !RTEST(ruby_debug) ) return;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    45
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    46
	snprintf( buf, BUFSIZ, "Jail Debug>>> %s", fmt );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    47
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    48
	va_init_list( args, fmt );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    49
	vsnprintf( buf2, BUFSIZ, buf, args );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    50
	fputs( buf2, stderr );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    51
	fputs( "\n", stderr );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    52
	fflush( stderr );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    53
	va_end( args );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    54
}
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    55
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    56
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    57
/*
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    58
struct jail {
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    59
	u_int32_t       version;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    60
	char            *path;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    61
	char            *hostname;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    62
	u_int32_t       ip_number;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    63
};
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    64
*/
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    65
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    66
/*
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    67
 * Allocation function
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    68
 */
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    69
static jail *
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    70
rbjail_jail_alloc() {
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    71
	jail *ptr = ALLOC( jail );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    72
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    73
	ptr->version	= 0;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    74
	ptr->path		= NULL;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    75
	ptr->hostname	= NULL;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    76
	ptr->ip_number	= 0;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    77
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    78
	debugMsg(( "Initialized a jail pointer <%p>", ptr ));
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    79
	return ptr;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    80
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    81
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    82
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    83
/*
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    84
 * GC Free function
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    85
 */
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    86
static void
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    87
rbjail_gc_free( jail *ptr ) {
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    88
	if ( ptr ) {
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    89
		if ( ptr->path ) xfree( ptr->path );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    90
		if ( ptr->hostname ) xfree( ptr->hostname );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    91
		
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    92
		ptr->path		= NULL;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    93
		ptr->hostname	= NULL;
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    94
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    95
		xfree( ptr );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    96
	}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    97
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
    98
	else {
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
    99
		debugMsg(( "Not freeing an uninitialized jail" ));
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   100
	}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   101
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   102
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   103
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   104
/*
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   105
 * Object validity checker. Returns the data pointer.
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   106
 */
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   107
static jail *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   108
rbjail_check_jail( VALUE self ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   109
	debugMsg(( "Checking a BSD::Jail object (%d).", self ));
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   110
	Check_Type( self, T_DATA );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   111
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   112
    if ( !rb_obj_is_kind_of(self, rbjail_cBSDJail) ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   113
		rb_raise( rb_eTypeError, "wrong argument type %s (expected BSD::Jail)",
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   114
				  rb_class2name(CLASS_OF( self )) );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   115
    }
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   116
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   117
	return DATA_PTR( self );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   118
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   119
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   120
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   121
/*
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   122
 * Fetch the data pointer and check it for sanity.
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   123
 */
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   124
static jail *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   125
rbjail_get_jail( VALUE self ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   126
	jail *ptr = check_sentence( self );
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   127
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   128
	debugMsg(( "Fetching a Jail (%p).", ptr ));
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   129
	if ( !ptr )
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   130
		rb_raise( rb_eRuntimeError, "uninitialized Sentence" );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   131
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   132
	return ptr;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   133
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   134
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   135
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   136
/* --------------------------------------------------------------
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   137
 * Jail utility functions
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   138
 * -------------------------------------------------------------- */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   139
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   140
/*
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   141
 * Try to jail_attach() to the specified +jid+, raising an exception if it fails.
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   142
 */
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   143
static void
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   144
rbjail_do_jail_attach( int jid )
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   145
{
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   146
	if ( jail_attach(jid) == -1 )
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   147
		rb_sys_fail( "jail_attach" );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   148
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   149
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   150
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   151
/* 
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   152
 * Fork + Block function for rbjail_attach(). Mostly stolen from Ruby's process.c.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   153
 */
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   154
static VALUE
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   155
rbjail_attach_block( int jid )
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   156
{
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   157
    int pid;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   158
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   159
    rb_secure(2);
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   160
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   161
    fflush( stdout );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   162
    fflush( stderr );
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   163
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   164
	switch ( pid = fork() ) {
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   165
		case 0:
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   166
			rb_thread_atfork();
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   167
			if ( rb_block_given_p() ) {
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   168
				int status;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   169
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   170
				rbjail_do_jail_attach( jid );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   171
				rb_protect( rb_yield, Qundef, &status );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   172
				ruby_stop( status );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   173
			}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   174
			return Qnil;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   175
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   176
		case -1:
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   177
			rb_sys_fail( "fork(2)" );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   178
			return Qnil;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   179
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   180
		default:
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   181
			return INT2FIX( pid );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   182
	}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   183
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   184
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   185
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   186
/* --------------------------------------------------------------
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   187
 * Class methods
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   188
 * -------------------------------------------------------------- */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   189
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   190
/*
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   191
 *  call-seq:
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   192
 *     BSD::Jail.allocate   -> bsdjail
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   193
 *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   194
 *  Allocate a new BSD::Jail object.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   195
 *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   196
 */
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   197
static VALUE
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   198
rbjail_jail_s_allocate( VALUE klass ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   199
	return Data_Wrap_Struct( klass, 0, rbjail_gc_free, 0 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   200
}
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   201
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   202
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   203
/*
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   204
 *  call-seq:
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   205
 *     BSD::Jail.list   -> array
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   206
 *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   207
 *  Return an Array of all the running jails on the host.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   208
 *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   209
 */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   210
static VALUE
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   211
rbjail_jail_s_list( VALUE klass ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   212
	VALUE rval = rb_ary_new();
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   213
	struct xprison *xp;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   214
	struct in_addr in;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   215
	size_t i, len;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   216
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   217
	if ( sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1 )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   218
		rb_sys_fail( "sysctlbyname(): jail.list" );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   219
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   220
	xp = ALLOCA_N( xprison, 1 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   221
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   222
	if ( sysctlbyname("jail.list", xp, &len, NULL, 0) == -1 ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   223
		rb_sys_fail( "sysctlbyname(): jail.list" );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   224
	}
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   225
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   226
	if ( len < sizeof(*xp) || len % sizeof(*xp) ||
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   227
		xp->pr_version != KINFO_PRISON_VERSION )
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   228
		rb_fatal( "Kernel and userland out of sync" );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   229
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   230
	len /= sizeof( *xp );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   231
	for ( i = 0; i < len; i++ ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   232
		VALUE jail, args[3];
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   233
		
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   234
		/* Hostname */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   235
		args[0] = rb_str_new2( xp->pr_host );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   236
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   237
		/* IP */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   238
		in.s_addr = ntohl( xp->pr_ip );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   239
		args[1] = rb_str_new2( inet_ntoa(in) );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   240
		
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   241
		/* Path */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   242
		args[2] = rb_str_new2( xp->pr_path );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   243
		
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   244
		jail = rb_class_new_instance( 3, args, klass );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   245
		rb_ary_push( rval, jail );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   246
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   247
		xp++;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   248
	}
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   249
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   250
	return rval;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   251
}
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   252
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   253
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   254
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   255
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   256
/* --------------------------------------------------------------
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   257
 * Instance methods
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   258
 * -------------------------------------------------------------- */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   259
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   260
/*
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   261
 *  call-seq:
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   262
 *     BSD::Jail.new( hostname, ip, path )           -> new_jail
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   263
 *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   264
 *  Create a new jail for the given +hostname+, +ip+, and +path+.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   265
 */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   266
static VALUE
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   267
rbjail_jail_initialize( VALUE self, VALUE hostname, VALUE ip, VALUE path ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   268
	if ( !rbjail_check_jail(self) ) {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   269
		struct jail *ptr = rbjail_jail_alloc();
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   270
		char *pathstr = NULL, *hostnamestr = NULL;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   271
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   272
		Check_Type( hostname, T_STRING );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   273
		Check_Type( ip, T_STRING );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   274
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   275
		pathstr = ALLOC_N( char, RSTRING(path)->len );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   276
		strncpy( pathstr, RSTRING(path)->ptr, RSTRING(path)->len );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   277
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   278
		hostnamestr = ALLOC_N( char, RSTRING(hostname)->len );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   279
		strncpy( hostnamestr, RSTRING(hostname)->ptr, RSTRING(hostname)->len );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   280
		
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   281
		/*
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   282
		struct jail {
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   283
			u_int32_t       version;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   284
			char            *path;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   285
			char            *hostname;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   286
			u_int32_t       ip_number;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   287
		};
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   288
		*/
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   289
		ptr->version = 0;   /* Per the manpage's recommendation */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   290
		ptr->ip_number = inet_addr( StringValuePtr(ip) );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   291
		ptr->path = path;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   292
		ptr->hostname = hostname;
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   293
	}
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   294
}
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   295
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   296
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   297
/*
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   298
 *  call-seq:
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   299
 *     jail.attach             -> true or false
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   300
 *     jail.attach { block }   -> pid
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   301
 *
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   302
 *  Attach to the given jail. In the non-block form, attach the current process to the
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   303
 *  jail and return +true+ if it succeeds. This is a one-way operation, and requires root
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   304
 *  privileges.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   305
 *  
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   306
 *  In the block form, the process will be forked, and the block will be attached to the jail and 
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   307
 *  run by the child. The parent process will receive the process ID of the child.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   308
 */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   309
static VALUE
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   310
rbjail_attach( int argc, VALUE *argv, VALUE self ) {
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   311
	VALUE jidnum, rval;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   312
	int jid;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   313
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   314
	rb_scan_args( argc, argv, "1", &jidnum );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   315
	jid = NUM2INT( jidnum );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   316
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   317
	if ( rb_block_given_p() ) {
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   318
		rval = rbjail_attach_block( jid );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   319
	}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   320
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   321
	else {
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   322
		rbjail_do_jail_attach( jid );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   323
		rval = Qtrue;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   324
	}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   325
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   326
	return rval;
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   327
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   328
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   329
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   330
/*
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   331
 * I can't remember how the hell you document a class, but that will go here.
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   332
 */
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   333
void
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   334
Init_bsdjail( void ) {
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   335
	rbjail_mBSD = rb_define_module( "BSD" );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   336
	rbjail_cBSDJail = rb_define_class_under( rbjail_mBSD, "Jail" );
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   337
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   338
	/* Class methods */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   339
	rb_define_alloc_function( rbjail_cBSDJail, rbjail_jail_s_allocate );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   340
	rb_define_singleton_method( rbjail_cBSDJail, "jail", rbjail_jail_s_jail, 0 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   341
	rb_define_singleton_method( rbjail_cBSDJail, "list", rbjail_jail_s_list, 0 );
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   342
	
2
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   343
	/* Instance methods */
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   344
	rb_define_method( rbjail_cBSDJail, "initialize", rbjail_jail_initialize, 3 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   345
	rb_define_method( rbjail_cBSDJail, "attach", rbjail_jail_attach, -1 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   346
	rb_define_method( rbjail_cBSDJail, "hostname", rbjail_jail_hostname, 0 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   347
	rb_define_method( rbjail_cBSDJail, "path", rbjail_jail_path, 0 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   348
	rb_define_method( rbjail_cBSDJail, "ip", rbjail_jail_ip, 0 );
0c24586f579a Checkpoint commit.
Michael Granger <ged@FaerieMUD.org>
parents: 0
diff changeset
   349
	rb_define_method( rbjail_cBSDJail, "jid", rbjail_jail_jid, 0 );
0
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   350
	
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   351
}
92d00ff32c56 Initial checkin
Michael Granger <ged@FaerieMUD.org>
parents:
diff changeset
   352