sd_socket.c 731 B

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