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