more diagnostics
[god.git] / ideas / execve / execve.c
blob4439807f5c2a1f5989892a1ce829c65103602847
1 #include "ruby.h"
3 static VALUE mKernel;
4 void Init_execve();
5 VALUE method_execve(VALUE self, VALUE cmd, VALUE env);
7 void Init_execve() {
8 mKernel = rb_const_get(rb_cObject, rb_intern("Kernel"));
9 rb_define_method(mKernel, "execve", method_execve, 2);
12 VALUE method_execve(VALUE self, VALUE r_cmd, VALUE r_env) {
13 char *shell = (char *)dln_find_exe("sh", 0);
14 char *arg[] = { "sh", "-c", StringValuePtr(r_cmd), (char *)0 };
16 struct RArray *env_array;
17 env_array = RARRAY(r_env);
18 char *env[env_array->len + 1];
20 int i;
21 for(i = 0; i < env_array->len; i++) {
22 env[i] = StringValuePtr(env_array->ptr[i]);
25 env[env_array->len] = (char *)0;
27 execve(shell, arg, env);
28 return Qnil;