svn commit: samba r17944 - in branches/SAMBA_3_0/source/libads: .
jra at samba.org
jra at samba.org
Thu Aug 31 01:27:52 GMT 2006
Author: jra
Date: 2006-08-31 01:27:51 +0000 (Thu, 31 Aug 2006)
New Revision: 17944
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17944
Log:
Handle locking madness.
Jeremy.
Modified:
branches/SAMBA_3_0/source/libads/kerberos.c
Changeset:
Modified: branches/SAMBA_3_0/source/libads/kerberos.c
===================================================================
--- branches/SAMBA_3_0/source/libads/kerberos.c 2006-08-31 01:20:21 UTC (rev 17943)
+++ branches/SAMBA_3_0/source/libads/kerberos.c 2006-08-31 01:27:51 UTC (rev 17944)
@@ -477,6 +477,7 @@
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,18 +494,38 @@
}
flen = strlen(file_contents);
- xfp = x_fopen(fname, O_CREAT|O_WRONLY, 0600);
- if (!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;
}
- /* Lock the file. */
- if (!fcntl_lock(xfp->fd, F_SETLKW, 0, 1, F_WRLCK)) {
- unlink(fname);
- x_fclose(xfp);
- TALLOC_FREE(fname);
- return False;
- }
if (x_fwrite(file_contents, flen, 1, xfp) != flen) {
unlink(fname);
More information about the samba-cvs
mailing list