From 7a0595b23461c259f2ce6662f0d2a5a047c1c0fb Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 18 Aug 1999 00:01:00 +0000 Subject: use read() instead of fread() as fread() fails on redhat 6. (This used to be commit b1025d499ba81233634daf78c3345b9620f9b3a6) --- source3/Makefile.in | 8 +++++--- source3/lib/util_status.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/source3/Makefile.in b/source3/Makefile.in index 53b51eb3ae..55ae4d795d 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -99,6 +99,8 @@ QUOTAOBJS=@QUOTAOBJS@ # object file lists ###################################################################### +LIBSTATUS_OBJ = lib/util_status.o + LIB_OBJ = lib/charcnv.o lib/charset.o lib/debug.o lib/fault.o \ lib/getsmbpass.o lib/interface.o lib/kanji.o \ lib/md5.o lib/hmacmd5.o lib/md4.o \ @@ -108,7 +110,7 @@ LIB_OBJ = lib/charcnv.o lib/charset.o lib/debug.o lib/fault.o \ lib/access.o lib/smbrun.o \ lib/bitmap.o lib/crc32.o lib/util_sid.o lib/snprintf.o \ lib/util_str.o lib/util_unistr.o \ - lib/util_file.o lib/util_status.o mem_man/mem_man.o \ + lib/util_file.o mem_man/mem_man.o \ lib/util_sock.o lib/unix_sec_ctxt.o @@ -191,7 +193,7 @@ PRINTING_OBJ = printing/pcap.o printing/print_svid.o printing/printing.o SMBD_OBJ = $(SMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \ $(RPC_SERVER_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \ $(LOCKING_OBJ) $(SAMPASSDB_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) \ - $(PRINTING_OBJ) $(PROFILE_OBJ) $(LIB_OBJ) + $(LIBSTATUS_OBJ) $(PRINTING_OBJ) $(PROFILE_OBJ) $(LIB_OBJ) NMBD_OBJ1 = nmbd/asyncdns.o nmbd/nmbd.o nmbd/nmbd_become_dmb.o \ @@ -226,7 +228,7 @@ MAKE_SMBCODEPAGE_OBJ = utils/make_smbcodepage.o $(PARAM_OBJ) \ MAKE_PRINTERDEF_OBJ = utils/make_printerdef.o $(PARAM_OBJ) \ $(UBIQX_OBJ) $(LIB_OBJ) -STATUS_OBJ = utils/status.o $(LOCKING_OBJ) $(PARAM_OBJ) \ +STATUS_OBJ = utils/status.o $(LIBSTATUS_OBJ) $(LOCKING_OBJ) $(PARAM_OBJ) \ $(UBIQX_OBJ) $(PROFILE_OBJ) $(LIB_OBJ) TESTPARM_OBJ = utils/testparm.o \ diff --git a/source3/lib/util_status.c b/source3/lib/util_status.c index ef6eff43c4..d635cb08b5 100644 --- a/source3/lib/util_status.c +++ b/source3/lib/util_status.c @@ -30,9 +30,12 @@ parse the STATUS..LCK file. caller is responsible for freeing *crec. BOOL get_connection_status(struct connect_record **crec, uint32 *connection_count) { - FILE *f; + int fd; pstring fname; int conn; + int num_recs; + struct connect_record *c; + int i; if (crec == NULL || connection_count == NULL) { @@ -44,37 +47,44 @@ BOOL get_connection_status(struct connect_record **crec, trim_string(fname,"","/"); pstrcat(fname,"/STATUS..LCK"); - f = sys_fopen(fname,"r"); - if (!f) { +fd = sys_open(fname,O_RDONLY, 0); + + if (fd == -1) + { DEBUG(0,("Couldn't open status file %s\n",fname)); return False; } - DEBUG(5,("Opened status file %s\n",fname)); - - conn=0; (*crec) = NULL; - while (!feof(f)) - { + num_recs = file_size(fname) / sizeof(*c); + + DEBUG(5,("Opened status file %s, record count %d\n",fname, num_recs)); + + for (i = 0, conn = 0; i < num_recs; i++) + { (*crec) = Realloc((*crec), (conn+1) * sizeof((*crec)[conn])); if ((*crec) == NULL) { DEBUG(0,("Realloc failed in get_connection_status\n")); return False; } - if (fread(&(*crec)[conn],sizeof((*crec)[conn]),1,f) != 1) + c = &((*crec)[conn]); + if (sys_lseek(fd,i*sizeof(*c),SEEK_SET) != i*sizeof(*c) || + read(fd,c,sizeof(*c)) != sizeof(*c)) + { + DEBUG(0,("unable to read a crec in get_connection_status\n")); break; - if ((*crec)[conn].cnum == -1) continue; - if ( (*crec)[conn].magic == 0x280267 && process_exists((*crec)[conn].pid) - ) + } + DEBUG(10,("cnum:%u. pid: %d magic: %x\n", + c->cnum, c->pid, c->magic)); + if ( c->magic == 0x280267 && process_exists(c->pid) ) { - DEBUG(10,("cnun : %u \n",(*crec)[conn].cnum)); conn++; } } - fclose(f); + close(fd); (*connection_count)=conn; return True; -- cgit