diff options
author | Samba Release Account <samba-bugs@samba.org> | 1997-05-20 00:32:51 +0000 |
---|---|---|
committer | Samba Release Account <samba-bugs@samba.org> | 1997-05-20 00:32:51 +0000 |
commit | aa864415c5183c948fe9ae221023d40265c38013 (patch) | |
tree | 29e0aa79328568d93211d175353f1fd1bc2d3737 /source3/utils/status.c | |
parent | 5495a3446d769a2501ee558bda54146bef507e78 (diff) | |
download | samba-aa864415c5183c948fe9ae221023d40265c38013.tar.gz samba-aa864415c5183c948fe9ae221023d40265c38013.tar.xz samba-aa864415c5183c948fe9ae221023d40265c38013.zip |
dir.c: Fixed double slash issue.
includes.h: Changed to ifdef FAST_SHARE_MODES.
ipc.c: Changed lp_workgroup() to myworkgroup.
loadparm.c: Added new shared mem parameters. Added Luke's fix.
locking.c: Rewrite to do share modes better (both fast and slow modes).
nameannounce.c: Changed lp_workgroup() to myworkgroup. Added Luke's fix.
nameconf.c: Changed lp_workgroup() to myworkgroup.
namedbname.c: Improved debug.
namedbserver.c: Changed lp_workgroup() to myworkgroup.
namedbsubnet.c: Added Luke's fix - rewritten somewhat.
namedbwork.c: Changed lp_workgroup() to myworkgroup.
nameelect.c: Added Luke's fix - rewritten somewhat.
nameresp.c: Stoped shadowing global.
nameserv.c: Added Luke's fix - Improved debug.
nameservreply.c: Improved debug.
namework.c: Changed lp_workgroup() to myworkgroup.
nmbd.c: Added Luke's fix - Changed lp_workgroup() to myworkgroup.
pipes.c: Changed lp_workgroup() to myworkgroup.
proto.h: Added Luke's fix, added smb_shm_ proto's.
reply.c: Changed lp_workgroup() to myworkgroup.
server.c: Rewrite to do share modes better (both fast and slow modes).
shmem.c: Rewrite to do share modes better (both fast and slow modes).
smb.h: Rewrite to do share modes better (both fast and slow modes).
status.c: Rewrite to do share modes better (both fast and slow modes).
trans2.c: Fixed double slash issue.
util.c: Tidied up, created myworkgroup.
Jeremy Allison (jallison@whistle.com).
(This used to be commit 2a1711eaaf08bb6776770cd3c96b3010f431a677)
Diffstat (limited to 'source3/utils/status.c')
-rw-r--r-- | source3/utils/status.c | 260 |
1 files changed, 177 insertions, 83 deletions
diff --git a/source3/utils/status.c b/source3/utils/status.c index e8e57b3dd7c..b439741e6c6 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -53,6 +53,81 @@ int Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */ int Ucrit_MaxPid=0; /* added by OH */ unsigned int Ucrit_IsActive = 0; /* added by OH */ +#ifndef FAST_SHARE_MODES +static char *read_share_file(int fd, char *fname, char *progname) +{ + struct stat sb; + char *buf; + int size; + + if(fstat(fd, &sb) != 0) + { + printf("%s: ERROR: read_share_file: Failed to do stat on share file %s (%s)\n", + progname, fname, strerror(errno)); + return 0; + } + + if(sb.st_size == 0) + { + return 0; + } + + /* Allocate space for the file */ + if((buf = (char *)malloc(sb.st_size)) == NULL) + { + printf("%s: read_share_file: malloc for file size %d fail !\n", + progname, (int)sb.st_size); + return 0; + } + + if(lseek(fd, 0, SEEK_SET) != 0) + { + printf("%s: ERROR: read_share_file: Failed to reset position to 0 \ +for share file %s (%s)\n", progname, fname, strerror(errno)); + if(buf) + free(buf); + return 0; + } + + if (read(fd,buf,sb.st_size) != sb.st_size) + { + printf("%s: ERROR: read_share_file: Failed to read share file %s (%s)\n", + progname, fname, strerror(errno)); + if(buf) + free(buf); + return 0; + } + + if (IVAL(buf,0) != LOCKING_VERSION) { + printf("%s: ERROR: read_share_file: share file %s has incorrect \ +locking version (was %d, should be %d).\n",fname, + progname, IVAL(buf,0), LOCKING_VERSION); + if(buf) + free(buf); + return 0; + } + + /* Sanity check for file contents */ + size = sb.st_size; + size -= 10; /* Remove the header */ + + /* Remove the filename component. */ + size -= SVAL(buf, 8); + + /* The remaining size must be a multiple of 16 - error if not. */ + if((size % 16) != 0) + { + printf("%s: ERROR: read_share_file: share file %s is an incorrect length.\n", + progname, fname); + if(buf) + free(buf); + return 0; + } + + return buf; +} +#endif /* FAST_SHARE_MODES */ + int main(int argc, char *argv[]) { FILE *f; @@ -64,16 +139,16 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ BOOL firstopen=True; BOOL processes_only=False; int last_pid=0; -#if FAST_SHARE_MODES +#ifdef FAST_SHARE_MODES pstring shmem_file_name; - share_mode_record *scanner_p; - share_mode_record *prev_p; + share_mode_record *file_scanner_p; + smb_shm_offset_t *mode_array; int bytes_free, bytes_used, bytes_overhead, bytes_total; -#else - int n; +#else /* FAST_SHARE_MODES */ void *dir; char *s; -#endif +#endif /* FAST_SHARE_MODES */ + int i; struct session_record *ptr; @@ -226,101 +301,110 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ printf("\n"); -#if FAST_SHARE_MODES +#ifdef FAST_SHARE_MODES /******************************************************************* initialize the shared memory for share_mode management ******************************************************************/ - strcpy(shmem_file_name,lp_lockdir()); trim_string(shmem_file_name,"","/"); if (!*shmem_file_name) exit(-1); strcat(shmem_file_name, "/SHARE_MEM_FILE"); - if(!smb_shm_open(shmem_file_name, SHMEM_SIZE)) exit(-1); + if(!smb_shm_open(shmem_file_name, lp_shmem_size())) exit(-1); - if(!smb_shm_lock()) + mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off()); + if(mode_array == NULL) { - smb_shm_close(); - exit (-1); + printf("%s: base of shared memory hash array == 0! Exiting.\n", argv[0]); + smb_shm_close(); + exit(-1); } - scanner_p = (share_mode_record *)smb_shm_offset2addr(smb_shm_get_userdef_off()); - prev_p = scanner_p; - while(scanner_p) + for( i = 0; i < lp_shmem_hash_size(); i++) { - int pid,mode; - struct timeval t; - - pid = scanner_p->pid; - - if ( !Ucrit_checkPid(pid) ) - { - prev_p = scanner_p ; - scanner_p = (share_mode_record *)smb_shm_offset2addr(scanner_p->next_offset); - continue; - } + smb_shm_lock_hash_entry(i); + if(mode_array[i] == NULL_OFFSET) + { + smb_shm_unlock_hash_entry(i); + continue; + } + file_scanner_p = (share_mode_record *)smb_shm_offset2addr(mode_array[i]); + while((file_scanner_p != 0) && (file_scanner_p->num_share_mode_entries != 0)) + { + share_mode_entry *entry_scanner_p = + (share_mode_entry *)smb_shm_offset2addr( + file_scanner_p->share_mode_entries); + + while(entry_scanner_p != 0) + { + struct timeval t; + int pid = entry_scanner_p->pid; + int mode = entry_scanner_p->share_mode; - if( (scanner_p->locking_version != LOCKING_VERSION) || !process_exists(pid)) + t.tv_sec = entry_scanner_p->time.tv_sec; + t.tv_usec = entry_scanner_p->time.tv_usec; + strcpy(fname, file_scanner_p->file_name); +#else /* FAST_SHARE_MODES */ + + /* For slow share modes go through all the files in + the share mode directory and read the entries in + each. + */ + + dir = opendir(lp_lockdir()); + if (!dir) { - DEBUG(2,("Deleting stale share mode record")); - if(prev_p == scanner_p) - { - smb_shm_set_userdef_off(scanner_p->next_offset); - smb_shm_free(smb_shm_addr2offset(scanner_p)); - scanner_p = (share_mode_record *)smb_shm_offset2addr(smb_shm_get_userdef_off()); - prev_p = scanner_p; - } - else - { - prev_p->next_offset = scanner_p->next_offset; - smb_shm_free(smb_shm_addr2offset(scanner_p)); - scanner_p = (share_mode_record *)smb_shm_offset2addr(prev_p->next_offset); - } - continue; + printf("%s: Unable to open lock directory %s.\n", argv[0], lp_lockdir()); + return(0); } - t.tv_sec = scanner_p->time.tv_sec; - t.tv_usec = scanner_p->time.tv_usec; - mode = scanner_p->share_mode; - strcpy(fname, scanner_p->file_name); -#else - dir = opendir(lp_lockdir()); - if (!dir) return(0); while ((s=readdirname(dir))) { - char buf[20]; - int pid,mode; - struct timeval t; + char *buf; + char *base; int fd; pstring lname; - int dev,inode; + uint32 dev,inode; - if (sscanf(s,"share.%d.%d",&dev,&inode)!=2) continue; + if (sscanf(s,"share.%u.%u",&dev,&inode)!=2) continue; strcpy(lname,lp_lockdir()); trim_string(lname,NULL,"/"); strcat(lname,"/"); strcat(lname,s); - fd = open(lname,O_RDONLY,0); - if (fd < 0) continue; - if (read(fd,buf,20) != 20) continue; - n = read(fd,fname,sizeof(fname)); - fname[MAX(n,0)]=0; - close(fd); - - t.tv_sec = IVAL(buf,4); - t.tv_usec = IVAL(buf,8); - mode = IVAL(buf,12); - pid = IVAL(buf,16); - - if ( !Ucrit_checkPid(pid) ) /* added by OH */ - continue; - - if (IVAL(buf,0) != LOCKING_VERSION || !process_exists(pid)) { - if (unlink(lname)==0) - printf("Deleted stale share file %s\n",s); - continue; + fd = open(lname,O_RDWR,0); + if (fd < 0) + { + printf("%s: Unable to open share file %s.\n", argv[0], lname); + continue; } -#endif + + /* Lock the share mode file while we read it. */ + if(fcntl_lock(fd, F_SETLKW, 0, 1, F_WRLCK) == False) + { + printf("%s: Unable to lock open share file %s.\n", argv[0], lname); + close(fd); + continue; + } + + if(( buf = read_share_file( fd, lname, argv[0] )) == NULL) + { + close(fd); + continue; + } + strcpy( fname, &buf[10]); + close(fd); + + base = buf + 10 + SVAL(buf,8); + for( i = 0; i < IVAL(buf, 4); i++) + { + char *p = base + (i*16); + struct timeval t; + int pid = IVAL(p,12); + int mode = IVAL(p,8); + + t.tv_sec = IVAL(p,0); + t.tv_usec = IVAL(p,4); +#endif /* FAST_SHARE_MODES */ fname[sizeof(fname)-1] = 0; @@ -349,28 +433,38 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ } printf(" %s %s",fname,asctime(LocalTime((time_t *)&t.tv_sec))); -#if FAST_SHARE_MODES - prev_p = scanner_p ; - scanner_p = (share_mode_record *)smb_shm_offset2addr(scanner_p->next_offset); - } /* end while */ +#ifdef FAST_SHARE_MODES + + entry_scanner_p = (share_mode_entry *)smb_shm_offset2addr( + entry_scanner_p->next_share_mode_entry); + } /* end while entry_scanner_p */ + file_scanner_p = (share_mode_record *)smb_shm_offset2addr( + file_scanner_p->next_offset); + } /* end while file_scanner_p */ + smb_shm_unlock_hash_entry(i); + } /* end for */ smb_shm_get_usage(&bytes_free, &bytes_used, &bytes_overhead); bytes_total = bytes_free + bytes_used + bytes_overhead; - smb_shm_unlock(); /******************************************************************* deinitialize the shared memory for share_mode management ******************************************************************/ smb_shm_close(); -#else +#else /* FAST_SHARE_MODES */ + } /* end for i */ + + if(buf) + free(buf); + base = 0; } /* end while */ closedir(dir); -#endif +#endif /* FAST_SHARE_MODES */ if (firstopen) printf("No locked files\n"); -#if FAST_SHARE_MODES +#ifdef FAST_SHARE_MODES printf("\nShare mode memory usage (bytes):\n"); printf(" %d(%d%%) free + %d(%d%%) used + %d(%d%%) overhead = %d(100%%) total\n", bytes_free, (bytes_free * 100)/bytes_total, @@ -378,7 +472,7 @@ unsigned int Ucrit_IsActive = 0; /* added by OH */ bytes_overhead, (bytes_overhead * 100)/bytes_total, bytes_total); -#endif +#endif /* FAST_SHARE_MODES */ return (0); } |