| 1 |
|
| /* |
| 2 |
|
| * Copyright (C) 2014 Bastian Friedrich |
| 3 |
|
| * <bastian.friedrich@collax.com> / <bastian@friedrich.link> |
| 4 |
|
| */ |
| 5 |
|
| #include "EXTERN.h" |
| 6 |
|
| #include "perl.h" |
| 7 |
|
| #include "XSUB.h" |
| 8 |
|
| #include <pwd.h> |
| 9 |
|
| #include <unistd.h> |
| 10 |
|
| #include <sys/fanotify.h> |
| 11 |
|
| |
| 12 |
|
| #include "const-c.inc" |
| 13 |
|
| |
| 14 |
|
| /* |
| 15 |
|
| ******************************************************************************* |
| 16 |
|
| * Code documentation for perl methods and functions can be found in the |
| 17 |
|
| * module's pod |
| 18 |
|
| ******************************************************************************* |
| 19 |
|
| */ |
| 20 |
|
| |
| 21 |
|
| #define PERLCLASS_NOTGRP "Linux::Fanotify::FanotifyGroup" |
| 22 |
|
| #define PERLCLASS_EVENT "Linux::Fanotify::Event" |
| 23 |
|
| |
| 24 |
|
| /* |
| 25 |
|
| * We don't want to expose functionality to write one event's fd to a |
| 26 |
|
| * notification group where it did not originate. fanotify_bundle |
| 27 |
|
| * is the event metadata, plus its originating notification group |
| 28 |
|
| */ |
| 29 |
|
| |
| 30 |
|
| struct fanotify_bundle { |
| 31 |
|
| struct fanotify_event_metadata metadata; |
| 32 |
|
| int fd; /* Notification group fd */ |
| 33 |
|
| unsigned short int needs_response; |
| 34 |
|
| }; |
| 35 |
|
| |
| 36 |
|
| /* |
| 37 |
|
| * Convert a perl SV for a notification group to a file descriptor |
| 38 |
|
| */ |
| 39 |
|
| int |
| 40 |
0 |
| notgrp2fd(SV *notgrp, int *dst) { |
| 41 |
|
| SV *sv; |
| 42 |
|
| |
| 43 |
0 |
▶ | if (!SvROK(notgrp)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(notgrp)) { |
0 |
0 |
0 |
|
| 44 |
|
| /* No RV */ |
| 45 |
0 |
| return 0; |
| 46 |
|
| } |
| 47 |
0 |
▶ | if (!sv_isobject(notgrp) || !sv_isa(notgrp, PERLCLASS_NOTGRP)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(notgrp) || !sv_isa(notgrp, PERLCLASS_NOTGRP)) { |
0 |
0 |
0 |
| if (!sv_isobject(notgrp) || !sv_isa(notgrp, PERLCLASS_NOTGRP)) { |
0 |
0 |
0 |
|
| 48 |
|
| /* No notification group obj */ |
| 49 |
0 |
| return 0; |
| 50 |
|
| } |
| 51 |
|
| |
| 52 |
0 |
| sv = SvRV(notgrp); |
| 53 |
|
| |
| 54 |
0 |
▶ | if (!SvIOK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvIOK(sv)) { |
0 |
0 |
0 |
|
| 55 |
|
| /* No int */ |
| 56 |
0 |
| return 0; |
| 57 |
|
| } |
| 58 |
|
| |
| 59 |
0 |
| *dst = SvIV(sv); |
| 60 |
|
| |
| 61 |
0 |
| return 1; |
| 62 |
|
| } |
| 63 |
|
| |
| 64 |
|
| /* |
| 65 |
|
| * Convert a perl SV for a fanotify_bundle (metadata plus fanotify group fd) to |
| 66 |
|
| * a fanotify_bundle structure |
| 67 |
|
| */ |
| 68 |
|
| struct fanotify_bundle * |
| 69 |
0 |
| event2bundle(SV *event) { |
| 70 |
|
| SV *deref; |
| 71 |
|
| |
| 72 |
0 |
▶ | if (!SvROK(event)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(event)) { |
0 |
0 |
0 |
|
| 73 |
|
| /* No RV */ |
| 74 |
0 |
| return NULL; |
| 75 |
|
| } |
| 76 |
0 |
▶ | if (!sv_isobject(event) || !sv_isa(event, PERLCLASS_EVENT)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(event) || !sv_isa(event, PERLCLASS_EVENT)) { |
0 |
0 |
0 |
| if (!sv_isobject(event) || !sv_isa(event, PERLCLASS_EVENT)) { |
0 |
0 |
0 |
|
| 77 |
|
| /* No notification group obj */ |
| 78 |
0 |
| return NULL; |
| 79 |
|
| } |
| 80 |
|
| |
| 81 |
0 |
| deref = SvRV(event); |
| 82 |
|
| |
| 83 |
0 |
▶ | if (!deref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!deref) { |
0 |
0 |
0 |
|
| 84 |
0 |
| return NULL; |
| 85 |
|
| } |
| 86 |
|
| |
| 87 |
0 |
| return (struct fanotify_bundle *)SvPV_nolen(deref); |
| 88 |
|
| |
| 89 |
|
| } |
| 90 |
|
| |
| 91 |
|
| /* |
| 92 |
|
| * Convert a notification event bundle to a string. |
| 93 |
|
| * Intended for debugging purposes only. |
| 94 |
|
| */ |
| 95 |
|
| char * |
| 96 |
0 |
| event2str(const struct fanotify_bundle *bundle, char *buf, int len) { |
| 97 |
|
| |
| 98 |
0 |
| const struct fanotify_event_metadata *event = &(bundle->metadata); |
| 99 |
|
| |
| 100 |
0 |
| char *fmt = "event at %p is: event_len = %d, vers = %d, reserved = %d, meta_len = %d, mask = %lld, fd = %d, pid = %d (fanotify group fd %d)"; |
| 101 |
|
| |
| 102 |
0 |
| if (snprintf(buf, len, fmt, |
| 103 |
0 |
▶ | event, event->event_len, event->vers, event->reserved, event->metadata_len, event->mask, event->fd, event->pid, bundle->fd) >= len) { |
Branch: 1 branch
| Branch | True | False | Total |
| event, event->event_len, event->vers, event->reserved, event->metadata_len, event->mask, event->fd, event->pid, bundle->fd) >= len) { |
0 |
0 |
0 |
|
| 104 |
0 |
| buf[len-1] = 0; |
| 105 |
|
| } |
| 106 |
|
| |
| 107 |
0 |
| return buf; |
| 108 |
|
| } |
| 109 |
|
| |
| 110 |
|
| /* |
| 111 |
|
| * Print an event's contents on the screen |
| 112 |
|
| */ |
| 113 |
|
| void |
| 114 |
0 |
| dumpEvent(const struct fanotify_bundle *bundle) { |
| 115 |
|
| char buf[256]; |
| 116 |
|
| |
| 117 |
0 |
| event2str(bundle, buf, sizeof(buf)); |
| 118 |
0 |
| printf("%s\n", buf); |
| 119 |
0 |
| } |
| 120 |
|
| |
| 121 |
|
| int |
| 122 |
0 |
| _event_write_response(SV *event, int response) { |
| 123 |
|
| struct fanotify_bundle *bundle; |
| 124 |
|
| struct fanotify_response rsp; |
| 125 |
|
| int fd; |
| 126 |
|
| int ret; |
| 127 |
|
| |
| 128 |
0 |
▶ | if (!(bundle = event2bundle(event))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(event))) { |
0 |
0 |
0 |
|
| 129 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 130 |
|
| } |
| 131 |
|
| |
| 132 |
0 |
▶ | if (!bundle->needs_response) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!bundle->needs_response) { |
0 |
0 |
0 |
|
| 133 |
0 |
| Perl_croak(aTHX_ "Event already responded to or non-respondable event"); |
| 134 |
|
| } |
| 135 |
|
| |
| 136 |
|
| /* only ALLOW and DENY are available/sensible responses */ |
| 137 |
0 |
▶ | if ((response != FAN_ALLOW) && (response != FAN_DENY)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((response != FAN_ALLOW) && (response != FAN_DENY)) { |
0 |
0 |
0 |
| if ((response != FAN_ALLOW) && (response != FAN_DENY)) { |
0 |
0 |
0 |
|
| 138 |
0 |
| Perl_croak(aTHX_ "Response is neither FAN_ALLOW nor FAN_DENY; refusing to write invalid response"); |
| 139 |
|
| } |
| 140 |
|
| |
| 141 |
0 |
| fd = bundle->fd; |
| 142 |
|
| |
| 143 |
0 |
| rsp.fd = bundle->metadata.fd; |
| 144 |
0 |
| rsp.response = response; |
| 145 |
|
| |
| 146 |
0 |
| ret = write(fd, &rsp, sizeof(struct fanotify_response)); |
| 147 |
|
| |
| 148 |
0 |
▶ | if (ret >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret >= 0) { |
0 |
0 |
0 |
|
| 149 |
0 |
| bundle->needs_response = 0; |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
0 |
| return ret; |
| 153 |
|
| } |
| 154 |
|
| |
| 155 |
|
| int |
| 156 |
0 |
| _event_close(SV *self) { |
| 157 |
|
| struct fanotify_bundle *bundle; |
| 158 |
|
| int ret; |
| 159 |
|
| SV *sv_default_response; |
| 160 |
0 |
| int default_response = FAN_DENY; |
| 161 |
|
| |
| 162 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 163 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 164 |
|
| } |
| 165 |
|
| |
| 166 |
0 |
▶ | if ((sv_default_response = get_sv("Linux::Fanotify::default_response", 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_default_response = get_sv("Linux::Fanotify::default_response", 0))) { |
0 |
0 |
0 |
|
| 167 |
0 |
| default_response = SvIV(sv_default_response); |
| 168 |
0 |
▶ | if (default_response == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (default_response == -1) { |
0 |
0 |
0 |
|
| 169 |
0 |
| default_response = FAN_DENY; |
| 170 |
|
| } |
| 171 |
|
| } |
| 172 |
|
| |
| 173 |
0 |
▶ | if (bundle->needs_response) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bundle->needs_response) { |
0 |
0 |
0 |
|
| 174 |
0 |
▶ | if (default_response) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (default_response) { |
0 |
0 |
0 |
|
| 175 |
0 |
| _event_write_response(self, default_response); |
| 176 |
|
| } |
| 177 |
|
| } |
| 178 |
|
| |
| 179 |
0 |
▶ | if (bundle->metadata.fd > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bundle->metadata.fd > 0) { |
0 |
0 |
0 |
|
| 180 |
0 |
| ret = close(bundle->metadata.fd); |
| 181 |
0 |
▶ | if (ret == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == 0) { |
0 |
0 |
0 |
|
| 182 |
0 |
| bundle->metadata.fd = -1; |
| 183 |
|
| } |
| 184 |
|
| } else { |
| 185 |
0 |
| errno = EBADF; |
| 186 |
0 |
| ret = -1; |
| 187 |
|
| } |
| 188 |
0 |
| return ret; |
| 189 |
|
| } |
| 190 |
|
| |
| 191 |
|
| /* |
| 192 |
|
| ******************************************************************************* |
| 193 |
|
| * Main package: Linux::Fanotify |
| 194 |
|
| */ |
| 195 |
|
| MODULE = Linux::Fanotify PACKAGE = Linux::Fanotify |
| 196 |
|
| PROTOTYPES: ENABLE |
| 197 |
|
| |
| 198 |
|
| INCLUDE: const-xs.inc |
| 199 |
|
| |
| 200 |
|
| # |
| 201 |
|
| # |
| 202 |
|
| # |
| 203 |
|
| SV * |
| 204 |
|
| fanotify_init(flags, event_f_flags) |
| 205 |
|
| unsigned int flags |
| 206 |
|
| unsigned int event_f_flags |
| 207 |
|
| INIT: |
| 208 |
|
| int fd; |
| 209 |
|
| SV *notgrp; |
| 210 |
|
| CODE: |
| 211 |
0 |
| fd = fanotify_init(flags, event_f_flags); |
| 212 |
|
| |
| 213 |
0 |
▶ | if (fd == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd == -1) { |
0 |
0 |
0 |
|
| 214 |
0 |
| XSRETURN_UNDEF; |
| 215 |
|
| } |
| 216 |
|
| |
| 217 |
0 |
| notgrp = newSV(0); |
| 218 |
|
| |
| 219 |
0 |
| sv_setref_iv(notgrp, PERLCLASS_NOTGRP, fd); |
| 220 |
|
| |
| 221 |
0 |
| SvREADONLY_on(SvRV(notgrp)); |
| 222 |
|
| |
| 223 |
0 |
| RETVAL = notgrp; |
| 224 |
|
| OUTPUT: |
| 225 |
|
| RETVAL |
| 226 |
|
| |
| 227 |
|
| # |
| 228 |
|
| # |
| 229 |
|
| # |
| 230 |
|
| int |
| 231 |
|
| fanotify_mark(notgrp, flags, mask = 0, dirfd = 0, pathname = NULL) |
| 232 |
|
| SV *notgrp |
| 233 |
|
| unsigned int flags |
| 234 |
|
| uint64_t mask |
| 235 |
|
| int dirfd |
| 236 |
|
| const char *pathname |
| 237 |
|
| INIT: |
| 238 |
|
| int ret; |
| 239 |
0 |
| int fd = -1; |
| 240 |
|
| CODE: |
| 241 |
0 |
▶ | if (!notgrp2fd(notgrp, &fd)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!notgrp2fd(notgrp, &fd)) { |
0 |
0 |
0 |
|
| 242 |
0 |
| Perl_croak(aTHX_ "Invalid fanotify_fd"); |
| 243 |
|
| } else { |
| 244 |
0 |
| ret = fanotify_mark(fd, flags, mask, dirfd, pathname); |
| 245 |
|
| |
| 246 |
0 |
▶ | if (ret == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == -1) { |
0 |
0 |
0 |
|
| 247 |
0 |
| XSRETURN_UNDEF; |
| 248 |
|
| } |
| 249 |
|
| } |
| 250 |
0 |
▶ | RETVAL = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = 1; |
0 |
0 |
0 |
|
| 251 |
|
| OUTPUT: |
| 252 |
|
| RETVAL |
| 253 |
|
| |
| 254 |
|
| # |
| 255 |
|
| # |
| 256 |
|
| # |
| 257 |
|
| void |
| 258 |
|
| fanotify_read(notgrp, max = 0) |
| 259 |
|
| SV *notgrp |
| 260 |
|
| int max |
| 261 |
|
| INIT: |
| 262 |
|
| struct fanotify_event_metadata *buf; |
| 263 |
|
| const struct fanotify_event_metadata *metadata; |
| 264 |
|
| struct fanotify_bundle *bundle; |
| 265 |
|
| ssize_t len; |
| 266 |
|
| int size; |
| 267 |
|
| int fd; |
| 268 |
|
| SV *event; |
| 269 |
|
| SV *eventref; |
| 270 |
|
| PPCODE: |
| 271 |
|
| /* |
| 272 |
|
| * Check arguments and allocate read buffer |
| 273 |
|
| */ |
| 274 |
0 |
▶ | if (max < 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (max < 1) { |
0 |
0 |
0 |
|
| 275 |
0 |
| max = 170; // Results in a buffer slightly smaller than 4k |
| 276 |
|
| } |
| 277 |
0 |
▶ | if (max > 4096) { // 4096 results in an almost 100k buffer. Don't allow more. |
Branch: 1 branch
| Branch | True | False | Total |
| if (max > 4096) { // 4096 results in an almost 100k buffer. Don't allow more. |
0 |
0 |
0 |
|
| 278 |
0 |
| Perl_croak(aTHX_ "Maximum buffer size exceeded (max = 4096)"); |
| 279 |
|
| } |
| 280 |
0 |
▶ | if (!notgrp2fd(notgrp, &fd)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!notgrp2fd(notgrp, &fd)) { |
0 |
0 |
0 |
|
| 281 |
0 |
| Perl_croak(aTHX_ "Invalid notification group object"); |
| 282 |
|
| } |
| 283 |
|
| |
| 284 |
0 |
| size = max * sizeof(struct fanotify_event_metadata); |
| 285 |
0 |
| buf = (struct fanotify_event_metadata *)malloc(size + (sizeof(struct fanotify_bundle) - sizeof(struct fanotify_event_metadata))); |
| 286 |
|
| |
| 287 |
0 |
▶ | if (!buf) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!buf) { |
0 |
0 |
0 |
|
| 288 |
0 |
| Perl_croak(aTHX_ "Could not allocate memory"); |
| 289 |
|
| } |
| 290 |
|
| |
| 291 |
|
| /* |
| 292 |
|
| * Read from fanotify queue |
| 293 |
|
| */ |
| 294 |
|
| |
| 295 |
|
| |
| 296 |
0 |
| len = read(fd, (void *)buf, size); |
| 297 |
|
| |
| 298 |
0 |
▶ | if (len == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == -1) { |
0 |
0 |
0 |
|
| 299 |
|
| /* Read error. errno is already set, we simply return an empty list and expect the user to check errno */ |
| 300 |
0 |
| free(buf); |
| 301 |
0 |
| XSRETURN_EMPTY; |
| 302 |
|
| } |
| 303 |
|
| |
| 304 |
|
| // printf("Number of event structures: %d\n", |
| 305 |
|
| // len/sizeof(struct fanotify_event_metadata)); |
| 306 |
|
| |
| 307 |
0 |
| metadata = buf; |
| 308 |
|
| |
| 309 |
0 |
▶ | while (FAN_EVENT_OK(metadata, len)) { |
Branch: 3 branches
| Branch | True | False | Total |
| while (FAN_EVENT_OK(metadata, len)) { |
0 |
0 |
0 |
| while (FAN_EVENT_OK(metadata, len)) { |
0 |
0 |
0 |
| while (FAN_EVENT_OK(metadata, len)) { |
0 |
0 |
0 |
|
| 310 |
0 |
▶ | if (metadata->vers != FANOTIFY_METADATA_VERSION) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (metadata->vers != FANOTIFY_METADATA_VERSION) { |
0 |
0 |
0 |
|
| 311 |
0 |
| Perl_croak(aTHX_ "Mismatch of fanotify metadata version."); |
| 312 |
|
| } |
| 313 |
|
| |
| 314 |
0 |
| event = newSVpvn((const char *)metadata, sizeof(struct fanotify_bundle)); |
| 315 |
0 |
| sv_2mortal(event); |
| 316 |
|
| |
| 317 |
0 |
| bundle = (struct fanotify_bundle *)SvPV_nolen(event); |
| 318 |
0 |
| bundle->fd = fd; |
| 319 |
0 |
▶ | if (metadata->mask & (FAN_ACCESS_PERM | FAN_OPEN_PERM)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (metadata->mask & (FAN_ACCESS_PERM | FAN_OPEN_PERM)) { |
0 |
0 |
0 |
|
| 320 |
0 |
| bundle->needs_response = 1; |
| 321 |
|
| } else { |
| 322 |
0 |
| bundle->needs_response = 0; |
| 323 |
|
| } |
| 324 |
|
| |
| 325 |
0 |
| eventref = newRV_inc(event); |
| 326 |
0 |
| sv_bless(eventref, gv_stashpv(PERLCLASS_EVENT, GV_ADD | SVf_UTF8)); |
| 327 |
0 |
| SvREADONLY_on(eventref); |
| 328 |
0 |
| sv_2mortal(eventref); |
| 329 |
|
| |
| 330 |
0 |
▶ | XPUSHs(eventref); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(eventref); |
0 |
0 |
0 |
|
| 331 |
|
| |
| 332 |
0 |
| metadata = FAN_EVENT_NEXT(metadata, len); |
| 333 |
|
| } |
| 334 |
|
| |
| 335 |
0 |
| free(buf); |
| 336 |
|
| |
| 337 |
|
| # |
| 338 |
|
| # |
| 339 |
|
| # |
| 340 |
|
| int |
| 341 |
|
| fanotify_write(event, response) |
| 342 |
|
| SV *event |
| 343 |
|
| int response |
| 344 |
|
| INIT: |
| 345 |
|
| int ret; |
| 346 |
|
| CODE: |
| 347 |
0 |
| ret = _event_write_response(event, response); |
| 348 |
|
| |
| 349 |
0 |
▶ | if (ret == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == -1) { |
0 |
0 |
0 |
|
| 350 |
0 |
| XSRETURN_UNDEF; |
| 351 |
|
| } |
| 352 |
|
| |
| 353 |
0 |
▶ | RETVAL = ret; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ret; |
0 |
0 |
0 |
|
| 354 |
|
| |
| 355 |
|
| OUTPUT: |
| 356 |
|
| RETVAL |
| 357 |
|
| |
| 358 |
|
| # /* |
| 359 |
|
| # ******************************************************************************* |
| 360 |
|
| # * Main package: Linux::Fanotify::FanotifyGroup |
| 361 |
|
| # */ |
| 362 |
|
| MODULE = Linux::Fanotify PACKAGE = Linux::Fanotify::FanotifyGroup PREFIX = fanogrp_ |
| 363 |
|
| |
| 364 |
|
| # |
| 365 |
|
| # |
| 366 |
|
| # |
| 367 |
|
| int |
| 368 |
|
| fanogrp_getfd(self) |
| 369 |
|
| SV *self |
| 370 |
|
| INIT: |
| 371 |
|
| int fd; |
| 372 |
|
| CODE: |
| 373 |
0 |
▶ | if (!notgrp2fd(self, &fd)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!notgrp2fd(self, &fd)) { |
0 |
0 |
0 |
|
| 374 |
0 |
| Perl_croak(aTHX_ "Invalid notification group object"); |
| 375 |
|
| } |
| 376 |
|
| |
| 377 |
0 |
▶ | if (fd > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd > 0) { |
0 |
0 |
0 |
|
| 378 |
0 |
| RETVAL = fd; |
| 379 |
|
| } else { |
| 380 |
0 |
| XSRETURN_UNDEF; |
| 381 |
|
| } |
| 382 |
|
| OUTPUT: |
| 383 |
|
| RETVAL |
| 384 |
|
| |
| 385 |
|
| # |
| 386 |
|
| # |
| 387 |
|
| # |
| 388 |
|
| int |
| 389 |
|
| fanogrp_close(self) |
| 390 |
|
| SV *self |
| 391 |
|
| INIT: |
| 392 |
|
| int fd; |
| 393 |
|
| SV *deref; |
| 394 |
|
| int ret; |
| 395 |
|
| CODE: |
| 396 |
0 |
▶ | if (!notgrp2fd(self, &fd)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!notgrp2fd(self, &fd)) { |
0 |
0 |
0 |
|
| 397 |
0 |
| Perl_croak(aTHX_ "Invalid notification group object"); |
| 398 |
|
| } |
| 399 |
|
| |
| 400 |
0 |
▶ | if (fd > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd > 0) { |
0 |
0 |
0 |
|
| 401 |
0 |
| ret = close(fd); |
| 402 |
|
| |
| 403 |
0 |
| deref = SvRV(self); |
| 404 |
0 |
| SvIV_set(deref, -1); |
| 405 |
|
| } else { |
| 406 |
0 |
| ret = -1; |
| 407 |
0 |
| errno = EBADF; |
| 408 |
|
| } |
| 409 |
|
| |
| 410 |
|
| // Convert C style 0/-1 to perl style 1/undef |
| 411 |
0 |
▶ | if (ret == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == -1) { |
0 |
0 |
0 |
|
| 412 |
0 |
| XSRETURN_UNDEF; |
| 413 |
|
| } else { |
| 414 |
0 |
| ret = 1; |
| 415 |
|
| } |
| 416 |
0 |
▶ | RETVAL = ret; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ret; |
0 |
0 |
0 |
|
| 417 |
|
| OUTPUT: |
| 418 |
|
| RETVAL |
| 419 |
|
| |
| 420 |
|
| # |
| 421 |
|
| # |
| 422 |
|
| # |
| 423 |
|
| void |
| 424 |
|
| fanogrp_DESTROY(self) |
| 425 |
|
| SV *self |
| 426 |
|
| INIT: |
| 427 |
|
| int fd; |
| 428 |
0 |
| int autoclose = 1; |
| 429 |
|
| SV *sv_autoclose; |
| 430 |
|
| CODE: |
| 431 |
0 |
▶ | if (!notgrp2fd(self, &fd)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!notgrp2fd(self, &fd)) { |
0 |
0 |
0 |
|
| 432 |
0 |
| Perl_croak(aTHX_ "Invalid notification group object"); |
| 433 |
|
| } |
| 434 |
|
| |
| 435 |
0 |
▶ | if (fd > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd > 0) { |
0 |
0 |
0 |
|
| 436 |
0 |
▶ | if ((sv_autoclose = get_sv("Linux::Fanotify::FanotifyGroup::autoclose", 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_autoclose = get_sv("Linux::Fanotify::FanotifyGroup::autoclose", 0))) { |
0 |
0 |
0 |
|
| 437 |
0 |
| autoclose = SvIV(sv_autoclose); |
| 438 |
|
| } |
| 439 |
0 |
▶ | if (autoclose) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (autoclose) { |
0 |
0 |
0 |
|
| 440 |
0 |
| close(fd); |
| 441 |
|
| } |
| 442 |
|
| } |
| 443 |
|
| |
| 444 |
|
| # /* |
| 445 |
|
| # ******************************************************************************* |
| 446 |
|
| # * Main package: Linux::Fanotify::Event |
| 447 |
|
| # */ |
| 448 |
|
| MODULE = Linux::Fanotify PACKAGE = Linux::Fanotify::Event PREFIX = event_ |
| 449 |
|
| |
| 450 |
|
| # |
| 451 |
|
| # |
| 452 |
|
| # |
| 453 |
|
| int |
| 454 |
|
| event_close(self) |
| 455 |
|
| SV *self |
| 456 |
|
| INIT: |
| 457 |
|
| int ret; |
| 458 |
|
| CODE: |
| 459 |
0 |
| ret = _event_close(self); |
| 460 |
|
| |
| 461 |
0 |
▶ | if (ret == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == -1) { |
0 |
0 |
0 |
|
| 462 |
0 |
| XSRETURN_UNDEF; |
| 463 |
|
| } else { |
| 464 |
0 |
| ret = 1; |
| 465 |
|
| } |
| 466 |
|
| |
| 467 |
0 |
▶ | RETVAL = ret; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ret; |
0 |
0 |
0 |
|
| 468 |
|
| OUTPUT: |
| 469 |
|
| RETVAL |
| 470 |
|
| |
| 471 |
|
| # |
| 472 |
|
| # |
| 473 |
|
| # |
| 474 |
|
| void |
| 475 |
|
| event_DESTROY(self) |
| 476 |
|
| SV *self |
| 477 |
|
| INIT: |
| 478 |
0 |
| int autoclose = 1; |
| 479 |
|
| SV *sv_autoclose; |
| 480 |
|
| CODE: |
| 481 |
0 |
▶ | if ((sv_autoclose = get_sv("Linux::Fanotify::Event::autoclose", 0))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((sv_autoclose = get_sv("Linux::Fanotify::Event::autoclose", 0))) { |
0 |
0 |
0 |
|
| 482 |
0 |
| autoclose = SvIV(sv_autoclose); |
| 483 |
|
| } |
| 484 |
0 |
▶ | if (autoclose) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (autoclose) { |
0 |
0 |
0 |
|
| 485 |
0 |
| _event_close(self); |
| 486 |
|
| } |
| 487 |
|
| |
| 488 |
|
| # |
| 489 |
|
| # |
| 490 |
|
| # |
| 491 |
|
| int |
| 492 |
|
| event_needsResponse(self) |
| 493 |
|
| SV *self |
| 494 |
|
| INIT: |
| 495 |
|
| struct fanotify_bundle *bundle; |
| 496 |
|
| CODE: |
| 497 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 498 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 499 |
|
| } |
| 500 |
|
| |
| 501 |
0 |
▶ | RETVAL = bundle->needs_response; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->needs_response; |
0 |
0 |
0 |
|
| 502 |
|
| OUTPUT: |
| 503 |
|
| RETVAL |
| 504 |
|
| |
| 505 |
|
| # |
| 506 |
|
| # |
| 507 |
|
| # |
| 508 |
|
| int |
| 509 |
|
| event__write(self, response) |
| 510 |
|
| SV *self |
| 511 |
|
| int response |
| 512 |
|
| INIT: |
| 513 |
|
| int ret; |
| 514 |
|
| CODE: |
| 515 |
0 |
| ret = _event_write_response(self, response); |
| 516 |
|
| |
| 517 |
0 |
▶ | if (ret == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == -1) { |
0 |
0 |
0 |
|
| 518 |
0 |
| XSRETURN_UNDEF; |
| 519 |
|
| } |
| 520 |
|
| |
| 521 |
0 |
▶ | RETVAL = ret; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ret; |
0 |
0 |
0 |
|
| 522 |
|
| OUTPUT: |
| 523 |
|
| RETVAL |
| 524 |
|
| |
| 525 |
|
| # |
| 526 |
|
| # |
| 527 |
|
| # |
| 528 |
|
| int |
| 529 |
|
| event_allow(self) |
| 530 |
|
| SV *self |
| 531 |
|
| INIT: |
| 532 |
|
| int ret; |
| 533 |
|
| CODE: |
| 534 |
0 |
| ret = _event_write_response(self, FAN_ALLOW); |
| 535 |
|
| |
| 536 |
0 |
▶ | if (ret == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == -1) { |
0 |
0 |
0 |
|
| 537 |
0 |
| XSRETURN_UNDEF; |
| 538 |
|
| } |
| 539 |
|
| |
| 540 |
0 |
▶ | RETVAL = ret; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ret; |
0 |
0 |
0 |
|
| 541 |
|
| OUTPUT: |
| 542 |
|
| RETVAL |
| 543 |
|
| |
| 544 |
|
| # |
| 545 |
|
| # |
| 546 |
|
| # |
| 547 |
|
| int |
| 548 |
|
| event_deny(self) |
| 549 |
|
| SV *self |
| 550 |
|
| INIT: |
| 551 |
|
| int ret; |
| 552 |
|
| CODE: |
| 553 |
0 |
| ret = _event_write_response(self, FAN_DENY); |
| 554 |
|
| |
| 555 |
0 |
▶ | if (ret == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret == -1) { |
0 |
0 |
0 |
|
| 556 |
0 |
| XSRETURN_UNDEF; |
| 557 |
|
| } |
| 558 |
|
| |
| 559 |
0 |
▶ | RETVAL = ret; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ret; |
0 |
0 |
0 |
|
| 560 |
|
| OUTPUT: |
| 561 |
|
| RETVAL |
| 562 |
|
| |
| 563 |
|
| # |
| 564 |
|
| # |
| 565 |
|
| # |
| 566 |
|
| void |
| 567 |
|
| event__dump(self) |
| 568 |
|
| SV *self |
| 569 |
|
| INIT: |
| 570 |
|
| struct fanotify_bundle *bundle; |
| 571 |
|
| char buf[256]; |
| 572 |
|
| CODE: |
| 573 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 574 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 575 |
|
| } |
| 576 |
0 |
| printf("object dump --\n%s\n", |
| 577 |
|
| event2str(bundle, buf, sizeof(buf))); |
| 578 |
|
| |
| 579 |
|
| # |
| 580 |
|
| # |
| 581 |
|
| # |
| 582 |
|
| SV * |
| 583 |
|
| event__stringify(self) |
| 584 |
|
| SV *self |
| 585 |
|
| INIT: |
| 586 |
|
| struct fanotify_bundle *bundle; |
| 587 |
|
| char buf[256]; |
| 588 |
|
| SV *s; |
| 589 |
|
| CODE: |
| 590 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 591 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 592 |
|
| } |
| 593 |
|
| |
| 594 |
0 |
| event2str(bundle, buf, sizeof(buf)); |
| 595 |
|
| |
| 596 |
0 |
| s = newSVpvn_utf8(buf, strlen(buf), 1); |
| 597 |
|
| // sv_2mortal(s); // XXX XXX Needed? |
| 598 |
|
| |
| 599 |
0 |
| RETVAL = s; |
| 600 |
|
| OUTPUT: |
| 601 |
|
| RETVAL |
| 602 |
|
| |
| 603 |
|
| ################################################################################ |
| 604 |
|
| # Accessor methods start here |
| 605 |
|
| # |
| 606 |
|
| unsigned int |
| 607 |
|
| event_event_len(self) |
| 608 |
|
| SV *self |
| 609 |
|
| INIT: |
| 610 |
|
| struct fanotify_bundle *bundle; |
| 611 |
|
| CODE: |
| 612 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 613 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 614 |
|
| } |
| 615 |
0 |
▶ | RETVAL = bundle->metadata.event_len; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->metadata.event_len; |
0 |
0 |
0 |
|
| 616 |
|
| OUTPUT: |
| 617 |
|
| RETVAL |
| 618 |
|
| |
| 619 |
|
| # |
| 620 |
|
| # |
| 621 |
|
| # |
| 622 |
|
| unsigned int |
| 623 |
|
| event_vers(self) |
| 624 |
|
| SV *self |
| 625 |
|
| INIT: |
| 626 |
|
| struct fanotify_bundle *bundle; |
| 627 |
|
| CODE: |
| 628 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 629 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 630 |
|
| } |
| 631 |
0 |
▶ | RETVAL = bundle->metadata.vers; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->metadata.vers; |
0 |
0 |
0 |
|
| 632 |
|
| OUTPUT: |
| 633 |
|
| RETVAL |
| 634 |
|
| |
| 635 |
|
| # |
| 636 |
|
| # |
| 637 |
|
| # |
| 638 |
|
| unsigned int |
| 639 |
|
| event_reserved(self) |
| 640 |
|
| SV *self |
| 641 |
|
| INIT: |
| 642 |
|
| struct fanotify_bundle *bundle; |
| 643 |
|
| CODE: |
| 644 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 645 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 646 |
|
| } |
| 647 |
0 |
▶ | RETVAL = bundle->metadata.reserved; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->metadata.reserved; |
0 |
0 |
0 |
|
| 648 |
|
| OUTPUT: |
| 649 |
|
| RETVAL |
| 650 |
|
| |
| 651 |
|
| # |
| 652 |
|
| # |
| 653 |
|
| # |
| 654 |
|
| unsigned int |
| 655 |
|
| event_metadata_len(self) |
| 656 |
|
| SV *self |
| 657 |
|
| INIT: |
| 658 |
|
| struct fanotify_bundle *bundle; |
| 659 |
|
| CODE: |
| 660 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 661 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 662 |
|
| } |
| 663 |
0 |
▶ | RETVAL = bundle->metadata.metadata_len; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->metadata.metadata_len; |
0 |
0 |
0 |
|
| 664 |
|
| OUTPUT: |
| 665 |
|
| RETVAL |
| 666 |
|
| |
| 667 |
|
| # |
| 668 |
|
| # |
| 669 |
|
| # |
| 670 |
|
| uint64_t |
| 671 |
|
| event_mask(self) |
| 672 |
|
| SV *self |
| 673 |
|
| INIT: |
| 674 |
|
| struct fanotify_bundle *bundle; |
| 675 |
|
| CODE: |
| 676 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 677 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 678 |
|
| } |
| 679 |
0 |
▶ | RETVAL = bundle->metadata.mask; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->metadata.mask; |
0 |
0 |
0 |
|
| 680 |
|
| OUTPUT: |
| 681 |
|
| RETVAL |
| 682 |
|
| |
| 683 |
|
| # |
| 684 |
|
| # |
| 685 |
|
| # |
| 686 |
|
| int |
| 687 |
|
| event_fd(self) |
| 688 |
|
| SV *self |
| 689 |
|
| INIT: |
| 690 |
|
| struct fanotify_bundle *bundle; |
| 691 |
|
| CODE: |
| 692 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 693 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 694 |
|
| } |
| 695 |
0 |
▶ | RETVAL = bundle->metadata.fd; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->metadata.fd; |
0 |
0 |
0 |
|
| 696 |
|
| OUTPUT: |
| 697 |
|
| RETVAL |
| 698 |
|
| |
| 699 |
|
| # |
| 700 |
|
| # |
| 701 |
|
| # |
| 702 |
|
| int |
| 703 |
|
| event_pid(self) |
| 704 |
|
| SV *self |
| 705 |
|
| INIT: |
| 706 |
|
| struct fanotify_bundle *bundle; |
| 707 |
|
| CODE: |
| 708 |
0 |
▶ | if (!(bundle = event2bundle(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bundle = event2bundle(self))) { |
0 |
0 |
0 |
|
| 709 |
0 |
| Perl_croak(aTHX_ "Invalid event object"); |
| 710 |
|
| } |
| 711 |
0 |
▶ | RETVAL = bundle->metadata.pid; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bundle->metadata.pid; |
0 |
0 |
0 |
|
| 712 |
|
| OUTPUT: |
| 713 |
|
| RETVAL |
| 714 |
|
| |