patchThe GNU Bourne-Again SHell - Patches: patch #8676, Fix truncating .bash_history

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #8676: Fix truncating .bash_history

Submitter:  Russell Stuart <rstuart>
Submitted:  Thu 28 May 2015 08:28:11 AM UTC
Votes:  10  
 
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  None Open/Closed:  Open
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       No canned response available

 

Thu 28 May 2015 08:28:11 AM UTC, original submission:  

Bash loses all my history on occasion.  This will eventually happen to everyone who runs multiple bash sessions, eg:

  http://superuser.com/questions/20900/bash-history-loss

The problem occurs when multiple instances exit simultaneously.  One example is when you close a multi tab xterm.

It happens when bash is enforcing HISTFILESIZE.  Bash re-reads the history, then truncates the file, then the smaller fine.  If several bash instances are doing this as the same time there is a race condition.  It's possible for one bash instance to read .bash_history between when it is truncated and when it is written, and thus it sees a zero length file.  If the last version of .bash_history is this 0 length version all history is lost.

The attached patch works around the problem by writing the new version to a temporary file, then renaming it.  Since POSIX guarantees rename() is atomic the race is gone.

Russell Stuart <rstuart>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #34121:  safe-history-write.patch added by rstuart (4KiB - text/x-patch - Eliminate another race condition)
file #34104:  safe-history-write.patch added by rstuart (4KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Updated the item)
  • -email is unavailable- added by balacobaco (Voted in favor of this item)
  • -email is unavailable- added by rstuart (Submitted the item)
  •  

    There are 10 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-06-05 chet StatusNone Done
    2015-06-03 balacobaco Carbon-Copy- Added balacobaco
    2015-05-29 rstuart Attached File- Added safe-history-write.patch, #34121
    2015-05-28 rstuart Attached File- Added safe-history-write.patch, #34104

    Back to the top


    Powered by Savane 3.9