diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index 11bd8ccdf..47f6ff3cd 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -24,6 +24,8 @@ __BEGIN_DECLS int killProcessGroup(uid_t uid, int initialPid, int signal); +int killProcessGroupOnce(uid_t uid, int initialPid, int signal); + int createProcessGroup(uid_t uid, int initialPid); void removeAllProcessGroups(void); diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index eb6672762..1572cb312 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -252,8 +252,7 @@ void removeAllProcessGroups() } } -static int killProcessGroupOnce(uid_t uid, int initialPid, int signal) -{ +static int doKillProcessGroupOnce(uid_t uid, int initialPid, int signal) { int processes = 0; struct ctx ctx; pid_t pid; @@ -282,13 +281,11 @@ static int killProcessGroupOnce(uid_t uid, int initialPid, int signal) return processes; } -int killProcessGroup(uid_t uid, int initialPid, int signal) -{ +static int killProcessGroup(uid_t uid, int initialPid, int signal, int retry) { std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - int retry = 40; int processes; - while ((processes = killProcessGroupOnce(uid, initialPid, signal)) > 0) { + while ((processes = doKillProcessGroupOnce(uid, initialPid, signal)) > 0) { LOG(VERBOSE) << "killed " << processes << " processes for processgroup " << initialPid; if (retry > 0) { std::this_thread::sleep_for(5ms); @@ -313,6 +310,14 @@ int killProcessGroup(uid_t uid, int initialPid, int signal) } } +int killProcessGroup(uid_t uid, int initialPid, int signal) { + return killProcessGroup(uid, initialPid, signal, 40 /*maxRetry*/); +} + +int killProcessGroupOnce(uid_t uid, int initialPid, int signal) { + return killProcessGroup(uid, initialPid, signal, 0 /*maxRetry*/); +} + static bool mkdirAndChown(const char *path, mode_t mode, uid_t uid, gid_t gid) { if (mkdir(path, mode) == -1 && errno != EEXIST) {