kill_process 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0eee211d248e931543803767cb234519d0ae612a
4
- data.tar.gz: 4d3d7928b586be170c5e00bedc8f4b2b3e4f838d
3
+ metadata.gz: 78d656160b9d6418bed23e50ad351e6623d2707d
4
+ data.tar.gz: e6b27120a7ea1f5536ddfed99a08d912eae14505
5
5
  SHA512:
6
- metadata.gz: 91595b1ae889a83224f0cec0fff72c7f0c8677d01199e82bb07e33387b01fcec1ebd61f265f0ee84dfcae96e8e977ac620cde12e1408dda5a76661271f61a004
7
- data.tar.gz: a036e1eafbc7179123c2fe9dddcea80907a6fe05955784a3d35acc812a81d0ee1c4939bb0c7e1bfd2c63f50426a2b50925b0c575655976f2d30a7e63d43f0231
6
+ metadata.gz: cc2bcc06c8bc517d054672dce90ba7c2c0213d4d59b12ec333e01b1e1a760636409fd0ab9db3531ff6bf9a4878e29c8446c61e42670ba650f0916feeb553296f
7
+ data.tar.gz: e715680a2811e3afde35bfcf831c31c9f72c0259f8b214b802b64365e26706058bb552b5fc2160f3dccc5686732ab7a0c18bea74caf4346733c2f971d6138af4
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # KillProcess
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kill_process`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
data/ext/extconf.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'mkmf'
2
2
 
3
- abort "missing rt library" unless have_library('rt')
3
+ warn "WARNING: missing rt library" unless have_library('rt')
4
4
  create_makefile 'kill_process_native'
@@ -4,38 +4,44 @@
4
4
  #include <time.h>
5
5
  #include <pthread.h>
6
6
 
7
- VALUE rb_posix_timer_set(VALUE self, VALUE seconds) {
8
- struct sigevent sev;
9
- timer_t tidlist;
10
- int return_val;
11
- struct timespec zero_time;
12
- struct timespec timeout_value;
13
- struct itimerspec timer_spec;
14
- double dbl_seconds = NUM2DBL(seconds);
15
-
16
- zero_time.tv_sec = 0;
17
- zero_time.tv_nsec = 0;
18
-
19
- timeout_value.tv_sec = (int)floor(dbl_seconds);
20
- timeout_value.tv_nsec = 0;
21
-
22
- timer_spec.it_interval = zero_time;
23
- timer_spec.it_value = timeout_value;
24
-
25
- sev.sigev_notify = SIGEV_SIGNAL;
26
- sev.sigev_signo = 9; //SIGKILL
27
-
28
- return_val = timer_create(CLOCK_REALTIME, &sev, &tidlist);
29
- if (return_val != 0) {
30
- rb_sys_fail(0);
7
+ #if _POSIX_C_SOURCE >= 199309L
8
+ VALUE rb_posix_timer_set(VALUE self, VALUE seconds) {
9
+ struct sigevent sev;
10
+ timer_t tidlist;
11
+ int return_val;
12
+ struct timespec zero_time;
13
+ struct timespec timeout_value;
14
+ struct itimerspec timer_spec;
15
+ double dbl_seconds = NUM2DBL(seconds);
16
+
17
+ zero_time.tv_sec = 0;
18
+ zero_time.tv_nsec = 0;
19
+
20
+ timeout_value.tv_sec = (int)floor(dbl_seconds);
21
+ timeout_value.tv_nsec = 0;
22
+
23
+ timer_spec.it_interval = zero_time;
24
+ timer_spec.it_value = timeout_value;
25
+
26
+ sev.sigev_notify = SIGEV_SIGNAL;
27
+ sev.sigev_signo = 9; //SIGKILL
28
+
29
+ return_val = timer_create(CLOCK_REALTIME, &sev, &tidlist);
30
+ if (return_val != 0) {
31
+ rb_sys_fail(0);
32
+ }
33
+ return_val = timer_settime(tidlist, 0, &timer_spec, NULL);
34
+ if (return_val != 0) {
35
+ rb_sys_fail(0);
36
+ }
37
+
38
+ return Qtrue;
31
39
  }
32
- return_val = timer_settime(tidlist, 0, &timer_spec, NULL);
33
- if (return_val != 0) {
34
- rb_sys_fail(0);
40
+ #else
41
+ VALUE rb_posix_timer_set(VALUE self, VALUE seconds) {
42
+ return Qfalse;
35
43
  }
36
-
37
- return Qtrue;
38
- }
44
+ #endif
39
45
 
40
46
  void Init_kill_process_native(void) {
41
47
  VALUE kill_process_module = rb_const_get(rb_cObject, rb_intern("KillProcess"));
data/lib/kill_process.rb CHANGED
@@ -4,7 +4,10 @@ module KillProcess
4
4
  require_relative './kill_process_native'
5
5
 
6
6
  def self.after(seconds)
7
- posix_timer_set(seconds)
7
+ success = posix_timer_set(seconds)
8
+ if !success
9
+ Kernel.warn "WARNING: KillProcess#after will not do anything because your system does not support POSIX advanced realtime timers"
10
+ end
8
11
  end
9
12
 
10
13
  end
@@ -1,3 +1,3 @@
1
1
  module KillProcess
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kill_process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Green