diff --git a/mx_util.h b/mx_util.h index aeb2489..f2adb2f 100644 --- a/mx_util.h +++ b/mx_util.h @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "mx_log.h" @@ -118,6 +120,18 @@ static inline void __mx_fclose(FILE **ptr) { #undef mx_streq_nocase #define mx_streq_nocase(a, b) (strcasecmp((a), (b)) == 0) +#define mx_within_rate_limit_or_return(sec, ret) \ + do {\ + static struct timeval _sleep = {0};\ + struct timeval _now;\ + struct timeval _delta;\ + gettimeofday(&_now, NULL);\ + timersub(&_now, &_sleep, &_delta);\ + if (_delta.tv_sec < (sec))\ + return (ret);\ + _sleep = _now;\ + } while(0) + int mx_strbeginswith(char *str, const char *start, char **endptr); int mx_stribeginswith(char *str, const char *start, char **endptr); int mx_strbeginswithany(char *str, char **starts, char **endptr); diff --git a/mxqd.c b/mxqd.c index 48b5e9b..047b6ed 100644 --- a/mxqd.c +++ b/mxqd.c @@ -1509,6 +1509,11 @@ int killall_over_time(struct mxq_server *server) assert(server); + /* limit killing to every >= 5 minutes */ + mx_within_rate_limit_or_return(5*60, 1); + + mx_log_info("killall_over_time: Sending signals to all jobs running longer than requested."); + gettimeofday(&now, NULL); for (user=server->users; user; user=user->next) { @@ -1906,7 +1911,6 @@ int main(int argc, char *argv[]) killallcancelled(&server, SIGTERM, 0); killallcancelled(&server, SIGINT, 0); killall_over_time(&server); - killall_over_time(&server); mx_log_info("jobs_running=%lu global_sigint_cnt=%d global_sigterm_cnt=%d : Exiting. Wating for jobs to finish. Sleeping for a while.", server.jobs_running, global_sigint_cnt, global_sigterm_cnt);