Changeset 535


Ignore:
Timestamp:
12/27/09 20:37:46 (2 years ago)
Author:
eagle
Message:
  • option -t did not work correctly
  • (optional) pid file is removed at exit
  • SIGUSR1 is handled in preparation for statistics output
  • controller sessions limited to MAX_DEF_CTRL_SESS (= 5 by default)
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r534 r535  
    22 - GarliCat branch merged back into trunk 
    33 - added onioncat-privatehosts.pl to trunk (written by zzz) 
     4 - option -t did not work correctly 
     5 - (optional) pid file is removed at exit 
     6 - SIGUSR1 is handled in preparation for statistics output 
     7 - controller sessions limited to MAX_DEF_CTRL_SESS (= 5 by default) 
    48  
    59* version 0.2.1 
  • trunk/configure

    r534 r535  
    11#! /bin/sh 
    22# Guess values for system-dependent variables and create Makefiles. 
    3 # Generated by GNU Autoconf 2.62 for onioncat 0.2.2.r534. 
     3# Generated by GNU Autoconf 2.62 for onioncat 0.2.2.r535. 
    44# 
    55# Report bugs to <rahra@cypherpunk.at>. 
     
    597597PACKAGE_NAME='onioncat' 
    598598PACKAGE_TARNAME='onioncat' 
    599 PACKAGE_VERSION='0.2.2.r534' 
    600 PACKAGE_STRING='onioncat 0.2.2.r534' 
     599PACKAGE_VERSION='0.2.2.r535' 
     600PACKAGE_STRING='onioncat 0.2.2.r535' 
    601601PACKAGE_BUGREPORT='rahra@cypherpunk.at' 
    602602 
     
    12611261  # This message is too long to be a string in the A/UX 3.1 sh. 
    12621262  cat <<_ACEOF 
    1263 \`configure' configures onioncat 0.2.2.r534 to adapt to many kinds of systems. 
     1263\`configure' configures onioncat 0.2.2.r535 to adapt to many kinds of systems. 
    12641264 
    12651265Usage: $0 [OPTION]... [VAR=VALUE]... 
     
    13311331if test -n "$ac_init_help"; then 
    13321332  case $ac_init_help in 
    1333      short | recursive ) echo "Configuration of onioncat 0.2.2.r534:";; 
     1333     short | recursive ) echo "Configuration of onioncat 0.2.2.r535:";; 
    13341334   esac 
    13351335  cat <<\_ACEOF 
     
    14231423if $ac_init_version; then 
    14241424  cat <<\_ACEOF 
    1425 onioncat configure 0.2.2.r534 
     1425onioncat configure 0.2.2.r535 
    14261426generated by GNU Autoconf 2.62 
    14271427 
     
    14371437running configure, to aid debugging if configure makes a mistake. 
    14381438 
    1439 It was created by onioncat $as_me 0.2.2.r534, which was 
     1439It was created by onioncat $as_me 0.2.2.r535, which was 
    14401440generated by GNU Autoconf 2.62.  Invocation command line was 
    14411441 
     
    20862086# Define the identity of the package. 
    20872087 PACKAGE='onioncat' 
    2088  VERSION='0.2.2.r534' 
     2088 VERSION='0.2.2.r535' 
    20892089 
    20902090 
     
    22372237 
    22382238cat >>confdefs.h <<\_ACEOF 
    2239 #define SVN_REVISION "534" 
     2239#define SVN_REVISION "535" 
    22402240_ACEOF 
    22412241 
     
    52215221# values after options handling. 
    52225222ac_log=" 
    5223 This file was extended by onioncat $as_me 0.2.2.r534, which was 
     5223This file was extended by onioncat $as_me 0.2.2.r535, which was 
    52245224generated by GNU Autoconf 2.62.  Invocation command line was 
    52255225 
     
    52745274cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 
    52755275ac_cs_version="\\ 
    5276 onioncat config.status 0.2.2.r534 
     5276onioncat config.status 0.2.2.r535 
    52775277configured by $0, generated by GNU Autoconf 2.62, 
    52785278  with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" 
  • trunk/src/ocat.c

    r534 r535  
    9494{ 
    9595   FILE *f; 
     96   char c; 
    9697 
    9798   if (!(f = fopen(CNF(pid_file), "w"))) 
     
    105106   log_debug("pid_file %s created, pid = %d", CNF(pid_file), getpid()); 
    106107 
    107    if (chown(CNF(pid_file), uid, 0) == -1) 
    108       log_msg(LOG_ERR, "could not change owner of pid_file \"%s\" to %d: %s", CNF(pid_file), uid, strerror(errno)); 
    109  
    110    return 0; 
     108   if (pipe(CNF(pid_fd)) == -1) 
     109   { 
     110      log_msg(LOG_WARNING, "could not open pid pipe: \"%s\"", strerror(errno)); 
     111      return -1; 
     112   } 
     113 
     114   switch (fork()) 
     115   { 
     116      case -1: 
     117         oe_close(CNF(pid_fd[0])); 
     118         oe_close(CNF(pid_fd[1])); 
     119         return -1; 
     120 
     121      // child 
     122      case 0: 
     123         oe_close(CNF(pid_fd[1])); 
     124         if (read(CNF(pid_fd[0]), &c, 1) == -1) 
     125            log_msg(LOG_ERR, "error reading from pid_fd %d: \"%s\"", 
     126                  CNF(pid_fd[0]), strerror(errno)), exit(1); 
     127 
     128         if (unlink(CNF(pid_file)) == -1) 
     129            log_msg(LOG_WARNING, "error deleting pid ]ile \"%s\": \"%s\"", 
     130                  CNF(pid_file), strerror(errno)), exit(1); 
     131         exit(0); 
     132 
     133      // parent 
     134      default: 
     135         oe_close(CNF(pid_fd[0])); 
     136 
     137   } 
     138 
     139   return CNF(pid_fd[1]); 
    111140} 
    112141 
     
    164193         CNF(sig_term) = 1; 
    165194         break; 
     195 
     196      case SIGUSR1: 
     197         CNF(sig_usr1) = 1; 
     198         break; 
    166199   } 
    167200} 
     
    181214   if (sigaction(SIGHUP, &sa, NULL) == -1) 
    182215      log_msg(LOG_ERR, "could not install SIGHUP handler: \"%s\"", strerror(errno)), exit(1); 
     216   if (sigaction(SIGUSR1, &sa, NULL) == -1) 
     217      log_msg(LOG_ERR, "could not install SIGUSR1 handler: \"%s\"", strerror(errno)), exit(1); 
    183218} 
    184219 
     
    187222{ 
    188223   OcatPeer_t *peer, *next; 
     224   char c; 
    189225 
    190226   log_msg(LOG_NOTICE, "waiting for system cleanup..."); 
     
    227263   delete_listeners(CNF(oc_listen), CNF(oc_listen_fd), CNF(oc_listen_cnt)); 
    228264 
    229    if (CNF(create_pid_file) && (unlink(CNF(pid_file)) == -1)) 
    230       log_msg(LOG_ERR, "could not remove pid file \"%s\": %s", CNF(pid_file), strerror(errno)); 
     265   if (CNF(create_pid_file) && (CNF(pid_fd[1]) != -1)) 
     266   { 
     267      if (write(CNF(pid_fd[1]), &c, 1) == -1) 
     268         log_msg(LOG_ERR, "cout not write to pid fd %d: \"%s\"", CNF(pid_fd[1]), strerror(errno)); 
     269   } 
    231270} 
    232271 
  • trunk/src/ocat.h

    r534 r535  
    200200//! RECONN_ATTEMPTS must not be faster than MIN_RECONNECT_TIME 
    201201#define MIN_RECONNECT_TIME 30 
     202//! define default maximum number of concurrent controller sessions 
     203#define MAX_DEF_CTRL_SESS 5 
    202204 
    203205#define MFD_SET(f,s,m) {FD_SET(f, s); m = f > m ? f : m;} 
     
    213215#define VERSION_STRING_LEN 256 
    214216 
     217#define MAX_DEF_CTRL 6 
    215218 
    216219#define NTYPE_TOR 0 
     
    292295   int socksfd[2]; 
    293296   int net_type; 
     297   int max_ctrl, ctrl_active; 
     298   //! pipe filedescriptors for pid deletion process 
     299   int pid_fd[2]; 
     300   int sig_usr1, clear_stats; 
    294301}; 
    295302 
  • trunk/src/ocatctrl.c

    r534 r535  
    7575      //CNF(config_read) = 1; 
    7676   } 
     77 
     78   lock_setup(); 
     79   CNF(ctrl_active)++; 
     80   unlock_setup(); 
    7781 
    7882   fprintf(fo, "%s\n", CNF(version)); 
     
    303307   oe_close(pfd[1]); 
    304308 
     309   lock_setup(); 
     310   CNF(ctrl_active)--; 
     311   unlock_setup(); 
     312 
    305313   return NULL; 
    306314} 
     
    309317int run_ctrl_handler(int fd) 
    310318{ 
     319   // check number of controller sessions 
     320   // FIXME: listener should be closed or acceptor delayed instead of 
     321   // counting after session acceptance. 
     322   lock_setup(); 
     323   if (CNF(ctrl_active) >= CNF(max_ctrl)) 
     324   { 
     325      log_msg(LOG_WARNING, "maximum number of controller sessions reached"); 
     326      oe_close(fd); 
     327      fd = -1; 
     328   } 
     329   unlock_setup(); 
     330   if (fd == -1) 
     331      return -1; 
     332 
    311333   return (int) run_ocat_thread("ctrl_handler", ctrl_handler, (void*) (long) fd); 
    312334} 
  • trunk/src/ocatlibe.c

    r534 r535  
    142142   struct sockaddr_in6 saddr; 
    143143 
    144    if (strsockaddr(buf, &saddr) == -1) 
     144   if (strsockaddr(buf, (struct sockaddr*) &saddr) == -1) 
    145145      log_msg(LOG_EMERG, "could not convert address string '%s'", buf), exit(1); 
    146146 
  • trunk/src/ocatroute.c

    r500 r535  
    631631{ 
    632632   int family; 
    633    int fd; 
     633   int fd, so; 
    634634 
    635635   switch (addr->sa_family) 
     
    652652   } 
    653653 
     654   so = 1;   
     655   if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &so, sizeof(so)) == -1) 
     656      log_msg(LOG_WARNING, "could not set socket %d to SO_REUSEADDR: \"%s\"", fd, strerror(errno)); 
    654657   if (bind(fd, addr, sock_len) == -1) 
    655658   { 
     
    822825               set_term_req(); 
    823826            } 
     827            if (CNF(sig_usr1)) 
     828            { 
     829               lock_setup(); 
     830               CNF(clear_stats) = 1; 
     831               unlock_setup(); 
     832               log_msg(LOG_NOTICE, "stats will be cleared after next stats output"); 
     833            } 
    824834         } 
    825835         log_debug("restarting"); 
     
    965975         stat_wup = act_time; 
    966976         log_msg(LOG_INFO, "stats: ... (not implemented yet)"); 
     977 
     978         lock_setup(); 
     979         if (CNF(clear_stats)) 
     980         { 
     981            CNF(clear_stats) = 0; 
     982            // FIXME: implement stats clearing here 
     983            log_debug("stats cleared"); 
     984         } 
     985         unlock_setup(); 
    967986      } 
    968987 
  • trunk/src/ocatsetup.c

    r534 r535  
    113113   {-1, -1}, 
    114114   // net_type 
    115    NTYPE_TOR 
     115   NTYPE_TOR, 
     116   // max_ctrl, ctrl_active 
     117   MAX_DEF_CTRL_SESS, 0, 
     118   // pid_fd 
     119   {-1, -1}, 
     120   // sig_usr1, clear_stats 
     121   0, 0 
    116122}; 
    117123 
     
    131137   //setup_.logf = stderr; 
    132138   setup_.uptime = time(NULL); 
     139   memset(&socks_dst6_, 0, sizeof(socks_dst6_)); 
     140   setup_.socks_dst->sin_family = AF_INET; 
     141   setup_.socks_dst->sin_addr.s_addr = htonl(INADDR_LOOPBACK); 
     142#ifdef HAVE_SIN_LEN 
     143   setup_.socks_dst->sin_len = SOCKADDR_SIZE(setup_.socks_dst); 
     144#endif 
    133145} 
    134146 
     
    141153   setup_.ocat_ctrl_port = NDESC(ctrl_port); 
    142154 
    143    setup_.socks_dst->sin_family = AF_INET; 
    144    setup_.socks_dst->sin_port = htons(NDESC(socks_port)); 
    145    setup_.socks_dst->sin_addr.s_addr = htonl(INADDR_LOOPBACK); 
    146 #ifdef HAVE_SIN_LEN 
    147    setup_.socks_dst->sin_len = SOCKADDR_SIZE(setup_.socks_dst); 
    148 #endif 
     155   if (!setup_.socks_dst->sin_port) 
     156      setup_.socks_dst->sin_port = htons(NDESC(socks_port)); 
    149157 
    150158   ctrl_listen_.sin_family = AF_INET; 
     
    227235         "term_req               = %d\n" 
    228236         "net_type               = %d (%s)\n" 
     237         "max_ctrl               = %d\n" 
     238         "ctrl_active            = %d\n" 
     239         "pid_fd[2]              = {%d, %d}\n" 
     240         "clear_stats            = %d\n" 
    229241         , 
    230242         IPV4_KEY, ntohl(setup_.fhd_key[IPV4_KEY]), IPV6_KEY, ntohl(setup_.fhd_key[IPV6_KEY]), 
     
    260272         setup_.sizeof_setup, 
    261273         setup_.term_req, 
    262          setup_.net_type, setup_.net_type == NTYPE_TOR ? "NTYPE_TOR" : setup_.net_type == NTYPE_I2P ? "NTYPE_I2P" : "unknown" 
     274         setup_.net_type, setup_.net_type == NTYPE_TOR ? "NTYPE_TOR" : setup_.net_type == NTYPE_I2P ? "NTYPE_I2P" : "unknown", 
     275         setup_.max_ctrl, setup_.ctrl_active, 
     276         setup_.pid_fd[0], setup_.pid_fd[1], 
     277         setup_.clear_stats 
    263278         ); 
    264279 
Note: See TracChangeset for help on using the changeset viewer.