posix 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1 +1,20 @@
1
1
  Fills some of the gaps in the stdlibrary
2
+
3
+ A small example of this is:
4
+
5
+ ```ruby
6
+ require 'posix'
7
+
8
+ mask = Posix::Sigset.new
9
+ mask << "INT"
10
+ mask << "USR2"
11
+
12
+ puts Posix.sigprocmask(Posix::SIG_SETMASK, mask)
13
+
14
+ Posix.execve("/bin/bash", ["/bin/bash"], {"rawr" => "Thing"})
15
+ ```
16
+
17
+ The notable differences are:
18
+ * The environment has becomes the child environmemt, instead of being merged into the current environment awkwardly.
19
+ * `sigprocmask` is a thing you can actually call.
20
+ * `Posix.execve` doesn't reset sigprocmask before exec'ing, unless `Process#.spawn`, `Kernel#exec` and friends.
data/ext/posix/posix.c CHANGED
@@ -60,6 +60,19 @@ VALUE posix_sigprocmask(VALUE self, VALUE _how, VALUE _set) {
60
60
  }
61
61
  }
62
62
 
63
+ VALUE posix_dup(VALUE self, VALUE _filedes) {
64
+ int filedes = FIX2INT(_filedes);
65
+
66
+ return INT2FIX(dup(filedes));
67
+ }
68
+
69
+ VALUE posix_dup2(VALUE self, VALUE _filedes, VALUE _filedes2) {
70
+ int filedes = FIX2INT(_filedes);
71
+ int filedes2 = FIX2INT(_filedes2);
72
+
73
+ return INT2FIX(dup2(filedes, filedes2));
74
+ }
75
+
63
76
  /* Export an argv that does sane, reasonable things instead of doing weird
64
77
  * shit.
65
78
  *
@@ -86,25 +99,16 @@ VALUE posix_execve(VALUE self, VALUE _binary, VALUE _argv, VALUE _envp) {
86
99
  /* Construct our environment. Note that this totally ignores the precedent
87
100
  * set by Process#spawn, Kernel#exec and fiends */
88
101
 
89
- fprintf(stderr, "Allocatin' some memory\n");
90
102
  char **envp = malloc(sizeof(char**)*RHASH(_envp)->ntbl->num_entries + 1);
91
- fprintf(stderr, "Allocated some memory\n");
92
- i = 0;
93
103
 
94
104
  keys = rb_hash_keys(_envp);
95
105
  for (i = 0; i < RARRAY_LEN(keys); i++) {
96
106
  akey = RARRAY_PTR(keys)[i];
97
107
  envk = rb_hash_aref(_envp, akey);
98
- fprintf(stderr, "printin' some stringz");
99
108
  asprintf(&envp[i], "%s=%s", StringValuePtr(akey), StringValuePtr(envk));
100
- fprintf(stderr, "printed some stringz");
101
109
  envp[i+1] = NULL; /* Ensure that we're null terminated */
102
110
  }
103
- fprintf(stderr,"%s", envp[0]);
104
111
 
105
- binary = "/bin/bash";
106
- char *__envp[] = { NULL };
107
- char *__argv[] = { "/bin/bash", NULL };
108
112
  execve(binary, argv, envp);
109
113
  fprintf(stderr, "Error: %s", strerror(errno));
110
114
  }
@@ -113,14 +117,18 @@ void Init_posix(void) {
113
117
  /* Create ::Posix */
114
118
  VALUE klass = rb_define_class("Posix", rb_cObject);
115
119
 
116
- /* Define constants */
120
+ /* Define constants for sigprocmask */
117
121
  rb_define_const(klass, "SIG_BLOCK", INT2FIX(RB_POSIX_SIG_BLOCK));
118
122
  rb_define_const(klass, "SIG_UNBLOCK", INT2FIX(RB_POSIX_SIG_UNBLOCK));
119
123
  rb_define_const(klass, "SIG_SETMASK", INT2FIX(RB_POSIX_SIG_SETMASK));
120
124
 
121
- /* Method binding */
125
+ /* Method binding for sigprocmask */
122
126
  rb_define_singleton_method(klass, "sigprocmask", posix_sigprocmask, 2);
123
127
  rb_define_singleton_method(klass, "execve", posix_execve, 3);
128
+
129
+ /* Method binding for dup */
130
+ rb_define_singleton_method(klass, "dup", posix_dup, 1);
131
+ rb_define_singleton_method(klass, "dup2", posix_dup2, 2);
124
132
  }
125
133
 
126
134
 
@@ -142,5 +150,3 @@ rb_hash_keys(VALUE hash)
142
150
 
143
151
  return ary;
144
152
  }
145
-
146
-
data/posix.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "posix"
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
  s.authors = ["Richo Healey"]
7
7
  s.email = ["richo@psych0tik.net"]
8
8
  s.homepage = "http://github.com/richo/ruby-posix"
@@ -0,0 +1,9 @@
1
+ require 'posix'
2
+
3
+ mask = Posix::Sigset.new
4
+ mask << "INT"
5
+ mask << "USR2"
6
+
7
+ puts Posix.sigprocmask(Posix::SIG_SETMASK, mask)
8
+
9
+ Posix.execve("/bin/bash", ["/bin/bash"], {"rawr" => "Thing"})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -25,6 +25,7 @@ files:
25
25
  - lib/posix.rb
26
26
  - lib/posix/sigset.rb
27
27
  - posix.gemspec
28
+ - test/sigprocmask.rb
28
29
  homepage: http://github.com/richo/ruby-posix
29
30
  licenses: []
30
31
  post_install_message:
@@ -49,4 +50,5 @@ rubygems_version: 1.8.24
49
50
  signing_key:
50
51
  specification_version: 3
51
52
  summary: Wrappers for some posix functions that I couldn't find in the stdlib
52
- test_files: []
53
+ test_files:
54
+ - test/sigprocmask.rb