diff options
author | Jeremy Allison <jra@samba.org> | 2006-08-31 01:27:51 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:39:01 -0500 |
commit | cceb492250ce7e273cdc48c030048c0879a7265a (patch) | |
tree | 71fa5e2fde11131747dbfd139d100a1c3180a5a6 /source3 | |
parent | 6fada7a82aa67e7b80ff003bd527092da68542c8 (diff) | |
download | samba-cceb492250ce7e273cdc48c030048c0879a7265a.tar.gz samba-cceb492250ce7e273cdc48c030048c0879a7265a.tar.bz2 samba-cceb492250ce7e273cdc48c030048c0879a7265a.zip |
r17944: Handle locking madness.
Jeremy.
(This used to be commit 408267a2d725a0596be37b019fe4513502b2c0ec)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/libads/kerberos.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c index 4e4e4cfebf..46b64ca22d 100644 --- a/source3/libads/kerberos.c +++ b/source3/libads/kerberos.c @@ -477,6 +477,7 @@ BOOL create_local_private_krb5_conf_for_domain(const char *realm, const char *do char *fname = talloc_asprintf(NULL, "%s/smb_krb5.conf.%s", lp_private_dir(), domain); char *file_contents = NULL; size_t flen = 0; + int loopcount = 0; if (!fname) { return False; @@ -493,17 +494,37 @@ BOOL create_local_private_krb5_conf_for_domain(const char *realm, const char *do } flen = strlen(file_contents); - xfp = x_fopen(fname, O_CREAT|O_WRONLY, 0600); - if (!xfp) { - TALLOC_FREE(fname); - return False; - } - /* Lock the file. */ - if (!fcntl_lock(xfp->fd, F_SETLKW, 0, 1, F_WRLCK)) { - unlink(fname); - x_fclose(xfp); - TALLOC_FREE(fname); - return False; + + while (loopcount < 10) { + SMB_STRUCT_STAT st; + + xfp = x_fopen(fname, O_CREAT|O_WRONLY, 0600); + if (!xfp) { + TALLOC_FREE(fname); + return False; + } + /* Lock the file. */ + if (!fcntl_lock(xfp->fd, F_SETLKW, 0, 1, F_WRLCK)) { + unlink(fname); + x_fclose(xfp); + TALLOC_FREE(fname); + return False; + } + + /* We got the lock. Is the file still there ? */ + if (sys_stat(fname,&st)==-1) { + if (errno == ENOENT) { + /* Nope - try again up to 10x */ + x_fclose(xfp); + loopcount++; + continue; + } + unlink(fname); + x_fclose(xfp); + TALLOC_FREE(fname); + return False; + } + break; } if (x_fwrite(file_contents, flen, 1, xfp) != flen) { |