From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Changes in update-game-score.c Date: Wed, 22 Jan 2014 19:33:58 -0800 Organization: UCLA Computer Science Department Message-ID: <52E08DA6.6040600@cs.ucla.edu> References: <8361pbg5vy.fsf@gnu.org> <87ha8vn6dg.fsf@fencepost.gnu.org> <834n4vg4r1.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030202060801020606090400" X-Trace: ger.gmane.org 1390448046 6562 80.91.229.3 (23 Jan 2014 03:34:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 23 Jan 2014 03:34:06 +0000 (UTC) To: Glenn Morris , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 23 04:34:14 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W6B3V-0007AU-Qi for ged-emacs-devel@m.gmane.org; Thu, 23 Jan 2014 04:34:14 +0100 Original-Received: from localhost ([::1]:38722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6B3V-0001U0-F9 for ged-emacs-devel@m.gmane.org; Wed, 22 Jan 2014 22:34:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58657) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6B3N-0001To-TL for emacs-devel@gnu.org; Wed, 22 Jan 2014 22:34:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6B3J-0000u3-CY for emacs-devel@gnu.org; Wed, 22 Jan 2014 22:34:05 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:41071) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6B3J-0000tx-1L; Wed, 22 Jan 2014 22:34:01 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 9A6FDA60003; Wed, 22 Jan 2014 19:34:00 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pkwPW9n+DYyv; Wed, 22 Jan 2014 19:33:58 -0800 (PST) Original-Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 96370A60002; Wed, 22 Jan 2014 19:33:58 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:168926 Archived-At: This is a multi-part message in MIME format. --------------030202060801020606090400 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Glenn Morris wrote: > Fcopy_file seems to have managed ok for the past 8 years. Although all mainstream POSIXish platforms have fchmod these days, one oldish platform (BeOS) lacks it. It's easy enough to port to such platforms, so we might as well. This problem isn't limited to update-game-score. I found three other instances in Emacs. The first was in qcopy_acl (called by Fcopy_file) and I fixed it in trunk bzr 116124. The other two are in fileio.c and filelock.c. The attached patch should fix it; I plan to install it unless someone points out a problem with it. --------------030202060801020606090400 Content-Type: text/x-patch; name="fnchmod.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fnchmod.diff" === modified file 'ChangeLog' --- ChangeLog 2014-01-23 02:48:44 +0000 +++ ChangeLog 2014-01-23 03:11:08 +0000 @@ -1,5 +1,10 @@ 2014-01-23 Paul Eggert + Port better to platforms lacking fchmod. + See the thread starting at: + http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01899.html + * lib/fnchmod.h: New file. + Merge from gnulib, incorporating: 2014-01-22 qacl: check for fchmod * m4/acl.m4: Update from gnulib. === modified file 'lib-src/ChangeLog' --- lib-src/ChangeLog 2014-01-22 19:38:31 +0000 +++ lib-src/ChangeLog 2014-01-23 03:11:08 +0000 @@ -1,3 +1,13 @@ +2014-01-23 Paul Eggert + + Port better to platforms lacking fchmod. + * Makefile.in (update-game-score${EXEEXT}): + Depend on ${srcdir}/../lib/fnchmod.h. + * update-game-score.c (INLINE): New macro. + Include . + (write_scores): Use fnchmod rather than chmod on WINDOWSNT and + fchmod elsewhere. + 2014-01-22 Eli Zaretskii * update-game-score.c (write_scores) [WINDOWSNT]: Use chmod === modified file 'lib-src/Makefile.in' --- lib-src/Makefile.in 2014-01-05 02:56:08 +0000 +++ lib-src/Makefile.in 2014-01-23 03:11:08 +0000 @@ -372,7 +372,8 @@ hexl${EXEEXT}: ${srcdir}/hexl.c $(NTLIB) $(config_h) $(CC) ${ALL_CFLAGS} ${srcdir}/hexl.c $(LOADLIBES) -o hexl${EXEEXT} -update-game-score${EXEEXT}: ${srcdir}/update-game-score.c $(NTLIB) $(config_h) +update-game-score${EXEEXT}: ${srcdir}/update-game-score.c \ + ${srcdir}/../lib/fnchmod.h $(NTLIB) $(config_h) $(CC) ${ALL_CFLAGS} -DHAVE_SHARED_GAME_DIR="\"$(gamedir)\"" \ ${srcdir}/update-game-score.c $(LOADLIBES) $(NTLIB) \ -o update-game-score${EXEEXT} === modified file 'lib-src/update-game-score.c' --- lib-src/update-game-score.c 2014-01-22 19:38:31 +0000 +++ lib-src/update-game-score.c 2014-01-23 03:11:08 +0000 @@ -31,6 +31,7 @@ Created 2002/03/22. */ +#define INLINE EXTERN_INLINE #include #include @@ -48,6 +49,8 @@ #include #include +#include + #ifdef WINDOWSNT #include "ntlib.h" #endif @@ -443,10 +446,8 @@ fd = mkostemp (tempfile, 0); if (fd < 0) return -1; -#ifndef WINDOWSNT - if (fchmod (fd, 0644) != 0) + if (fnchmod (fd, filename, 0644) != 0) return -1; -#endif f = fdopen (fd, "w"); if (! f) return -1; @@ -459,10 +460,6 @@ return -1; if (rename (tempfile, filename) != 0) return -1; -#ifdef WINDOWSNT - if (chmod (filename, 0644) < 0) - return -1; -#endif return 0; } === added file 'lib/fnchmod.h' --- lib/fnchmod.h 1970-01-01 00:00:00 +0000 +++ lib/fnchmod.h 2014-01-23 03:11:08 +0000 @@ -0,0 +1,45 @@ +/* Set file mode based on a file descriptor or name. + + Copyright 2014 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef FNCHMOD_H +#define FNCHMOD_H + +#include + +#include + +INLINE_HEADER_BEGIN + +/* On systems that have fchmod, use it to change the mode of FD. + On other systems, use chmod on NAME instead; NAME should identify + the same file that FD does. Typically fchmod is preferable, as it + can avoid some races. MODE is the desired mode. Return 0 if + successful. Return -1 and set errno upon failure. */ + +INLINE int +fnchmod (int fd, char const *name, mode_t mode) +{ +#if HAVE_FCHMOD + return fchmod (fd, mode); +#else + return chmod (name, mode); +#endif +} + +INLINE_HEADER_END + +#endif === modified file 'src/ChangeLog' --- src/ChangeLog 2014-01-22 10:29:23 +0000 +++ src/ChangeLog 2014-01-23 03:11:08 +0000 @@ -1,3 +1,10 @@ +2014-01-23 Paul Eggert + + Port better to platforms lacking fchmod. + * fileio.c, filelock.c: Include . + * fileio.c (Fcopy_file): + * filelock.c (create_lock_file): Use fnchmod, not fchmod. + 2014-01-22 Martin Rudalics Fixes in window size functions around Bug#16430 and Bug#16470. === modified file 'src/fileio.c' --- src/fileio.c 2014-01-03 06:47:27 +0000 +++ src/fileio.c 2014-01-23 03:11:08 +0000 @@ -41,6 +41,7 @@ #endif #include +#include #include "lisp.h" #include "intervals.h" @@ -2113,7 +2114,7 @@ : (already_exists || (new_mask & ~realmask) == default_permissions) ? 0 - : fchmod (ofd, default_permissions)) + : fnchmod (ofd, SSDATA (encoded_newname), default_permissions)) { case -2: report_file_error ("Copying permissions from", file); case -1: report_file_error ("Copying permissions to", newname); === modified file 'src/filelock.c' --- src/filelock.c 2014-01-01 07:43:34 +0000 +++ src/filelock.c 2014-01-23 03:11:08 +0000 @@ -39,6 +39,7 @@ #include #include +#include #include "lisp.h" #include "character.h" @@ -424,7 +425,7 @@ /* Use 'write', not 'emacs_write', as garbage collection might signal an error, which would leak FD. */ if (write (fd, lock_info_str, lock_info_len) != lock_info_len - || fchmod (fd, S_IRUSR | S_IRGRP | S_IROTH) != 0) + || fnchmod (fd, nonce, S_IRUSR | S_IRGRP | S_IROTH) != 0) err = errno; /* There is no need to call fsync here, as the contents of the lock file need not survive system crashes. */ --------------030202060801020606090400--