udhcpc_handler.py 721 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python
  2. import json
  3. import sys
  4. from os import environ as env
  5. import posix_ipc
  6. if __name__ != '__main__':
  7. print('You shouldn\'t be importing this script!')
  8. sys.exit(1)
  9. event = {'type': sys.argv[1]}
  10. if event['type'] in ('bound', 'renew'):
  11. if 'ipv6' in env:
  12. event['ip'] = env['ipv6']
  13. else:
  14. event['ip'] = f'{env["ip"]}/{env["mask"]}'
  15. if 'router' in env:
  16. event['gateway'] = env['router']
  17. if 'domain' in env:
  18. event['domain'] = env['domain']
  19. elif event['type'] in ('deconfig', 'leasefail', 'nak'):
  20. pass
  21. else:
  22. event['type'] = 'unknown'
  23. queue = posix_ipc.MessageQueue(env['EVENT_QUEUE'])
  24. queue.send(json.dumps(event))
  25. queue.close()