From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22718 invoked by alias); 12 Jan 2015 19:05:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 22685 invoked by uid 89); 12 Jan 2015 19:05:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 12 Jan 2015 19:05:54 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0CJ5pR4007066 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Jan 2015 14:05:51 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0CJ5fKh013977; Mon, 12 Jan 2015 14:05:45 -0500 Message-ID: <54B41B03.5030306@redhat.com> Date: Mon, 12 Jan 2015 19:05:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Patrick Palka , gdb-patches@sourceware.org Subject: Re: [PATCH] Append to input history file instead of overwriting it References: <1420915570-5605-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1420915570-5605-1-git-send-email-patrick@parcs.ath.cx> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-01/txt/msg00315.txt.bz2 On 01/10/2015 06:46 PM, Patrick Palka wrote: > +/* Safely append new history entries to the history file in a corruption-free > + way using an intermediate local history file. */ > + > +static void > +gdb_safe_append_history (void) > +{ > + int ret, saved_errno; > + char *local_history_filename; > + > + local_history_filename = xstrprintf ("%s.%d", history_filename, getpid ()); IMO just appending a number is not sufficiently distinct from what a user might reasonably want to name alternate history files. How about picking a more obscure name, like what I had originally suggested: local_history_filename = xstrprintf ("%s-gdb%d~", history_filename, getpid ()); ? > + > + ret = rename (history_filename, local_history_filename); > + saved_errno = errno; > + if (ret < 0 && saved_errno == ENOENT) > + { > + /* If the rename failed with ENOENT then either the global history file > + never existed in the first place or another GDB process is currently > + appending to it (and has thus temporarily renamed it). Since we can't > + distinguish between these two cases, we have to conservatively assume > + the first case and therefore must write out (not append) our known > + history to our local history file and try to move it back anyway. > + Otherwise a global history file would never get created! */ > + write_history (local_history_filename); > + } > + else if (ret < 0) > + { > + warning (_("Could not rename %s to %s: %s"), > + history_filename, local_history_filename, strerror (saved_errno)); use safe_strerror. Watch out for line too long. > + goto out; Let's avoid gotos when simple enough. In this case, seems to me that to skip the second rename call, we only need to move the "else if" and "else" within a parent "else" branch. Also, please use a cleanup instead of the xfree at the end: local_history_filename = xstrprintf ("%s-gdb%d~", history_filename, getpid ()); old_chain = make_cleanup (xfree, local_history_filename); ... do_cleanups (old_chain); > + } > + else > + { > + append_history (command_count, local_history_filename); > + history_truncate_file (local_history_filename, history_max_entries); > + } > + > + ret = rename (local_history_filename, history_filename); > + saved_errno = errno; > + if (ret < 0 && saved_errno != EEXIST) > + warning (_("Could not rename %s to %s: %s"), > + local_history_filename, history_filename, strerror (saved_errno)); safe_strerror. > + > +out: > + xfree (local_history_filename); > +} > + This is OK with these changes. Thanks! -- Pedro Alves