[syslinux:master] libinstaller: Explicit failure if path isn' t writable

syslinux-bot for Erwan Velu erwanaliasr1 at gmail.com
Thu Sep 10 03:06:07 PDT 2015


Commit-ID:  054f9453859b3d3e610721fca4ffdea8b6a8b85f
Gitweb:     http://www.syslinux.org/commit/054f9453859b3d3e610721fca4ffdea8b6a8b85f
Author:     Erwan Velu <erwanaliasr1 at gmail.com>
AuthorDate: Thu, 3 Sep 2015 15:12:26 +0200
Committer:  Erwan Velu <erwanaliasr1 at gmail.com>
CommitDate: Tue, 8 Sep 2015 20:30:47 +0200

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 at 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 56f607d..66e477e 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);


More information about the Syslinux-commits mailing list