You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
654B

  1. /*
  2. * This file is Copyright (c) 2011-2018 by Eckhart Wörner
  3. * SPDX-License-Identifier: BSD-2-clause
  4. */
  5. #include "gpsd_config.h" /* must be before all includes */
  6. #include <limits.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include "sd_socket.h"
  10. int sd_get_socket_count(void) {
  11. unsigned long n;
  12. const char* env;
  13. env = getenv("LISTEN_PID");
  14. if (!env)
  15. return 0;
  16. n = strtoul(env, NULL, 10);
  17. if (n == ULONG_MAX || (pid_t)n != getpid())
  18. return 0;
  19. env = getenv("LISTEN_FDS");
  20. if (!env)
  21. return 0;
  22. n = strtoul(env, NULL, 10);
  23. if (n == ULONG_MAX)
  24. return 0;
  25. return (int)n;
  26. }