Hi,<div>I have attached a patch which adds a locking mechanism to Flashrom to prevent multiple instances from running simultaneously. It may need some modification to fit different Flashrom use cases better, but I think it's a good start.</div>

<div><br></div><div>The size of the patch is somewhat misleading -- The only real changes to Flashrom's current code are some of the exit points in cli_classic() and some added stuff in the Makefile. Everything else is contained in new files. The new files are:</div>

<div>csem.{c,h}: Low-level code that interfaces with semctl(), semget(), etc.</div><div><meta http-equiv="content-type" content="text/html; charset=utf-8">ipc_lock.{c,h}: Wrapper for csem stuff.</div><div>locks.h: A listing of locks that Flashrom cares about.</div>

<div>big_lock.{c,h}: An even higher-level wrapper around ipc_lock stuff, useful for simple, coarse-grained locking.</div><div>util/use_big_lock.sh: Used by the Makefile to test for POSIX.1-2001 compliance.</div><div><br>
</div>
<div>The advantages of this approach are:</div><div>- The semaphore can be shared easily with other processes.</div><div>- The semaphore is cleaned automagically in case of abnormal program termination.</div><div>- Semaphore info can be viewed and managed easily using standard utilities like ipcs.</div>

<div>- On Linux at least, a second instance of Flashrom will automatically begin immediately after the first instance is done. No busy waiting, no excessive delays.</div><div>- We avoid errata with other locking mechanisms (there are known issues with flock(), for example).</div>

<div><br></div><div>Disadvantages:</div><div>- The current patch is very coarse-grained, which could be problematic for people who wish to flash multiple chips simultaneously.</div><div><meta http-equiv="content-type" content="text/html; charset=utf-8">- Requires >= POSIX.1-2001 compliance.</div>

<div><br></div><div>Please note that some files in this patch are BSD-licensed. Much of it is based off code which was open-sourced by Sun Microsystems, after acquiring it from Cobalt Networks.<br clear="all"><br></div><div>

Signed-off-by: David Hendricks <<a href="mailto:dhendrix@google.com">dhendrix@google.com</a>></div><div><br>-- <br>David Hendricks (dhendrix)<br>Systems Software Engineer, Google Inc.<br>
</div>