From 686a8267f3ad753143303673e21dfed5cb314447 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 7 Sep 2011 12:13:44 +0000 Subject: [PATCH] Fix more warnings; output errors to the users. --- citadel/textclient/client_chat.c | 7 +++++++ citadel/textclient/commands.c | 10 +++++++--- citadel/textclient/messages.c | 27 +++++++++++++++++++-------- citadel/textclient/rooms.c | 21 ++++++++++----------- citadel/textclient/routines2.c | 10 ++++++++-- citadel/textclient/tuiconfig.c | 15 +++++---------- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/citadel/textclient/client_chat.c b/citadel/textclient/client_chat.c index dbe0ce900..7bf21af22 100644 --- a/citadel/textclient/client_chat.c +++ b/citadel/textclient/client_chat.c @@ -108,6 +108,13 @@ void chatmode(CtdlIPC *ipc) tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); + if (retval < 0) { + color(BRIGHT_WHITE); + scr_printf("Server gone Exiting chat mode\n"); + scr_flush(); + return; + } + /* If there's data from the keyboard... */ if (FD_ISSET(0, &rfds)) { ch = scr_getc(SCR_BLOCK); diff --git a/citadel/textclient/commands.c b/citadel/textclient/commands.c index 7e5a80e88..e98dad387 100644 --- a/citadel/textclient/commands.c +++ b/citadel/textclient/commands.c @@ -135,7 +135,7 @@ char was_a_key_pressed(void) { * in the middle of a data transfer from the server, in which case * sending a NOOP would throw the client protocol out of sync. */ - if (FD_ISSET(0, &rfds)) { + if ((retval > 0) && FD_ISSET(0, &rfds)) { set_keepalives(KA_NO); the_character = inkey(); set_keepalives(KA_YES); @@ -284,7 +284,6 @@ void set_keepalives(int s) static time_t idlet = 0; static void really_do_keepalive(void) { - int r; /* IPC response code */ time(&idlet); @@ -298,7 +297,7 @@ static void really_do_keepalive(void) { * wait for a response. */ if (keepalives_enabled == KA_YES) { - r = CtdlIPCNoop(ipc_for_signal_handlers); + CtdlIPCNoop(ipc_for_signal_handlers); if (instant_msgs > 0) { if (ok_to_interrupt == 1) { scr_printf("\r%64s\r", ""); @@ -1476,6 +1475,11 @@ void look_for_ansi(void) if (FD_ISSET(0, &rfds)) { abuf[strlen(abuf) + 1] = 0; rv = read(0, &abuf[strlen(abuf)], 1); + if (rv < 0) { + scr_printf("failed to read after select: %s", + strerror(errno)); + break; + } } } while (FD_ISSET(0, &rfds)); diff --git a/citadel/textclient/messages.c b/citadel/textclient/messages.c index 77ec79e62..3935355cc 100644 --- a/citadel/textclient/messages.c +++ b/citadel/textclient/messages.c @@ -363,7 +363,10 @@ void citedit(FILE *fp) putc(10, fp); fflush(fp); rv = ftruncate(fileno(fp), ftell(fp)); + if (rv < 0) + scr_printf("failed to set message buffer: %s\n", strerror(errno)); + /* and deallocate the memory we used */ while (textlist != NULL) { ptr = textlist->next; @@ -801,6 +804,10 @@ void replace_string(char *filename, long int startpos) rpos = ftell(fp); fseek(fp, wpos, 0); rv = fwrite((char *) buf, 128, 1, fp); + if (rv < 0) { + scr_printf("failed to replace string: %s\n", strerror(errno)); + break; /*whoopsi! */ + } strcpy(buf, &buf[128]); wpos = ftell(fp); fseek(fp, rpos, 0); @@ -877,8 +884,6 @@ int client_make_message(CtdlIPC *ipc, newprompt("Subject: ", subject, 70); } - beg = 0L; - if (mode == 1) { scr_printf("(Press ctrl-d when finished)\n"); } @@ -888,6 +893,9 @@ int client_make_message(CtdlIPC *ipc, if (fp != NULL) { fmout(screenwidth, fp, NULL, NULL, 0); beg = ftell(fp); + if (beg < 0) + scr_printf("failed to get stream position %s\n", + strerror(errno)); fclose(fp); } else { fp = fopen(filename, "w"); @@ -1000,7 +1008,11 @@ MECR: if (mode >= 2) { fp = fopen(filename, "r"); if (fp != NULL) { fmout(screenwidth, fp, NULL, NULL, 0); + /* TODO: why ftell if we ignore the result? */ beg = ftell(fp); + if (beg < 0) + scr_printf("failed to get stream position %s\n", + strerror(errno)); fclose(fp); } goto MECR; @@ -1362,6 +1374,8 @@ void list_urls(CtdlIPC *ipc) snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]); rv = system(cmd); + if (rv != 0) + scr_printf("failed to '%s' by %d\n", cmd, rv); scr_printf("\n"); } @@ -1497,7 +1511,7 @@ void readmsgs(CtdlIPC *ipc, enum MessageDirection rdir, /* 1=Forward (-1)=Reverse */ int q /* Number of msgs to read (if c==3) */ ) { - int a, b, e, f, g, start; + int a, e, f, g, start; int savedpos; int hold_sw = 0; char arcflag = 0; @@ -1515,11 +1529,6 @@ void readmsgs(CtdlIPC *ipc, static int att_seq = 0; /* Attachment download sequence number */ int rv = 0; /* silence the stupid warn_unused_result warnings */ - if (c < 0) - b = (num_msgs - 1); - else - b = 0; - CtdlMakeTempFileName(prtfile, sizeof prtfile); if (msg_arr) { @@ -1826,6 +1835,8 @@ DONE_QUOTING: switch (e) { save_buffer(attachment, extract_unsigned_long(cmd, 0), save_to); snprintf(cmd, sizeof cmd, rc_open_cmd, save_to); rv = system(cmd); + if (rv != 0) + scr_printf("failed to save %s Reason %d\n", cmd, rv); } else { /* save attachment to disk */ destination_directory(save_to, filename); diff --git a/citadel/textclient/rooms.c b/citadel/textclient/rooms.c index 415d7c046..f88d82b34 100644 --- a/citadel/textclient/rooms.c +++ b/citadel/textclient/rooms.c @@ -852,7 +852,7 @@ void download(CtdlIPC *ipc, int proto) char tempname[PATH_MAX]; char transmit_cmd[SIZ]; FILE *tpipe = NULL; - int broken = 0; +/* int broken = 0;*/ int r; int rv = 0; void *file = NULL; /* The downloaded file */ @@ -891,8 +891,8 @@ void download(CtdlIPC *ipc, int proto) snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename); tpipe = fopen(tempname, "wb"); if (fwrite(file, filelen, 1, tpipe) < filelen) { - /* FIXME: restart syscall on EINTR */ - broken = 1; + /* FIXME: restart syscall on EINTR + broken = 1;*/ } fclose(tpipe); if (file) free(file); @@ -915,6 +915,8 @@ void download(CtdlIPC *ipc, int proto) stty_ctdl(SB_RESTORE); rv = system(transmit_cmd); + if (rv != 0) + scr_printf("failed to download '%s': %d\n", transmit_cmd, rv); stty_ctdl(SB_NO_INTR); /* clean up the temporary directory */ @@ -971,13 +973,12 @@ void invite(CtdlIPC *ipc) { char username[USERNAME_SIZE]; char buf[SIZ]; - int r; /* IPC response code */ newprompt("Name of user? ", username, USERNAME_SIZE); if (username[0] == 0) return; - r = CtdlIPCInviteUserToRoom(ipc, username, buf); + CtdlIPCInviteUserToRoom(ipc, username, buf); scr_printf("%s\n", buf); } @@ -989,13 +990,12 @@ void kickout(CtdlIPC *ipc) { char username[USERNAME_SIZE]; char buf[SIZ]; - int r; /* IPC response code */ newprompt("Name of user? ", username, USERNAME_SIZE); if (username[0] == 0) return; - r = CtdlIPCKickoutUserFromRoom(ipc, username, buf); + CtdlIPCKickoutUserFromRoom(ipc, username, buf); scr_printf("%s\n", buf); } @@ -1324,14 +1324,13 @@ void edit_floor(CtdlIPC *ipc) { char buf[SIZ]; struct ExpirePolicy *ep = NULL; - int r; /* IPC response code */ load_floorlist(ipc); /* Fetch the expire policy (this will silently fail on old servers, * resulting in "default" policy) */ - r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf); + CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf); /* Interact with the user */ scr_printf("You are editing the floor called \"%s\"\n", @@ -1368,8 +1367,8 @@ void edit_floor(CtdlIPC *ipc) } /* Save it */ - r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf); - r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf); + CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf); + CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf); scr_printf("%s\n", buf); load_floorlist(ipc); } diff --git a/citadel/textclient/routines2.c b/citadel/textclient/routines2.c index 7282584f2..caf7c9e17 100644 --- a/citadel/textclient/routines2.c +++ b/citadel/textclient/routines2.c @@ -313,7 +313,6 @@ void upload(CtdlIPC *ipc, int c) int xfer_pid; int a, b; FILE *fp, *lsfp; - int r; int rv; if ((room_flags & QR_UPLOAD) == 0) { @@ -342,6 +341,13 @@ void upload(CtdlIPC *ipc, int c) xfer_pid = fork(); if (xfer_pid == 0) { rv = chdir(tempdir); + if (rv < 0) { + scr_printf("failed to change into %s Reason %s\nAborting now.\n", + tempdir, + strerror(errno)); + nukedir(tempdir); + return; + } switch (c) { case 0: stty_ctdl(0); @@ -394,7 +400,7 @@ void upload(CtdlIPC *ipc, int c) flnm); newprompt(buf, desc, 150); snprintf(buf, sizeof buf, "%s/%s", tempdir, flnm); - r = CtdlIPCFileUpload(ipc, flnm, desc, buf, progress, tbuf); + CtdlIPCFileUpload(ipc, flnm, desc, buf, progress, tbuf); scr_printf("%s\n", tbuf); } pclose(lsfp); diff --git a/citadel/textclient/tuiconfig.c b/citadel/textclient/tuiconfig.c index f23b56036..60c1ada10 100644 --- a/citadel/textclient/tuiconfig.c +++ b/citadel/textclient/tuiconfig.c @@ -434,7 +434,6 @@ void do_internet_configuration(CtdlIPC *ipc) int num_recs = 0; char **recs = NULL; char ch; - int badkey; int i, j; int quitting = 0; int modified = 0; @@ -527,7 +526,7 @@ void do_internet_configuration(CtdlIPC *ipc) "Quit without saving", 0); break; default: - badkey = 1; + break; } } while (!quitting); @@ -687,7 +686,6 @@ void do_ignet_configuration(CtdlIPC *ipc) { int num_recs = 0; char **recs = NULL; char ch; - int badkey; int i, j; int quitting = 0; int modified = 0; @@ -797,7 +795,7 @@ void do_ignet_configuration(CtdlIPC *ipc) { "Quit without saving", 0); break; default: - badkey = 1; + break; } } while (!quitting); @@ -817,7 +815,6 @@ void do_filterlist_configuration(CtdlIPC *ipc) int num_recs = 0; char **recs = NULL; char ch; - int badkey; int i, j; int quitting = 0; int modified = 0; @@ -922,7 +919,7 @@ void do_filterlist_configuration(CtdlIPC *ipc) "Quit without saving", 0); break; default: - badkey = 1; + break; } } while (!quitting); @@ -944,7 +941,6 @@ void do_pop3client_configuration(CtdlIPC *ipc) int num_recs = 0; char **recs = NULL; char ch; - int badkey; int i, j; int quitting = 0; int modified = 0; @@ -1090,7 +1086,7 @@ void do_pop3client_configuration(CtdlIPC *ipc) "Quit without saving", 0); break; default: - badkey = 1; + break; } } while (!quitting); @@ -1114,7 +1110,6 @@ void do_rssclient_configuration(CtdlIPC *ipc) int num_recs = 0; char **recs = NULL; char ch; - int badkey; int i, j; int quitting = 0; int modified = 0; @@ -1235,7 +1230,7 @@ void do_rssclient_configuration(CtdlIPC *ipc) "Quit without saving", 0); break; default: - badkey = 1; + break; } } while (!quitting); -- 2.30.2