Skip to content

Commit

Permalink
Fix SIGINT problem in Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Sep 4, 2024
1 parent 4e6055f commit 87fab84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM ubuntu AS builder
FROM yhirose4dockerhub/ubuntu-builder AS builder
WORKDIR /build
COPY httplib.h .
COPY docker/main.cc .
RUN apt update && apt install g++ -y
RUN g++ -std=c++23 -static -o server -O2 -I. -DCPPHTTPLIB_USE_POLL main.cc && strip server

FROM scratch
Expand Down
4 changes: 4 additions & 0 deletions docker/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ constexpr auto error_html = R"(<html>
</html>
)";

void sigint_handler(int s) { exit(1); }

std::string time_local() {
auto p = std::chrono::system_clock::now();
auto t = std::chrono::system_clock::to_time_t(p);
Expand All @@ -49,6 +51,8 @@ std::string log(auto &req, auto &res) {
}

int main(int argc, const char **argv) {
signal(SIGINT, sigint_handler);

auto base_dir = "./html";
auto host = "0.0.0.0";
auto port = 80;
Expand Down

0 comments on commit 87fab84

Please sign in to comment.