mirror of
https://github.com/NikitaIvanovV/ctpv.git
synced 2024-11-28 07:23:07 +01:00
2bdeb6aad9
cmd on-quit is not available in the latest lf release (r27)
49 lines
899 B
C
49 lines
899 B
C
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
|
|
int main (int argc, char *argv[])
|
|
{
|
|
if (argc <= 1) {
|
|
fprintf(stderr, "id not given\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
char *pid_s = argv[1];
|
|
|
|
char *endptr;
|
|
|
|
errno = 0;
|
|
long pid = strtol(pid_s, &endptr, 10);
|
|
|
|
if (errno != 0) {
|
|
perror("strtol");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if (endptr == pid_s) {
|
|
fprintf(stderr, "%s: invalid number\n", pid_s);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
while (1) {
|
|
sleep(5);
|
|
|
|
if (kill(pid, 0) == -1) {
|
|
if (errno != ESRCH) {
|
|
perror("kill");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
execlp("ctpv", "ctpv", "-e", pid_s, NULL);
|
|
perror("execlp");
|
|
break;
|
|
}
|
|
}
|
|
|
|
return EXIT_FAILURE;
|
|
}
|