Index: b/g10/tdbio.c =================================================================== --- b/g10/tdbio.c +++ b/g10/tdbio.c @@ -477,7 +477,7 @@ int tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile) { - char *fname; + char *fname, *p; struct stat statbuf; static int initialized = 0; @@ -513,6 +513,20 @@ /* OK, we have the valid trustdb.gpg already. */ return 0; + /* + * Make sure the directory exists. This should be done before + * acquiring the lock, which assumes the directory existence. + */ + p = strrchr( fname, DIRSEP_C ); + assert(p); /* See the code above. Always, it has DIRSEP_C. */ + *p = 0; + if( access( fname, F_OK ) ) { + try_make_homedir( fname ); + if (access (fname, F_OK )) + log_fatal (_("%s: directory does not exist!\n"), p); + } + *p = DIRSEP_C; + take_write_lock (); if( access( fname, R_OK ) ) { @@ -525,18 +539,8 @@ FILE *fp; TRUSTREC rec; int rc; - char *p = strrchr( fname, DIRSEP_C ); mode_t oldmask; - assert(p); - *p = 0; - if( access( fname, F_OK ) ) { - try_make_homedir( fname ); - if (access (fname, F_OK )) - log_fatal (_("%s: directory does not exist!\n"), fname); - } - *p = DIRSEP_C; - oldmask=umask(077); if (is_secured_filename (fname)) { fp = NULL;