Fixes a few serious xget bugfixes:
-Commented out spc_close calls on an error as there is still a library
bug.  I will fix this library bug next week.
-Fixes segfault in redir_read
-Fixes problem with file names being stored incorrectly (Thanks Abhishek
for pointing this out)

-Adds a -m option to specify the maximum number of connections allowed

-  
Hugh Greenberg
Los Alamos National Laboratory, CCS-1
Email: [EMAIL PROTECTED]
Phone: (505) 665-6471

Index: xget.c
===================================================================
--- xget.c	(revision 714)
+++ xget.c	(working copy)
@@ -106,7 +106,7 @@
 
 static void 
 usage(char *name) {
-	fprintf(stderr, "usage as the master server: %s [-D debuglevel] [-p port] [-o] [-x] %s", 
+	fprintf(stderr, "usage as the master server: %s [-D debuglevel] [-p port] [-o] [-x] [-m] %s", 
 		name, " file|directory\n");
 	fprintf(stderr, "usage as a client         : %s [-D debuglevel] [-p port] %s %s", 
 		name, "<-n netaddr> [-s] [-o] <src file | src dir | .> ", 
@@ -492,14 +492,14 @@
 
 			if (f->finished == 4) {
 				debug(Dbgfn, "Error downloading file %s\n", f->lname);
-				if (f->datafid) {
+/*				if (f->datafid) {
 					spc_close(f->datafid);
 					f->datafid = NULL;
 				}
-				
+			
 				if (f->fs && f->fs != masterfs)
 					spc_umount(f->fs);		       
-				
+*/			
 				f->finished = 2;
 			}
 			
@@ -839,8 +839,14 @@
 	    Spuser *usr, Spgroup *grp, void *aux)
 {
 	Spfile *ret;
+	char *sname;
 
-	ret = spfile_alloc(parent, name, mode, qpath, ops, aux);
+	if (name && (sname = strrchr(name, '/'))) 
+		sname++;
+	else 
+		sname = name;
+	
+	ret = spfile_alloc(parent, sname, mode, qpath, ops, aux);
 	if (!ret)
 		return NULL;
 
@@ -954,11 +960,6 @@
 	grp = NULL;
 	nextf = NULL;
 
-	if ((name = strrchr(filename, '/'))) 
-		name++;
-	else 
-		name = filename;
-
 	if (lstat(filename, &st) < 0) {
 		sp_uerror(errno);
 		goto error;
@@ -966,7 +967,12 @@
 
 	if (skipmnt && (st.st_dev != fs_dev))
 		goto error;
-	
+
+	if ((name = strstr(filename, path)) != NULL) 
+		name = filename + strlen(path);
+	else
+		name = filename;
+
 	npmode = umode2npmode(st.st_mode);
 	if (!rootonly) {
 		usr = sp_unix_users->uid2user(sp_unix_users, st.st_uid);
@@ -1224,7 +1230,7 @@
 	    u32 npmode, Spuser *usr, Spgroup *grp)
 {
 	int n, blen, checksum;
-	char *buf, *fname, *redirto;
+	char *buf, *redirto;
 	Spcfid *datafid, *checksumfid, *availfid, *redirfid;
 	Spcfsys *redirfs;
 	File *file;
@@ -1254,13 +1260,7 @@
 	buf[n] = '\0';
 	checksum = strtoul(buf, NULL, 0);
 	spc_close(checksumfid);
-	fname = strrchr(nname, '/');
-	if (!fname)
-		fname = nname;
-	else
-		fname++;
-
-	file = filealloc(dir, fname, lname, len, 0, mtime, 0, npmode, 
+	file = filealloc(dir, nname, lname, len, 0, mtime, 0, npmode, 
 			 usr, grp);
 	if (!file)
 		goto error;
@@ -1269,6 +1269,7 @@
 	file->datafid = NULL;
 	file->datafd = NULL;
 	file->availfid = NULL;
+	
 	/* check if we should go somewhere else for the file */
 	sprintf(buf, "%s/redir", nname);
 	redirfid = spc_open(masterfs, buf, Oread);
@@ -1320,8 +1321,9 @@
 	return 0;
 
 error:
-	file->finished = 4;	
-	if (datafid)
+	if (file)
+		file->finished = 4;	
+	/*	if (datafid)
 		spc_close(datafid);
 
 	if (checksumfid)
@@ -1334,9 +1336,9 @@
 		spc_umount(redirfs);
 		file->fs = NULL;
 	}
-	
+	*/
 	free(buf);
-	return -1;
+	return 0;
 }
 
 static int
@@ -1356,12 +1358,6 @@
 	if (!fid)
 		return -1;
 
-	dname = strrchr(nname, '/');
-	if (!dname)
-		dname = nname;
-	else
-		dname++;
-
 	if (stat(lname, &ustat) < 0) {
 		if (mkdir(lname, 0700) < 0) {
 			sp_uerror(errno);
@@ -1379,7 +1375,7 @@
 	}
 
 	if (strlen(nname) > 0)
-		dir = create_file(parent, dname, npmode, qpath++ * 16, &dir_ops,
+		dir = create_file(parent, nname, npmode, qpath++ * 16, &dir_ops,
 				  usr, grp, NULL);
 	else {
 		dir = parent;
@@ -1532,7 +1528,7 @@
 	
        	if (ret == -1 || sp_haserror()) {
 		sp_rerror(&ename, &ecode);
-		debug(Dbgfn, "Fatal error while setting up file %s\n", nname);
+		debug(Dbgfn, "Fatal error while setting up file %s: %s\n", nname, ename);
 		sp_werror(NULL, 0);
 		
 	}
@@ -1660,7 +1656,7 @@
 	xget_ename = NULL;
 	xget_ecode = 0;
 	
-	while ((c = getopt(argc, argv, "D:p:n:w:r:sox")) != -1) {
+	while ((c = getopt(argc, argv, "D:p:n:w:r:m:sox")) != -1) {
 		switch (c) {
 		case 'p':
 			port = strtol(optarg, &s, 10);
@@ -1690,6 +1686,11 @@
 		case 'x':
 			skipmnt = 1;
 			break;
+		case 'm':
+			maxconnections = strtol(optarg, &s, 10);
+			if (*s != '\0')
+				usage(argv[0]);
+			break;
 		default:
 			usage(argv[0]);
 		}
@@ -1872,16 +1873,16 @@
 
 	f = files;
 	while (f != NULL) {
-		if (f->datafd)
-			spcfd_remove(f->datafd);
-		if (f->datafid)
-			spc_close(f->datafid);
-		if (f->availfid)
+		/*if (f->datafd)
+		  spcfd_remove(f->datafd);
+		  if (f->datafid)
+		  spc_close(f->datafid);
+		  if (f->availfid)
 			spc_close(f->availfid);
 
 		if (netaddress && f->fs && f->fs != masterfs)
 			spc_umount(f->fs);
-		
+	  */
 		f1 = f->next;
 		free(f);
 		f = f1;
@@ -2023,7 +2024,7 @@
 			  of connections.  If the desired level cannot be found, just find
 			  a worker with the least number of connections. */
 
-			if (!t) {
+			if (!t && w->server) {
 				if (w->server->conns < maxconnections &&
 				    dl == w->slevel)
 					t = w;
@@ -2031,7 +2032,7 @@
 				else if (w->server->conns < maxconnections) 
 					t = w;
 			}
-			else {
+			else if (w->server) {
 				if (t->server->conns > w->server->conns && 
 				    dl == w->slevel)
 					t = w;
@@ -2175,7 +2176,7 @@
 			debug(Dbgsrvfn, "Could not find worker with address: %s\n",
 			      address);
 			free(address);
-			return -1;
+			return 0;
 		}
 
 		free(address);

Reply via email to