/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: Teddy Hogeborn
  • Date: 2011-12-21 17:09:12 UTC
  • mfrom: (526 trunk)
  • mto: This revision was merged to the branch mainline in revision 527.
  • Revision ID: teddy@recompile.se-20111221170912-tr0v60ul607zhd2q
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
  perror(print_text);
176
176
}
177
177
 
178
 
__attribute__((format (gnu_printf, 2, 3)))
179
178
int fprintf_plus(FILE *stream, const char *format, ...){
180
179
  va_list ap;
181
180
  va_start (ap, format);
203
202
}
204
203
 
205
204
/* Add server to set of servers to retry periodically */
206
 
bool add_server(const char *ip, uint16_t port, AvahiIfIndex if_index,
207
 
                int af){
 
205
int add_server(const char *ip, uint16_t port, AvahiIfIndex if_index,
 
206
               int af){
208
207
  int ret;
209
208
  server *new_server = malloc(sizeof(server));
210
209
  if(new_server == NULL){
211
210
    perror_plus("malloc");
212
 
    return false;
 
211
    return -1;
213
212
  }
214
213
  *new_server = (server){ .ip = strdup(ip),
215
214
                          .port = port,
217
216
                          .af = af };
218
217
  if(new_server->ip == NULL){
219
218
    perror_plus("strdup");
220
 
    return false;
 
219
    return -1;
221
220
  }
222
221
  /* Special case of first server */
223
222
  if (mc.current_server == NULL){
234
233
  ret = clock_gettime(CLOCK_MONOTONIC, &mc.current_server->last_seen);
235
234
  if(ret == -1){
236
235
    perror_plus("clock_gettime");
237
 
    return false;
 
236
    return -1;
238
237
  }
239
 
  return true;
 
238
  return 0;
240
239
}
241
240
 
242
241
/* 
1031
1030
      if(ret == 0){
1032
1031
        avahi_simple_poll_quit(mc.simple_poll);
1033
1032
      } else {
1034
 
        if(not add_server(ip, port, interface,
1035
 
                          avahi_proto_to_af(proto))){
1036
 
          fprintf_plus(stderr, "Failed to add server \"%s\" to server"
1037
 
                       " list\n", name);
1038
 
        }
 
1033
        ret = add_server(ip, port, interface,
 
1034
                         avahi_proto_to_af(proto));
1039
1035
      }
1040
1036
    }
1041
1037
  }
1471
1467
          _exit(EX_OSERR);
1472
1468
        }
1473
1469
        free(delaystring);
1474
 
        if(execl(fullname, direntry->d_name, mode, NULL) == -1){
1475
 
          perror_plus("execl");
1476
 
          _exit(EXIT_FAILURE);
1477
 
        }
 
1470
        ret = execl(fullname, direntry->d_name, mode, NULL);
 
1471
        perror_plus("execl");
1478
1472
      } else {
1479
1473
        int status;
1480
1474
        if(TEMP_FAILURE_RETRY(waitpid(hook_pid, &status, 0)) == -1){
1677
1671
        argp_state_help(state, state->out_stream,
1678
1672
                        ARGP_HELP_USAGE | ARGP_HELP_EXIT_ERR);
1679
1673
      case 'V':                 /* --version */
 
1674
        fprintf_plus(state->out_stream,
 
1675
                     "Mandos plugin mandos-client: ");
1680
1676
        fprintf_plus(state->out_stream, "%s\n", argp_program_version);
1681
1677
        exit(argp_err_exit_status);
1682
1678
        break;