Specifically on Mac OS X, is it possible to make a program ignore SIGTERM via DYLD_INSERT_LIBRARIES, in a way which works for any or most programs?
I tried compiling and inserting this:
#include<stdio.h>
#include<signal.h>
#include<unistd.h>
void sig_handler(int signo)
{
if (signo == SIGTERM)
printf("received SIGTERM\n");
}
int main(void)
{
signal(SIGTERM, sig_handler);
return 0;
}
However,
DYLD_INSERT_LIBRARIES=libignore.dylib sleep 60
was able to be kill -15'd without issue.
You can create an executable that sets the action for SIGTERM
to SIG_IGN
and then execvp()
the program you would like to run with that signal ignored:
Signals set to the default action (SIG_DFL) in the calling process image shall be set to the default action in the new process image. Except for SIGCHLD, signals set to be ignored (SIG_IGN) by the calling process image shall be set to be ignored by the new process image. Signals set to be caught by the calling process image shall be set to the default action in the new process image
You can do that even with bash:
#!/bin/bash
# no-sigterm.sh
trap "" SIGTERM
exec "$@"
And then:
no-sigterm.sh sleep 60