Skip to content

Commit

Permalink
fix: failed to run app after ll-cli reviced SIGINT
Browse files Browse the repository at this point in the history
* If the errno which returns from ::wait in ll-cli
  is EINTR, wait child more times. And if interrupt
  by SIGINT one more time, kill child immediately.
* If the pid which in container json  is not exists,
  remove the json.

Log:
  • Loading branch information
kamiyadm committed Jul 1, 2024
1 parent f8cf372 commit 758c9bc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
29 changes: 28 additions & 1 deletion apps/ll-box/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ enum globalOption { OPTION_CGROUP_MANAGER = 1000 };

enum execOption { OPTION_CWD = 1000 };

void containerJsonCleanUp()
{
auto containers = linglong::readAllContainerJson();

auto it = containers.begin();
while (it != containers.end()) {
auto boxPid = it->value("pid", -1);
if (boxPid == -1) {
++it;
continue;
}

if (kill(boxPid, 0) != 0) {
auto jsonPath = std::filesystem::path("/run") / "user" / std::to_string(getuid())
/ "linglong" / "box" / (it->value("id", "unknown") + ".json");

if (!std::filesystem::remove(jsonPath)) {
logErr() << "remove" << jsonPath << "failed";
}
it = containers.erase(it);
} else {
++it;
}
}
}

int list(struct arg_list *arg) noexcept
{
auto containers = linglong::readAllContainerJson();
Expand Down Expand Up @@ -539,7 +565,8 @@ int main(int argc, char **argv)
logErr() << "please specify a command";
return -1;
}

// make sure that all containers status are valid
containerJsonCleanUp();
struct argp_option options[] = { {
.name = "cgroup-manager",
.key = OPTION_CGROUP_MANAGER,
Expand Down
25 changes: 23 additions & 2 deletions libs/ocppi/src/ocppi/cli/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,19 @@ int runProcess(const std::string &binaryPath,
output.append(buffer.data(), readCount);
}

if (::wait(&ret) == -1) {

int interrupteTime = 0;
while (true) {
if (::wait(&ret) == -1) {
if (errno == EINTR) {
interrupteTime < 2 ? ++interrupteTime : kill(childId, SIGKILL);
continue;
}

throw std::system_error(errno, std::generic_category(), "wait");
} else {
break;
}
}

::close(pipes[0]);
Expand Down Expand Up @@ -98,8 +109,18 @@ int runProcess(const std::string &binaryPath,
"execvp");
}

if (::wait(&ret) == -1) {
int interrupteTime = 0;
while (true) {
if (::wait(&ret) == -1) {
if (errno == EINTR) {
interrupteTime < 2 ? ++interrupteTime : kill(childId, SIGKILL);
continue;
}

throw std::system_error(errno, std::generic_category(), "wait");
} else {
break;
}
}

return ret;
Expand Down

0 comments on commit 758c9bc

Please sign in to comment.