Send a notification message to systemd.
(message)
| 15 | |
| 16 | |
| 17 | def _notify(message): |
| 18 | """Send a notification message to systemd.""" |
| 19 | addr = os.environ.get("NOTIFY_SOCKET", None) |
| 20 | |
| 21 | if not addr or len(addr) == 1 or addr[0] not in ('/', '@'): |
| 22 | return False |
| 23 | |
| 24 | addr = '\0' + addr[1:] if addr[0] == '@' else addr |
| 25 | |
| 26 | try: |
| 27 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) |
| 28 | except (OSError, IOError) as e: |
| 29 | debug1("Error creating socket to notify systemd: %s" % e) |
| 30 | return False |
| 31 | |
| 32 | if not message: |
| 33 | return False |
| 34 | |
| 35 | assert isinstance(message, bytes) |
| 36 | |
| 37 | try: |
| 38 | return (sock.sendto(message, addr) > 0) |
| 39 | except (OSError, IOError) as e: |
| 40 | debug1("Error notifying systemd: %s" % e) |
| 41 | return False |
| 42 | |
| 43 | |
| 44 | def send(*messages): |