/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-09-03 09:00:31 UTC
  • Revision ID: teddy@recompile.se-20170903090031-zhxw13lca97zuysr
Plymouth plugin bug fix: Actually try the old PID file location

* plugins.d/plymouth.c (get_pid): Try both plymouth_pid and
  plymouth_old_pid, not just plymouth_pid twice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
282
282
  }
283
283
  /* Try the old pid file location */
284
284
  if(proc_id == 0){
285
 
    pidfile = fopen(plymouth_pid, "r");
 
285
    pidfile = fopen(plymouth_old_pid, "r");
286
286
    if(pidfile != NULL){
287
287
      ret = fscanf(pidfile, "%" SCNuMAX, &proc_id);
288
288
      if(ret != 1){
299
299
      error_plus(0, errno, "scandir");
300
300
    }
301
301
    if(ret > 0){
302
 
      ret = sscanf(direntries[0]->d_name, "%" SCNuMAX, &proc_id);
303
 
      if(ret < 0){
304
 
        error_plus(0, errno, "sscanf");
 
302
      for(int i = ret-1; i >= 0; i--){
 
303
        if(proc_id == 0){
 
304
          ret = sscanf(direntries[i]->d_name, "%" SCNuMAX, &proc_id);
 
305
          if(ret < 0){
 
306
            error_plus(0, errno, "sscanf");
 
307
          }
 
308
        }
 
309
        free(direntries[i]);
305
310
      }
306
311
    }
307
312
    /* scandir might preallocate for this variable (man page unclear).
317
322
  return 0;
318
323
}
319
324
 
320
 
const char * const * getargv(pid_t pid){
 
325
char **getargv(pid_t pid){
321
326
  int cl_fd;
322
327
  char *cmdline_filename;
323
328
  ssize_t sret;
384
389
    return NULL;
385
390
  }
386
391
  argz_extract(cmdline, cmdline_len, argv); /* Create argv */
387
 
  return (const char * const *)argv;
 
392
  return argv;
388
393
}
389
394
 
390
395
int main(__attribute__((unused))int argc,
465
470
  }
466
471
  kill_and_wait(plymouth_command_pid);
467
472
  
468
 
  const char * const *plymouthd_argv;
 
473
  char **plymouthd_argv = NULL;
469
474
  pid_t pid = get_pid();
470
475
  if(pid == 0){
471
476
    error_plus(0, 0, "plymouthd pid not found");
472
 
    plymouthd_argv = plymouthd_default_argv;
473
477
  } else {
474
478
    plymouthd_argv = getargv(pid);
475
479
  }
478
482
                       { plymouth_path, "quit", NULL },
479
483
                       false, false);
480
484
  if(not bret){
 
485
    if(plymouthd_argv != NULL){
 
486
      free(*plymouthd_argv);
 
487
      free(plymouthd_argv);
 
488
    }
481
489
    exit(EXIT_FAILURE);
482
490
  }
483
 
  bret = exec_and_wait(NULL, plymouthd_path, plymouthd_argv,
 
491
  bret = exec_and_wait(NULL, plymouthd_path,
 
492
                       (plymouthd_argv != NULL)
 
493
                       ? (const char * const *)plymouthd_argv
 
494
                       : plymouthd_default_argv,
484
495
                       false, true);
 
496
  if(plymouthd_argv != NULL){
 
497
    free(*plymouthd_argv);
 
498
    free(plymouthd_argv);
 
499
  }
485
500
  if(not bret){
486
501
    exit(EXIT_FAILURE);
487
502
  }