/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

  • Committer: Björn Påhlsson
  • Date: 2011-06-23 22:27:15 UTC
  • mto: This revision was merged to the branch mainline in revision 485.
  • Revision ID: belorn@fukt.bsnet.se-20110623222715-q5wro9ma9iyjl367
* Makefile (CFLAGS): Added "-lrt" to include real time library.
* plugins.d/mandos-client.c: use scandir(3) instead of readdir(3)
                             Prefix all debug output with "Mandos plugin " + program_invocation_short_name
                             Retry servers that failed to provide password.
                             New option --retry SECONDS that sets the interval between rechecking.
                             --retry also controls how often it retries a server when using --connect.
* plugins.d/splashy.c:  Prefix all debug output with "Mandos plugin " + program_invocation_short_name
* plugins.d/usplash.c: --||--
* plugins.d/askpass-fifo.c: --||--
* plugins.d/password-prompt.c: --||--
* plugins.d/plymouth.c: --||--
* mandos: Lower logger level from warning to info on failed client requests because client was disabled or unknown fingerprint.
* plugins.d/plymouth.c (get_pid): bug fix. Was not calling free on direntries. 

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