From: Davin McCall Date: Sat, 18 Jun 2016 17:05:01 +0000 (+0100) Subject: Fix calculation of buffer size for LISTEN_FDS environment variable. X-Git-Tag: v0.03~10 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3fe7413b4dc54fc4190e41b210823707d9f24414;p=oweals%2Fdinit.git Fix calculation of buffer size for LISTEN_FDS environment variable. (Fortunately, it still gave the correct result in all expected cases). --- diff --git a/src/service.cc b/src/service.cc index 770f875..b81c323 100644 --- a/src/service.cc +++ b/src/service.cc @@ -682,8 +682,10 @@ bool ServiceRecord::start_ps_process(const std::vector &cmd, bool sigaddset(&sigwait_set, SIGTERM); sigprocmask(SIG_UNBLOCK, &sigwait_set, NULL); - constexpr int bufsz = ((CHAR_BIT * sizeof(pid_t) - 1) / 3 + 2) + 11; - // "LISTEN_PID=" - 11 characters + constexpr int bufsz = ((CHAR_BIT * sizeof(pid_t)) / 3 + 2) + 11; + // "LISTEN_PID=" - 11 characters; the expression above gives a conservative estimate + // on the maxiumum number of bytes required for LISTEN=xxx, including nul terminator, + // where xxx is a pid_t in decimal (i.e. one decimal digit is worth just over 3 bits). char nbuf[bufsz]; if (socket_fd != -1) {