From ea96ef48cbf4980b7dd3dd61f944091ead821f20 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" <june@causal.agency> Date: Mon, 17 Aug 2020 16:06:40 -0400 Subject: Use a non-blocking lock on the PID file --- daemon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/daemon.c b/daemon.c index 1643200..a1be594 100644 --- a/daemon.c +++ b/daemon.c @@ -247,11 +247,13 @@ int main(int argc, char *argv[]) { int pidFile = -1; if (pidPath) { - pidFile = open( - pidPath, O_WRONLY | O_CREAT | O_EXLOCK | O_CLOEXEC, 0600 - ); + pidFile = open(pidPath, O_WRONLY | O_CREAT | O_CLOEXEC, 0600); if (pidFile < 0) err(EX_CANTCREAT, "%s", pidPath); + error = flock(pidFile, LOCK_EX | LOCK_NB); + if (error && errno != EWOULDBLOCK) err(EX_IOERR, "%s", pidPath); + if (error) errx(EX_CANTCREAT, "%s: file is locked", pidPath); + error = ftruncate(pidFile, 0); if (error) err(EX_IOERR, "%s", pidPath); } -- cgit 1.4.1 'v1'>v1</option> <option value='v2' selected='selected'>v2</option> </optgroup></select> <input type='submit' value='switch'/></form></td></tr> <tr><td class='sub'>collaborative ASCII art </td><td class='sub right'></td></tr></table> <table class='tabs'><tr><td> <a href='/torus/about/?h=v2'>about</a> <a href='/torus/?h=v2'>summary</a> <a href='/torus/refs/?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd'>refs</a> <a class='active' href='/torus/log/Makefile?h=v2&follow=1'>log</a> <a href='/torus/tree/Makefile?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd'>tree</a> <a href='/torus/commit/Makefile?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd&follow=1'>commit</a> <a href='/torus/diff/Makefile?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd&follow=1'>diff</a> <a href='https://ascii.town'>homepage</a></td><td class='form'><form class='right' method='get' action='/torus/log/Makefile'> <input type='hidden' name='h' value='v2'/><input type='hidden' name='id' value='6dadef0381d8b7a63f40b185b3592f27b55453cd'/><select name='qt'> <option value='grep'>log msg</option> <option value='author'>author</option> <option value='committer'>committer</option> <option value='range'>range</option> </select> <input class='txt' type='search' size='10' name='q' value=''/> <input type='submit' value='search'/> </form> </td></tr></table> <div class='path'>path: <a href='/torus/log/?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd&follow=1'>root</a>/<a href='/torus/log/Makefile?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd&follow=1'>Makefile</a> (<a href='/torus/log/Makefile?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd'>unfollow</a>)</div><div class='content'><table class='list nowrap'><tr class='nohover'><th></th><th class='left'>Commit message (<a href='/torus/log/Makefile?h=v2&id=6dadef0381d8b7a63f40b185b3592f27b55453cd&showmsg=1&follow=1'>Expand</a>)</th><th class='left'>Author</th></tr> <tr><td><span title='2018-04-09 01:00:54 -0400'>2018-04-09</span></td><td><a href='/torus/commit/torus.h?h=v2&id=99e3c574a02fdb779e97186119891fbe46390d72&follow=1'>Replace #define with enum or const where possible</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-31 22:05:47 -0400'>2018-03-31</span></td><td><a href='/torus/commit/Makefile?h=v2&id=96b09c86e6838c8bd2e39ff70c4840332a2d06ea&follow=1'>Link against ncurses</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:58:58 -0500'>2018-03-05</span></td><td><a href='/torus/commit/server.c?h=v2&id=2dcf768ed895f65771da689236db0a25bf827fe9&follow=1'>Miscellaneous code cleanup</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:58:18 -0500'>2018-03-05</span></td><td><a href='/torus/commit/server.c?h=v2&id=9387958f8a6bae28f4c9b115aef12e8163393aec&follow=1'>Pass message structs by value</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:55:46 -0500'>2018-03-05</span></td><td><a href='/torus/commit/meta.c?h=v2&id=3e7377a479f49d2a8f2b0b893b6f8ea946b56fc9&follow=1'>Use stdio in merge and meta</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:55:18 -0500'>2018-03-05</span></td><td><a href='/torus/commit/torus.h?h=v2&id=e2033ccf64792e0f78363981ffcd56c78c41de9a&follow=1'>Clean up spawn constants</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:54:26 -0500'>2018-03-05</span></td><td><a href='/torus/commit/torus.h?h=v2&id=79ab120ad31ed74a2a3221d14b7472703296a921&follow=1'>Rename Tile timestamps {create,modify,access}Time</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:45:17 -0500'>2018-03-05</span></td><td><a href='/torus/commit/torus.h?h=v2&id=7bac64b1b3d8a0ab763aa584e3b085b45ae082b7&follow=1'>Pack message type enums</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:39:40 -0500'>2018-03-05</span></td><td><a href='/torus/commit/torus.h?h=v2&id=2dda5826731ce18d0d24ae3d13de1c80008227e6&follow=1'>Undef COLOR_ constants in torus.h</a></td><td>June McEnroe</td></tr> <tr><td><span title='2018-03-05 12:37:52 -0500'>2018-03-05</span></td><td><a href='/torus/commit/Makefile?h=v2&id=69dbc210391ff7829e2ceeb05770d1de517a329b&follow=1'>Generate tags</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-10-03 12:32:05 -0400'>2017-10-03</span></td><td><a href='/torus/commit/Makefile?h=v2&id=f595106dee331dd864ebb15bab9ae17675967168&follow=1'>Simplify Makefile with pattern rule</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-09-27 15:28:16 -0400'>2017-09-27</span></td><td><a href='/torus/commit/torus.h?h=v2&id=46abcc7b70cfa8da069aceeddb0039b3e18827cf&follow=1'>Remove leading blank lines</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-09-27 15:25:58 -0400'>2017-09-27</span></td><td><a href='/torus/commit/README?h=v2&id=038957c275278559d6e3f814e9b06e9349e80738&follow=1'>Add merge.c to README</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-09-03 15:34:21 -0400'>2017-09-03</span></td><td><a href='/torus/commit/server.c?h=v2&id=0c5568b6a60d67bbbf84fd037d41826ccc497b8e&follow=1'>Assert client coords are valid after movement</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-09-03 14:57:17 -0400'>2017-09-03</span></td><td><a href='/torus/commit/torus.h?h=v2&id=58eb1831071734bafbdd6c6d846fb493b17a4961&follow=1'>Relicense AGPL</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-09-01 13:55:48 -0400'>2017-09-01</span></td><td><a href='/torus/commit/torus.h?h=v2&id=9915cb618fd8552372756ce3d1877d6e8564d021&follow=1'>Revert "Add client readOnly mode"</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-09-01 12:33:54 -0400'>2017-09-01</span></td><td><a href='/torus/commit/server.c?h=v2&id=2f5f73d10a13f612f54ae1e5be8519d72a9372a0&follow=1'>Remove clientRemove call from clientCast</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-09-01 00:08:07 -0400'>2017-09-01</span></td><td><a href='/torus/commit/torus.h?h=v2&id=9a6c9c91c8092603b914cc0b3085d059e162ca29&follow=1'>Add client readOnly mode</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-31 15:37:36 -0400'>2017-08-31</span></td><td><a href='/torus/commit/merge.c?h=v2&id=2aa5fe545bdba997bdb728a2dfb2e3bca93766ae&follow=1'>Clean up merge tool</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-31 13:45:12 -0400'>2017-08-31</span></td><td><a href='/torus/commit/merge.c?h=v2&id=22198d6399a006f59d162b2e00a7b8205c8f6e9b&follow=1'>Choose B for tiles with equal modify times</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-31 01:00:02 -0400'>2017-08-31</span></td><td><a href='/torus/commit/merge.c?h=v2&id=2188bd834c546b40d4b19258f8729ecae86be853&follow=1'>Add quick data file merge tool</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-30 11:16:22 -0400'>2017-08-30</span></td><td><a href='/torus/commit/client.c?h=v2&id=38d460d2bae7569ec0c2d99086fd2fd5e8a8897c&follow=1'>Use only foreground color for selecting spawn</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-29 18:33:59 -0400'>2017-08-29</span></td><td><a href='/torus/commit/torus.h?h=v2&id=af645c09089d1ed8e99c760f05234ac3df402901&follow=1'>Add four additional spawns</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-28 23:38:40 -0400'>2017-08-28</span></td><td><a href='/torus/commit/torus.h?h=v2&id=ce13621292bdfeafd7c6561c432a1d96deccbd3a&follow=1'>Add respawning</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-26 23:46:14 -0400'>2017-08-26</span></td><td><a href='/torus/commit/torus.h?h=v2&id=ccdad79970a150eec64758e1a3b14b084d4cb42f&follow=1'>Move license above includes</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-26 19:32:55 -0400'>2017-08-26</span></td><td><a href='/torus/commit/snapshot.sh?h=v2&id=e5184500830e04f3c9839d2dac62108fcb28133f&follow=1'>Snapshot metadata</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-26 16:51:14 -0400'>2017-08-26</span></td><td><a href='/torus/commit/README?h=v2&id=7cfc2d9b309c4c664a177e55441f88a64e15561c&follow=1'>Add meta.c to README</a></td><td>June McEnroe</td></tr> <tr><td><span title='2017-08-26 16:47:57 -0400'>2017-08-26</span></td><td><a href='/torus/commit/server.c?h=v2&id=592d0fbdc59c19c89bf4fd5498591d07b0d9c132&follow=1'>Use Makefile</a></td><td>June McEnroe