Add context missing info to few system call errors (mostly:
authorwwp <wwp@free.fr>
Thu, 12 Jan 2017 15:31:10 +0000 (16:31 +0100)
committerwwp <wwp@free.fr>
Thu, 12 Jan 2017 15:31:10 +0000 (16:31 +0100)
file operations).

src/common/utils.c
src/crash.c
src/partial_download.c
src/plugins/archive/archiver_gtk.c
src/plugins/archive/libarchive_archive.c
src/plugins/mailmbox/maillock.c
src/plugins/pgpinline/pgpinline.c
src/plugins/pgpmime/pgpmime.c
src/plugins/smime/smime.c
src/plugins/vcalendar/vcal_meeting_gtk.c
src/procmime.c

index 1a662123f54ac4f80e31b449a22bb508b19c3757..10c3764ad30508f73763bdca3429da78cf7116b5 100644 (file)
@@ -5385,7 +5385,7 @@ get_random_bytes(void *buf, size_t count)
 
        rnd = open("/dev/urandom", O_RDONLY);
        if (rnd == -1) {
-               perror("open on /dev/urandom");
+               FILE_OP_ERROR("/dev/urandom", "open");
                debug_print("Could not open /dev/urandom.\n");
                return FALSE;
        }
@@ -5401,7 +5401,7 @@ get_random_bytes(void *buf, size_t count)
 #else
        ret = read(rnd, buf, count);
        if (ret != count) {
-               perror("read from /dev/urandom");
+               FILE_OP_ERROR("/dev/urandom", "read");
                debug_print("Could not read enough data from /dev/urandom, read only %ld of %lu bytes.\n", ret, count);
                close(rnd);
                return FALSE;
index 386958127a9d257a61229ce930e0701032712dc2..a48401271f679793d40401fb8274f083d02ddbab 100644 (file)
@@ -541,7 +541,7 @@ static void crash_handler(int sig)
                args[4] = NULL;
 
                if (chdir(claws_get_startup_dir()) != 0)
-                       perror("chdir");
+                       FILE_OP_ERROR(claws_get_startup_dir(), "chdir");
                if (setgid(getgid()) != 0)
                        perror("setgid");
                if (setuid(getuid()) != 0 )
index 5694b0d8e6b60701339ae4e706c848a997deca29..d59ae80a3cd281eee98341445270bb42b09fce3e 100644 (file)
@@ -171,7 +171,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                           "-", sanitized_uid, NULL);
 
        if ((fp = g_fopen(path, "rb")) == NULL) {
-               perror("fopen1");
+               FILE_OP_ERROR(path, "fopen");
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
@@ -191,7 +191,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        g_free(sanitized_uid);
 
        if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
-               perror("fopen2");
+               FILE_OP_ERROR(pathnew, "fopen");
                fclose(fp);
                g_free(pathnew);
                goto bail;
@@ -263,12 +263,12 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        g_free(pathnew);
        
        if ((fp = g_fopen(filename,"rb")) == NULL) {
-               perror("fopen3");
+               FILE_OP_ERROR(filename, "fopen");
                goto bail;
        }
        pathnew = g_strdup_printf("%s.new", filename);
        if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
-               perror("fopen4");
+               FILE_OP_ERROR(pathnew, "fopen");
                fclose(fp);
                g_free(pathnew);
                goto bail;
index 55156ed62a092a6f2cd1ab0697abc756e0c854aa..11c166f4856d35471df90997337b7e682cec33b8 100644 (file)
@@ -313,6 +313,7 @@ static void create_md5sum(const gchar* file, const gchar* md5_file) {
        debug_print("md5sum: %s\n", md5sum);
        if ((fd = 
                open(md5_file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1) {
+               FILE_OP_ERROR(md5_file, "create");
                free(md5sum);
                return;
        }
@@ -326,7 +327,7 @@ static void create_md5sum(const gchar* file, const gchar* md5_file) {
        g_free(md5sum);
        debug_print("md5sum: %s\n", text);
        if (write(fd, text, strlen(text)) < 0)
-               perror("write");
+               FILE_OP_ERROR(md5_file, "write");
        close(fd);
        g_free(text);
 }
@@ -388,7 +389,7 @@ static gchar* descriptive_file_name(
        debug_print("New_file: %s\n", new_file);
        if (link(file, new_file) != 0) {
                if (errno != EEXIST) {
-                       perror("link");
+                       FILE_OP_ERROR(new_file, "link");
                        g_free(new_file);
                        new_file = g_strdup(file);
                        page->rename = FALSE;
index a348c546a7264e34b273bf92f588de78be68fbd9..e7b32452242e3fe92ecc94a6fdce64cdca356cd8 100644 (file)
@@ -588,19 +588,19 @@ const gchar* archive_create(const char* archive_name, GSList* files,
 #endif
                        entry = archive_entry_new();
                        if ((fd = open(filename, O_RDONLY)) == -1) {
-                               perror("open file");
+                               FILE_OP_ERROR(filename, "open");
                        }
                        else {
                                if (lstat(filename, &st) == -1) {
-                                       perror("lstat file");
+                                       FILE_OP_ERROR(filename, "lstat");
                                } else {
                                        archive_entry_copy_stat(entry, &st);
                                        archive_entry_set_pathname(entry, filename);
                                        if (S_ISLNK(st.st_mode)) {
                                                if ((buf = malloc(PATH_MAX + 1)) != NULL) {
-                                                       if ((len = readlink(filename, buf, PATH_MAX)) < 0)
-                                                               perror("error in readlink");
-                                                       else
+                                                       if ((len = readlink(filename, buf, PATH_MAX)) < 0) {
+                                                               FILE_OP_ERROR(filename, "readlink");
+                                                       else
                                                                buf[len] = '\0';
                                                        archive_entry_set_symlink(entry, buf);
                                                        g_free(buf);
index 475070fd151e13c6f57e40ca390c1674b69c47d5..5c6e704d1785f810bfe83dd5b4d27fb835501067 100644 (file)
@@ -159,6 +159,7 @@ static int lock_common(const char * filename, int fd, short locktype)
   r = fcntl(fd, F_SETLKW, &lock);
   if (r < 0) {
     /* WARNING POSIX lock could not be applied */
+    perror("lock");
   }
 
   /* dot lock file */
@@ -175,7 +176,7 @@ static int lock_common(const char * filename, int fd, short locktype)
     int fd;
     GStatBuf st;
     time_t now;
-    
+
     /* global timeout */
     time(&now);
     if (now > start + LOCKTO_GLOB) {
@@ -187,14 +188,16 @@ static int lock_common(const char * filename, int fd, short locktype)
     if (fd >= 0) {
       /* defeat lock checking programs which test pid */
       if (write(fd, "0", 2) < 0)
-             perror("write");
+          FILE_OP_ERROR(lockfilename, "write");
       close(fd);
       break;
+    } else {
+      FILE_OP_ERROR(lockfilename, "open");
     }
-    
+
     /* libEtPan! - adds a delay of 5 seconds between each tries */
     sleep(5);
-    
+
     if (g_stat(lockfilename, &st) < 0) {
       if (statfailed++ > 5) {
        res = -1;
@@ -207,7 +210,7 @@ static int lock_common(const char * filename, int fd, short locktype)
 
     if (now < st.st_ctime + LOCKTO_RM)
       continue;
-    
+
     /* try to remove stale lockfile */
     if (unlink(lockfilename) < 0) {
       res = -1;
@@ -235,6 +238,7 @@ static int lock_common(const char * filename, int fd, short locktype)
   r = fcntl(fd, F_SETLK, &lock);
   if (r < 0) {
     /* WARNING POSIX lock could not be applied */
+    perror("lock");
   }
   return res;
 }
index 5c1c1d36352efdcf4674b7ec8917d85eeccb9797..6ebb8836df3541ad8b3ecd9752799c7d8bc5fa81 100644 (file)
@@ -500,7 +500,7 @@ static gboolean pgpinline_sign(MimeInfo *mimeinfo, PrefsAccount *account, const
        fp = my_tmpfile();
        if (fp == NULL) {
                perror("my_tmpfile");
-               privacy_set_error(_("Couldn't create temporary file."));
+               privacy_set_error(_("Couldn't create temporary file, %s"), g_strerror(errno));
                return FALSE;
        }
        procmime_write_mimeinfo(msgcontent, fp);
index 837e37948477f7c04dbdd871a1d0be0aaf84ed22..e14ebe0405473e34b9e6d6e89480c7d2a3732157 100644 (file)
@@ -452,6 +452,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr
        
        fp = my_tmpfile();
        if (fp == NULL) {
+               perror("my_tmpfile");
                privacy_set_error(_("Couldn't create temporary file: %s"), g_strerror(errno));
                return FALSE;
        }
@@ -688,6 +689,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        /* write message content to temporary file */
        fp = my_tmpfile();
        if (fp == NULL) {
+               perror("my_tmpfile");
                privacy_set_error(_("Couldn't create temporary file, %s"), g_strerror(errno));
                g_free(kset);
                return FALSE;
index 03ed6692735b7afd95d270f23c2e3c831f395211..7e3af5ede7f2ea216f5c542544e1c2f6162ae682 100644 (file)
@@ -793,7 +793,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        tmpfile = get_tmp_file();
        fp = g_fopen(tmpfile, "wb");
        if (fp == NULL) {
-               perror("get_tmp_file");
+               FILE_OP_ERROR(tmpfile, "create");
                g_free(kset);
                return FALSE;
        }
@@ -804,7 +804,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
        canonicalize_file_replace(tmpfile);
        fp = g_fopen(tmpfile, "rb");
        if (fp == NULL) {
-               perror("get_tmp_file");
+               FILE_OP_ERROR(tmpfile, "open");
                g_free(kset);
                return FALSE;
        }
@@ -850,7 +850,7 @@ gboolean smime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
                        return FALSE;
                }
        } else {
-               perror("get_tmp_file");
+               FILE_OP_ERROR(tmpfile, "create");
                g_free(tmpfile);
                g_free(enccontent);
                return FALSE;
index 99e43fd4055d19253655007e5df7732406a5bff2..a4a99d0bc240b6b974e9731df8fb75bfee996938 100644 (file)
@@ -1981,13 +1981,13 @@ void multisync_export(void)
                for (cur = files; cur; cur = cur->next) {
                        file = (char *)cur->data;
                        if (fprintf(fp, "1 1 %s\n", file) < 0)
-                               perror(file);
+                               FILE_OP_ERROR(file, "fprintf");
                        g_free(file);
                }
                if (fclose(fp) == EOF)
-                       perror(file);
+                       FILE_OP_ERROR(file, "fclose");
        } else {
-               perror(file);
+               FILE_OP_ERROR(file, "fopen");
        }
        g_free(path);
        g_slist_free(files);
index c29da8c7ad90c9b512dcb69f043192f5f95b5724..e41394db50c81c7cf85b89e44fb68d4f680e787b 100644 (file)
@@ -359,11 +359,11 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 
        infp = procmime_fopen(mimeinfo->data.filename, "rb");
        if (!infp) {
-               perror("fopen");
+               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return FALSE;
        }
        if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
-               perror("fseek");
+               FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                procmime_fclose(infp);
                return FALSE;
        }
@@ -408,7 +408,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        uncanonicalize = TRUE;
                        tmpfp = my_tmpfile();
                        if (!tmpfp) {
-                               perror("tmpfile");
+                               perror("my_tmpfile");
                                if (tmp_file) 
                                        procmime_fclose(outfp);
                                procmime_fclose(infp);
@@ -861,7 +861,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
        gboolean err;
 
        if ((outfp = my_tmpfile()) == NULL) {
-               perror("tmpfile");
+               perror("my_tmpfile");
                return NULL;
        }
 #ifdef HAVE_FGETS_UNLOCKED