Although mkswap has recently been -L option to create a label nothing appears to
have been change to swapon to display said labels. (rh#430386)
+ * use canonicalize_file_name() when exist in glibc (see lib/canonicalize.v)
+
* try improve compilation against others libc:
- klibc
- ???
--- /dev/null
+#ifndef CANONICALIZE_H
+#define CANONICALIZE_H
+
+#include <limits.h>
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+
+extern char *canonicalize_path(const char *path);
+
+#endif /* CANONICALIZE_H */
/*
- * realpath.c -- canonicalize pathname by removing symlinks
+ * canonicalize.c -- canonicalize pathname by removing symlinks
* Copyright (C) 1993 Rick Sladkey <jrs@world.std.com>
*
* This program is free software; you can redistribute it and/or modify
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library Public License for more details.
+ *
*/
-#define resolve_symlinks
-
/*
* This routine is part of libc. We include it nevertheless,
* since the libc version has some security flaws.
+ *
+ * TODO: use canonicalize_file_name() when exist in glibc
*/
#include <unistd.h>
#include <string.h>
#include <errno.h>
-#include "realpath.h"
-#include "sundries.h" /* for xstrdup */
+#include <stdlib.h>
+
+#include "canonicalize.h"
#ifndef MAXSYMLINKS
# define MAXSYMLINKS 256
#endif
-int
-is_pseudo_fs(const char *type)
-{
- if (type == NULL || *type == '/')
- return 0;
- if (streq(type, "none") ||
- streq(type, "proc") ||
- streq(type, "tmpfs") ||
- streq(type, "sysfs") ||
- streq(type, "devpts"))
- return 1;
- return 0;
-}
-
-/* Make a canonical pathname from PATH. Returns a freshly malloced string.
- It is up the *caller* to ensure that the PATH is sensible. i.e.
- canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
- is not a legal pathname for ``/dev/fd0''. Anything we cannot parse
- we return unmodified. */
-char *
-canonicalize_spec (const char *path)
-{
- if (path == NULL)
- return NULL;
- if (is_pseudo_fs(path))
- return xstrdup(path);
- return canonicalize(path);
-}
-
-char *
-canonicalize (const char *path) {
- char canonical[PATH_MAX+2];
-
- if (path == NULL)
- return NULL;
-
- if (myrealpath (path, canonical, PATH_MAX+1))
- return xstrdup(canonical);
-
- return xstrdup(path);
-}
-
-char *
+static char *
myrealpath(const char *path, char *resolved_path, int maxreslth) {
int readlinks = 0;
char *npath;
if (errno != EINVAL)
goto err;
} else {
-#ifdef resolve_symlinks /* Richard Gooch dislikes sl resolution */
int m;
char *newbuf;
/* Insert symlink contents into path. */
m = strlen(path);
- newbuf = xmalloc(m + n + 1);
+ newbuf = malloc(m + n + 1);
+ if (!newbuf)
+ goto err;
memcpy(newbuf, link_path, n);
memcpy(newbuf + n, path, m + 1);
free(buf);
path = buf = newbuf;
-#endif
}
*npath++ = '/';
}
free(buf);
return NULL;
}
+
+char *
+canonicalize_path(const char *path) {
+ char canonical[PATH_MAX+2];
+
+ if (path == NULL)
+ return NULL;
+
+ if (myrealpath (path, canonical, PATH_MAX+1))
+ return strdup(canonical);
+
+ return strdup(path);
+}
+
+
sbin_PROGRAMS = losetup swapon
dist_man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
-utils_common = sundries.c xmalloc.c realpath.c fsprobe.c
+utils_common = sundries.c xmalloc.c ../lib/canonicalize.c
headers_common = fstab.h mount_mntent.h mount_constants.h \
- lomount.h fsprobe.h realpath.h xmalloc.h \
+ lomount.h fsprobe.h xmalloc.h \
getusername.h loop.h sundries.h
mount_common = fstab.c mount_mntent.c getusername.c lomount.c \
$(utils_common) $(headers_common) ../lib/env.c ../lib/linux_version.c \
- ../lib/blkdev.c
+ ../lib/blkdev.c fsprobe.c
mount_SOURCES = mount.c $(mount_common) ../lib/setproctitle.c
mount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS)
umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
swapon_SOURCES = swapon.c swap_constants.h $(utils_common) \
- ../lib/linux_version.c ../lib/blkdev.c
+ ../lib/linux_version.c ../lib/blkdev.c fsprobe.c
-losetup_SOURCES = lomount.c sundries.c xmalloc.c realpath.c \
- loop.h lomount.h xmalloc.h sundries.h realpath.h
+losetup_SOURCES = lomount.c $(utils_common) \
+ loop.h lomount.h xmalloc.h sundries.h
losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
mount_LDADD = $(LDADD_common)
endif
if HAVE_BLKID
-utils_common += fsprobe_blkid.c
+mount_common += fsprobe_blkid.c
+swapon_SOURCES += fsprobe_blkid.c
LDADD_common += $(BLKID_LIBS)
LDADD_common_static += $(BLKID_LIBS_STATIC)
endif
endif
if HAVE_VOLUME_ID
-utils_common += fsprobe_volumeid.c
+mount_common += fsprobe_volumeid.c
+swapon_SOURCES += fsprobe_volumeid.c
LDADD_common += $(VOLUMEID_LIBS)
LDADD_common_static += $(VOLUMEID_LIBS_STATIC)
endif
noinst_PROGRAMS = mtab_lock_test
-mtab_lock_test_SOURCES = fstab.c sundries.c xmalloc.c $(headers_common)
+mtab_lock_test_SOURCES = fstab.c sundries.c xmalloc.c $(headers_common) \
+ ../lib/canonicalize.c
mtab_lock_test_CPPFLAGS = -DMAIN_TEST_MTABLOCK $(AM_CPPFLAGS)
install-exec-hook:
#include "fsprobe.h"
#include "sundries.h" /* for xstrdup */
#include "nls.h"
-#include "realpath.h"
/* list of already tested filesystems by fsprobe_procfsloop_mount() */
static struct tried {
#include "blkdev.h"
#include "fsprobe.h"
-#include "realpath.h"
#include "pathnames.h"
#include "sundries.h"
#include "fsprobe.h"
#include "pathnames.h"
#include "nls.h"
-#include "realpath.h"
#define streq(s, t) (strcmp ((s), (t)) == 0)
void my_endmntent (mntFILE *mfp) { }
int my_addmntent (mntFILE *mfp, struct my_mntent *mnt) { return 0; }
-char *canonicalize (const char *path) { return NULL; }
-char *canonicalize_spec (const char *path) { return NULL; }
-int is_pseudo_fs(const char *type) { return 0; };
-
int
main(int argc, char **argv)
{
#include "nls.h"
#include "sundries.h"
#include "xmalloc.h"
-#include "realpath.h"
#include "pathnames.h"
#define SIZE(a) (sizeof(a)/sizeof(a[0]))
#include "env.h"
#include "nls.h"
#include "blkdev.h"
-#include "realpath.h"
#define DO_PS_FIDDLING
+++ /dev/null
-#ifndef REALPATH_H
-#define REALPATH_H
-
-#include <limits.h>
-#ifndef PATH_MAX
-# define PATH_MAX 4096
-#endif
-
-extern char *myrealpath(const char *path, char *resolved_path, int m);
-extern char *canonicalize (const char *path);
-extern char *canonicalize_spec (const char *path);
-extern int is_pseudo_fs(const char *type);
-
-#endif /* REALPATH_H */
#include <stdio.h>
#include <string.h>
#include <mntent.h> /* for MNTTYPE_SWAP */
+
+#include "canonicalize.h"
+
#include "fstab.h"
#include "sundries.h"
-#include "realpath.h"
#include "xmalloc.h"
#include "nls.h"
return 0;
}
+int
+is_pseudo_fs(const char *type)
+{
+ if (type == NULL || *type == '/')
+ return 0;
+ if (streq(type, "none") ||
+ streq(type, "proc") ||
+ streq(type, "tmpfs") ||
+ streq(type, "sysfs") ||
+ streq(type, "devpts"))
+ return 1;
+ return 0;
+}
+
+/* Make a canonical pathname from PATH. Returns a freshly malloced string.
+ It is up the *caller* to ensure that the PATH is sensible. i.e.
+ canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
+ is not a legal pathname for ``/dev/fd0''. Anything we cannot parse
+ we return unmodified. */
+char *
+canonicalize_spec (const char *path)
+{
+ char *res;
+
+ if (path == NULL)
+ return NULL;
+ if (is_pseudo_fs(path))
+ return xstrdup(path);
+
+ res = canonicalize_path(path);
+ if (!res)
+ die(EX_SYSERR, _("not enough memory"));
+ return res;
+}
+
+char *canonicalize (const char *path)
+{
+ char *res = canonicalize_path(path);
+
+ if (!res)
+ die(EX_SYSERR, _("not enough memory"));
+ return res;
+}
+
int parse_spec(const char *spec, char **name, char **value);
+int is_pseudo_fs(const char *type);
+
+char *canonicalize (const char *path);
+char *canonicalize_spec (const char *path);
+
/* exit status - bits below are ORed */
#define EX_USAGE 1 /* incorrect invocation or permission */
#define EX_SYSERR 2 /* out of memory, cannot fork, ... */
#include "swap_constants.h"
#include "nls.h"
#include "fsprobe.h"
-#include "realpath.h"
#include "pathnames.h"
#include "sundries.h"
#include "swapheader.h"
#include "fstab.h"
#include "env.h"
#include "nls.h"
-#include "realpath.h"
#if defined(MNT_FORCE)
/* Interesting ... it seems libc knows about MNT_FORCE and presumably