|
21 | 21 | #define BADNESS_PREFER 300
|
22 | 22 | #define BADNESS_AVOID -300
|
23 | 23 |
|
| 24 | +// Buffer size for UID/GID/PID string conversion |
| 25 | +#define UID_BUFSIZ 128 |
| 26 | + |
24 | 27 | static int isnumeric(char* str)
|
25 | 28 | {
|
26 | 29 | int i = 0;
|
@@ -61,6 +64,32 @@ static void notify(const char* summary, const char* body)
|
61 | 64 | exit(1);
|
62 | 65 | }
|
63 | 66 |
|
| 67 | +static void notify_ext(const char* script, const procinfo_t victim) |
| 68 | +{ |
| 69 | + pid_t pid1 = fork(); |
| 70 | + |
| 71 | + if (pid1 == -1) { |
| 72 | + warn("fork() returned -1: %s\n", strerror(errno)); |
| 73 | + return; |
| 74 | + } else if (pid1 != 0) { |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + char pid_str[UID_BUFSIZ]; |
| 79 | + char uid_str[UID_BUFSIZ]; |
| 80 | + |
| 81 | + snprintf(pid_str, UID_BUFSIZ, "%d", victim.pid); |
| 82 | + snprintf(uid_str, UID_BUFSIZ, "%d", victim.uid); |
| 83 | + |
| 84 | + setenv("EARLYOOM_PID", pid_str, 1); |
| 85 | + setenv("EARLYOOM_UID", uid_str, 1); |
| 86 | + setenv("EARLYOOM_NAME", victim.name, 1); |
| 87 | + |
| 88 | + execlp(script, script, NULL); |
| 89 | + warn("notify_ext: exec failed: %s\n", strerror(errno)); |
| 90 | + exit(1); |
| 91 | +} |
| 92 | + |
64 | 93 | /*
|
65 | 94 | * Send the selected signal to "pid" and wait for the process to exit
|
66 | 95 | * (max 10 seconds)
|
@@ -312,6 +341,9 @@ void kill_process(const poll_loop_args_t* args, int sig, const procinfo_t victim
|
312 | 341 | if (args->notify) {
|
313 | 342 | notify("earlyoom", notif_args);
|
314 | 343 | }
|
| 344 | + if (args->notify_ext) { |
| 345 | + notify_ext(args->notify_ext, victim); |
| 346 | + } |
315 | 347 | }
|
316 | 348 |
|
317 | 349 | if (sig == 0) {
|
|
0 commit comments