/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

  • Committer: Björn Påhlsson
  • Date: 2011-06-23 22:27:15 UTC
  • mto: (237.7.33 trunk)
  • mto: This revision was merged to the branch mainline in revision 284.
  • 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
 
__attribute__((format (gnu_printf, 3, 4)))
79
 
void error_plus(int status, int errnum, const char *formatstring,
80
 
                ...){
 
75
void error_plus(int status, int errnum, const char *formatstring, ...){
81
76
  va_list ap;
82
77
  char *text;
83
78
  int ret;
85
80
  va_start(ap, formatstring);
86
81
  ret = vasprintf(&text, formatstring, ap);
87
82
  if (ret == -1){
88
 
    fprintf(stderr, "Mandos plugin %s: ",
89
 
            program_invocation_short_name);
 
83
    fprintf(stderr, "Mandos plugin %s: ", program_invocation_short_name);
90
84
    vfprintf(stderr, formatstring, ap);
91
85
    fprintf(stderr, ": ");
92
86
    fprintf(stderr, "%s\n", strerror(errnum));
154
148
  return true;
155
149
}
156
150
 
157
 
__attribute__((nonnull (2, 3)))
158
151
bool exec_and_wait(pid_t *pid_return, const char *path,
159
152
                   const char **argv, bool interruptable,
160
153
                   bool daemonize){
214
207
  return false;
215
208
}
216
209
 
217
 
__attribute__((nonnull))
218
210
int is_plymouth(const struct dirent *proc_entry){
219
211
  int ret;
220
212
  {
265
257
 
266
258
pid_t get_pid(void){
267
259
  int ret;
 
260
  FILE *pidfile = fopen(plymouth_pid, "r");
268
261
  uintmax_t maxvalue = 0;
269
 
  FILE *pidfile = fopen(plymouth_pid, "r");
270
 
  /* Try the new pid file location */
271
262
  if(pidfile != NULL){
272
263
    ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
273
264
    if(ret != 1){
275
266
    }
276
267
    fclose(pidfile);
277
268
  }
278
 
  /* Try the old pid file location */
279
 
  if(maxvalue == 0){
280
 
    pidfile = fopen(plymouth_pid, "r");
281
 
    if(pidfile != NULL){
282
 
      ret = fscanf(pidfile, "%" SCNuMAX, &maxvalue);
283
 
      if(ret != 1){
284
 
        maxvalue = 0;
285
 
      }
286
 
      fclose(pidfile);
287
 
    }
288
 
  }
289
 
  /* Look for a plymouth process */
290
269
  if(maxvalue == 0){
291
270
    struct dirent **direntries = NULL;
292
271
    ret = scandir("/proc", &direntries, is_plymouth, alphasort);
300
279
      }
301
280
    }
302
281
    /* scandir might preallocate for this variable (man page unclear).
303
 
       even if ret == 0, therefore we need to free it. */
 
282
       even if ret == 0, we need to free it. */
304
283
    free(direntries);
305
284
  }
306
285
  pid_t pid;