From patchwork Sat Sep 19 01:43:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 519620 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BAA62140789 for ; Sat, 19 Sep 2015 11:44:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=thunk.org header.i=@thunk.org header.b=xWTkw47T; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753375AbbISBnM (ORCPT ); Fri, 18 Sep 2015 21:43:12 -0400 Received: from imap.thunk.org ([74.207.234.97]:59692 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbbISBnL (ORCPT ); Fri, 18 Sep 2015 21:43:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date; bh=hS8IF2elXcyqpODMvIKrGQn2N/jwhlmntNXx8mWloa4=; b=xWTkw47T7jZBu7Ocz+DQB5aDZmbADXemrvA2pz0UD5fT/jr6R1XMBBTZsoRnCrOBwJ1hUBUUWkN/StUngTCKBtuEt7OSh7SCPMfaavobTM3sivt38pX3ET0ypS5xkSC2pWMLnSJEbEDgWOZOhaZ6ENmprmTxso/jxBPenugBI1o=; Received: from root (helo=closure.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.84) (envelope-from ) id 1Zd7BF-0007p8-4K; Sat, 19 Sep 2015 01:43:09 +0000 Received: by closure.thunk.org (Postfix, from userid 15806) id D4EB08208E4; Fri, 18 Sep 2015 21:43:07 -0400 (EDT) Date: Fri, 18 Sep 2015 21:43:07 -0400 From: Theodore Ts'o To: Andreas Dilger , "linux-ext4@vger.kernel.org" Subject: Re: [PATCH e2fsprogs] subst: use 0644 perms Message-ID: <20150919014307.GA2921@thunk.org> References: <1442562858-862-1-git-send-email-vapier@gentoo.org> <20150918180824.GE2213@vapier.lan> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150918180824.GE2213@vapier.lan> User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Sep 18, 2015 at 02:08:24PM -0400, Mike Frysinger wrote: > > i think you misread my report. this has nothing to do with people trying > to modify the files after the fact. NFS can (and sometimes does) throw an > error at the time of the *open* call even if the file doesn't exist. I believe Andreas did understand your report; he was just objecting to the claim in the git description that there is "no reason" to have the files generated subst to be read-only. > if you want to try to "protect" people, then it needs to be a chmod after > all the data has been written & closed. this is how it used to behave, > but commit 2873927d15ffb9ee9ed0e2700791a0e519c715aa changed it. I think Andreas was asking you to make this change to the patch. I had a bit of spare time (thanks to perfcrastination :-), so I took care of it. - Ted commit e5a82003d1b3b7ea01f60dadb49c3bbc60e4ebb7 Author: Theodore Ts'o Date: Fri Sep 18 21:37:53 2015 -0400 subst: work around an NFS bug When running on NFS, opening files with 0444 perms for writing can sometimes fail. This is arguably an NFS server bug, but work around it by creating the file with 0644 permissions, and only change the permissions to be 0444 right before we close the file. URL: https://bugs.gentoo.org/550986 Reported-by: Mike Frysinger Signed-off-by: Theodore Ts'o --- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/util/subst.c b/util/subst.c index f36adb4..70dc0bc 100644 --- a/util/subst.c +++ b/util/subst.c @@ -319,7 +319,7 @@ int main(int argc, char **argv) { char line[2048]; int c; - int fd; + int fd, ofd = -1; FILE *in, *out, *old = NULL; char *outfn = NULL, *newfn = NULL; int verbose = 0; @@ -370,12 +370,12 @@ int main(int argc, char **argv) } strcpy(newfn, outfn); strcat(newfn, ".new"); - fd = open(newfn, O_CREAT|O_TRUNC|O_RDWR, 0444); - if (fd < 0) { + ofd = open(newfn, O_CREAT|O_TRUNC|O_RDWR, 0644); + if (ofd < 0) { perror(newfn); exit(1); } - out = fdopen(fd, "w+"); + out = fdopen(ofd, "w+"); if (!out) { perror("fdopen"); exit(1); @@ -429,12 +429,16 @@ int main(int argc, char **argv) printf("Using original atime\n"); set_utimes(outfn, fileno(old), tv); } + if (ofd >= 0) + (void) fchmod(ofd, 0444); fclose(out); if (unlink(newfn) < 0) perror("unlink"); } else { if (verbose) printf("Creating or replacing %s.\n", outfn); + if (ofd >= 0) + (void) fchmod(ofd, 0444); fclose(out); if (old) fclose(old);