summaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorJérémie Koenig2010-03-26 19:08:53 +0100
committerDenys Vlasenko2010-03-26 19:08:53 +0100
commitfbedacfc8caa1ec8f14e664a881cb0a93c8f8712 (patch)
tree6c08780bbaad6320149930bdbcfbee5a2eed9f5d /util-linux
parent35fdb1bc9cb82fa5630c2d40ae49110ecd7c88ea (diff)
downloadbusybox-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.zip
busybox-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.tar.gz
Hurd compat fixes. Mostly dealing with absent PATH_MAX
Signed-off-by: Jérémie Koenig <jk@jk.fr.eu.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/umount.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/util-linux/umount.c b/util-linux/umount.c
index a4b2bd0..a19f86c 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;