chiark / gitweb /
Spelling fixes
[elogind.git] / src / python-systemd / daemon.py
1 from ._daemon import (booted,
2                       _listen_fds,
3                       _is_fifo,
4                       _is_socket,
5                       _is_socket_inet,
6                       _is_socket_unix,
7                       _is_mq,
8                       LISTEN_FDS_START)
9 from socket import AF_UNSPEC as _AF_UNSPEC
10
11 def _convert_fileobj(fileobj):
12     try:
13         return fileobj.fileno()
14     except AttributeError:
15         return fileobj
16
17 def is_fifo(fileobj, path=None):
18     fd = _convert_fileobj(fileobj)
19     return _is_fifo(fd, path)
20
21 def is_socket(fileobj, family=_AF_UNSPEC, type=0, listening=-1):
22     fd = _convert_fileobj(fileobj)
23     return _is_socket(fd, family, type, listening)
24
25 def is_socket_inet(fileobj, family=_AF_UNSPEC, type=0, listening=-1, port=0):
26     fd = _convert_fileobj(fileobj)
27     return _is_socket_inet(fd, family, type, listening)
28
29 def is_socket_unix(fileobj, type=0, listening=-1, path=None):
30     fd = _convert_fileobj(fileobj)
31     return _is_socket_unix(fd, type, listening, path)
32
33 def is_mq(fileobj, path=None):
34     fd = _convert_fileobj(fileobj)
35     return _is_mq(fd, path)
36
37 def listen_fds(unset_environment=True):
38     """Return a list of socket activated descriptors
39
40     Example::
41
42       (in primary window)
43       $ systemd-activate -l 2000 python3 -c \\
44           'from systemd.daemon import listen_fds; print(listen_fds())'
45       (in another window)
46       $ telnet localhost 2000
47       (in primary window)
48       ...
49       Execing python3 (...)
50       [3]
51     """
52     num = _listen_fds(unset_environment)
53     return list(range(LISTEN_FDS_START, LISTEN_FDS_START + num))