From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11063 invoked from network); 16 Dec 2005 08:49:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 Dec 2005 08:49:55 -0000 Received: (qmail 83101 invoked from network); 16 Dec 2005 08:49:48 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Dec 2005 08:49:48 -0000 Received: (qmail 27473 invoked by alias); 16 Dec 2005 08:49:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22087 Received: (qmail 26850 invoked from network); 16 Dec 2005 08:43:03 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 16 Dec 2005 08:43:03 -0000 Received: (qmail 78454 invoked from network); 16 Dec 2005 08:43:03 -0000 Received: from outgoing.smtp.agnat.pl (193.239.44.83) by a.mx.sunsite.dk with SMTP; 16 Dec 2005 08:43:01 -0000 Received: from [193.19.104.204] (helo=[192.168.1.155]) by tekla.agnat.pl with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.60) (envelope-from ) id 1EnBB3-0008E5-GI for zsh-workers@sunsite.dk; Fri, 16 Dec 2005 09:42:58 +0100 From: Arkadiusz Miskiewicz Organization: SelfOrganizing To: zsh-workers@sunsite.dk Subject: [PATCH]: restore permissions and mode on HISTFILE when renaming it Date: Fri, 16 Dec 2005 09:42:29 +0100 User-Agent: KMail/1.9 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_23noDMGqKV0Wu5N" Message-Id: <200512160942.30494.arekm@pld-linux.org> X-Authenticated-Id: arekm --Boundary-00=_23noDMGqKV0Wu5N Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, There is one annoying thing in handling history file in zsh. When it uses=20 tmpfile (not append mode) and just does rename(".historyz.new", ".history")= =20 it looses all permissions and user/owner of the original .historyz file. Exaple, I'm working as user arekm and .historyz has arekm:users user/group = but=20 if I do sudo zsh; ls; exit then it's renamed and I end up with .historyz=20 being root:root and since I've exited sudo and I'm back as arekm:users my=20 history is no longer saved. Attached patch makes zsh restore original permissions/owner/group of HISTFI= LE=20 after sucessful rename. It's against HEAD (4.3) cvs version. Any races here (between stat and chown/chmod) shouldn't be unsafe I guess. Thanks! =2D-=20 Arkadiusz Mi=B6kiewicz PLD/Linux Team http://www.t17.ds.pwr.wroc.pl/~misiek/ http://ftp.pld-linux.org/ --Boundary-00=_23noDMGqKV0Wu5N Content-Type: text/x-diff; charset="iso-8859-2"; name="zsh-restore-histfile.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="zsh-restore-histfile.patch" --- zsh.org/Src/hist.c.org 2005-12-16 10:51:24.680963000 +0100 +++ zsh/Src/hist.c 2005-12-16 10:59:14.100963000 +0100 @@ -2127,8 +2127,18 @@ } fclose(out); if (tmpfile) { + struct stat sb; + int restore = 0; + if (stat(unmeta(fn), &sb) == 0) + restore = 1; if (rename(tmpfile, unmeta(fn)) < 0) zerr("can't rename %s.new to $HISTFILE", fn, 0); + else if (restore) { + if (chown(unmeta(fn), sb.st_uid, sb.st_gid) < 0) + zerr("can't restore user/group on $HISTFILE", NULL, 0); + if (chmod(unmeta(fn), sb.st_mode) < 0) + zerr("can't restore permissions on $HISTFILE", NULL, 0); + } free(tmpfile); } --Boundary-00=_23noDMGqKV0Wu5N--