prometheus-client-mmap 0.7.0.beta45.9 → 0.7.0.beta45.10

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: 26cd3edd6cdca37f12302661dcc43f4ef1fa2426
4
- data.tar.gz: 572236f8217e968c1f2f229a8b4303e570ad838f
3
+ metadata.gz: 5be03b2cf017dc8f05006a950baed4584f438ea2
4
+ data.tar.gz: 8710f5d2514afc53a5bf38f0d5169c1b20f9b1cd
5
5
  SHA512:
6
- metadata.gz: a5b3f0d352da5227e3611bb246105f5a5f1e4f28addaa1ab99ed942e56a502b135b205e83e8fb55972337c851665ba396904821310ac1b3d1722d29ab4753110
7
- data.tar.gz: e0e9af3be98632d44649882878aa5d20349187010746b7dffa84586910a469ae46a2197f73d915d351c1112905c8152c93dfe9bb42fe94d222fdad24587ef3bb
6
+ metadata.gz: 43aff1c44ec220cec46f22fee1c0566dcfd9e147edeb6eae86b0671f26e7f0bb2fb4da003545df6a15d9a0361d7298168e1080f4169dc6ecbba39aa14cd49b3a
7
+ data.tar.gz: 43d52f9e8614382c930b856c538f4dfbd7e95b7753ecd9c5dd368cdb8512b60fd9e364994bdfbc8f7f404a73d377e2795f6f089c6ff6433584ab108402aef96f
@@ -226,12 +226,12 @@ VALUE mm_init(VALUE obj, VALUE fname) {
226
226
  }
227
227
 
228
228
  addr = mmap(0, size, pmode, vscope, fd, offset);
229
- close(fd);
230
229
 
231
230
  if (addr == MAP_FAILED || !addr) {
231
+ close(fd);
232
232
  rb_raise(rb_eArgError, "mmap failed (%d)", errno);
233
233
  }
234
-
234
+ i_mm->t->fd = fd;
235
235
  i_mm->t->addr = addr;
236
236
  i_mm->t->len = size;
