diff scp.c @ 299:740e782679be ucc-axis-hack

Various changes to compile+kind of run on UCC's axis board. Note that fprintf(stdin -> printf( accounts for many of the changes
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 12:57:09 +0000
parents 161557a9dde8
children 973fccb59ea4
line wrap: on
line diff
--- a/scp.c	Fri Dec 09 06:10:27 2005 +0000
+++ b/scp.c	Sat Mar 25 12:57:09 2006 +0000
@@ -144,7 +144,7 @@
 	int pin[2], pout[2], reserved[2];
 
 	if (verbose_mode)
-		fprintf(stderr,
+		printf(
 		    "Executing: program %s host %s, user %s, command %s\n",
 		    ssh_program, host,
 		    remuser ? remuser : "(unspecified)", cmd);
@@ -158,7 +158,7 @@
 	/* Create a socket pair for communicating with ssh. */
 	if (pipe(pin) < 0 || pipe(pout) < 0)
 	{
-		fprintf(stderr, "Fatal error: pipe: %s\n", strerror(errno));
+		printf( "Fatal error: pipe: %s\n", strerror(errno));
 		exit(1);
 	}
 
@@ -166,8 +166,22 @@
 	close(reserved[0]);
 	close(reserved[1]);
 
+    // uClinux needs to build the args here before vforking,
+    // otherwise we do it later on.
+#ifdef __uClinux__
+	args.list[0] = ssh_program;
+	if (remuser != NULL)
+		addargs(&args, "-l%s", remuser);
+	addargs(&args, "%s", host);
+	addargs(&args, "%s", cmd);
+#endif /* __uClinux__ */
+
 	/* Fork a child to execute the command on the remote host using ssh. */
+#ifdef __uClinux__
+	do_cmd_pid = vfork();
+#else
 	do_cmd_pid = fork();
+#endif /* __uClinux__ */
 	if (do_cmd_pid == 0) {
 		/* Child. */
 		close(pin[1]);
@@ -177,6 +191,7 @@
 		close(pin[0]);
 		close(pout[1]);
 
+#ifndef __uClinux__
 		args.list[0] = ssh_program;
 		if (remuser != NULL) {
 			addargs(&args, "-l");
@@ -184,14 +199,31 @@
 		}
 		addargs(&args, "%s", host);
 		addargs(&args, "%s", cmd);
+#endif
 
 		execvp(ssh_program, args.list);
 		perror(ssh_program);
 		exit(1);
 	} else if (do_cmd_pid == -1) {
-		fprintf(stderr, "Fatal error: fork: %s\n", strerror(errno));
+		printf( "Fatal error: fork: %s\n", strerror(errno));
 		exit(1);
 	}
+
+#if 0 //__uClinux__
+	/* clean up command */
+	/* pop cmd */
+	free(args->list[--args->num]);
+	args->list[args->num]=NULL;
+	/* pop host */
+	free(args->list[--args->num-1]);
+	args->list[args->num]=NULL;
+	/* pop user */
+	if (remuser != NULL) {
+		free(args->list[--args->num-1]);
+		args->list[args->num]=NULL;
+	}
+#endif /* __uClinux__ */
+	  
 	/* Parent.  Close the other side, and return the local side. */
 	close(pin[0]);
 	*fdout = pin[1];
@@ -320,7 +352,7 @@
 	argv += optind;
 
 	if ((pwd = getpwuid(userid = getuid())) == NULL) {
-		fprintf(stderr, "unknown user %u", (u_int) userid);
+		printf( "unknown user %u", (u_int) userid);
 	}
 
 #ifdef PROGRESS_METER
@@ -451,7 +483,7 @@
 				    thost, targ);
 			}
 			if (verbose_mode)
-				fprintf(stderr, "Executing: %s\n", bp);
+				printf( "Executing: %s\n", bp);
 			(void) system(bp);
 			(void) xfree(bp);
 		} else {	/* local to remote */
@@ -487,7 +519,7 @@
 			    iamrecursive ? " -r" : "", pflag ? " -p" : "",
 			    argv[i], argv[argc - 1]);
 			if (verbose_mode)
-				fprintf(stderr, "Executing: %s\n", bp);
+				printf( "Executing: %s\n", bp);
 			if (system(bp))
 				++errs;
 			(void) xfree(bp);
@@ -584,7 +616,7 @@
 		    (u_int) (stb.st_mode & FILEMODEMASK),
 		    (int64_t)stb.st_size, last);
 		if (verbose_mode) {
-			fprintf(stderr, "Sending file modes: %s", buf);
+			printf( "Sending file modes: %s", buf);
 		}
 		(void) atomicio(vwrite, remout, buf, strlen(buf));
 		if (response() < 0)
@@ -662,7 +694,7 @@
 	(void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",
 	    (u_int) (statp->st_mode & FILEMODEMASK), 0, last);
 	if (verbose_mode)
-		fprintf(stderr, "Entering directory: %s", path);
+		printf( "Entering directory: %s", path);
 	(void) atomicio(vwrite, remout, path, strlen(path));
 	if (response() < 0) {
 		closedir(dirp);
@@ -1051,7 +1083,7 @@
 void
 usage(void)
 {
-	(void) fprintf(stderr,
+	(void) printf(
 	    "usage: scp [-pqrvBC1246] [-F config] [-S program] [-P port]\n"
 	    "           [-c cipher] [-i identity] [-l limit] [-o option]\n"
 	    "           [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
@@ -1077,9 +1109,9 @@
 
 	if (!iamremote) {
 		va_start(ap, fmt);
-		vfprintf(stderr, fmt, ap);
+		vprintf( fmt, ap);
 		va_end(ap);
-		fprintf(stderr, "\n");
+		printf( "\n");
 	}
 }
 
@@ -1123,7 +1155,7 @@
 	} while (*++cp);
 	return (1);
 
-bad:	fprintf(stderr, "%s: invalid user name\n", cp0);
+bad:	printf( "%s: invalid user name\n", cp0);
 	return (0);
 }