diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-09-01 20:06:26 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-09-01 20:06:26 +0000 |
commit | f80ac31d742c2d86f1812b895ef61a5885e2447e (patch) | |
tree | 9b223723aced9e7a8acc55044120cc406c77bd9b /src/or/router.c | |
parent | 6a29ad853b630a1970fd95e17ecd79306e7c39e6 (diff) | |
download | tor-f80ac31d742c2d86f1812b895ef61a5885e2447e.tar.gz tor-f80ac31d742c2d86f1812b895ef61a5885e2447e.zip |
Add a lockfile to the Tor data directory to avoid situations where two Tors start with the same datadir, or where a --list-fingerprints races with a server to create keys, or such.
svn:r16722
Diffstat (limited to 'src/or/router.c')
-rw-r--r-- | src/or/router.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/or/router.c b/src/or/router.c index 842cb7b52a..4c85a7b2ab 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -235,6 +235,17 @@ init_key_from_file(const char *fname, int generate, int severity) goto error; case FN_NOENT: if (generate) { + if (!have_lockfile()) { + if (try_locking(get_options(), 0)<0) { + /* Make sure that --list-fingerprint only creates new keys + * if there is no possibility for a deadlock. */ + log(severity, LD_FS, "Another Tor process has locked \"%s\". Not " + "writing any new keys.", fname); + /*XXXX The 'other process' might make a key in a second or two; + * maybe we should wait for it. */ + goto error; + } + } log_info(LD_GENERAL, "No key found in \"%s\"; generating fresh key.", fname); if (crypto_pk_generate_key(prkey)) { |