Skip to content

Commit

Permalink
libinstaller: Explicit failure if path isn't writable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ErwanAliasr1 committed Sep 8, 2015
1 parent bc0578c commit 054f945
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libinstaller/advio.c
Expand Up @@ -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);
Expand Down

0 comments on commit 054f945

Please sign in to comment.