| 53 | struct timespec _tm = {0, 0}; // used for poll |
| 54 | |
| 55 | int init() { |
| 56 | if (_kq >= 0) |
| 57 | LOG_ERROR_RETURN(EALREADY, -1, "already init-ed"); |
| 58 | |
| 59 | static char* argv[] = { |
| 60 | (char*) "proc-name-not-used", |
| 61 | (char*) "--conf=/etc/f-stack.conf", |
| 62 | (char*) "--proc-type=primary", |
| 63 | (char*) "--proc-id=0", |
| 64 | }; |
| 65 | // f-stack will exit the program if init failed. |
| 66 | // Unable to change the behavior unless it provides more flexible APIs ... |
| 67 | if (ff_init(LEN(argv), argv)) |
| 68 | return -1; |
| 69 | |
| 70 | _kq = ff_kqueue(); |
| 71 | if (_kq < 0) |
| 72 | LOG_ERRNO_RETURN(0, -1, "failed to create kqueue()"); |
| 73 | |
| 74 | if (enqueue(_kq, EVFILT_USER, EV_ADD | EV_CLEAR, 0, nullptr, true) < 0) { |
| 75 | DEFER({ close(_kq); _kq = -1; }); |
| 76 | LOG_ERRNO_RETURN(0, -1, "failed to setup self-wakeup EVFILT_USER event by kevent()"); |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int reset() override { |
| 82 | return -1; |
no test coverage detected