/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/plymouth.c

* network-hooks.d: New directory.
* network-hooks.d/bridge: New example hook.
* network-hooks.d/bridge.conf: Config file for bridge example hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Plymouth - Read a password from Plymouth and output it
4
4
 * 
5
 
 * Copyright © 2010-2012 Teddy Hogeborn
6
 
 * Copyright © 2010-2012 Björn Påhlsson
 
5
 * Copyright © 2010-2011 Teddy Hogeborn
 
6
 * Copyright © 2010-2011 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
75
75
}
76
76
 
77
77
/* Function to use when printing errors */
78
 
__attribute__((format (gnu_printf, 3, 4)))
79
78
void error_plus(int status, int errnum, const char *formatstring,
80
79
                ...){
81
80
  va_list ap;
154
153
  return true;
155
154
}
156
155
 
157
 
__attribute__((nonnull (2, 3)))
158
156
bool exec_and_wait(pid_t *pid_return, const char *path,
159
157
                   const char **argv, bool interruptable,
160
158
                   bool daemonize){
214
212
  return false;
215
213
}
216
214
 
217
 
__attribute__((nonnull))
218
215
int is_plymouth(const struct dirent *proc_entry){
219
216
  int ret;
220
217
  {
221
 
    uintmax_t proc_id;
 
218
    uintmax_t maxvalue;
222
219
    char *tmp;
223
220
    errno = 0;
224
 
    proc_id = strtoumax(proc_entry->d_name, &tmp, 10);
 
221
    maxvalue = strtoumax(proc_entry->d_name, &tmp, 10);
225
222
 
226
223
    if(errno != 0 or *tmp != '\0'
227
 
       or proc_id != (uintmax_t)((pid_t)proc_id)){
 
224
       or maxvalue != (uintmax_t)((pid_t)maxvalue)){
228
225
      return 0;
229
226
    }
230
227
  }
265
262
 
266
263
pid_t get_pid(void){
267
264
  int ret;
268
 
  uintmax_t proc_id = 0;
 
265
  uintmax_t maxvalue = 0;
269
266
  FILE *pidfile = fopen(plymouth_pid, "r");
270
267
  /* Try the new pid file location */
271
268
  if(pidfile != NULL){
272
 
    ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
 
269
    ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
273
270
    if(ret != 1){
274
 
      proc_id = 0;
 
271
      maxvalue = 0;
275
272
    }
276
273
    fclose(pidfile);
277
274
  }
278
275
  /* Try the old pid file location */
279
 
  if(proc_id == 0){
 
276
  if(maxvalue == 0){
280
277
    pidfile = fopen(plymouth_pid, "r");
281
278
    if(pidfile != NULL){
282
 
      ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
 
279
      ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
283
280
      if(ret != 1){
284
 
        proc_id = 0;
 
281
        maxvalue = 0;
285
282
      }
286
283
      fclose(pidfile);
287
284
    }
288
285
  }
289
286
  /* Look for a plymouth process */
290
 
  if(proc_id == 0){
 
287
  if(maxvalue == 0){
291
288
    struct dirent **direntries = NULL;
292
289
    ret = scandir("/proc", &direntries, is_plymouth, alphasort);
293
290
    if (ret == -1){
294
291
      error_plus(0, errno, "scandir");
295
292
    }
296
293
    if (ret > 0){
297
 
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &proc_id);
 
294
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &maxvalue);
298
295
      if (ret < 0){
299
296
        error_plus(0, errno, "sscanf");
300
297
      }
304
301
    free(direntries);
305
302
  }
306
303
  pid_t pid;
307
 
  pid = (pid_t)proc_id;
308
 
  if((uintmax_t)pid == proc_id){
 
304
  pid = (pid_t)maxvalue;
 
305
  if((uintmax_t)pid == maxvalue){
309
306
    return pid;
310
307
  }
311
308