prometheus-client-mmap 0.9.1.pre.rc.1 → 0.9.1.pre.rc.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -166,6 +166,7 @@ VALUE mm_s_alloc(VALUE obj) {
166
166
  res = Data_Make_Struct(obj, mm_ipc, 0, mm_free, i_mm);
167
167
  i_mm->t = ALLOC_N(mm_mmap, 1);
168
168
  MEMZERO(i_mm->t, mm_mmap, 1);
169
+ i_mm->t->fd = -1;
169
170
  return res;
170
171
  }
171
172
 
@@ -25,11 +25,10 @@ typedef struct {
25
25
  int smode, pmode, vscope;
26
26
  int advice, flag;
27
27
  VALUE key;
28
- int semid, shmid;
29
28
  size_t len, real;
30
29
  off_t offset;
31
30
  int fd;
32
- char *path, *template;
31
+ char *path;
33
32
  } mm_mmap;
34
33
 
35
34
  typedef struct {
@@ -37,13 +36,13 @@ typedef struct {
37
36
  mm_mmap *t;
38
37
  } mm_ipc;
39
38
 
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"); \
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->fd < 0 || i_mm->t->addr == NULL || 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"); \
47
46
  }
48
47
 
49
48
  VALUE mm_s_alloc(VALUE obj);
@@ -1,20 +1,22 @@
1
+ #include <errno.h>
1
2
  #include <ruby.h>
2
3
 
3
4
  #include "utils.h"
4
5
 
5
- static void va_save_exception(VALUE exception, const char *fmt, va_list args) {
6
- VALUE message = rb_vsprintf(fmt, args);
7
-
6
+ static void rb_save_exception(VALUE exception, VALUE message) {
8
7
  VALUE current_thread = rb_thread_current();
8
+
9
9
  rb_thread_local_aset(current_thread, rb_intern("prometheus_last_exception"), exception);
10
10
  rb_thread_local_aset(current_thread, rb_intern("prometheus_last_exception_message"), message);
11
11
  }
12
-
12
+ /* @deprecated - use with_exception ignoring return value */
13
13
  void save_exception(VALUE exception, const char *fmt, ...) {
14
14
  va_list args;
15
15
 
16
16
  va_start(args, fmt);
17
- va_save_exception(exception, fmt, args);
17
+ VALUE message = rb_vsprintf(fmt, args);
18
+
19
+ rb_save_exception(exception, message);
18
20
  va_end(args);
19
21
  }
20
22
 
@@ -22,7 +24,22 @@ int with_exception(VALUE exception, const char *fmt, ...) {
22
24
  va_list args;
23
25
 
24
26
  va_start(args, fmt);
25
- va_save_exception(exception, fmt, args);
27
+ VALUE message = rb_vsprintf(fmt, args);
28
+
29
+ rb_save_exception(exception, message);
30
+ va_end(args);
31
+
32
+ return FAILURE;
33
+ }
34
+
35
+ int with_exception_errno(VALUE exception, const char *fmt, ...) {
36
+ va_list args;
37
+
38
+ va_start(args, fmt);
39
+ VALUE message = rb_vsprintf(fmt, args);
40
+ rb_str_catf(message, " (%s)", strerror(errno));
41
+
42
+ rb_save_exception(exception, message);
26
43
  va_end(args);
27
44
 
28
45
  return FAILURE;
@@ -16,5 +16,6 @@
16
16
  NORETURN(void raise_last_exception());
17
17
  void save_exception(VALUE exception, const char *fmt, ...);
18
18
  int with_exception(VALUE exception, const char *fmt, ...);
19
+ int with_exception_errno(VALUE exception, const char *fmt, ...);
19
20
 
20
21
  #endif
@@ -14,28 +14,29 @@
14
14
 
15
15
  static void close_file(mm_ipc *i_mm) {
16
16
  close(i_mm->t->fd);
17
- i_mm->t->fd = 0;
17
+ i_mm->t->fd = -1;
18
18
  }
19
19
 
20
20
  static int open_and_extend_file(mm_ipc *i_mm, size_t len) {
21
- if (i_mm->t->fd == 0) {
22
- int fd = i_mm->t->fd;
21
+ if (i_mm->t->fd < 0) {
22
+ int fd;
23
23
 
24
24
  if ((fd = open(i_mm->t->path, i_mm->t->smode)) == -1) {
25
- return with_exception(rb_eArgError, "%s: Can't open %s", __FILE__, i_mm->t->path);
25
+ return with_exception_errno(rb_eArgError, "%s: Can't open %s", __FILE__, i_mm->t->path);
26
26
  }
27
27
  i_mm->t->fd = fd;
28
28
  }
29
29
 
30
- if (lseek(i_mm->t->fd, len - i_mm->t->len - 1, SEEK_END) == -1) {
30
+ if (lseek(i_mm->t->fd, len - 1, SEEK_SET) == -1) {
31
31
  close_file(i_mm);
32
- return with_exception(rb_eIOError, "Can't lseek %zu", len - i_mm->t->len - 1);
32
+ return with_exception_errno(rb_eIOError, "Can't lseek %zu", len - 1);
33
33
  }
34
34
 
35
35
  if (write(i_mm->t->fd, "\000", 1) != 1) {
36
36
  close_file(i_mm);
37
- return with_exception(rb_eIOError, "Can't extend %s", i_mm->t->path);
37
+ return with_exception_errno(rb_eIOError, "Can't extend %s", i_mm->t->path);
38
38
  }
39
+ i_mm->t->len = len;
39
40
 
40
41
  return SUCCESS;
41
42
  }
@@ -43,7 +44,7 @@ static int open_and_extend_file(mm_ipc *i_mm, size_t len) {
43
44
  static int perform_munmap(mm_ipc *i_mm) {
44
45
  if (i_mm->t->addr != NULL && munmap(i_mm->t->addr, i_mm->t->len)) {
45
46
  i_mm->t->addr = NULL;
46
- return with_exception(rb_eArgError, "munmap failed");
47
+ return with_exception_errno(rb_eArgError, "munmap failed");
47
48
  }
48
49
 
49
50
  i_mm->t->addr = NULL;
@@ -57,7 +58,7 @@ static int perform_mmap(mm_ipc *i_mm, size_t len) {
57
58
  MMAP_RETTYPE addr = mmap(0, len, i_mm->t->pmode, i_mm->t->vscope, i_mm->t->fd, i_mm->t->offset);
58
59
 
59
60
  if (addr == MAP_FAILED) {
60
- return with_exception(rb_eArgError, "mmap failed");
61
+ return with_exception_errno(rb_eArgError, "mmap failed");
61
62
  }
62
63
 
63
64
  i_mm->t->addr = addr;
@@ -86,7 +87,7 @@ static int expand(mm_ipc *i_mm, size_t len) {
86
87
  }
87
88
 
88
89
  if ((i_mm->t->flag & MM_LOCK) && mlock(i_mm->t->addr, len) == -1) {
89
- return with_exception(rb_eArgError, "mlock(%d)", errno);
90
+ return with_exception_errno(rb_eArgError, "mlock(%d)", errno);
90
91
  }
91
92
 
92
93
  return SUCCESS;
Binary file
@@ -1,5 +1,5 @@
1
1
  module Prometheus
2
2
  module Client
3
- VERSION = '0.9.1.pre.rc.1'.freeze
3
+ VERSION = '0.9.1.pre.rc.2'.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.9.1.pre.rc.1
4
+ version: 0.9.1.pre.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schmidt