From fbedacfc8caa1ec8f14e664a881cb0a93c8f8712 Mon Sep 17 00:00:00 2001 From: Jérémie Koenig Date: Fri, 26 Mar 2010 19:08:53 +0100 Subject: Hurd compat fixes. Mostly dealing with absent PATH_MAX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Koenig Signed-off-by: Denys Vlasenko --- util-linux/umount.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'util-linux') diff --git a/util-linux/umount.c b/util-linux/umount.c index a4b2bd087..a19f86c3a 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c @@ -39,6 +39,10 @@ # define MS_RELATIME (1 << 21) #endif #include "libbb.h" +#ifndef PATH_MAX +# define PATH_MAX (4*1024) +#endif + #if defined(__dietlibc__) /* 16.12.2006, Sampo Kellomaki (sampo@iki.fi) @@ -69,7 +73,7 @@ int umount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int umount_main(int argc UNUSED_PARAM, char **argv) { int doForce; - char *const path = xmalloc(PATH_MAX + 2); /* to save stack */ + char *const buf = xmalloc(PATH_MAX * 2 + 128); /* to save stack */ struct mntent me; FILE *fp; char *fstype = NULL; @@ -100,7 +104,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_ALL) bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file); } else { - while (getmntent_r(fp, &me, path, PATH_MAX)) { + while (getmntent_r(fp, &me, buf, PATH_MAX * 2 + 128)) { /* Match fstype if passed */ if (!match_fstype(&me, fstype)) continue; @@ -124,10 +128,11 @@ int umount_main(int argc UNUSED_PARAM, char **argv) for (;;) { int curstat; char *zapit = *argv; + char *path; // Do we already know what to umount this time through the loop? if (m) - safe_strncpy(path, m->dir, PATH_MAX); + path = xstrdup(m->dir); // For umount -a, end of mtab means time to exit. else if (opt & OPT_ALL) break; @@ -136,10 +141,12 @@ int umount_main(int argc UNUSED_PARAM, char **argv) if (!zapit) break; argv++; - realpath(zapit, path); - for (m = mtl; m; m = m->next) - if (!strcmp(path, m->dir) || !strcmp(path, m->device)) - break; + path = xmalloc_realpath(zapit); + if (path) { + for (m = mtl; m; m = m->next) + if (strcmp(path, m->dir) == 0 || strcmp(path, m->device) == 0) + break; + } } // If we couldn't find this sucker in /etc/mtab, punt by passing our // command line argument straight to the umount syscall. Otherwise, @@ -181,9 +188,13 @@ int umount_main(int argc UNUSED_PARAM, char **argv) // Find next matching mtab entry for -a or umount /dev // Note this means that "umount /dev/blah" will unmount all instances // of /dev/blah, not just the most recent. - if (m) while ((m = m->next) != NULL) - if ((opt & OPT_ALL) || !strcmp(path, m->device)) - break; + if (m) { + while ((m = m->next) != NULL) + // NB: if m is non-NULL, path is non-NULL as well + if ((opt & OPT_ALL) || strcmp(path, m->device) == 0) + break; + } + free(path); } // Free mtab list if necessary @@ -195,7 +206,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv) free(mtl); mtl = m; } - free(path); + free(buf); } return status; -- cgit v1.2.3