/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/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:
19
19
 * along with this program.  If not, see
20
20
 * <http://www.gnu.org/licenses/>.
21
21
 * 
22
 
 * Contact the authors at <mandos@fukt.bsnet.se>.
 
22
 * Contact the authors at <mandos@recompile.se>.
23
23
 */
24
24
 
25
25
#define _GNU_SOURCE             /* asprintf(), TEMP_FAILURE_RETRY() */
36
36
#include <stddef.h>             /* NULL */
37
37
#include <string.h>             /* strchr(), memcmp() */
38
38
#include <stdio.h>              /* asprintf(), perror(), fopen(),
39
 
                                   fscanf(), vasprintf(), fprintf(), vfprintf() */
 
39
                                   fscanf(), vasprintf(), fprintf(),
 
40
                                   vfprintf() */
40
41
#include <unistd.h>             /* close(), readlink(), read(),
41
42
                                   fork(), setsid(), chdir(), dup2(),
42
43
                                   STDERR_FILENO, execv(), access() */
53
54
#include <stdarg.h>             /* va_list, va_start(), ... */
54
55
 
55
56
sig_atomic_t interrupted_by_signal = 0;
56
 
const char plymouth_pid[] = "/dev/.initramfs/plymouth.pid";
 
57
 
 
58
/* Used by Ubuntu 11.04 (Natty Narwahl) */
 
59
const char plymouth_old_pid[] = "/dev/.initramfs/plymouth.pid";
 
60
/* Used by Ubuntu 11.10 (Oneiric Ocelot) */
 
61
const char plymouth_pid[] = "/run/initramfs/plymouth.pid";
 
62
 
57
63
const char plymouth_path[] = "/bin/plymouth";
58
64
const char plymouthd_path[] = "/sbin/plymouthd";
59
65
const char *plymouthd_default_argv[] = {"/sbin/plymouthd",
60
66
                                        "--mode=boot",
61
67
                                        "--attach-to-session",
62
 
                                        "--pid-file="
63
 
                                        "/dev/.initramfs/"
64
 
                                        "plymouth.pid",
65
68
                                        NULL };
66
69
 
67
70
static void termination_handler(__attribute__((unused))int signum){
72
75
}
73
76
 
74
77
/* Function to use when printing errors */
75
 
void error_plus(int status, int errnum, const char *formatstring, ...){
 
78
void error_plus(int status, int errnum, const char *formatstring,
 
79
                ...){
76
80
  va_list ap;
77
81
  char *text;
78
82
  int ret;
80
84
  va_start(ap, formatstring);
81
85
  ret = vasprintf(&text, formatstring, ap);
82
86
  if (ret == -1){
83
 
    fprintf(stderr, "Mandos plugin %s: ", program_invocation_short_name);
 
87
    fprintf(stderr, "Mandos plugin %s: ",
 
88
            program_invocation_short_name);
84
89
    vfprintf(stderr, formatstring, ap);
85
90
    fprintf(stderr, ": ");
86
91
    fprintf(stderr, "%s\n", strerror(errnum));
257
262
 
258
263
pid_t get_pid(void){
259
264
  int ret;
 
265
  uintmax_t maxvalue = 0;
260
266
  FILE *pidfile = fopen(plymouth_pid, "r");
261
 
  uintmax_t maxvalue = 0;
 
267
  /* Try the new pid file location */
262
268
  if(pidfile != NULL){
263
269
    ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
264
270
    if(ret != 1){
266
272
    }
267
273
    fclose(pidfile);
268
274
  }
 
275
  /* Try the old pid file location */
 
276
  if(maxvalue == 0){
 
277
    pidfile = fopen(plymouth_pid, "r");
 
278
    if(pidfile != NULL){
 
279
      ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
 
280
      if(ret != 1){
 
281
        maxvalue = 0;
 
282
      }
 
283
      fclose(pidfile);
 
284
    }
 
285
  }
 
286
  /* Look for a plymouth process */
269
287
  if(maxvalue == 0){
270
288
    struct dirent **direntries = NULL;
271
289
    ret = scandir("/proc", &direntries, is_plymouth, alphasort);
279
297
      }
280
298
    }
281
299
    /* scandir might preallocate for this variable (man page unclear).
282
 
       even if ret == 0, we need to free it. */
 
300
       even if ret == 0, therefore we need to free it. */
283
301
    free(direntries);
284
302
  }
285
303
  pid_t pid;