File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 15
15
CONTROL_CHARS = dict .fromkeys (range (32 ))
16
16
17
17
18
+ def get_systemd_socket ():
19
+ """Attempt to get a socket from systemd."""
20
+ fdnames = os .environ .get ("LISTEN_FDNAMES" , "" ).split (":" )
21
+ if "mpd" not in fdnames :
22
+ return None
23
+ fd = fdnames .index ("mpd" ) + 3 # 3 is the first systemd file handle
24
+ return socket .socket (fileno = fd )
25
+
26
+
18
27
def get_unix_socket_path (socket_path ):
19
28
match = re .search ("^unix:(.*)" , socket_path )
20
29
if not match :
@@ -122,6 +131,10 @@ def __init__(
122
131
self .watcher = self .register_server_socket (self .server_socket .fileno ())
123
132
124
133
def create_server_socket (self , host , port ):
134
+ sock = get_systemd_socket ()
135
+ if sock is not None :
136
+ return sock
137
+
125
138
socket_path = get_unix_socket_path (host )
126
139
if socket_path is not None : # host is a path so use unix socket
127
140
sock = create_unix_socket ()
You can’t perform that action at this time.
0 commit comments