mincore 0.0.9.3.pre.5 → 0.0.9.3.pre.6
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Rakefile +5 -2
- data/lib/mincore.rb +24 -20
- data/mincore.gemspec +1 -1
- data/test/mincore_test.rb +10 -9
- data/test/test_helper.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04072cb8e6a47e2caf76f1bfec55c96d61dab4c4
|
4
|
+
data.tar.gz: 91a65f908ef21bd83006065033f4c862bec9bd62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11aeb4e96b4b84e22dd7d2b0d29d2c9027aedbf09890ce6387e1d64c664850b2322674de660640a7a18187cbf299829d7346394ae2dda42e8cfc67e2a45ba516
|
7
|
+
data.tar.gz: 38d74cee2c2d15e0aba22ad0be2bdd426cfc2cb424b1ea90367986c5753bf3d59c04f5063123abb1b1f6eacb6be4a426864b0d21ef7f29d35e6b3a712e80c3d0
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ WORKDIR='writable_tmp_dir'
|
|
5
5
|
|
6
6
|
CLEAN.include("#{WORKDIR}/*")
|
7
7
|
|
8
|
-
Rake::TestTask.new(:
|
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
|
|
data/lib/mincore.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
58
|
-
|
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
|
-
|
129
|
-
|
131
|
+
errno = EBADF;
|
132
|
+
exiterr("not a regular file");
|
130
133
|
}
|
131
134
|
|
132
135
|
for(i = 0; i < count; i++) {
|
133
|
-
|
134
|
-
|
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
|
data/mincore.gemspec
CHANGED
data/test/mincore_test.rb
CHANGED
@@ -41,15 +41,7 @@ class TestableFile
|
|
41
41
|
# alias_method :fill, :cli_fill
|
42
42
|
|
43
43
|
def read(pages=@size_kb)
|
44
|
-
if
|
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
|
data/test/test_helper.rb
CHANGED