# Path: sshuttle/helpers.py
# def debug1(s):
#     if verbose >= 1:
#         log(s)


import socket
import os
from sshuttle.helpers import debug1
"""When sshuttle is run via a systemd service file, we can communicate
to systemd about the status of the sshuttle process. In particular, we
can send READY status to tell systemd that sshuttle has completed
startup and send STOPPING to indicate that sshuttle is beginning
shutdown.

For details, see:
https://www.freedesktop.org/software/systemd/man/sd_notify.html
"""




def _notify(message):
    """Send a notification message to systemd."""
    addr = os.environ.get("NOTIFY_SOCKET", None)

    if not addr or len(addr) == 1 or addr[0] not in ('/', '@'):
        return False

    addr = '\0' + addr[1:] if addr[0] == '@' else addr

    try:
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
    except (OSError, IOError) as e:

# Path: sshuttle/helpers.py
# def debug1(s):
#     if verbose >= 1:
#         log(s)


# Path: sshuttle/sdnotify.py
import socket
import os
from sshuttle.helpers import debug1

"""When sshuttle is run via a systemd service file, we can communicate
to systemd about the status of the sshuttle process. In particular, we
can send READY status to tell systemd that sshuttle has completed
startup and send STOPPING to indicate that sshuttle is beginning
shutdown.

For details, see:
https://www.freedesktop.org/software/systemd/man/sd_notify.html
"""




def _notify(message):
    """Send a notification message to systemd."""
    addr = os.environ.get("NOTIFY_SOCKET", None)

    if not addr or len(addr) == 1 or addr[0] not in ('/', '@'):
        return False

    addr = '\0' + addr[1:] if addr[0] == '@' else addr

    try:
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
    except (OSError, IOError) as e:

        debug1("Error creating socket to notify systemd: %s" % e)