mincore 0.0.9.3.pre.5 → 0.0.9.3.pre.6

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: a0c5eec397c85e7a6ae6dcd06f6573a2d38b7a41
4
- data.tar.gz: 97ab5400c69017429c46a386ec608e8994ae1c71
3
+ metadata.gz: 04072cb8e6a47e2caf76f1bfec55c96d61dab4c4
4
+ data.tar.gz: 91a65f908ef21bd83006065033f4c862bec9bd62
5
5
  SHA512:
6
- metadata.gz: 893e4f55fdcfda9003080cf12fe14ceb0d56d2e8e7c46d8ecf24fb2519403c2a462375aae639e9e51dd05963186f837f611e2993dfee4afdab48c3ab4174253a
7
- data.tar.gz: 646240810002f8cf79a3dba7b37a6c720a1392b35d14bdb40ffcd031f0f681d3f025de8c9afc69a4a599bb20ddaaef2c4e0a95eef7b67717b0703c05416a4f60
6
+ metadata.gz: 11aeb4e96b4b84e22dd7d2b0d29d2c9027aedbf09890ce6387e1d64c664850b2322674de660640a7a18187cbf299829d7346394ae2dda42e8cfc67e2a45ba516
7
+ data.tar.gz: 38d74cee2c2d15e0aba22ad0be2bdd426cfc2cb424b1ea90367986c5753bf3d59c04f5063123abb1b1f6eacb6be4a426864b0d21ef7f29d35e6b3a712e80c3d0
@@ -2,7 +2,7 @@ language: ruby
2
2
 
3
3
  before_script: ./bin/ci/before_build.sh
4
4
 
5
- script: "bundle exec rake test"
5
+ script: "bundle exec rake ci_test"
6
6
 
7
7
  rvm:
8
8
  - 1.9.3
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ WORKDIR='writable_tmp_dir'
5
5
 
6
6
  CLEAN.include("#{WORKDIR}/*")
7
7
 
8
- Rake::TestTask.new(:test) do |t|
8
+ Rake::TestTask.new(:ci_test) do |t|
9
9
  t.libs << 'lib'
10
10
  t.libs << 'test'
11
11
  t.pattern = 'test/**/*_test.rb'
@@ -13,7 +13,10 @@ Rake::TestTask.new(:test) do |t|
13
13
  end
14
14
 
15
15
 
16
-
16
+ task :test do
17
+ ENV["COVERALLS"]="DISABLE"
18
+ Rake::Task["ci_test"].invoke
19
+ end
17
20
 
18
21
  task :default => :test
19
22
 
@@ -12,10 +12,11 @@ class File
12
12
  builder.include("<fcntl.h>")
13
13
  builder.include("<unistd.h>")
14
14
  builder.include("<sys/mman.h>")
15
- # builder.include("<fcntl.h>")
15
+ builder.include("<errno.h>")
16
16
  # builder.include("<fcntl.h>")
17
17
 
18
- builder.prefix("#define exiterr(s) { perror(s); exit(-1); }")
18
+ # builder.prefix("#define exiterr(s) { perror(s); exit(-1); }")
19
+ builder.prefix("#define exiterr(s) { rb_sys_fail(s); }")
19
20
  end
20
21
 
21
22
  inline do |builder|
