diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-03-05 00:40:32 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-03-05 00:40:32 -0600 |
| commit | 5dc85e72a002efce36b440a98b17a6c80234a142 (patch) | |
| tree | 11f0d3af31b88c079d1598a5842dc47d9e024aa9 /pkgs/tmux-lift/unlift.c | |
| parent | 743a205dd9bff31e0ed63ebba8dd3327614ac188 (diff) | |
Restructure flake source hierarchy
Diffstat (limited to 'pkgs/tmux-lift/unlift.c')
| -rw-r--r-- | pkgs/tmux-lift/unlift.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/pkgs/tmux-lift/unlift.c b/pkgs/tmux-lift/unlift.c new file mode 100644 index 0000000..d8d3a72 --- /dev/null +++ b/pkgs/tmux-lift/unlift.c @@ -0,0 +1,41 @@ +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <signal.h> +#include <unistd.h> +#include <sys/types.h> + + +#include "lift.h" + + +int main +( + int argc, + const char* argv[] +) +{ + char* formatted_pid = getenv( LIFT_PID_ENV ); + if( formatted_pid == NULL ) + { + fprintf( stderr, "%s: variable " LIFT_PID_ENV " is not set\n", argv[ 0 ] ); + return EXIT_FAILURE; + } + + char* formatted_end; + long pid = strtol( formatted_pid, &formatted_end, 10 ); + if( *formatted_pid == '\0' || *formatted_end != '\0' ) + { + fprintf( stderr, "%s: invalid value for " LIFT_PID_ENV ": %s\n", argv[ 0 ], formatted_pid ); + return EXIT_FAILURE; + } + + if( kill( (pid_t)pid, SIGTERM ) < 0 ) + { + fprintf( stderr, "kill(%ld): %s\n", pid, strerror( errno ) ); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} |
