/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: Teddy Hogeborn
  • Date: 2017-08-20 16:20:54 UTC
  • Revision ID: teddy@recompile.se-20170820162054-jwig602syxx2k4l0
Alter copyright notices slightly.  Actual license is unchanged!

This alters all copyright notices to use the Free Software
Foundation's recommendations for license notices; from
<https://www.gnu.org/licenses/gpl-howto.html>:

  For programs that are more than one file, it is better to replace
  “this program” with the name of the program, and begin the statement
  with a line saying “This file is part of NAME”.

* DBUS-API: Use program name "Mandos" explicitly in license notice.
* debian/copyright: - '' -
* initramfs-unpack: - '' -
* legalnotice.xml: - '' -
* mandos: - '' -
* mandos-ctl: - '' -
* mandos-keygen: - '' -
* mandos-monitor: - '' -
* plugin-helpers/mandos-client-iprouteadddel.c: - '' -
* plugin-runner.c: - '' -
* plugins.d/askpass-fifo.c: - '' -
* plugins.d/mandos-client.c: - '' -
* plugins.d/password-prompt.c: - '' -
* plugins.d/plymouth.c: - '' -
* plugins.d/splashy.c: - '' -
* plugins.d/usplash.c: - '' -

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-2018 Teddy Hogeborn
6
 
 * Copyright © 2010-2018 Björn Påhlsson
 
5
 * Copyright © 2010-2017 Teddy Hogeborn
 
6
 * Copyright © 2010-2017 Björn Påhlsson
7
7
 * 
8
8
 * This file is part of Mandos.
9
9
 * 
57
57
sig_atomic_t interrupted_by_signal = 0;
58
58
 
59
59
/* Used by Ubuntu 11.04 (Natty Narwahl) */
60
 
const char plymouth_old_old_pid[] = "/dev/.initramfs/plymouth.pid";
 
60
const char plymouth_old_pid[] = "/dev/.initramfs/plymouth.pid";
61
61
/* Used by Ubuntu 11.10 (Oneiric Ocelot) */
62
 
const char plymouth_old_pid[] = "/run/initramfs/plymouth.pid";
63
 
/* Used by Debian 9 (stretch) */
64
 
const char plymouth_pid[] = "/run/plymouth/pid";
 
62
const char plymouth_pid[] = "/run/initramfs/plymouth.pid";
65
63
 
66
64
const char plymouth_path[] = "/bin/plymouth";
67
65
const char plymouthd_path[] = "/sbin/plymouthd";
284
282
  }
285
283
  /* Try the old pid file location */
286
284
  if(proc_id == 0){
287
 
    pidfile = fopen(plymouth_old_pid, "r");
288
 
    if(pidfile != NULL){
289
 
      ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
290
 
      if(ret != 1){
291
 
        proc_id = 0;
292
 
      }
293
 
      fclose(pidfile);
294
 
    }
295
 
  }
296
 
  /* Try the old old pid file location */
297
 
  if(proc_id == 0){
298
 
    pidfile = fopen(plymouth_old_old_pid, "r");
 
285
    pidfile = fopen(plymouth_pid, "r");
299
286
    if(pidfile != NULL){
300
287
      ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
301
288
      if(ret != 1){
312
299
      error_plus(0, errno, "scandir");
313
300
    }
314
301
    if(ret > 0){
315
 
      for(int i = ret-1; i >= 0; i--){
316
 
        if(proc_id == 0){
317
 
          ret = sscanf(direntries[i]->d_name, "%" SCNuMAX, &proc_id);
318
 
          if(ret < 0){
319
 
            error_plus(0, errno, "sscanf");
320
 
          }
321
 
        }
322
 
        free(direntries[i]);
 
302
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &proc_id);
 
303
      if(ret < 0){
 
304
        error_plus(0, errno, "sscanf");
323
305
      }
324
306
    }
325
307
    /* scandir might preallocate for this variable (man page unclear).
335
317
  return 0;
336
318
}
337
319
 
338
 
char **getargv(pid_t pid){
 
320
const char * const * getargv(pid_t pid){
339
321
  int cl_fd;
340
322
  char *cmdline_filename;
341
323
  ssize_t sret;
402
384
    return NULL;
403
385
  }
404
386
  argz_extract(cmdline, cmdline_len, argv); /* Create argv */
405
 
  return argv;
 
387
  return (const char * const *)argv;
406
388
}
407
389
 
408
390
int main(__attribute__((unused))int argc,
483
465
  }
484
466
  kill_and_wait(plymouth_command_pid);
485
467
  
486
 
  char **plymouthd_argv = NULL;
 
468
  const char * const *plymouthd_argv;
487
469
  pid_t pid = get_pid();
488
470
  if(pid == 0){
489
471
    error_plus(0, 0, "plymouthd pid not found");
 
472
    plymouthd_argv = plymouthd_default_argv;
490
473
  } else {
491
474
    plymouthd_argv = getargv(pid);
492
475
  }
495
478
                       { plymouth_path, "quit", NULL },
496
479
                       false, false);
497
480
  if(not bret){
498
 
    if(plymouthd_argv != NULL){
499
 
      free(*plymouthd_argv);
500
 
      free(plymouthd_argv);
501
 
    }
502
481
    exit(EXIT_FAILURE);
503
482
  }
504
 
  bret = exec_and_wait(NULL, plymouthd_path,
505
 
                       (plymouthd_argv != NULL)
506
 
                       ? (const char * const *)plymouthd_argv
507
 
                       : plymouthd_default_argv,
 
483
  bret = exec_and_wait(NULL, plymouthd_path, plymouthd_argv,
508
484
                       false, true);
509
 
  if(plymouthd_argv != NULL){
510
 
    free(*plymouthd_argv);
511
 
    free(plymouthd_argv);
512
 
  }
513
485
  if(not bret){
514
486
    exit(EXIT_FAILURE);
515
487
  }