]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #6975 from sourcejedi/logind_pid_0_v2
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 4 Oct 2017 19:33:52 +0000 (21:33 +0200)
committerGitHub <noreply@github.com>
Wed, 4 Oct 2017 19:33:52 +0000 (21:33 +0200)
Selectively revert "tree-wide: use pid_is_valid() at more places"

1  2 
src/basic/process-util.c
src/systemctl/systemctl.c

diff --combined src/basic/process-util.c
index b1cdc4257d59dc5c1a3c7fb3ab0b65ceb4abd9b4,44ebf49f90db777370c79a1748c37aef46f9441e..99b0946a0375d9db8d95e872d1404300380f30f1
@@@ -34,7 -34,7 +34,7 @@@
  #include <sys/wait.h>
  #include <syslog.h>
  #include <unistd.h>
 -#ifdef HAVE_VALGRIND_VALGRIND_H
 +#if HAVE_VALGRIND_VALGRIND_H
  #include <valgrind/valgrind.h>
  #endif
  
@@@ -392,7 -392,7 +392,7 @@@ int is_kernel_thread(pid_t pid) 
          bool eof;
          FILE *f;
  
 -        if (pid == 0 || pid == 1 || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a kernel thread */
 +        if (IN_SET(pid, 0, 1) || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a kernel thread */
                  return 0;
  
          assert(pid > 1);
@@@ -475,7 -475,7 +475,7 @@@ static int get_process_id(pid_t pid, co
          assert(field);
          assert(uid);
  
-         if (!pid_is_valid(pid))
+         if (pid < 0)
                  return -EINVAL;
  
          p = procfs_file_alloca(pid, "status");
@@@ -787,7 -787,7 +787,7 @@@ int getenv_for_pid(pid_t pid, const cha
  bool pid_is_unwaited(pid_t pid) {
          /* Checks whether a PID is still valid at all, including a zombie */
  
-         if (!pid_is_valid(pid))
+         if (pid < 0)
                  return false;
  
          if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */
@@@ -807,7 -807,7 +807,7 @@@ bool pid_is_alive(pid_t pid) 
  
          /* Checks whether a PID is still valid and not a zombie */
  
-         if (!pid_is_valid(pid))
+         if (pid < 0)
                  return false;
  
          if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */
                  return true;
  
          r = get_process_state(pid);
 -        if (r == -ESRCH || r == 'Z')
 +        if (IN_SET(r, -ESRCH, 'Z'))
                  return false;
  
          return true;
  int pid_from_same_root_fs(pid_t pid) {
          const char *root;
  
-         if (!pid_is_valid(pid))
+         if (pid < 0)
                  return false;
  
          if (pid == 0 || pid == getpid_cached())
@@@ -945,7 -945,7 +945,7 @@@ int opinionated_personality(unsigned lo
  }
  
  void valgrind_summary_hack(void) {
 -#ifdef HAVE_VALGRIND_VALGRIND_H
 +#if HAVE_VALGRIND_VALGRIND_H
          if (getpid_cached() == 1 && RUNNING_ON_VALGRIND) {
                  pid_t pid;
                  pid = raw_clone(SIGCHLD);
index 280d786daa422a08e7a996b03dbaf680e70086c5,ca03fb49fbd6c4de088669b11453c5c16d99b2e0..8d90850a5300c3d2e65cf18426f820e9e1ec5a01
@@@ -3219,7 -3219,7 +3219,7 @@@ static int start_unit(int argc, char *a
          return r;
  }
  
 -#ifdef ENABLE_LOGIND
 +#if ENABLE_LOGIND
  static int logind_set_wall_message(void) {
          _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
          sd_bus *bus;
  /* Ask systemd-logind, which might grant access to unprivileged users
   * through PolicyKit */
  static int logind_reboot(enum action a) {
 -#ifdef ENABLE_LOGIND
 +#if ENABLE_LOGIND
          _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
          const char *method, *description;
          sd_bus *bus;
  }
  
  static int logind_check_inhibitors(enum action a) {
 -#ifdef ENABLE_LOGIND
 +#if ENABLE_LOGIND
          _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
          _cleanup_strv_free_ char **sessions = NULL;
          const char *what, *who, *why, *mode;
                          return log_oom();
  
                  if (!pid_is_valid((pid_t) pid)) {
-                         log_error("Invalid PID %" PRIu32 ".", pid);
+                         log_error("Invalid PID "PID_FMT".", (pid_t) pid);
                          return -ERANGE;
                  }
  
  }
  
  static int logind_prepare_firmware_setup(void) {
 -#ifdef ENABLE_LOGIND
 +#if ENABLE_LOGIND
          _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
          sd_bus *bus;
          int r;
@@@ -5903,7 -5903,7 +5903,7 @@@ static int import_environment(int argc
  static int enable_sysv_units(const char *verb, char **args) {
          int r = 0;
  
 -#if defined(HAVE_SYSV_COMPAT)
 +#if HAVE_SYSV_COMPAT
          _cleanup_lookup_paths_free_ LookupPaths paths = {};
          unsigned f = 0;
  
@@@ -7815,7 -7815,7 +7815,7 @@@ static int halt_parse_argv(int argc, ch
          assert(argv);
  
          if (utmp_get_runlevel(&runlevel, NULL) >= 0)
 -                if (runlevel == '0' || runlevel == '6')
 +                if (IN_SET(runlevel, '0', '6'))
                          arg_force = 2;
  
          while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0)
@@@ -8211,7 -8211,7 +8211,7 @@@ static int parse_argv(int argc, char *a
          return systemctl_parse_argv(argc, argv);
  }
  
 -#ifdef HAVE_SYSV_COMPAT
 +#if HAVE_SYSV_COMPAT
  _pure_ static int action_to_runlevel(void) {
  
          static const char table[_ACTION_MAX] = {
  #endif
  
  static int talk_initctl(void) {
 -#ifdef HAVE_SYSV_COMPAT
 +#if HAVE_SYSV_COMPAT
          struct init_request request = {
                  .magic = INIT_MAGIC,
                  .sleeptime  = 0,
@@@ -8426,7 -8426,7 +8426,7 @@@ static int halt_now(enum action a) 
  
  static int logind_schedule_shutdown(void) {
  
 -#ifdef ENABLE_LOGIND
 +#if ENABLE_LOGIND
          _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
          char date[FORMAT_TIMESTAMP_MAX];
          const char *action;
@@@ -8555,7 -8555,7 +8555,7 @@@ static int runlevel_main(void) 
  }
  
  static int logind_cancel_shutdown(void) {
 -#ifdef ENABLE_LOGIND
 +#if ENABLE_LOGIND
          _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
          sd_bus *bus;
          int r;