From 303833d59007e48a70c12599a175b6d18a21a625 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT service" Date: Mon, 28 Dec 2009 23:53:09 +0100 Subject: [PATCH] Ticket #1897: Build breaks on ignored return values Changes into lib directory * samba: handling result of system() call * rpc: handling write errors * ftpfs: ignoring result of fwrite() on logfile (make compiler happy ;-)) * fish: proper handling of file io calls * ignoring result of fwrite() on logfile (make compiler happy ;-)) * lib/util.c: handling fwrite() call errors in mc_util_write_backup_content() * lib/utilunix.c: * handling possible error on dup() in close_error_pipe() * handling possible error on getcwd() in mc_realpath() Signed-off-by: Slava Zanko --- lib/util.c | 14 +++++++++----- lib/utilunix.c | 28 +++++++++++++++++++--------- lib/vfs/mc-vfs/direntry.c | 12 ++++++++---- lib/vfs/mc-vfs/extfs.c | 2 +- lib/vfs/mc-vfs/fish.c | 26 ++++++++++++++++---------- lib/vfs/mc-vfs/ftpfs.c | 6 ++++-- lib/vfs/mc-vfs/mcfsutil.c | 24 ++++++++++++++++++++---- lib/vfs/mc-vfs/samba/lib/util.c | 4 +++- 8 files changed, 80 insertions(+), 36 deletions(-) diff --git a/lib/util.c b/lib/util.c index 2b7576198..77cc74384 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1241,6 +1241,7 @@ mc_util_write_backup_content (const char *from_file_name, const char *to_file_na FILE *backup_fd; char *contents; gsize length; + gboolean ret1 = TRUE; if (!g_file_get_contents (from_file_name, &contents, &length, NULL)) return FALSE; @@ -1252,12 +1253,15 @@ mc_util_write_backup_content (const char *from_file_name, const char *to_file_na return FALSE; } - fwrite ((const void *) contents, length, 1, backup_fd); - - fflush (backup_fd); - fclose (backup_fd); + if (fwrite ((const void *) contents, length, 1, backup_fd) != length) + ret1 = FALSE; + { + int ret2; + ret2 = fflush (backup_fd); + ret2 = fclose (backup_fd); + } g_free (contents); - return TRUE; + return ret1; } /* Finds out a relative path from first to second, i.e. goes as many .. diff --git a/lib/utilunix.c b/lib/utilunix.c index 9b71718aa..8c2bb58e4 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -410,8 +410,11 @@ close_error_pipe (int error, const char *text) else title = _("Warning"); if (old_error >= 0){ - close (2); - dup (old_error); + if (dup2 (old_error, 2)) + { + message (error, MSG_ERROR, "%s", _("Error dup'ing old error pipe")); + return 1; + } close (old_error); len = read (error_pipe[0], msg, MAX_PIPE_SIZE - 1); @@ -617,13 +620,20 @@ mc_realpath (const char *path, char resolved_path[]) max_path = copy_path + PATH_MAX - 2; /* If it's a relative pathname use getwd for starters. */ if (*path != '/') { - /* Ohoo... */ -#ifdef HAVE_GETCWD - getcwd (new_path, PATH_MAX - 1); -#else - getwd (new_path); -#endif - new_path += strlen (new_path); + + new_path = g_get_current_dir (); + if (new_path == NULL) + { + strcpy(got_path, ""); + } + else + { + g_snprintf(got_path, PATH_MAX, "%s", new_path); + g_free(new_path); + new_path = got_path; + } + + new_path += strlen (got_path); if (new_path[-1] != '/') *new_path++ = '/'; } else { diff --git a/lib/vfs/mc-vfs/direntry.c b/lib/vfs/mc-vfs/direntry.c index 4e6a13340..7de3f7612 100644 --- a/lib/vfs/mc-vfs/direntry.c +++ b/lib/vfs/mc-vfs/direntry.c @@ -1261,8 +1261,10 @@ vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char ter return 0; if (logfile) { - fwrite (buf, 1, 1, logfile); - fflush (logfile); + size_t ret1; + int ret2; + ret1 = fwrite (buf, 1, 1, logfile); + ret2 = fflush (logfile); } if (*buf == term) { @@ -1277,8 +1279,10 @@ vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char ter { if (logfile) { - fwrite (&c, 1, 1, logfile); - fflush (logfile); + size_t ret1; + int ret2; + ret1 = fwrite (&c, 1, 1, logfile); + ret2 = fflush (logfile); } if (c == '\n') return 1; diff --git a/lib/vfs/mc-vfs/extfs.c b/lib/vfs/mc-vfs/extfs.c index ea8c9bc15..2ff3ee0f1 100644 --- a/lib/vfs/mc-vfs/extfs.c +++ b/lib/vfs/mc-vfs/extfs.c @@ -706,7 +706,7 @@ extfs_resolve_symlinks_int (struct entry *entry, GSList * list) looping = g_slist_prepend (list, entry); pent = extfs_find_entry_int (entry->dir, entry->inode->linkname, looping, FALSE, FALSE); - g_slist_delete_link (looping, looping); + looping = g_slist_delete_link (looping, looping); if (pent == NULL) my_errno = ENOENT; diff --git a/lib/vfs/mc-vfs/fish.c b/lib/vfs/mc-vfs/fish.c index 966317f30..2a657f887 100644 --- a/lib/vfs/mc-vfs/fish.c +++ b/lib/vfs/mc-vfs/fish.c @@ -159,8 +159,9 @@ fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, c if (logfile) { - fwrite (str, strlen (str), 1, logfile); - fflush (logfile); + size_t ret; + ret = fwrite (str, strlen (str), 1, logfile); + ret = fflush (logfile); } tty_enable_interrupt_key (); @@ -217,15 +218,13 @@ fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[]) } else { - close (0); - dup (fileset1[0]); + res = dup2 (fileset1[0], 0); close (fileset1[0]); close (fileset1[1]); - close (1); + res = dup2 (fileset2[1], 1); close (2); - dup (fileset2[1]); /* stderr to /dev/null */ - open ("/dev/null", O_WRONLY); + res = open ("/dev/null", O_WRONLY); close (fileset2[0]); close (fileset2[1]); execvp (path, const_cast (char **, argv)); @@ -294,7 +293,6 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) print_vfs_message ("%s", answer); if (strstr (answer, "assword")) { - /* Currently, this does not work. ssh reads passwords from /dev/tty, not from stdin :-(. */ @@ -312,8 +310,16 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) SUP.password = op; } print_vfs_message (_("fish: Sending password...")); - write (SUP.sockw, SUP.password, strlen (SUP.password)); - write (SUP.sockw, "\n", 1); + + { + size_t str_len; + str_len = strlen (SUP.password); + if ((write (SUP.sockw, SUP.password, str_len ) != (ssize_t) str_len) + || (write (SUP.sockw, "\n", 1) != 1)) + { + ERRNOR(EIO, -1); + } + } } } diff --git a/lib/vfs/mc-vfs/ftpfs.c b/lib/vfs/mc-vfs/ftpfs.c index 93bfab624..7f6467cbf 100644 --- a/lib/vfs/mc-vfs/ftpfs.c +++ b/lib/vfs/mc-vfs/ftpfs.c @@ -361,8 +361,10 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, if (MEDATA->logfile) { if (strncmp (cmdstr, "PASS ", 5) == 0) { fputs ("PASS \r\n", MEDATA->logfile); - } else - fwrite (cmdstr, cmdlen, 1, MEDATA->logfile); + } else { + size_t ret; + ret = fwrite (cmdstr, cmdlen, 1, MEDATA->logfile); + } fflush (MEDATA->logfile); } diff --git a/lib/vfs/mc-vfs/mcfsutil.c b/lib/vfs/mc-vfs/mcfsutil.c index 28fd4f341..744338805 100644 --- a/lib/vfs/mc-vfs/mcfsutil.c +++ b/lib/vfs/mc-vfs/mcfsutil.c @@ -113,7 +113,11 @@ rpc_send (int sock, ...) case RPC_INT: tmp = htonl (va_arg (ap, int)); - write (sock, &tmp, sizeof (tmp)); + if (write (sock, &tmp, sizeof (tmp)) != sizeof(tmp)) + { + vfs_die ( "RPC: write failed (RPC_INT)" ); + break; + } CHECK_SIG_PIPE (sock); break; @@ -121,9 +125,17 @@ rpc_send (int sock, ...) text = va_arg (ap, char *); len = strlen (text); tmp = htonl (len); - write (sock, &tmp, sizeof (tmp)); + if (write (sock, &tmp, sizeof (tmp)) != sizeof(tmp)) + { + vfs_die ( "RPC: write failed (RPC_STRING)" ); + break; + } CHECK_SIG_PIPE (sock); - write (sock, text, len); + if (write (sock, text, len) != len) + { + vfs_die ( "RPC: write failed (RPC_STRING)" ); + break; + } CHECK_SIG_PIPE (sock); break; @@ -131,7 +143,11 @@ rpc_send (int sock, ...) len = va_arg (ap, int); text = va_arg (ap, char *); tmp = htonl (len); - write (sock, text, len); + if (write (sock, text, len) != len) + { + vfs_die ( "RPC: write failed (RPC_BLOCK)" ); + break; + } CHECK_SIG_PIPE (sock); break; diff --git a/lib/vfs/mc-vfs/samba/lib/util.c b/lib/vfs/mc-vfs/samba/lib/util.c index 98df37ae8..0e78d360c 100644 --- a/lib/vfs/mc-vfs/samba/lib/util.c +++ b/lib/vfs/mc-vfs/samba/lib/util.c @@ -2330,7 +2330,9 @@ void smb_panic(const char *why) { const char *cmd = lp_panic_action(); if (cmd && *cmd) { - system(cmd); + if (system(cmd)) { + DEBUG(0,("PANIC: cannot run panic handler command \"%s\"\n", cmd)); + } } DEBUG(0,("PANIC: %s\n", why)); dbgflush(); -- 2.11.4.GIT