/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: Teddy Hogeborn
  • Date: 2018-02-06 19:49:19 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 362.
  • Revision ID: teddy@recompile.se-20180206194919-rfmlt49naz5jnpfx
Fix Python 3 issue

* (mandos/MandosServer.handle_ipc): Decode bytes into string.

Show diffs side-by-side

added added

removed removed

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