Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] makedevs: unlink device nodes before they are created
@ 2016-11-05  0:14 Arnout Vandecappelle
  2016-11-05  0:47 ` Fabio Estevam
  2016-11-05  9:30 ` Yann E. MORIN
  0 siblings, 2 replies; 5+ messages in thread
From: Arnout Vandecappelle @ 2016-11-05  0:14 UTC (permalink / raw)
  To: buildroot

We use makedevs to create device nodes in the target rootfs. However,
this can be called several times, e.g. when building several filesystem
images or when rebuilding. When the script is called the second time,
the device node already exists so mknod() errors out.

This wasn't noticed before because fakeroot's mknod() wrapper
(incorrectly) does _not_ error out when the file exists already. Now
we switched from fakeroot to pseudo, the problem becomes apparent.

The simplest solution is to change makedevs to first remove the target
file before creating it. This is simpler than two alternative
approaches:

- Removing the target files before makedevs is called is difficult,
  because we would have to parse the device table file to find out
  which files have to be deleted.

- Silently skipping device creation if it exists already is also easy,
  but then we really should also check if the device numbers and mode
  are correct, and that is more complicated.

The other types don't have to be changed. The 'd' (directory) type is
already OK because it already only creates directories if they don't
exist yet. The 'f' (file mode) and 'r' (recursive) types only operate
on files and directories that exist already.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Reported-by: Fabio Estevam <festevam@gmail.com>
---
 package/makedevs/makedevs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/package/makedevs/makedevs.c b/package/makedevs/makedevs.c
index cacb144..d477292 100644
--- a/package/makedevs/makedevs.c
+++ b/package/makedevs/makedevs.c
@@ -622,6 +622,7 @@ int main(int argc, char **argv)
 				for (i = 0; i < count; i++) {
 					sprintf(full_name_inc, "%s%d", full_name, start + i);
 					rdev = makedev(major, minor + i * increment);
+					unlink(full_name_inc);
 					if (mknod(full_name_inc, mode, rdev) == -1) {
 						bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name_inc);
 						ret = EXIT_FAILURE;
@@ -638,6 +639,7 @@ int main(int argc, char **argv)
 				free(full_name_inc);
 			} else {
 				rdev = makedev(major, minor);
+				unlink(full_name);
 				if (mknod(full_name, mode, rdev) == -1) {
 					bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name);
 					ret = EXIT_FAILURE;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-11-05 11:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-05  0:14 [Buildroot] [PATCH] makedevs: unlink device nodes before they are created Arnout Vandecappelle
2016-11-05  0:47 ` Fabio Estevam
2016-11-05  9:30 ` Yann E. MORIN
2016-11-05 11:05   ` Arnout Vandecappelle
2016-11-05 11:21     ` Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox