Changeset b9a4230bc7f65c1268a1569d08ffc92d1074bc68

Show
Ignore:
Timestamp:
08/16/09 01:38:33 (5 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
  • src/eventer/eventer.c

    r88a7178 rb9a4230  
    3434#include "eventer/eventer.h" 
    3535#include "utils/noit_hash.h" 
     36#include <sys/types.h> 
     37#include <sys/stat.h> 
     38#include <fcntl.h> 
    3639 
    3740eventer_t eventer_alloc() { 
     
    5760void eventer_free(eventer_t e) { 
    5861  free(e); 
     62} 
     63 
     64int 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} 
     71int 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; 
    5977} 
    6078 
  • src/eventer/eventer.h

    r88a7178 rb9a4230  
    142142API_EXPORT(int) eventer_get_epoch(struct timeval *epoch); 
    143143 
     144/* Helpers to set sockets non-blocking / blocking */ 
     145API_EXPORT(int) eventer_set_fd_nonblocking(int fd); 
     146API_EXPORT(int) eventer_set_fd_blocking(int fd); 
     147 
    144148#endif 
  • src/modules/collectd.c

    r1072271 rb9a4230  
    14361436  collectd_mod_config_t *conf; 
    14371437  conf = noit_module_get_userdata(self); 
    1438   socklen_t on; 
    14391438  int portint = 0; 
    14401439  struct sockaddr_in skaddr; 
     
    14861485      noitL(noit_error, "Cannot get sndbuf size: %s\n", strerror(errno)); 
    14871486    */ 
    1488     on = 1; 
    1489     if(ioctl(conf->ipv4_fd, FIONBIO, &on)) { 
     1487    if(eventer_set_fd_nonblocking(conf->ipv4_fd)) { 
    14901488      close(conf->ipv4_fd); 
    14911489      conf->ipv4_fd = -1; 
     
    15221520  } 
    15231521  else { 
    1524     on = 1; 
    1525     if(ioctl(conf->ipv6_fd, FIONBIO, &on)) { 
     1522    if(eventer_set_fd_nonblocking(conf->ipv6_fd)) { 
    15261523      close(conf->ipv6_fd); 
    15271524      conf->ipv6_fd = -1; 
  • src/modules/external.c

    r88a7178 rb9a4230  
    3939#include <fcntl.h> 
    4040#include <assert.h> 
    41 #include <sys/ioctl.h> 
    4241#include <sys/uio.h> 
    4342#ifdef HAVE_SYS_WAIT_H 
     
    378377  /* Now the parent must set its bits non-blocking, the child need not */ 
    379378  if(data->child != 0) { 
    380     long on = 1; 
    381379    /* in the parent */ 
    382     if(ioctl(data->pipe_e2n[0], FIONBIO, &on) == -1) { 
     380    if(eventer_set_fd_nonblocking(data->pipe_e2n[0]) == -1) { 
    383381      close(data->pipe_n2e[1]); 
    384382      close(data->pipe_e2n[0]); 
  • src/modules/lua_noit.c

    r88a7178 rb9a4230  
    529529  struct nl_slcl *cl; 
    530530  noit_lua_check_info_t *ci; 
    531   socklen_t on, optlen; 
     531  socklen_t optlen; 
    532532  int fd; 
    533533  eventer_t e; 
     
    538538    return 1; 
    539539  } 
    540   on = 1; 
    541   if(ioctl(fd, FIONBIO, &on)) { 
     540  if(eventer_set_fd_nonblocking(fd)) { 
    542541    close(fd); 
    543542    lua_pushnil(L); 
  • src/modules/ping_icmp.c

    rfe3d821 rb9a4230  
    3838#include <errno.h> 
    3939#include <fcntl.h> 
    40 #include <sys/ioctl.h> 
    4140#ifdef HAVE_SYS_FILIO_H 
    4241#include <sys/filio.h> 
     
    301300      noitL(noit_error, "Cannot get sndbuf size: %s\n", strerror(errno)); 
    302301 
    303     on = 1; 
    304     if(ioctl(data->ipv4_fd, FIONBIO, &on)) { 
     302    if(eventer_set_fd_nonblocking(data->ipv4_fd)) { 
    305303      close(data->ipv4_fd); 
    306304      data->ipv4_fd = -1; 
     
    326324  } 
    327325  else { 
    328     on = 1; 
    329     if(ioctl(data->ipv6_fd, FIONBIO, &on)) { 
     326    if(eventer_set_fd_nonblocking(data->ipv6_fd)) { 
    330327      close(data->ipv6_fd); 
    331328      data->ipv6_fd = -1; 
  • src/modules/ssh2.c

    r88a7178 rb9a4230  
    118118                              struct timeval *now) { 
    119119  int i; 
    120   long on; 
    121120  const char *fingerprint; 
    122121  ssh2_check_info_t *ci = closure; 
     
    132131  switch(mask) { 
    133132    case EVENTER_ASYNCH_WORK: 
    134       on = 0; 
    135       if(ioctl(e->fd, FIONBIO, &on)) { 
     133      if(eventer_set_fd_blocking(e->fd)) { 
    136134        ci->timed_out = 0; 
    137135        ci->error = strdup("socket error"); 
     
    233231  unsigned short ssh_port = DEFAULT_SSH_PORT; 
    234232  const char *port_str = NULL; 
    235   long on; 
    236233 
    237234  /* We cannot be running */ 
     
    257254 
    258255  /* Make it non-blocking */ 
    259   on = 1; 
    260   if(ioctl(fd, FIONBIO, &on)) goto fail; 
     256  if(eventer_set_fd_nonblocking(fd)) goto fail; 
    261257 
    262258  if(noit_hash_retr_str(check->config, "port", strlen("port"), 
  • src/noit_console.c

    r88a7178 rb9a4230  
    306306int 
    307307allocate_pty(int *master, int *slave) { 
    308   long on = 1; 
    309308#ifdef HAVE_OPENPTY 
    310309  if(openpty(master, slave, NULL, NULL, NULL)) return -1; 
     
    331330  ioctl(*master, I_PUSH, "ldterm");     /* push ldterm*/ 
    332331#endif 
    333   if(ioctl(*master, FIONBIO, &on)) return -1; 
     332  if(eventer_set_fd_nonblocking(*master)) return -1; 
    334333  noitL(noit_debug, "allocate_pty -> %d,%d\n", *master, *slave); 
    335334  return 0; 
  • src/noit_jlog_listener.c

    r88a7178 rb9a4230  
    4040 
    4141#include <unistd.h> 
    42 #include <sys/ioctl.h> 
    4342#define MAX_ROWS_AT_ONCE 1000 
    4443#define DEFAULT_SECONDS_BETWEEN_BATCHES 10 
     
    144143  acceptor_closure_t *ac = e->closure; 
    145144  noit_jlog_closure_t *jcl = ac->service_ctx; 
    146   long off = 0; 
    147145  char inbuff[sizeof(jlog_id)]; 
    148146 
    149   /* Go into blocking mode */ 
    150   ioctl(e->fd, FIONBIO, &off); 
     147  eventer_set_fd_blocking(e->fd); 
    151148 
    152149  while(1) { 
  • src/noit_listener.c

    r1818db2 rb9a4230  
    3838#include <sys/types.h> 
    3939#include <sys/socket.h> 
    40 #include <sys/ioctl.h> 
    4140#include <netinet/in.h> 
    4241#include <sys/un.h> 
     
    121120  conn = e->opset->accept(e->fd, &ac->remote.remote_addr, &salen, &newmask, e); 
    122121  if(conn >= 0) { 
    123     socklen_t on = 1; 
    124122    eventer_t newe; 
    125     if(ioctl(conn, FIONBIO, &on)) { 
     123    if(eventer_set_fd_nonblocking(conn)) { 
    126124      close(conn); 
    127125      goto accept_bail; 
     
    180178  int8_t family; 
    181179  int sockaddr_len; 
    182   socklen_t on, reuse; 
     180  socklen_t reuse; 
    183181  listener_closure_t listener_closure; 
    184182  eventer_t event; 
     
    225223  } 
    226224 
    227   on = 1; 
    228   if(ioctl(fd, FIONBIO, &on)) { 
     225  if(eventer_set_fd_nonblocking(fd)) { 
    229226    close(fd); 
    230227    noitL(noit_stderr, "Cannot make socket non-blocking: %s\n", 
  • src/noit_listener.h

    r88a7178 rb9a4230  
    4040#include <sys/types.h> 
    4141#include <sys/socket.h> 
    42 #include <sys/ioctl.h> 
    4342#ifdef HAVE_SYS_FILIO_H 
    4443#include <sys/filio.h> 
  • src/noit_livestream_listener.c

    r88a7178 rb9a4230  
    4141 
    4242#include <unistd.h> 
    43 #include <sys/ioctl.h> 
    4443#include <errno.h> 
    4544 
     
    162161  acceptor_closure_t *ac = e->closure; 
    163162  noit_livestream_closure_t *jcl = ac->service_ctx; 
    164   long off = 0; 
    165163 
    166164  /* 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", 
    169167          errno, strerror(errno)); 
    170168    goto alldone; 
  • src/noitd.c

    r17f1624 rb9a4230  
    3737#include <unistd.h> 
    3838#include <errno.h> 
    39 #include <sys/ioctl.h> 
    4039#include <fcntl.h> 
    4140#include <sys/mman.h> 
  • src/stratcon_iep.c

    r66b174e rb9a4230  
    852852  } 
    853853  /* in the parent */ 
    854   socklen_t on = 1; 
    855  
    856854  close(info->stdin_pipe[0]); 
    857855  info->stdin_pipe[0] = -1; 
    858856  close(info->stderr_pipe[1]); 
    859857  info->stderr_pipe[1] = -1; 
    860   if(ioctl(info->stderr_pipe[0], FIONBIO, &on)) { 
     858  if(eventer_set_fd_nonblocking(info->stderr_pipe[0])) { 
    861859    goto bail; 
    862860  } 
  • src/stratcon_jlog_streamer.c

    r76d9e48 rb9a4230  
    408408  eventer_t e; 
    409409  int rv, fd = -1; 
    410   long on; 
    411410 
    412411  /* Open a socket */ 
     
    415414 
    416415  /* Make it non-blocking */ 
    417   on = 1; 
    418   if(ioctl(fd, FIONBIO, &on)) goto reschedule; 
     416  if(eventer_set_fd_nonblocking(fd)) goto reschedule; 
    419417 
    420418  /* Initiate a connection */ 
  • src/stratcond.c

    r5b63423 rb9a4230  
    3838#include <unistd.h> 
    3939#include <errno.h> 
    40 #include <sys/ioctl.h> 
    4140#include <fcntl.h> 
    4241