version 1.135, 2012/12/14 11:10:03 |
version 1.136, 2015/07/28 14:22:26 |
|
|
static void notice_signal(int); |
static void notice_signal(int); |
static void setup_all_signals(void); |
static void setup_all_signals(void); |
static const char *really_kill(Job *, int); |
static const char *really_kill(Job *, int); |
static void kill_with_sudo_maybe(pid_t, int, const char *); |
static void kill_with_doas_maybe(pid_t, int, const char *); |
static void debug_kill_printf(const char *, ...); |
static void debug_kill_printf(const char *, ...); |
static void debug_vprintf(const char *, va_list); |
static void debug_vprintf(const char *, va_list); |
static void may_remove_target(Job *); |
static void may_remove_target(Job *); |
|
|
const char * basedirectory = NULL; |
const char * basedirectory = NULL; |
|
|
static void |
static void |
kill_with_sudo_maybe(pid_t pid, int signo, const char *p) |
kill_with_doas_maybe(pid_t pid, int signo, const char *p) |
{ |
{ |
char buf[32]; /* largely enough */ |
char buf[32]; /* largely enough */ |
|
int sudo; |
|
|
for (;*p != '\0'; p++) { |
for (;*p != '\0'; p++) { |
if (*p != 's') |
if (*p == 's') |
|
sudo = 1; |
|
else if (*p == 'd') |
|
sudo = 0; |
|
else |
continue; |
continue; |
if (p[1] != 'u') |
if (sudo && p[1] != 'u' || !sudo && p[1] != 'o') |
continue; |
continue; |
p++; |
p++; |
if (p[1] != 'd') |
if (sudo && p[1] != 'd' || !sudo && p[1] != 'a') |
continue; |
continue; |
p++; |
p++; |
if (p[1] != 'o') |
if (sudo && p[1] != 'o' || !sudo && p[1] != 's') |
continue; |
continue; |
snprintf(buf, sizeof buf, "sudo -n /bin/kill -%d %ld", |
snprintf(buf, sizeof buf, "%s -n /bin/kill -%d %ld", |
|
sudo ? "sudo" : "doas", |
signo, (long)pid); |
signo, (long)pid); |
debug_kill_printf("trying to kill with %s", buf); |
debug_kill_printf("trying to kill with %s", buf); |
system(buf); |
system(buf); |
|
|
job->flags |= JOB_LOST; |
job->flags |= JOB_LOST; |
return "not found"; |
return "not found"; |
} else if (errno == EPERM) { |
} else if (errno == EPERM) { |
kill_with_sudo_maybe(pid, signo, job->cmd); |
kill_with_doas_maybe(pid, signo, job->cmd); |
return ""; |
return ""; |
} else |
} else |
return "should not happen"; |
return "should not happen"; |