util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [pull] build-sys and lsblk enhancements
@ 2011-10-05 20:42 Sami Kerola
  2011-10-10 13:02 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Sami Kerola @ 2011-10-05 20:42 UTC (permalink / raw)
  To: util-linux

Hi,

The libtoolize thing does not really require any explanation. The
definition change is align with this package being independent from
kernel headers, alternative would be to trust the definition in kernel
header to be suitable and define only if that would exist. Last two
patches where outcome of me knowing that this package has nice block
device utilities, and a try to make a oracle storage migration on
quite old system at work easier. Obviously that did not work, but as a
outcome I thought that for others understanding what is wrong, how,
where and what to do about it could be made easier.

The following changes since commit fd96508a27d60abbe2574ce852cc1526d6529029:

  docs: add prlimit to the TODO file (2011-09-30 12:40:44 +0200)

are available in the git repository at:
  https://github.com/kerolasa/lelux-utiliteetit build-sys

Sami Kerola (4):
      build-sys: enhance error message for missing libtoolize
      build-sys: rename BUILD_BUG_ON_ZERO definition
      build-sys: check scanf %ms modifier
      lsblk: inform about depencency to /sys/dev/block

 autogen.sh               |    1 +
 configure.ac             |   34 ++++++++++++++++++++++++++++++++++
 include/c.h              |    4 ++--
 libmount/src/tab_parse.c |   20 +++++++++++++++++++-
 misc-utils/lsblk.8       |    9 +++++++++
 misc-utils/lsblk.c       |   12 ++++++++++++
 6 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index c07984b..14a795f 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -55,6 +55,7 @@ test -f mount/mount.c || {
 }

 ltver=$(libtoolize --version | awk '/^libtoolize/ { print $4 }')
+ltver=${ltver:-"none"}
 test ${ltver##2.} = "$ltver" && {
 	echo "You must have libtool version >= 2.x.x, but you have $ltver."
 	DIE=1
diff --git a/configure.ac b/configure.ac
index fb0b0eb..62664b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -477,6 +477,40 @@ elif test "x$enable_libmount" = xno; then
     build_libmount=no
 fi

+AC_DEFUN([UTIL_SCANF_TYPE_MODIFIER], [dnl
+# include <stdio.h>
+int main()
+{
+	int i;
+	char *s;
+	i = sscanf("x", $1, &s);
+	if (i == 1)
+		return 0;
+	return 1;
+}])
+AC_MSG_CHECKING([needed scanf type modifiers])
+AC_CACHE_VAL([scanf_cv_type_modifier],
+  AC_RUN_IFELSE([AC_LANG_SOURCE([UTIL_SCANF_TYPE_MODIFIER(["%ms"])])],
+    [scanf_cv_type_modifier=ms],
+    AC_RUN_IFELSE([AC_LANG_SOURCE([UTIL_SCANF_TYPE_MODIFIER(["%as"])])],
+      [scanf_cv_type_modifier=as],
+      [scanf_cv_type_modifier=no]
+    )
+  )
+)
+if test "x$scanf_cv_type_modifier" = "xms"; then
+  AC_MSG_RESULT([yes])
+  AC_DEFINE([HAVE_SCANF_MS_MODIFIER], [1], [scanf %ms modifier])
+else
+  if test "x$scanf_cv_type_modifier" = "xas"; then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE([HAVE_SCANF_AS_MODIFIER], [1], [scanf %as modifier])
+  else
+    build_libmount=no
+    AC_MSG_RESULT([no])
+  fi
+fi
+
 case "$enable_libblkid:$build_libmount" in
 no:yes)
   AC_MSG_ERROR([cannot enable libmount when libblkid is disabled]) ;;
diff --git a/include/c.h b/include/c.h
index f5b4bcd..259e6b6 100644
--- a/include/c.h
+++ b/include/c.h
@@ -33,7 +33,7 @@

 /* &a[0] degrades to a pointer: a different type from an array */
 # define __must_be_array(a) \
-	BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a),
__typeof__(&a[0])))
+	UL_BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a),
__typeof__(&a[0])))

 # define ignore_result(x) ({ \
 	__typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
