From 054f9453859b3d3e610721fca4ffdea8b6a8b85f Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 3 Sep 2015 15:12:26 +0200 Subject: [PATCH] libinstaller: Explicit failure if path isn't writable As per bug #4, we should report a clear failure if the target path is not writable. The current code was catching the fact the file was not writable but it didn't wrote an explicit message and even more confusing, was trying to process the file descriptor leading to a creepy "Bad file descriptor" error message. This patch does return EACCES to avoid process the file description. It also print an explicit message saying a particular file isn't writable which generates a fatal error. A typical output looks like : [root@host]: extlinux --once=plop /boot /boot is device /dev/sda Cannot open file '/boot/ldlinux.sys' in read/write mode ! Fatal error, exiting. --- libinstaller/advio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libinstaller/advio.c b/libinstaller/advio.c index 56f607d0c..66e477edd 100644 --- a/libinstaller/advio.c +++ b/libinstaller/advio.c @@ -130,7 +130,8 @@ int write_adv(const char *path, const char *cfg) close(fd); fd = open(file, O_RDWR | O_SYNC); if (fd < 0) { - err = -1; + fprintf(stderr, "Cannot open file '%s' in read/write mode !\nFatal error, exiting.\n", file); + return -EACCES; } else if (fstat(fd, &xst) || xst.st_ino != st.st_ino || xst.st_dev != st.st_dev || xst.st_size != st.st_size) { fprintf(stderr, "%s: race condition on write\n", file);