From f473a173b8c8b825a66297502dee39b11fe3d99c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 6 Feb 2013 13:14:07 +0000 Subject: [PATCH] daemon: Add more information to certain calls to perror. Replace selected calls to 'perror (filename)' with: fprintf (stderr, "syscall: %s: %m\n", filename); so that more information is available about precisely which syscall failed. Note this is *not* reply_with_perror. These messages are only printed in verbose output, for the benefit of debugging. --- daemon/9p.c | 4 ++-- daemon/base64.c | 4 ++-- daemon/checksum.c | 4 ++-- daemon/compress.c | 4 ++-- daemon/find.c | 4 ++-- daemon/initrd.c | 6 ++---- daemon/ls.c | 4 ++-- daemon/lvm-filter.c | 2 +- daemon/mount.c | 8 ++++---- daemon/ntfsclone.c | 4 ++-- daemon/sync.c | 2 +- daemon/tar.c | 4 ++-- daemon/upload.c | 8 ++++---- 13 files changed, 28 insertions(+), 30 deletions(-) diff --git a/daemon/9p.c b/daemon/9p.c index 747cbfd12..024ac2479 100644 --- a/daemon/9p.c +++ b/daemon/9p.c @@ -147,7 +147,7 @@ read_whole_file (const char *filename) */ ssize_t n = read (fd, r + size, alloc - size - 1); if (n == -1) { - perror (filename); + fprintf (stderr, "read: %s: %m\n", filename); free (r); close (fd); return NULL; @@ -158,7 +158,7 @@ read_whole_file (const char *filename) } if (close (fd) == -1) { - perror (filename); + fprintf (stderr, "close: %s: %m\n", filename); free (r); return NULL; } diff --git a/daemon/base64.c b/daemon/base64.c index f36542f88..7f4d85bdf 100644 --- a/daemon/base64.c +++ b/daemon/base64.c @@ -130,14 +130,14 @@ do_base64_out (const char *file) } if (ferror (fp)) { - perror (file); + fprintf (stderr, "fread: %s: %m\n", file); send_file_end (1); /* Cancel. */ pclose (fp); return -1; } if (pclose (fp) != 0) { - perror (file); + fprintf (stderr, "pclose: %s: %m\n", file); send_file_end (1); /* Cancel. */ return -1; } diff --git a/daemon/checksum.c b/daemon/checksum.c index 457f78d37..37e63c768 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -187,14 +187,14 @@ do_checksums_out (const char *csumtype, const char *dir) } if (ferror (fp)) { - perror (dir); + fprintf (stderr, "fread: %s: %m\n", dir); send_file_end (1); /* Cancel. */ pclose (fp); return -1; } if (pclose (fp) != 0) { - perror (dir); + fprintf (stderr, "pclose: %s: %m\n", dir); send_file_end (1); /* Cancel. */ return -1; } diff --git a/daemon/compress.c b/daemon/compress.c index 6c4e3b744..7cab68a8f 100644 --- a/daemon/compress.c +++ b/daemon/compress.c @@ -88,14 +88,14 @@ do_compressX_out (const char *file, const char *filter, int is_device) } if (ferror (fp)) { - perror (file); + fprintf (stderr, "fread: %s: %m\n", file); send_file_end (1); /* Cancel. */ pclose (fp); return -1; } if (pclose (fp) != 0) { - perror (file); + fprintf (stderr, "pclose: %s: %m\n", file); send_file_end (1); /* Cancel. */ return -1; } diff --git a/daemon/find.c b/daemon/find.c index fd9beb8fe..7749e4df4 100644 --- a/daemon/find.c +++ b/daemon/find.c @@ -122,14 +122,14 @@ do_find0 (const char *dir) } if (ferror (fp)) { - perror (dir); + fprintf (stderr, "fgetc: %s: %m\n", dir); send_file_end (1); /* Cancel. */ pclose (fp); return -1; } if (pclose (fp) != 0) { - perror (dir); + fprintf (stderr, "pclose: %s: %m\n", dir); send_file_end (1); /* Cancel. */ return -1; } diff --git a/daemon/initrd.c b/daemon/initrd.c index 11a156a6d..afc4fda96 100644 --- a/daemon/initrd.c +++ b/daemon/initrd.c @@ -185,8 +185,7 @@ do_initrd_cat (const char *path, const char *filename, size_t *size_r) /* Remove the file. */ if (unlink (fullpath) == -1) { - fprintf (stderr, "unlink: "); - perror (fullpath); + fprintf (stderr, "unlink: %s: %m\n", fullpath); /* non-fatal */ } @@ -196,8 +195,7 @@ do_initrd_cat (const char *path, const char *filename, size_t *size_r) if (!p) break; *p = '\0'; if (rmdir (fullpath) == -1) { - fprintf (stderr, "rmdir: "); - perror (fullpath); + fprintf (stderr, "rmdir: %s: %m\n", fullpath); /* non-fatal */ } } while (STRNEQ (fullpath, tmpdir)); diff --git a/daemon/ls.c b/daemon/ls.c index 3b49730dc..96e7bf287 100644 --- a/daemon/ls.c +++ b/daemon/ls.c @@ -77,14 +77,14 @@ do_ls0 (const char *path) } if (errno != 0) { - perror (path); + fprintf (stderr, "readdir: %s: %m\n", path); send_file_end (1); /* Cancel. */ closedir (dir); return -1; } if (closedir (dir) == -1) { - perror (path); + fprintf (stderr, "closedir: %s: %m\n", path); send_file_end (1); /* Cancel. */ return -1; } diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c index d96fa3bf0..56abc49e3 100644 --- a/daemon/lvm-filter.c +++ b/daemon/lvm-filter.c @@ -70,7 +70,7 @@ copy_lvm (void) } if (mkdtemp (lvm_system_dir) == NULL) { - perror (lvm_system_dir); + fprintf (stderr, "mkdtemp: %s: %m\n", lvm_system_dir); exit (EXIT_FAILURE); } diff --git a/daemon/mount.c b/daemon/mount.c index 5cee5d3cb..af9283452 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -50,7 +50,7 @@ is_root_mounted (void) */ fp = setmntent ("/proc/mounts", "r"); if (fp == NULL) { - perror ("/proc/mounts"); + fprintf (stderr, "setmntent: %s: %m\n", "/proc/mounts"); exit (EXIT_FAILURE); } @@ -92,7 +92,7 @@ is_device_mounted (const char *device) */ fp = setmntent ("/proc/mounts", "r"); if (fp == NULL) { - perror ("/proc/mounts"); + fprintf (stderr, "setmntent: %s: %m\n", "/proc/mounts"); exit (EXIT_FAILURE); } @@ -246,7 +246,7 @@ mounts_or_mountpoints (int mp) */ fp = setmntent ("/proc/mounts", "r"); if (fp == NULL) { - perror ("/proc/mounts"); + fprintf (stderr, "setmntent: %s: %m\n", "/proc/mounts"); exit (EXIT_FAILURE); } @@ -348,7 +348,7 @@ do_umount_all (void) */ fp = setmntent ("/proc/mounts", "r"); if (fp == NULL) { - perror ("/proc/mounts"); + fprintf (stderr, "setmntent: %s: %m\n", "/proc/mounts"); exit (EXIT_FAILURE); } diff --git a/daemon/ntfsclone.c b/daemon/ntfsclone.c index 3e8447bc0..76bd545e9 100644 --- a/daemon/ntfsclone.c +++ b/daemon/ntfsclone.c @@ -190,14 +190,14 @@ do_ntfsclone_out (const char *device, } if (ferror (fp)) { - perror (device); + fprintf (stderr, "fread: %s: %m\n", device); send_file_end (1); /* Cancel. */ pclose (fp); return -1; } if (pclose (fp) != 0) { - perror (device); + fprintf (stderr, "pclose: %s: %m\n", device); send_file_end (1); /* Cancel. */ return -1; } diff --git a/daemon/sync.c b/daemon/sync.c index de293f1e6..2d9a97f4a 100644 --- a/daemon/sync.c +++ b/daemon/sync.c @@ -134,7 +134,7 @@ fsync_devices (void) /* Close the directory handle */ if (closedir (dir) == -1) - perror ("closedir"); + perror ("closedir: /sys/block"); } #endif /* HAVE_FSYNC */ diff --git a/daemon/tar.c b/daemon/tar.c index 32ea18297..4a27dfe2d 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -352,14 +352,14 @@ do_tar_out (const char *dir, const char *compress, int numericowner, } if (ferror (fp)) { - perror (dir); + fprintf (stderr, "fread: %s: %m\n", dir); send_file_end (1); /* Cancel. */ pclose (fp); return -1; } if (pclose (fp) != 0) { - perror (dir); + fprintf (stderr, "pclose: %s: %m\n", dir); send_file_end (1); /* Cancel. */ return -1; } diff --git a/daemon/upload.c b/daemon/upload.c index f96148b47..6db332871 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -183,14 +183,14 @@ do_download (const char *filename) } if (r == -1) { - perror (filename); + fprintf (stderr, "read: %s: %m\n", filename); send_file_end (1); /* Cancel. */ close (fd); return -1; } if (close (fd) == -1) { - perror (filename); + fprintf (stderr, "close: %s: %m\n", filename); send_file_end (1); /* Cancel. */ return -1; } @@ -248,7 +248,7 @@ do_download_offset (const char *filename, int64_t offset, int64_t size) while (usize > 0) { r = read (fd, buf, usize > sizeof buf ? sizeof buf : usize); if (r == -1) { - perror (filename); + fprintf (stderr, "read: %s: %m\n", filename); send_file_end (1); /* Cancel. */ close (fd); return -1; @@ -271,7 +271,7 @@ do_download_offset (const char *filename, int64_t offset, int64_t size) } if (close (fd) == -1) { - perror (filename); + fprintf (stderr, "close: %s: %m\n", filename); send_file_end (1); /* Cancel. */ return -1; }