@@ -69,7 +69,7 @@
  * e.g. in a structure initializer (or where-ever else comma expressions
  * aren't permitted).
  */
-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+#define UL_BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))

 #ifndef ARRAY_SIZE
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index dba6002..7859e36 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -54,10 +54,17 @@ static int mnt_parse_table_line(struct libmnt_fs
*fs, char *s)
 	int rc, n = 0;
 	char *src, *fstype, *optstr;

+#ifdef HAVE_SCANF_MS_MODIFIER
 	rc = sscanf(s,	"%ms "	/* (1) source */
 			"%ms "	/* (2) target */
 			"%ms "	/* (3) FS type */
 			"%ms "  /* (4) options */
+#elif defined(HAVE_SCANF_AS_MODIFIER)
+	rc = sscanf(s,	"%as "	/* (1) source */
+			"%as "	/* (2) target */
+			"%as "	/* (3) FS type */
+			"%as "  /* (4) options */
+#endif
 			"%n",	/* byte count */
 			&src,
 			&fs->target,
@@ -114,9 +121,15 @@ static int mnt_parse_mountinfo_line(struct
libmnt_fs *fs, char *s)
 	rc = sscanf(s,	"%u "		/* (1) id */
 			"%u "		/* (2) parent */
 			"%u:%u "	/* (3) maj:min */
+#ifdef HAVE_SCANF_MS_MODIFIER
 			"%ms "		/* (4) mountroot */
 			"%ms "		/* (5) target */
 			"%ms"		/* (6) vfs options (fs-independent) */
+#elif defined(HAVE_SCANF_AS_MODIFIER)
+			"%as "		/* (4) mountroot */
+			"%as "		/* (5) target */
+			"%as"		/* (6) vfs options (fs-independent) */
+#endif
 			"%n",		/* number of read bytes */

 			&fs->id,
@@ -138,10 +151,15 @@ static int mnt_parse_mountinfo_line(struct
libmnt_fs *fs, char *s)
 	}
 	s = p + 3;

+#ifdef HAVE_SCANF_MS_MODIFIER
 	rc += sscanf(s,	"%ms "		/* (8) FS type */
 			"%ms "		/* (9) source */
 			"%ms",		/* (10) fs options (fs specific) */
-
+#elif defined(HAVE_SCANF_AS_MODIFIER)
+	rc += sscanf(s,	"%as "		/* (8) FS type */
+			"%as "		/* (9) source */
+			"%as",		/* (10) fs options (fs specific) */
+#endif
 			&fstype,
 			&src,
 			&fs->fs_optstr);
diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8
index 72085ac..028b19f 100644
--- a/misc-utils/lsblk.8
+++ b/misc-utils/lsblk.8
@@ -63,6 +63,15 @@ This option is equivalent to "-o
NAME,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,RO
 .SH NOTES
 For the partitions are some information (e.g. queue attributes) inherited from
 parental device.
+.PP
+The
+.B lsblk
+needs to be able to lookup sysfs path by major:minor, which is done
+done by using
+.BR /sys/dev/block .
+The block sysfs appeared in kernel 2.6.27 (October 2008).  In case of
+problem with new enough kernel check that CONFIG_SYSFS was enabled at
+the time of kernel build.
 .SH AUTHORS
 .nf
 Milan Broz <mbroz@redhat.com>
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 3c4555d..48b0b25 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -906,6 +906,16 @@ errx_mutually_exclusive(const char *opts)
 	errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
 }

+static void check_sysdevblock(void)
+{
+	DIR *dir;
+	if (!(dir = opendir(_PATH_SYS_DEVBLOCK)))
+		err(EXIT_FAILURE, _("failed to open sysfs directory: %s"),
+		    _PATH_SYS_DEVBLOCK);
+	closedir(dir);
+	return;
+}
+
 int main(int argc, char *argv[])
 {
 	struct lsblk _ls;
@@ -1018,6 +1028,8 @@ int main(int argc, char *argv[])
 		}
 	}

+	check_sysdevblock();
+
 	if (!ncolumns) {
 		columns[ncolumns++] = COL_NAME;
 		columns[ncolumns++] = COL_MAJMIN;

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

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

* Re: [pull] build-sys and lsblk enhancements
  2011-10-05 20:42 [pull] build-sys and lsblk enhancements Sami Kerola
@ 2011-10-10 13:02 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2011-10-10 13:02 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux

On Wed, Oct 05, 2011 at 10:42:38PM +0200, Sami Kerola wrote:
>  autogen.sh               |    1 +
>  configure.ac             |   34 ++++++++++++++++++++++++++++++++++
>  include/c.h              |    4 ++--
>  libmount/src/tab_parse.c |   20 +++++++++++++++++++-
>  misc-utils/lsblk.8       |    9 +++++++++
>  misc-utils/lsblk.c       |   12 ++++++++++++
>  6 files changed, 77 insertions(+), 3 deletions(-)

 Applied (with some changes), thanks.

> +if test "x$scanf_cv_type_modifier" = "xms"; then
> +  AC_MSG_RESULT([yes])
> +  AC_DEFINE([HAVE_SCANF_MS_MODIFIER], [1], [scanf %ms modifier])
> +else
> +  if test "x$scanf_cv_type_modifier" = "xas"; then
> +    AC_MSG_RESULT([yes])
> +    AC_DEFINE([HAVE_SCANF_AS_MODIFIER], [1], [scanf %as modifier])
> +  else
> +    build_libmount=no
> +    AC_MSG_RESULT([no])
> +  fi
> +fi

 It usually more readable to use "case .. esac".

 [...]

> +#ifdef HAVE_SCANF_MS_MODIFIER
>  	rc = sscanf(s,	"%ms "	/* (1) source */
>  			"%ms "	/* (2) target */
>  			"%ms "	/* (3) FS type */
>  			"%ms "  /* (4) options */
> +#elif defined(HAVE_SCANF_AS_MODIFIER)
> +	rc = sscanf(s,	"%as "	/* (1) source */
> +			"%as "	/* (2) target */
> +			"%as "	/* (3) FS type */
> +			"%as "  /* (4) options */
> +#endif

 I have add UL_SCNsA macro with %{ms,as} modifiers to c.h, so we don't 
 have to use #ifdef everywhere.

 [...]

> +static void check_sysdevblock(void)
> +{
> +	DIR *dir;
> +	if (!(dir = opendir(_PATH_SYS_DEVBLOCK)))
> +		err(EXIT_FAILURE, _("failed to open sysfs directory: %s"),
> +		    _PATH_SYS_DEVBLOCK);
> +	closedir(dir);
> +	return;
> +}

 access() should be enough :-)

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

end of thread, other threads:[~2011-10-10 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-05 20:42 [pull] build-sys and lsblk enhancements Sami Kerola
2011-10-10 13:02 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).