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.
This commit is contained in:
Jordan K. Hubbard 1994-09-28 14:53:20 +00:00
parent ccd314ec46
commit 66f8414941
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=3163
7 changed files with 48 additions and 24 deletions

View File

@ -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 */

View File

@ -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);

View File

@ -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 */

View File

@ -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);

View File

@ -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 */

View File

@ -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);

View File

@ -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;