237
237
  if (!init) {
@@ -28,6 +28,7 @@ typedef struct {
28
28
  int semid, shmid;
29
29
  size_t len, real;
30
30
  off_t offset;
31
+ int fd;
31
32
  char *path, *template;
32
33
  } mm_mmap;
33
34
 
@@ -36,13 +37,13 @@ typedef struct {
36
37
  mm_mmap *t;
37
38
  } mm_ipc;
38
39
 
39
- #define GET_MMAP(obj, i_mm, t_modify) \
40
- Data_Get_Struct(obj, mm_ipc, i_mm); \
41
- if (!i_mm->t->path || i_mm->t->addr == 0 || i_mm->t->addr == MAP_FAILED) { \
42
- rb_raise(rb_eIOError, "unmapped file"); \
43
- } \
44
- if ((t_modify & MM_MODIFY) && (i_mm->t->flag & MM_FROZEN)) { \
45
- rb_error_frozen("mmap"); \
40
+ #define GET_MMAP(obj, i_mm, t_modify) \
41
+ Data_Get_Struct(obj, mm_ipc, i_mm); \
42
+ if (!i_mm->t->path || i_mm->t->fd == 0 || i_mm->t->addr == NULL || i_mm->t->addr == MAP_FAILED) { \
43
+ rb_raise(rb_eIOError, "unmapped file"); \
44
+ } \
45
+ if ((t_modify & MM_MODIFY) && (i_mm->t->flag & MM_FROZEN)) { \
46
+ rb_error_frozen("mmap"); \
46
47
  }
47
48
 
48
49
  VALUE mm_s_alloc(VALUE obj);
@@ -12,24 +12,32 @@
12
12
 
13
13
  #include "utils.h"
14
14
 
15
- static int open_and_extend_file(mm_ipc *i_mm, size_t len, int *fd_p) {
16
- int fd;
15
+ static int close_file(mm_ipc *i_mm) {
16
+ int rv = close(i_mm->t->fd);
17
+ i_mm->t->fd = 0;
18
+ return rv;
19
+ }
20
+
21
+ static int open_and_extend_file(mm_ipc *i_mm, size_t len) {
22
+ if (i_mm->t->fd == 0) {
23
+ int fd = i_mm->t->fd;
17
24
 
18
- if ((fd = open(i_mm->t->path, i_mm->t->smode)) == -1) {
19
- return with_exception(rb_eArgError, "Can't open %s", i_mm->t->path);
25
+ if ((fd = open(i_mm->t->path, i_mm->t->smode)) == -1) {
26
+ return with_exception(rb_eArgError, "%s: Can't open %s", __FILE__, i_mm->t->path);
27
+ }
28
+ i_mm->t->fd = fd;
20
29
  }
21
30
 
22
- if (lseek(fd, len - i_mm->t->len - 1, SEEK_END) == -1) {
23
- close(fd);
31
+ if (lseek(i_mm->t->fd, len - i_mm->t->len - 1, SEEK_END) == -1) {
32
+ close_file(i_mm);
24
33
  return with_exception(rb_eIOError, "Can't lseek %zu", len - i_mm->t->len - 1);
25
34
  }
26
35
 
27
- if (write(fd, "\000", 1) != 1) {
28
- close(fd);
36
+ if (write(i_mm->t->fd, "\000", 1) != 1) {
37
+ close_file(i_mm);
29
38
  return with_exception(rb_eIOError, "Can't extend %s", i_mm->t->path);
30
39
  }
31
40
 
32
- *fd_p = fd;
33
41
  return SUCCESS;
34
42
  }
35
43
 
@@ -46,8 +54,8 @@ static int perform_munmap(mm_ipc *i_mm) {
46
54
  return SUCCESS;
47
55
  }
48
56
 
49
- static int perform_mmap(mm_ipc *i_mm, int fd, size_t len) {
50
- MMAP_RETTYPE addr = mmap(0, len, i_mm->t->pmode, i_mm->t->vscope, fd, i_mm->t->offset);
57
+ static int perform_mmap(mm_ipc *i_mm, size_t len) {
58
+ MMAP_RETTYPE addr = mmap(0, len, i_mm->t->pmode, i_mm->t->vscope, i_mm->t->fd, i_mm->t->offset);
51
59
 
52
60
  if (addr == MAP_FAILED) {
53
61
  return with_exception(rb_eArgError, "mmap failed");
@@ -69,21 +77,15 @@ static int expand(mm_ipc *i_mm, size_t len) {
69
77
  return FAILURE;
70
78
  }
71
79
 
72
- int fd = 0;
73
-
74
- if (!open_and_extend_file(i_mm, len, &fd)) {
80
+ if (!open_and_extend_file(i_mm, len)) {
75
81
  return FAILURE;
76
82
  }
77
83
 
78
- if (!perform_mmap(i_mm, fd, len)) {
79
- close(fd);
84
+ if (!perform_mmap(i_mm, len)) {
85
+ close_file(i_mm);
80
86
  return FAILURE;
81
87
  }
82
88
 
83
- if (close(fd) == -1) {
84
- return with_exception(rb_eArgError, "Can't close %s", i_mm->t->path);
85
- }
86
-
87
89
  if ((i_mm->t->flag & MM_LOCK) && mlock(i_mm->t->addr, len) == -1) {
88
90
  return with_exception(rb_eArgError, "mlock(%d)", errno);
89
91
  }
Binary file
@@ -1,5 +1,5 @@
1
1
  module Prometheus
2
2
  module Client
3
- VERSION = '0.7.0.beta45.9'.freeze
3
+ VERSION = '0.7.0.beta45.10'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-client-mmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.beta45.9
4
+ version: 0.7.0.beta45.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schmidt