()
| 96 | |
| 97 | |
| 98 | def _setup_daemon_for_unix_like(): |
| 99 | if not is_admin_user(): |
| 100 | raise Fatal('You must have root privileges (or enable su/sudo) to set the firewall') |
| 101 | |
| 102 | # don't disappear if our controlling terminal or stdout/stderr |
| 103 | # disappears; we still have to clean up. |
| 104 | signal.signal(signal.SIGHUP, signal.SIG_IGN) |
| 105 | signal.signal(signal.SIGPIPE, signal.SIG_IGN) |
| 106 | signal.signal(signal.SIGTERM, firewall_exit) |
| 107 | signal.signal(signal.SIGINT, firewall_exit) |
| 108 | |
| 109 | # Calling setsid() here isn't strictly necessary. However, it forces |
| 110 | # Ctrl+C to get sent to the main sshuttle process instead of to |
| 111 | # the firewall process---which is our preferred way to shutdown. |
| 112 | # Nonetheless, if the firewall process receives a SIGTERM/SIGINT |
| 113 | # signal, it will relay a SIGINT to the main sshuttle process |
| 114 | # automatically. |
| 115 | try: |
| 116 | os.setsid() |
| 117 | except OSError: |
| 118 | # setsid() fails if sudo is configured with the use_pty option. |
| 119 | pass |
| 120 | |
| 121 | return sys.stdin.buffer, sys.stdout.buffer |
| 122 | |
| 123 | |
| 124 | def _setup_daemon_for_windows(): |
nothing calls this directly
no test coverage detected