-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix sigint handling when running in helper mode #869
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the only solution is lsof
, we need to add it as a dependency of our packages. Would prefer a more standalone solution if there is a practical/sane one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks much better now 👍
kart/helper.py
Outdated
# Join the process group of the calling process - so that if they get killed, we get killed to. | ||
os.setpgid(0, calling_environment["pid"]) | ||
os.environ["_KART_PGID_SET"] = "1" | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this could catch a more specific exception class (OSError? or one of the subclasses: https://docs.python.org/3/library/exceptions.html#os-exceptions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the possible error codes from setpgid()
are all mapped to subclasses of OSError
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cli_helper/kart.c
Outdated
char *socket_filename = malloc(strlen(getenv("HOME")) + strlen(".kart.1234567890.socket") + 2); | ||
sprintf(socket_filename, "%s/.kart.%d.socket", getenv("HOME"), getsid(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sprintf
is evil 👿
char *socket_filename = malloc(strlen(getenv("HOME")) + strlen(".kart.1234567890.socket") + 2); | |
sprintf(socket_filename, "%s/.kart.%d.socket", getenv("HOME"), getsid(0)); | |
size_t socket_filename_sz = strlen(getenv("HOME")) + strlen("/.kart..socket") + sizeof(pid_t) * 3 + 1; | |
char *socket_filename = malloc(socket_filename_sz); | |
int r = snprintf(socket_filename, socket_filename_sz, "%s/.kart.%d.socket", getenv("HOME"), getsid(0)); | |
if (r < 0 || (size_t) r >= socket_filename_sz) | |
{ | |
fprintf(stderr, "Error allocating socket filename\n"); | |
exit(1); | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after tidyups
tests/test_cli.py
Outdated
@pytest.mark.parametrize("use_helper", [False, True]) | ||
def test_sigint_handling_unix(use_helper, tmp_path): | ||
if is_windows: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pytest.mark.parametrize("use_helper", [False, True]) | |
def test_sigint_handling_unix(use_helper, tmp_path): | |
if is_windows: | |
return | |
@pytest.mark.skipif(os.name == "nt") | |
@pytest.mark.parametrize("use_helper", [False, True]) | |
def test_sigint_handling_unix(use_helper, tmp_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
kart/helper.py
Outdated
# Join the process group of the calling process - so that if they get killed, we get killed to. | ||
os.setpgid(0, calling_environment["pid"]) | ||
os.environ["_KART_PGID_SET"] = "1" | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except Exception as e: | |
except OSError as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Description
If kart.c receives a SIGINT while its waiting for python kart_cli, we need to SIGINT python kart_cli too.