/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-12-26 15:23:45 UTC
  • Revision ID: belorn@recompile.se-20111226152345-cd9mz98e7eiqbfbx
nicer stacktrace when mandos-monitor fail during startup

Show diffs side-by-side

added added

removed removed

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