summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-08-18 00:01:00 +0000
committerLuke Leighton <lkcl@samba.org>1999-08-18 00:01:00 +0000
commit7a0595b23461c259f2ce6662f0d2a5a047c1c0fb (patch)
tree233cdf95e294fcd24fbc24aa95e5fa1bf0443e67
parent0cf1de5fdd6ac496781b0952fa2375c92ad0ed51 (diff)
downloadsamba-7a0595b23461c259f2ce6662f0d2a5a047c1c0fb.tar.gz
samba-7a0595b23461c259f2ce6662f0d2a5a047c1c0fb.tar.bz2
samba-7a0595b23461c259f2ce6662f0d2a5a047c1c0fb.zip
use read() instead of fread() as fread() fails on redhat 6.
(This used to be commit b1025d499ba81233634daf78c3345b9620f9b3a6)
-rw-r--r--source3/Makefile.in8
-rw-r--r--source3/lib/util_status.c38
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;