/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

  • Committer: Björn Påhlsson
  • Date: 2011-07-25 18:46:19 UTC
  • mfrom: (487 trunk)
  • mto: This revision was merged to the branch mainline in revision 489.
  • Revision ID: belorn@fukt.bsnet.se-20110725184619-l7vfsobr0bh9fc3l
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
  return buffer_capacity;
188
188
}
189
189
 
190
 
/* Add server to set of servers to retry periodically */
191
190
int add_server(const char *ip, uint16_t port,
192
191
                 AvahiIfIndex if_index,
193
192
                 int af){
205
204
    perror_plus("strdup");
206
205
    return -1;
207
206
  }
208
 
  /* Special case of first server */
 
207
  /* unique case of first server */
209
208
  if (mc.current_server == NULL){
210
209
    new_server->next = new_server;
211
210
    new_server->prev = new_server;
212
211
    mc.current_server = new_server;
213
 
  /* Place the new server last in the list */
 
212
  /* Placing the new server last in the list */
214
213
  } else {
215
214
    new_server->next = mc.current_server;
216
215
    new_server->prev = mc.current_server->prev;
1206
1205
  struct timespec now;
1207
1206
  struct timespec waited_time;
1208
1207
  intmax_t block_time;
1209
 
  
 
1208
 
1210
1209
  while(true){
1211
1210
    if(mc.current_server == NULL){
1212
1211
      if (debug){
1237
1236
      block_time = ((retry_interval
1238
1237
                     - ((intmax_t)waited_time.tv_sec * 1000))
1239
1238
                    - ((intmax_t)waited_time.tv_nsec / 1000000));
1240
 
      
 
1239
 
1241
1240
      if (debug){
1242
 
        fprintf(stderr, "Blocking for %" PRIdMAX " ms\n", block_time);
 
1241
        fprintf(stderr, "Blocking for %ld ms\n", block_time);
1243
1242
      }
1244
 
      
 
1243
 
1245
1244
      if(block_time <= 0){
1246
1245
        ret = start_mandos_communication(mc.current_server->ip,
1247
1246
                                         mc.current_server->port,
1412
1411
        errno = 0;
1413
1412
        retry_interval = strtod(arg, &tmp);
1414
1413
        if(errno != 0 or tmp == arg or *tmp != '\0'
1415
 
           or (retry_interval * 1000) > INT_MAX
1416
 
           or retry_interval < 0){
 
1414
           or (retry_interval * 1000) > INT_MAX){
1417
1415
          argp_error(state, "Bad retry interval");
1418
1416
        }
1419
1417
        break;
1831
1829
    
1832
1830
    port = (uint16_t)tmpmax;
1833
1831
    *address = '\0';
 
1832
    address = connect_to;
1834
1833
    /* Colon in address indicates IPv6 */
1835
1834
    int af;
1836
 
    if(strchr(connect_to, ':') != NULL){
 
1835
    if(strchr(address, ':') != NULL){
1837
1836
      af = AF_INET6;
1838
 
      /* Accept [] around IPv6 address - see RFC 5952 */
1839
 
      if(connect_to[0] == '[' and address[-1] == ']')
1840
 
        {
1841
 
          connect_to++;
1842
 
          address[-1] = '\0';
1843
 
        }
1844
1837
    } else {
1845
1838
      af = AF_INET;
1846
1839
    }
1847
 
    address = connect_to;
1848
1840
    
1849
1841
    if(quit_now){
1850
1842
      goto end;
1851
1843
    }
1852
 
    
 
1844
 
1853
1845
    while(not quit_now){
1854
1846
      ret = start_mandos_communication(address, port, if_index, af);
1855
1847
      if(quit_now or ret == 0){
1856
1848
        break;
1857
1849
      }
1858
 
      if(debug){
1859
 
        fprintf(stderr, "Retrying in %d seconds\n",
1860
 
                (int)retry_interval);
1861
 
      }
1862
 
      sleep((int)retry_interval);
 
1850
      sleep((int)retry_interval or 1);
1863
1851
    };
1864
1852
 
1865
1853
    if (not quit_now){