From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7316C1F51E for ; Sat, 1 Oct 2022 22:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yhbt.net; s=selector1; t=1664665060; bh=l7poQEN/qEiEeW1VMyeQuynaQdaSa0Ogb2PsfI5mtPE=; h=From:To:Subject:Date:From; b=ZlA1vFDAHxie73FND2woWxYCHPF4czA75xeZ6nPdap1y3ywoM0oNRRL0qx9dSevv6 viFqSn1TKaFMb5briWQk17PaWLUxKyHV/k/voZdzBkoTM5CyRjwbpnp6GnGQDDGF4Z NfL3dJhT51B69CcaHPJRJrZN3dMMOVq15pGA4G2I= From: Eric Wong To: unicorn-public@yhbt.net Subject: [PATCH] http_server: detect disk-full when writing PID file Date: Sat, 1 Oct 2022 22:57:40 +0000 Message-Id: <20221001225740.831378-1-BOFH@YHBT.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While unlikely, it's possible for write(2) to return a truncated value or ENOSPC error if the device is full when writing a tiny PID file. As optimism has no place in engineering, use IO#write instead of IO#syswrite since the former will retry on truncation and raise a exception on ENOSPC. --- lib/unicorn/http_server.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb index 21f2a05a..3416808f 100644 --- a/lib/unicorn/http_server.rb +++ b/lib/unicorn/http_server.rb @@ -187,7 +187,8 @@ def clobber_pid(path) rescue Errno::EEXIST retry end - fp.syswrite("#$$\n") + fp.sync = true + fp.write("#$$\n") File.rename(fp.path, path) fp.close end