@@ -47,15 +48,19 @@ static VALUE _mincore(char *filename) {
47
48
  PAGESIZE = getpagesize();
48
49
 
49
50
  fd = open(filename, O_RDONLY);
50
- // fprintf(stderr, "running fstat() on %s", filename);
51
51
 
52
+ if ( fd == -1 ) {
53
+ exiterr("can't open file");
54
+ }
52
55
 
53
56
 
54
- if(fstat(fd, &st) == -1)
55
- exiterr("fstat");
57
+ if(fstat(fd, &st) == -1) { // untested path
58
+ exiterr("fstat failed");
59
+ }
60
+
56
61
  if(!S_ISREG(st.st_mode)) {
57
- fprintf(stderr, "%s: S_ISREG: not a regular file", filename);
58
- return EXIT_FAILURE;
62
+ errno = EBADF;
63
+ exiterr("not a regular file");
59
64
  }
60
65
 
61
66
  if ( st.st_size == 0 ) {
@@ -68,13 +73,14 @@ static VALUE _mincore(char *filename) {
68
73
  pages = (st.st_size + PAGESIZE - 1) / PAGESIZE;
69
74
  pageinfo = calloc(sizeof(*pageinfo), pages);
70
75
 
71
- if(!pageinfo) {
76
+ if(!pageinfo) { // untested path
72
77
  exiterr("calloc");
73
78
  }
74
79
 
75
80
  file = mmap(NULL, st.st_size, PROT_NONE, MAP_SHARED, fd, 0);
76
81
 
77
- if(file == MAP_FAILED) {
82
+ if(file == MAP_FAILED) { // untested path
83
+ free(pageinfo);
78
84
  exiterr("mmap");
79
85
  }
80
86
 
@@ -88,16 +94,13 @@ static VALUE _mincore(char *filename) {
88
94
 
89
95
  pageinfo_arr = rb_ary_new2(pages);
90
96
  for(i=0; i<pages; i++) {
91
- VALUE status = ((pageinfo[i] & 1)?Qtrue:Qfalse);
97
+ VALUE status = ((pageinfo[i] & 1) ? Qtrue : Qfalse);
92
98
  rb_ary_push(pageinfo_arr, status);
93
99
  }
94
100
 
95
101
 
96
102
  rb_ary_push(val, pageinfo_arr);
97
103
 
98
- // val = (long long) st.st_size;
99
- // fprintf (stderr, "val=%d\\n", val);
100
-
101
104
  munmap(file, st.st_size);
102
105
  free(pageinfo);
103
106
 
@@ -117,21 +120,22 @@ static VALUE _cachedel(char *filename, int count) {
117
120
  fd = open(filename, O_RDONLY);
118
121
 
119
122
  if(fd == -1) {
120
- exiterr("open");
123
+ exiterr("can't open file");
121
124
  }
122
125
 
123
126
  if(fstat(fd, &st) == -1) {
124
- exiterr("fstat");
127
+ exiterr("fstat failed");
125
128
  }
126
129
 
127
130
  if(!S_ISREG(st.st_mode)) {
128
- fprintf(stderr, "%s: S_ISREG: not a regular file", filename);
129
- ret = -1;
131
+ errno = EBADF;
132
+ exiterr("not a regular file");
130
133
  }
131
134
 
132
135
  for(i = 0; i < count; i++) {
133
- if(posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) == -1) {
134
- exiterr("posix_fadvise");
136
+ ret = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) ;
137
+ if(ret) {
138
+ exiterr("posix_fadvise failed");
135
139
  }
136
140
  }
137
141
 
@@ -160,7 +164,7 @@ C_CODE
160
164
  #
161
165
  # @param filename [String] file name
162
166
  # @param count [Int] times `posix_fadvise()` will be run
163
- # @return [Int] execution status
167
+ # @return [Int] execution status of the last `posix_fadvise()` call
164
168
  def self.cachedel(filename, count=1)
165
169
  self._cachedel(filename, count)
166
170
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mincore'
3
- s.version = '0.0.9.3.pre.5'
3
+ s.version = '0.0.9.3.pre.6'
4
4
  s.date = '2013-11-19'
5
5
 
6
6
  s.homepage = 'http://github.com/noushi/ruby-mincore'
@@ -41,15 +41,7 @@ class TestableFile
41
41
  # alias_method :fill, :cli_fill
42
42
 
43
43
  def read(pages=@size_kb)
44
- if pages == @size_kb
45
- `cat #{@name} >/dev/null`
46
- else
47
- 4.times do
48
- File.open(@name, "r").each do |line|
49
- line
50
- end
51
- end
52
- end
44
+ `dd if=#{@name} of=/dev/null bs=#{File.PAGESIZE} count=#{pages}`
53
45
  end
54
46
 
55
47
  def delete
@@ -88,6 +80,15 @@ class MincoreTest < Test::Unit::TestCase
88
80
  _generic_mincore_test 40, :delete => true
89
81
  end
90
82
 
83
+ def test_mincore_devnull
84
+ assert_raise(Errno::EBADF) { File.mincore("/dev/null") }
85
+ end
86
+
87
+ # don't run this as root, mincore() will succeed!
88
+ def test_mincore_etcshadow
89
+ assert_raise(Errno::EACCES) { File.mincore("/etc/shadow") }
90
+ end
91
+
91
92
  def test_cachedel_empty_file
92
93
  _generic_cachedel_test 0
93
94
  end
@@ -28,8 +28,8 @@ class Array
28
28
  end
29
29
 
30
30
 
31
-
32
- require 'coveralls'
33
- Coveralls.wear!
34
-
31
+ unless ENV["COVERALLS"] == "DISABLE"
32
+ require 'coveralls'
33
+ Coveralls.wear!
34
+ end
35
35
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mincore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9.3.pre.5
4
+ version: 0.0.9.3.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reda NOUSHI