[gnome-commander] src/utils.cc: check return value for system() and chdir()



commit ea5080c8d1c2ef2f4d5d064b1f4557672bb7499c
Author: Mamoru TASAKA <mtasaka fedoraproject org>
Date:   Sat Apr 29 01:36:48 2017 +0900

    src/utils.cc: check return value for system() and chdir()
    
    src/utils.cc:1033:15: error: ignoring return value of 'int chdir(const char*)', declared with attribute 
warn_unused_result [-Werror=unused-result]
             chdir (tmp_dir);
    
    src/utils.cc:1056:16: error: ignoring return value of 'int system(const char*)', declared with attribute 
warn_unused_result [-Werror=unused-result]
             system (command);

 src/utils.cc |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/src/utils.cc b/src/utils.cc
index fcb073b..99374e6 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -1029,8 +1029,13 @@ gchar *get_temp_download_filepath (const gchar *fname)
 
     if (!tmp_file_dir)
     {
+        if (chdir (tmp_dir))
+        {
+            gnome_cmd_show_message (NULL, _("Failed to change working directory to a temporary directory."), 
strerror (errno));
+
+            return NULL;
+        }
         gchar *tmp_file_dir_template = g_strdup_printf ("gcmd-%s-XXXXXX", g_get_user_name());
-        chdir (tmp_dir);
         tmp_file_dir = mkdtemp (tmp_file_dir_template);
         if (!tmp_file_dir)
         {
@@ -1053,7 +1058,11 @@ void remove_temp_download_dir ()
         gchar *path = g_build_filename (g_get_tmp_dir (), tmp_file_dir, NULL);
         gchar *command = g_strdup_printf ("rm -rf %s", path);
         g_free (path);
-        system (command);
+        int status;
+        if ((status = system (command)))
+        {
+            g_warning ("executing \"%s\" failed with exit status %d\n", command, status);
+        }
         g_free (command);
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]