Skip to content

Commit

Permalink
add pdeathsigger
Browse files Browse the repository at this point in the history
  • Loading branch information
slicklash committed Sep 2, 2024
1 parent c825eb7 commit a5d8045
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions executable.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ RUN if grep -q "CentOS Linux 7" /etc/os-release ; then \
RUN ./node_builder_glibc_env.sh
COPY scripts/build_node_package.sh .
RUN ./build_node_package.sh

COPY scripts/pdeathsigger.c .
RUN gcc -o pdeathsigger pdeathsigger.c

# needed for hadolint
WORKDIR /app
USER 1001
Expand Down Expand Up @@ -261,6 +265,8 @@ COPY --from=async-profiler-builder-musl /tmp/async-profiler/build/lib/libasyncPr
COPY --from=node-package-builder-musl /tmp/module_build gprofiler/resources/node/module/musl
COPY --from=node-package-builder-glibc /tmp/module_build gprofiler/resources/node/module/glibc

COPY --from=node-package-builder-glibc /tmp/pdeathsigger gprofiler/resources/pdeathsigger

COPY --from=burn-builder /tmp/burn/burn gprofiler/resources/burn

COPY gprofiler gprofiler
Expand Down
28 changes: 28 additions & 0 deletions scripts/pdeathsigger.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <signal.h>

/*
preexec_fn is not safe to use in the presence of threads,
child process could deadlock before exec is called.
this little shim is a workaround to avoid using preexe_fn and
still get the desired behavior (PR_SET_PDEATHSIG).
*/
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: %s /path/to/binary [args...]\n", argv[0]);
return 1;
}

if (prctl(PR_SET_PDEATHSIG, SIGKILL) == -1) {
perror("prctl");
return 1;
}

execvp(argv[1], &argv[1]);

perror("execvp");
return 1;
}

0 comments on commit a5d8045

Please sign in to comment.