From af8a277de03d7e265cc03c1aa6a80f800227b73e Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 27 Sep 2021 17:01:15 +0000 Subject: Die at compile time when notification-fd == lock-fd Signed-off-by: Laurent Bercot --- src/s6-rc/s6-rc-compile.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c index 84f7bdc..b0ec688 100644 --- a/src/s6-rc/s6-rc-compile.c +++ b/src/s6-rc/s6-rc-compile.c @@ -1254,6 +1254,7 @@ static inline void write_servicedirs (char const *compiled, s6rc_db_t const *db, { size_t srcdirlen = strlen(srcdirs[i]) ; size_t len = strlen(db->string + db->services[i].name) ; + unsigned int fdnotif = 0 ; unsigned int u ; int ispipelined = db->services[i].x.longrun.nproducers || db->services[i].x.longrun.consumer < db->nlong ; char srcfn[srcdirlen + len + 18] ; @@ -1303,20 +1304,38 @@ static inline void write_servicedirs (char const *compiled, s6rc_db_t const *db, memcpy(srcfn + srcdirlen + len + 2, "notification-fd", 16) ; memcpy(dstfn + clen + 14 + len, "notification-fd", 16) ; - if (copy_uint(compiled, srcfn, dstfn, &u) && u < 3 && verbosity) + if (copy_uint(compiled, srcfn, dstfn, &u)) { - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, u)] = 0 ; - strerr_warnw4x("longrun ", db->string + db->services[i].name, " has a notification-fd of ", fmt) ; + if (u < 3) + { + if (verbosity) + { + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, u)] = 0 ; + strerr_warnw4x("longrun ", db->string + db->services[i].name, " has a notification-fd of ", fmt) ; + } + } + else fdnotif = u ; } memcpy(srcfn + srcdirlen + len + 2, "lock-fd", 8) ; memcpy(dstfn + clen + 14 + len, "lock-fd", 8) ; - if (copy_uint(compiled, srcfn, dstfn, &u) && u < 3 && verbosity) + if (copy_uint(compiled, srcfn, dstfn, &u)) { - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, u)] = 0 ; - strerr_warnw4x("longrun ", db->string + db->services[i].name, " has a lock-fd of ", fmt) ; + if (u < 3) + { + if (verbosity) + { + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, u)] = 0 ; + strerr_warnw4x("longrun ", db->string + db->services[i].name, " has a lock-fd of ", fmt) ; + } + } + else if (fdnotif == u) + { + cleanup(compiled) ; + strerr_dief3x(1, "longrun ", db->string + db->services[i].name, " has the same value for notification-fd and lock-fd") ; + } } memcpy(srcfn + srcdirlen + len + 2, "timeout-kill", 13) ; -- cgit v1.2.3