summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1994-09-28 14:53:20 +0000
committerjkh <jkh@FreeBSD.org>1994-09-28 14:53:20 +0000
commitecee3a20ff01b3919059cc0362277de08546ef6f (patch)
tree9a9aa16f8a6915608786dee9d7fd63baee01ec4e
parent0a36b6fcaa35545c0ca52c5a3c36e9880b82cdc2 (diff)
downloadFreeBSD-src-ecee3a20ff01b3919059cc0362277de08546ef6f.zip
FreeBSD-src-ecee3a20ff01b3919059cc0362277de08546ef6f.tar.gz
Ye GODS! What I had to go through to make this thing exit with a non-zero
return status when a transfer failed! Hopefully, the next release will do this more elegantly and make these changes short-lived.
-rw-r--r--usr.bin/ncftp/cmds.c40
-rw-r--r--usr.bin/ncftp/cmds.h4
-rw-r--r--usr.bin/ncftp/ftprc.c5
-rw-r--r--usr.bin/ncftp/ftprc.h2
-rw-r--r--usr.bin/ncftp/main.c12
-rw-r--r--usr.bin/ncftp/main.h2
-rw-r--r--usr.bin/ncftp/open.c7
7 files changed, 48 insertions, 24 deletions
diff --git a/usr.bin/ncftp/cmds.c b/usr.bin/ncftp/cmds.c
index 0ff1055..c467c3b 100644
--- a/usr.bin/ncftp/cmds.c
+++ b/usr.bin/ncftp/cmds.c
@@ -594,6 +594,7 @@ int mget(int argc, char **argv)
char *cp;
longstring local;
Sig_t oldintr;
+ int errs;
if (argc < 2)
argv = re_makeargv("(remote-files) ", &argc);
@@ -604,7 +605,7 @@ int mget(int argc, char **argv)
activemcmd = 1;
oldintr = Signal(SIGINT, mabort);
(void) setjmp(jabort);
- while ((cp = remglob(argv)) != NULL) {
+ while ((cp = remglob(argv, &errs)) != NULL) {
if (*cp == '\0') {
activemcmd = 0;
continue;
@@ -621,19 +622,22 @@ int mget(int argc, char **argv)
}
(void) Signal(SIGINT,oldintr);
activemcmd = 0;
- return NOERR;
+ if (!errs)
+ return NOERR;
+ else
+ return CMDERR;
} /* mget */
-char *remglob(char *argv[])
+char *remglob(char *argv[], int *errs)
{
static FILE *ftemp = NULL;
int oldverbose, i;
char *cp, *mode;
static string tmpname, str;
- int result, errs;
+ int result;
if (!activemcmd) {
xx:
@@ -647,7 +651,7 @@ xx:
if (ftemp == NULL) {
(void) tmp_name(tmpname);
oldverbose = verbose, verbose = V_QUIET;
- errs = 0;
+ *errs = 0;
for (mode = "w", i=1; argv[i] != NULL; i++, mode = "a") {
result = recvrequest ("NLST", tmpname, argv[i], mode);
if (i == 1)
@@ -658,11 +662,11 @@ xx:
(strpbrk(argv[i], globchars) != NULL) ? "No match" :
"No such file"
);
- errs++;
+ ++(*errs);
}
}
verbose = oldverbose;
- if (errs == (i - 1)) {
+ if (*errs == (i - 1)) {
/* Every pattern was in error, so we can't try anything. */
(void) unlink(tmpname); /* Shouldn't be there anyway. */
return NULL;
@@ -876,6 +880,7 @@ int mdelete(int argc, char **argv)
char *cp;
Sig_t oldintr;
string str;
+ int errs;
if (argc < 2)
argv = re_makeargv("(remote-files) ", &argc);
@@ -886,7 +891,7 @@ int mdelete(int argc, char **argv)
activemcmd = 1;
oldintr = Signal(SIGINT, mabort);
(void) setjmp(jabort);
- while ((cp = remglob(argv)) != NULL) {
+ while ((cp = remglob(argv, &errs)) != NULL) {
if (*cp == '\0') {
activemcmd = 0;
continue;
@@ -903,7 +908,10 @@ int mdelete(int argc, char **argv)
}
(void) Signal(SIGINT, oldintr);
activemcmd = 0;
- return NOERR;
+ if (!errs)
+ return NOERR;
+ else
+ return CMDERR;
} /* mdelete */
@@ -1282,9 +1290,12 @@ int rmthelp(int argc, char **argv)
/*ARGSUSED*/
int quit(int argc, char **argv)
{
- close_up_shop();
+ int rc;
+
+ /* slightly kludge. argc == -1 means failure from some other caller */
+ rc = close_up_shop() || argc == -1;
trim_log();
- exit(0);
+ exit(rc);
} /* quit */
@@ -1331,19 +1342,22 @@ int disconnect(int argc, char **argv)
-void
+int
close_up_shop(void)
{
static int only_once = 0;
+ int rcode = 0;
+
if (only_once++ > 0)
return;
if (connected)
(void) disconnect(0, NULL);
- WriteRecentSitesFile();
+ rcode = WriteRecentSitesFile();
if (logf != NULL) {
(void) fclose(logf);
logf = NULL;
}
+ return rcode;
} /* close_up_shop */
diff --git a/usr.bin/ncftp/cmds.h b/usr.bin/ncftp/cmds.h
index fe1cacc..11dff6a 100644
--- a/usr.bin/ncftp/cmds.h
+++ b/usr.bin/ncftp/cmds.h
@@ -77,7 +77,7 @@ int rem_glob_one(char *pattern);
int get(int argc, char **argv);
void mabort SIG_PARAMS;
int mget(int argc, char **argv);
-char *remglob(char *argv[]);
+char *remglob(char *argv[], int *);
int setverbose(int argc, char **argv);
int setprompt(int argc, char **argv);
int setdebug(int argc, char **argv);
@@ -100,7 +100,7 @@ int rmthelp(int argc, char **argv);
int quit(int argc, char **argv);
void close_streams(int wantShutDown);
int disconnect(int argc, char **argv);
-void close_up_shop(void);
+int close_up_shop(void);
int globulize(char **cpp);
int cdup(int argc, char **argv);
int syst(int argc, char **argv);
diff --git a/usr.bin/ncftp/ftprc.c b/usr.bin/ncftp/ftprc.c
index e8380ce..c048852 100644
--- a/usr.bin/ncftp/ftprc.c
+++ b/usr.bin/ncftp/ftprc.c
@@ -258,11 +258,12 @@ static void SortRecentList(void)
-void WriteRecentSitesFile(void)
+int WriteRecentSitesFile(void)
{
FILE *rfp;
recentsite *r;
int i;
+ int retcode = 0;
if ((recent_file[0] != 0) && (nRecents > 0) && (keep_recent)) {
dbprintf("Attempting to write %s...\n", recent_file);
@@ -279,8 +280,10 @@ void WriteRecentSitesFile(void)
(void) chmod(recent_file, 0600);
} else {
perror(recent_file);
+ ++retcode;
}
}
+ return retcode;
} /* WriteRecentSitesFile */
diff --git a/usr.bin/ncftp/ftprc.h b/usr.bin/ncftp/ftprc.h
index 14eec88..eed0217 100644
--- a/usr.bin/ncftp/ftprc.h
+++ b/usr.bin/ncftp/ftprc.h
@@ -30,7 +30,7 @@ void AddNewSitePtr(char *word);
int ruserpass2(char *host, char **user, char **pass, char **acct);
void GetFullSiteName(char *host, char *lastdir);
void ReadRecentSitesFile(void);
-void WriteRecentSitesFile(void);
+int WriteRecentSitesFile(void);
void AddRecentSite(char *host, char *lastdir);
void UpdateRecentSitesList(char *host, char *lastdir);
void PrintSiteList(void);
diff --git a/usr.bin/ncftp/main.c b/usr.bin/ncftp/main.c
index 446c1c3..e2f620a 100644
--- a/usr.bin/ncftp/main.c
+++ b/usr.bin/ncftp/main.c
@@ -390,7 +390,8 @@ For testing purposes only. Do not re-distribute or subject to novice users."
(void) Signal(SIGPIPE, lostpeer);
}
for (;;) {
- (void) cmdscanner(top);
+ if (cmdscanner(top))
+ exit(1);
top = 1;
}
} /* main */
@@ -569,9 +570,10 @@ void lostpeer SIG_PARAMS
/*
* Command parser.
*/
-void cmdscanner(int top)
+int cmdscanner(int top)
{
register struct cmd *c;
+ int cmd_status, rcode = 0;
if (!top)
(void) putchar('\n');
@@ -601,13 +603,17 @@ void cmdscanner(int top)
(void) printf ("Not connected.\n");
continue;
}
- if ((*c->c_handler)(margc, margv) == USAGE)
+ cmd_status = (*c->c_handler)(margc, margv);
+ if (cmd_status == USAGE)
cmd_usage(c);
+ else if (cmd_status == CMDERR)
+ rcode = 1;
if (c->c_handler != help)
break;
}
(void) Signal(SIGINT, intr);
(void) Signal(SIGPIPE, lostpeer);
+ return rcode;
} /* cmdscanner */
diff --git a/usr.bin/ncftp/main.h b/usr.bin/ncftp/main.h
index 1891b61..fd6438c 100644
--- a/usr.bin/ncftp/main.h
+++ b/usr.bin/ncftp/main.h
@@ -22,7 +22,7 @@ int init_arrays(void);
void init_transfer_buffer(void);
void init_prompt(void);
void lostpeer SIG_PARAMS;
-void cmdscanner(int top);
+int cmdscanner(int top);
char *strprompt(void);
void makeargv(void);
char *slurpstring(void);
diff --git a/usr.bin/ncftp/open.c b/usr.bin/ncftp/open.c
index 66733a8..fbbe794 100644
--- a/usr.bin/ncftp/open.c
+++ b/usr.bin/ncftp/open.c
@@ -399,6 +399,7 @@ void CheckRemoteSystemType(int force_binary)
void ColonMode(OpenOptions *openopt)
{
int tmpverbose;
+ int cmdstatus;
/* How do we tell if colonmodepath is a file or a directory?
* We first try cd'ing to the path first. If we can, then it
@@ -437,15 +438,15 @@ void ColonMode(OpenOptions *openopt)
/* get() also handles 'more'. */
if (openopt->ftpcat)
- (void) get(margc, margv);
+ cmdstatus = get(margc, margv);
else
- (void) mget(margc, margv);
+ cmdstatus = mget(margc, margv);
/* If we were invoked from the command line, quit
* after we got this file.
*/
if (eventnumber == 0L) {
- (void) quit(0, NULL);
+ (void) quit(cmdstatus == CMDERR ? -1 : 0, NULL);
}
}
verbose = tmpverbose;
OpenPOWER on IntegriCloud