Changeset b9a4230bc7f65c1268a1569d08ffc92d1074bc68
- Timestamp:
- 08/16/09 01:38:33
(4 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1250386713 +0000
- git-parent:
[d28cd24a4ee6fb5b897aa9c5c17082587b6fb54b]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1250386713 +0000
- Message:
first whack at using fcntl everywhere. Heads up, a lot could break. resf #167.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r88a7178 |
rb9a4230 |
|
| 34 | 34 | #include "eventer/eventer.h" |
|---|
| 35 | 35 | #include "utils/noit_hash.h" |
|---|
| | 36 | #include <sys/types.h> |
|---|
| | 37 | #include <sys/stat.h> |
|---|
| | 38 | #include <fcntl.h> |
|---|
| 36 | 39 | |
|---|
| 37 | 40 | eventer_t eventer_alloc() { |
|---|
| … | … | |
| 57 | 60 | void eventer_free(eventer_t e) { |
|---|
| 58 | 61 | free(e); |
|---|
| | 62 | } |
|---|
| | 63 | |
|---|
| | 64 | int eventer_set_fd_nonblocking(int fd) { |
|---|
| | 65 | int flags; |
|---|
| | 66 | if(((flags = fcntl(fd, F_GETFL, 0)) == -1) || |
|---|
| | 67 | (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)) |
|---|
| | 68 | return -1; |
|---|
| | 69 | return 0; |
|---|
| | 70 | } |
|---|
| | 71 | int eventer_set_fd_blocking(int fd) { |
|---|
| | 72 | int flags; |
|---|
| | 73 | if(((flags = fcntl(fd, F_GETFL, 0)) == -1) || |
|---|
| | 74 | (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == -1)) |
|---|
| | 75 | return -1; |
|---|
| | 76 | return 0; |
|---|
| 59 | 77 | } |
|---|
| 60 | 78 | |
|---|
| r88a7178 |
rb9a4230 |
|
| 142 | 142 | API_EXPORT(int) eventer_get_epoch(struct timeval *epoch); |
|---|
| 143 | 143 | |
|---|
| | 144 | /* Helpers to set sockets non-blocking / blocking */ |
|---|
| | 145 | API_EXPORT(int) eventer_set_fd_nonblocking(int fd); |
|---|
| | 146 | API_EXPORT(int) eventer_set_fd_blocking(int fd); |
|---|
| | 147 | |
|---|
| 144 | 148 | #endif |
|---|
| r1072271 |
rb9a4230 |
|
| 1436 | 1436 | collectd_mod_config_t *conf; |
|---|
| 1437 | 1437 | conf = noit_module_get_userdata(self); |
|---|
| 1438 | | socklen_t on; |
|---|
| 1439 | 1438 | int portint = 0; |
|---|
| 1440 | 1439 | struct sockaddr_in skaddr; |
|---|
| … | … | |
| 1486 | 1485 | noitL(noit_error, "Cannot get sndbuf size: %s\n", strerror(errno)); |
|---|
| 1487 | 1486 | */ |
|---|
| 1488 | | on = 1; |
|---|
| 1489 | | if(ioctl(conf->ipv4_fd, FIONBIO, &on)) { |
|---|
| | 1487 | if(eventer_set_fd_nonblocking(conf->ipv4_fd)) { |
|---|
| 1490 | 1488 | close(conf->ipv4_fd); |
|---|
| 1491 | 1489 | conf->ipv4_fd = -1; |
|---|
| … | … | |
| 1522 | 1520 | } |
|---|
| 1523 | 1521 | else { |
|---|
| 1524 | | on = 1; |
|---|
| 1525 | | if(ioctl(conf->ipv6_fd, FIONBIO, &on)) { |
|---|
| | 1522 | if(eventer_set_fd_nonblocking(conf->ipv6_fd)) { |
|---|
| 1526 | 1523 | close(conf->ipv6_fd); |
|---|
| 1527 | 1524 | conf->ipv6_fd = -1; |
|---|
| r88a7178 |
rb9a4230 |
|
| 39 | 39 | #include <fcntl.h> |
|---|
| 40 | 40 | #include <assert.h> |
|---|
| 41 | | #include <sys/ioctl.h> |
|---|
| 42 | 41 | #include <sys/uio.h> |
|---|
| 43 | 42 | #ifdef HAVE_SYS_WAIT_H |
|---|
| … | … | |
| 378 | 377 | /* Now the parent must set its bits non-blocking, the child need not */ |
|---|
| 379 | 378 | if(data->child != 0) { |
|---|
| 380 | | long on = 1; |
|---|
| 381 | 379 | /* in the parent */ |
|---|
| 382 | | if(ioctl(data->pipe_e2n[0], FIONBIO, &on) == -1) { |
|---|
| | 380 | if(eventer_set_fd_nonblocking(data->pipe_e2n[0]) == -1) { |
|---|
| 383 | 381 | close(data->pipe_n2e[1]); |
|---|
| 384 | 382 | close(data->pipe_e2n[0]); |
|---|
| r88a7178 |
rb9a4230 |
|
| 529 | 529 | struct nl_slcl *cl; |
|---|
| 530 | 530 | noit_lua_check_info_t *ci; |
|---|
| 531 | | socklen_t on, optlen; |
|---|
| | 531 | socklen_t optlen; |
|---|
| 532 | 532 | int fd; |
|---|
| 533 | 533 | eventer_t e; |
|---|
| … | … | |
| 538 | 538 | return 1; |
|---|
| 539 | 539 | } |
|---|
| 540 | | on = 1; |
|---|
| 541 | | if(ioctl(fd, FIONBIO, &on)) { |
|---|
| | 540 | if(eventer_set_fd_nonblocking(fd)) { |
|---|
| 542 | 541 | close(fd); |
|---|
| 543 | 542 | lua_pushnil(L); |
|---|
| rfe3d821 |
rb9a4230 |
|
| 38 | 38 | #include <errno.h> |
|---|
| 39 | 39 | #include <fcntl.h> |
|---|
| 40 | | #include <sys/ioctl.h> |
|---|
| 41 | 40 | #ifdef HAVE_SYS_FILIO_H |
|---|
| 42 | 41 | #include <sys/filio.h> |
|---|
| … | … | |
| 301 | 300 | noitL(noit_error, "Cannot get sndbuf size: %s\n", strerror(errno)); |
|---|
| 302 | 301 | |
|---|
| 303 | | on = 1; |
|---|
| 304 | | if(ioctl(data->ipv4_fd, FIONBIO, &on)) { |
|---|
| | 302 | if(eventer_set_fd_nonblocking(data->ipv4_fd)) { |
|---|
| 305 | 303 | close(data->ipv4_fd); |
|---|
| 306 | 304 | data->ipv4_fd = -1; |
|---|
| … | … | |
| 326 | 324 | } |
|---|
| 327 | 325 | else { |
|---|
| 328 | | on = 1; |
|---|
| 329 | | if(ioctl(data->ipv6_fd, FIONBIO, &on)) { |
|---|
| | 326 | if(eventer_set_fd_nonblocking(data->ipv6_fd)) { |
|---|
| 330 | 327 | close(data->ipv6_fd); |
|---|
| 331 | 328 | data->ipv6_fd = -1; |
|---|
| r88a7178 |
rb9a4230 |
|
| 118 | 118 | struct timeval *now) { |
|---|
| 119 | 119 | int i; |
|---|
| 120 | | long on; |
|---|
| 121 | 120 | const char *fingerprint; |
|---|
| 122 | 121 | ssh2_check_info_t *ci = closure; |
|---|
| … | … | |
| 132 | 131 | switch(mask) { |
|---|
| 133 | 132 | case EVENTER_ASYNCH_WORK: |
|---|
| 134 | | on = 0; |
|---|
| 135 | | if(ioctl(e->fd, FIONBIO, &on)) { |
|---|
| | 133 | if(eventer_set_fd_blocking(e->fd)) { |
|---|
| 136 | 134 | ci->timed_out = 0; |
|---|
| 137 | 135 | ci->error = strdup("socket error"); |
|---|
| … | … | |
| 233 | 231 | unsigned short ssh_port = DEFAULT_SSH_PORT; |
|---|
| 234 | 232 | const char *port_str = NULL; |
|---|
| 235 | | long on; |
|---|
| 236 | 233 | |
|---|
| 237 | 234 | /* We cannot be running */ |
|---|
| … | … | |
| 257 | 254 | |
|---|
| 258 | 255 | /* Make it non-blocking */ |
|---|
| 259 | | on = 1; |
|---|
| 260 | | if(ioctl(fd, FIONBIO, &on)) goto fail; |
|---|
| | 256 | if(eventer_set_fd_nonblocking(fd)) goto fail; |
|---|
| 261 | 257 | |
|---|
| 262 | 258 | if(noit_hash_retr_str(check->config, "port", strlen("port"), |
|---|
| r88a7178 |
rb9a4230 |
|
| 306 | 306 | int |
|---|
| 307 | 307 | allocate_pty(int *master, int *slave) { |
|---|
| 308 | | long on = 1; |
|---|
| 309 | 308 | #ifdef HAVE_OPENPTY |
|---|
| 310 | 309 | if(openpty(master, slave, NULL, NULL, NULL)) return -1; |
|---|
| … | … | |
| 331 | 330 | ioctl(*master, I_PUSH, "ldterm"); /* push ldterm*/ |
|---|
| 332 | 331 | #endif |
|---|
| 333 | | if(ioctl(*master, FIONBIO, &on)) return -1; |
|---|
| | 332 | if(eventer_set_fd_nonblocking(*master)) return -1; |
|---|
| 334 | 333 | noitL(noit_debug, "allocate_pty -> %d,%d\n", *master, *slave); |
|---|
| 335 | 334 | return 0; |
|---|
| r88a7178 |
rb9a4230 |
|
| 40 | 40 | |
|---|
| 41 | 41 | #include <unistd.h> |
|---|
| 42 | | #include <sys/ioctl.h> |
|---|
| 43 | 42 | #define MAX_ROWS_AT_ONCE 1000 |
|---|
| 44 | 43 | #define DEFAULT_SECONDS_BETWEEN_BATCHES 10 |
|---|
| … | … | |
| 144 | 143 | acceptor_closure_t *ac = e->closure; |
|---|
| 145 | 144 | noit_jlog_closure_t *jcl = ac->service_ctx; |
|---|
| 146 | | long off = 0; |
|---|
| 147 | 145 | char inbuff[sizeof(jlog_id)]; |
|---|
| 148 | 146 | |
|---|
| 149 | | /* Go into blocking mode */ |
|---|
| 150 | | ioctl(e->fd, FIONBIO, &off); |
|---|
| | 147 | eventer_set_fd_blocking(e->fd); |
|---|
| 151 | 148 | |
|---|
| 152 | 149 | while(1) { |
|---|
| r1818db2 |
rb9a4230 |
|
| 38 | 38 | #include <sys/types.h> |
|---|
| 39 | 39 | #include <sys/socket.h> |
|---|
| 40 | | #include <sys/ioctl.h> |
|---|
| 41 | 40 | #include <netinet/in.h> |
|---|
| 42 | 41 | #include <sys/un.h> |
|---|
| … | … | |
| 121 | 120 | conn = e->opset->accept(e->fd, &ac->remote.remote_addr, &salen, &newmask, e); |
|---|
| 122 | 121 | if(conn >= 0) { |
|---|
| 123 | | socklen_t on = 1; |
|---|
| 124 | 122 | eventer_t newe; |
|---|
| 125 | | if(ioctl(conn, FIONBIO, &on)) { |
|---|
| | 123 | if(eventer_set_fd_nonblocking(conn)) { |
|---|
| 126 | 124 | close(conn); |
|---|
| 127 | 125 | goto accept_bail; |
|---|
| … | … | |
| 180 | 178 | int8_t family; |
|---|
| 181 | 179 | int sockaddr_len; |
|---|
| 182 | | socklen_t on, reuse; |
|---|
| | 180 | socklen_t reuse; |
|---|
| 183 | 181 | listener_closure_t listener_closure; |
|---|
| 184 | 182 | eventer_t event; |
|---|
| … | … | |
| 225 | 223 | } |
|---|
| 226 | 224 | |
|---|
| 227 | | on = 1; |
|---|
| 228 | | if(ioctl(fd, FIONBIO, &on)) { |
|---|
| | 225 | if(eventer_set_fd_nonblocking(fd)) { |
|---|
| 229 | 226 | close(fd); |
|---|
| 230 | 227 | noitL(noit_stderr, "Cannot make socket non-blocking: %s\n", |
|---|
| r88a7178 |
rb9a4230 |
|
| 40 | 40 | #include <sys/types.h> |
|---|
| 41 | 41 | #include <sys/socket.h> |
|---|
| 42 | | #include <sys/ioctl.h> |
|---|
| 43 | 42 | #ifdef HAVE_SYS_FILIO_H |
|---|
| 44 | 43 | #include <sys/filio.h> |
|---|
| r88a7178 |
rb9a4230 |
|
| 41 | 41 | |
|---|
| 42 | 42 | #include <unistd.h> |
|---|
| 43 | | #include <sys/ioctl.h> |
|---|
| 44 | 43 | #include <errno.h> |
|---|
| 45 | 44 | |
|---|
| … | … | |
| 162 | 161 | acceptor_closure_t *ac = e->closure; |
|---|
| 163 | 162 | noit_livestream_closure_t *jcl = ac->service_ctx; |
|---|
| 164 | | long off = 0; |
|---|
| 165 | 163 | |
|---|
| 166 | 164 | /* Go into blocking mode */ |
|---|
| 167 | | if(ioctl(e->fd, FIONBIO, &off) == -1) { |
|---|
| 168 | | noitL(noit_error, "ioctl failed setting livestream to blocking: [%d] [%s]\n", |
|---|
| | 165 | if(eventer_set_fd_blocking(e->fd) == -1) { |
|---|
| | 166 | noitL(noit_error, "failed setting livestream to blocking: [%d] [%s]\n", |
|---|
| 169 | 167 | errno, strerror(errno)); |
|---|
| 170 | 168 | goto alldone; |
|---|
| r17f1624 |
rb9a4230 |
|
| 37 | 37 | #include <unistd.h> |
|---|
| 38 | 38 | #include <errno.h> |
|---|
| 39 | | #include <sys/ioctl.h> |
|---|
| 40 | 39 | #include <fcntl.h> |
|---|
| 41 | 40 | #include <sys/mman.h> |
|---|
| r66b174e |
rb9a4230 |
|
| 852 | 852 | } |
|---|
| 853 | 853 | /* in the parent */ |
|---|
| 854 | | socklen_t on = 1; |
|---|
| 855 | | |
|---|
| 856 | 854 | close(info->stdin_pipe[0]); |
|---|
| 857 | 855 | info->stdin_pipe[0] = -1; |
|---|
| 858 | 856 | close(info->stderr_pipe[1]); |
|---|
| 859 | 857 | info->stderr_pipe[1] = -1; |
|---|
| 860 | | if(ioctl(info->stderr_pipe[0], FIONBIO, &on)) { |
|---|
| | 858 | if(eventer_set_fd_nonblocking(info->stderr_pipe[0])) { |
|---|
| 861 | 859 | goto bail; |
|---|
| 862 | 860 | } |
|---|
| r76d9e48 |
rb9a4230 |
|
| 408 | 408 | eventer_t e; |
|---|
| 409 | 409 | int rv, fd = -1; |
|---|
| 410 | | long on; |
|---|
| 411 | 410 | |
|---|
| 412 | 411 | /* Open a socket */ |
|---|
| … | … | |
| 415 | 414 | |
|---|
| 416 | 415 | /* Make it non-blocking */ |
|---|
| 417 | | on = 1; |
|---|
| 418 | | if(ioctl(fd, FIONBIO, &on)) goto reschedule; |
|---|
| | 416 | if(eventer_set_fd_nonblocking(fd)) goto reschedule; |
|---|
| 419 | 417 | |
|---|
| 420 | 418 | /* Initiate a connection */ |
|---|
| r5b63423 |
rb9a4230 |
|
| 38 | 38 | #include <unistd.h> |
|---|
| 39 | 39 | #include <errno.h> |
|---|
| 40 | | #include <sys/ioctl.h> |
|---|
| 41 | 40 | #include <fcntl.h> |
|---|
| 42 | 41 | |
|---|