]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 't/mmap_sanity'
authorAndre Noll <maan@systemlinux.org>
Sun, 26 Feb 2012 13:23:59 +0000 (14:23 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 26 Feb 2012 13:33:00 +0000 (14:33 +0100)
Conflicts:
error.h

NEWS
afh.c
error.h
fd.c

diff --git a/NEWS b/NEWS
index f14f2879a8f61726f1c2464d4498b2f771e510c7..e5ae590e22605236ada049eb5d758eb293ba901e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,9 +5,11 @@
        - The --no_default_filters option of para_filter has been
          depricated. It still works but has no effect and will be
          removed in the next version.
-
-        - Cleanup and consolidation of the various wrappers for
-          write(), writev(), send() and friends.
+       - Cleanup and consolidation of the various wrappers for
+         write(), writev(), send() and friends.
+       - The obscure error messages on mmap() failures have been
+         replaced by meaningful messages. This affects mainly
+         para_afh.
 
 -------------------------------------
 0.4.9 (2011-12-06) "hybrid causality"
diff --git a/afh.c b/afh.c
index b76c72fdab6dbe445b1466de76c4f3dd58e33b92..bffe63216e71627dde4b4b49b53c436388500444 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -187,8 +187,10 @@ int main(int argc, char **argv)
                int ret2;
                ret = mmap_full_file(conf.inputs[i], O_RDONLY, &audio_file_data,
                        &audio_file_size, &fd);
-               if (ret < 0)
+               if (ret < 0) {
+                       PARA_ERROR_LOG("failed to mmap \"%s\"\n", conf.inputs[i]);
                        goto out;
+               }
                ret = compute_afhi(conf.inputs[i], audio_file_data, audio_file_size,
                        fd, &afhi);
                if (ret < 0)
diff --git a/error.h b/error.h
index f7216ea35ee031795a0bf2e916aa8c5bb5b788a9..e34d8094ccd60215fccdf566b3c4cb592060c6ad 100644 (file)
--- a/error.h
+++ b/error.h
@@ -442,6 +442,7 @@ extern const char **para_errlist[];
        PARA_ERROR(EOF, "end of file"), \
        PARA_ERROR(READ_PATTERN, "did not read expected pattern"), \
        PARA_ERROR(SHORT_WRITE, "unexpected short write"), \
+       PARA_ERROR(EMPTY, "file is empty"), \
 
 
 #define ALSA_WRITE_ERRORS \
diff --git a/fd.c b/fd.c
index a04232f84b3fd239249c866cb5a109551ad2b926..3a8406d9c9fd1454a0807c8584bae78aa1b2f543 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -617,6 +617,22 @@ int mmap_full_file(const char *path, int open_mode, void **map,
                goto out;
        }
        *size = file_status.st_size;
+       /*
+        * If the file is empty, *size is zero and mmap() would return EINVAL
+        * (Invalid argument). This error is common enough to spend an extra
+        * error code which explicitly states the problem.
+        */
+       ret = -E_EMPTY;
+       if (*size == 0)
+               goto out;
+       /*
+        * If fd refers to a directory, mmap() returns ENODEV (No such device),
+        * at least on Linux. "Is a directory" seems to be more to the point.
+        */
+       ret = -ERRNO_TO_PARA_ERROR(EISDIR);
+       if (S_ISDIR(file_status.st_mode))
+               goto out;
+
        ret = para_mmap(*size, mmap_prot, mmap_flags, fd, 0, map);
 out:
        if (ret < 0 || !fd_ptr)