diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-10-23 01:26:46 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-10-23 01:26:46 +0000 |
commit | d6ad9474b297e900bc3b7576f3b968b0eb70cae4 (patch) | |
tree | 0ffeb37bb550ad50d3321cb0b98db79b2140d8bc | |
parent | 5d6ed11ef3c860c95ae7b3a855b0ddb123bd9737 (diff) | |
download | samba-d6ad9474b297e900bc3b7576f3b968b0eb70cae4.tar.gz samba-d6ad9474b297e900bc3b7576f3b968b0eb70cae4.tar.xz samba-d6ad9474b297e900bc3b7576f3b968b0eb70cae4.zip |
make the shared variable stuff slightly more sophisticated
(This used to be commit 636182f18346af457f905cd784e68ae5d4f75d0e)
-rw-r--r-- | source3/smbwrapper/shared.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/source3/smbwrapper/shared.c b/source3/smbwrapper/shared.c index 58a37254e88..7a5cbcee22e 100644 --- a/source3/smbwrapper/shared.c +++ b/source3/smbwrapper/shared.c @@ -65,6 +65,7 @@ void smbw_setup_shared(void) exit(1); } +static int locked; /***************************************************** lock the shared variable area @@ -79,10 +80,12 @@ static void lockit(void) } shared_fd = atoi(p); } - if (fcntl_lock(shared_fd,SMB_F_SETLKW,0,1,F_WRLCK)==False) { + if (locked==0 && + fcntl_lock(shared_fd,SMB_F_SETLKW,0,1,F_WRLCK)==False) { DEBUG(0,("ERROR: can't get smbw shared lock\n")); exit(1); } + locked++; } /***************************************************** @@ -90,7 +93,10 @@ unlock the shared variable area *******************************************************/ static void unlockit(void) { - fcntl_lock(shared_fd,SMB_F_SETLK,0,1,F_UNLCK); + locked--; + if (locked == 0) { + fcntl_lock(shared_fd,SMB_F_SETLK,0,1,F_UNLCK); + } } @@ -122,11 +128,14 @@ char *smbw_getshared(const char *name) i=0; while (i < shared_size) { char *n, *v; + int l1, l2; + + l1 = SVAL(&variables[i], 0); + l2 = SVAL(&variables[i], 2); - n = &variables[i]; - i += strlen(n)+1; - v = &variables[i]; - i += strlen(v)+1; + n = &variables[i+4]; + v = &variables[i+4+l1]; + i += 4+l1+l2; if (strcmp(name,n)) { continue; @@ -150,25 +159,30 @@ set a variable in the shared area void smbw_setshared(const char *name, const char *val) { int len; + int l1, l2; /* we don't allow variable overwrite */ if (smbw_getshared(name)) return; lockit(); - len = strlen(name) + strlen(val) + 2; + l1 = strlen(name)+1; + l2 = strlen(val)+1; - variables = (char *)Realloc(variables, shared_size + len); + variables = (char *)Realloc(variables, shared_size + l1+l2+4); if (!variables) { DEBUG(0,("out of memory in smbw_setshared\n")); exit(1); } - pstrcpy(&variables[shared_size], name); - shared_size += strlen(name)+1; - pstrcpy(&variables[shared_size], val); - shared_size += strlen(val)+1; + SSVAL(&variables[shared_size], 0, l1); + SSVAL(&variables[shared_size], 2, l2); + + pstrcpy(&variables[shared_size] + 4, name); + pstrcpy(&variables[shared_size] + 4 + l1, val); + + shared_size += l1+l2+4; lseek(shared_fd, 0, SEEK_SET); if (write(shared_fd, variables, shared_size) != shared_size) { |