Skip to content

Commit

Permalink
统一各系统进程退出码
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Dec 3, 2023
1 parent ba2210b commit 5f39f7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/main/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ struct argp config = {
.parser = parseOption,
};

volatile int exitCode = 0;
bool running = true;
std::mutex mutex;
std::condition_variable condition;
Expand Down Expand Up @@ -191,6 +192,7 @@ std::string getLastestAddress(const std::string &name) {

namespace Candy {
void shutdown() {
exitCode = 1;
signalHandler(SIGTERM);
}
} // namespace Candy
Expand Down Expand Up @@ -219,8 +221,6 @@ int main(int argc, char *argv[]) {
client.run();
}

spdlog::info("service started successfully");

std::signal(SIGINT, signalHandler);
std::signal(SIGTERM, signalHandler);

Expand All @@ -236,9 +236,13 @@ int main(int argc, char *argv[]) {
saveLatestAddress(arguments.name, client.getAddress());
}

spdlog::info("service stopped successfully");
if (exitCode == 0) {
spdlog::info("service exit: normal");
} else {
spdlog::warn("service exit: internal exception");
}

return 0;
return exitCode;
}

#endif
10 changes: 6 additions & 4 deletions src/main/windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ int main() {
client.run();
}

spdlog::info("service started successfully");

signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);

Expand All @@ -141,8 +139,12 @@ int main() {

windowsNetworkCleanup();

spdlog::info("service stopped successfully");
spdlog::info("exit code: {}", exitCode);
if (exitCode == 0) {
spdlog::info("service exit: normal");
} else {
spdlog::warn("service exit: internal exception");
}

return exitCode;
}

Expand Down

0 comments on commit 5f39f7c

Please sign in to comment.