/mandos/release

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

« back to all changes in this revision

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

* initramfs-tools-hook: Set DEVICE for network hooks.

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