All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc.
@ 2015-11-17  8:54 Casper Ti. Vector
  2015-11-17  9:05 ` [PATCH 2/2] linux_reboot.h: remove code that is unused anyway Casper Ti. Vector
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Casper Ti. Vector @ 2015-11-17  8:54 UTC (permalink / raw)
  To: util-linux

Original code assumes 1-argument reboot() is only provided by glibc 2.x
and later; but as far as the patch author knows, at least the following
alternative C libraries for linux also provide the 1-argument variant:

* uclibc: all public releases.
* dietlibc: 0.7.2 and all later releases; reboot() was not provided in
            0.7.1 and earlier versions.
* musl: all public releases.
* klibc: all public releases.
* bionic: all public releases.

... which should already cover most use cases.
---
 include/linux_reboot.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux_reboot.h b/include/linux_reboot.h
index 9cebc67..7ba4bca 100644
--- a/include/linux_reboot.h
+++ b/include/linux_reboot.h
@@ -39,12 +39,12 @@
 #ifdef USE_LIBC
 
 /* libc version */
-#if defined __GLIBC__ && __GLIBC__ >= 2
-#  include <sys/reboot.h>
-#  define REBOOT(cmd) reboot(cmd)
-#else
+#if defined __GLIBC__ && __GLIBC__ < 2
 extern int reboot(int, int, int);
 #  define REBOOT(cmd) reboot(LINUX_REBOOT_MAGIC1,LINUX_REBOOT_MAGIC2,(cmd))
+#else
+#  include <sys/reboot.h>
+#  define REBOOT(cmd) reboot(cmd)
 #endif
 static inline int my_reboot(int cmd) {
 	return REBOOT(cmd);
-- 
2.6.3


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

* [PATCH 2/2] linux_reboot.h: remove code that is unused anyway.
  2015-11-17  8:54 [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Casper Ti. Vector
@ 2015-11-17  9:05 ` Casper Ti. Vector
  2015-11-17 21:04 ` [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Christoph Hellwig
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Casper Ti. Vector @ 2015-11-17  9:05 UTC (permalink / raw)
  To: util-linux

---
 include/linux_reboot.h | 22 ----------------------
 1 file changed, 22 deletions(-)

diff --git a/include/linux_reboot.h b/include/linux_reboot.h
index 7ba4bca..ce7fa68 100644
--- a/include/linux_reboot.h
+++ b/include/linux_reboot.h
@@ -34,10 +34,6 @@
 #include <unistd.h>
 #include "linux_reboot.h"
 
-#define USE_LIBC
-
-#ifdef USE_LIBC
-
 /* libc version */
 #if defined __GLIBC__ && __GLIBC__ < 2
 extern int reboot(int, int, int);
@@ -50,23 +46,5 @@ static inline int my_reboot(int cmd) {
 	return REBOOT(cmd);
 }
 
-#else /* no USE_LIBC */
-
-/* direct syscall version */
-#include <linux/unistd.h>
-
-#ifdef _syscall3
-_syscall3(int,  reboot,  int,  magic, int, magic_too, int, cmd);
-#else
-/* Let us hope we have a 3-argument reboot here */
-extern int reboot(int, int, int);
-#endif
-
-static inline int my_reboot(int cmd) {
-	return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd);
-}
-
-#endif
-
 
 #endif /*  _LINUX_REBOOT_H  */
-- 
2.6.3


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

* Re: [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc.
  2015-11-17  8:54 [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Casper Ti. Vector
  2015-11-17  9:05 ` [PATCH 2/2] linux_reboot.h: remove code that is unused anyway Casper Ti. Vector
@ 2015-11-17 21:04 ` Christoph Hellwig
  2015-11-18 12:59 ` Karel Zak
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2015-11-17 21:04 UTC (permalink / raw)
  To: Casper Ti. Vector; +Cc: util-linux

On Tue, Nov 17, 2015 at 04:54:15PM +0800, Casper Ti. Vector wrote:
> Original code assumes 1-argument reboot() is only provided by glibc 2.x
> and later; but as far as the patch author knows, at least the following
> alternative C libraries for linux also provide the 1-argument variant:
> 
> * uclibc: all public releases.
> * dietlibc: 0.7.2 and all later releases; reboot() was not provided in
>             0.7.1 and earlier versions.
> * musl: all public releases.
> * klibc: all public releases.
> * bionic: all public releases.
> 
> ... which should already cover most use cases.

Or rather all useful cases.  I'd say remove the old version
entirely and the wrappers entirely.

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

* Re: [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc.
  2015-11-17  8:54 [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Casper Ti. Vector
  2015-11-17  9:05 ` [PATCH 2/2] linux_reboot.h: remove code that is unused anyway Casper Ti. Vector
  2015-11-17 21:04 ` [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Christoph Hellwig
@ 2015-11-18 12:59 ` Karel Zak
  2015-11-19  2:52 ` [PATCH v2 1/2] ctrlaltdel: use reboot() provided by libc, assuming it is 1-adic Casper Ti. Vector
  2015-11-19  2:56 ` [PATCH v2 2/2] Remove now useless linux_reboot.h Casper Ti. Vector
  4 siblings, 0 replies; 8+ messages in thread
From: Karel Zak @ 2015-11-18 12:59 UTC (permalink / raw)
  To: Casper Ti. Vector; +Cc: util-linux

On Tue, Nov 17, 2015 at 04:54:15PM +0800, Casper Ti. Vector wrote:
> Original code assumes 1-argument reboot() is only provided by glibc 2.x
> and later; but as far as the patch author knows, at least the following
> alternative C libraries for linux also provide the 1-argument variant:
> 
> * uclibc: all public releases.
> * dietlibc: 0.7.2 and all later releases; reboot() was not provided in
>             0.7.1 and earlier versions.
> * musl: all public releases.
> * klibc: all public releases.
> * bionic: all public releases.
> 
> ... which should already cover most use cases.
> ---
>  include/linux_reboot.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

I think Christoph is right, let's remove all the wrappers from
linux_reboot.h and use directly reboot() in the code.

It's always fragile to check for libc version in source code. The
better solution is to use ./configure and care about the function/feature 
than about any version number.

 AC_CHECK_FUNCS([reboot], [have_open_reboot=yes],[have_open_reboot=no])
 ...

 UL_BUILD_INIT([ctrlaltdel], [check])
 UL_REQUIRES_LINUX([ctrlaltdel])
 UL_REQUIRES_HAVE([ctrlaltdel], [reboot])
 AM_CONDITIONAL([BUILD_CTRLALTDEL], [test "x$build_ctrlaltdel" = xyes])

then it will compile ctrlaltdel only when we have reboot().

And if you want to be really pedantic then you can use
AC_COMPILE_IFELSE() to check for 1-argument reboot(), but it seems
it's unnecessary.

    Karel

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

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

* [PATCH v2 1/2] ctrlaltdel: use reboot() provided by libc, assuming it is 1-adic.
  2015-11-17  8:54 [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Casper Ti. Vector
                   ` (2 preceding siblings ...)
  2015-11-18 12:59 ` Karel Zak
@ 2015-11-19  2:52 ` Casper Ti. Vector
  2015-11-19 11:12   ` Karel Zak
  2015-11-19  2:56 ` [PATCH v2 2/2] Remove now useless linux_reboot.h Casper Ti. Vector
  4 siblings, 1 reply; 8+ messages in thread
From: Casper Ti. Vector @ 2015-11-19  2:52 UTC (permalink / raw)
  To: util-linux

---
 configure.ac           | 6 ++++++
 sys-utils/ctrlaltdel.c | 8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6748dd2..6075f72 100644
--- a/configure.ac
+++ b/configure.ac
@@ -378,6 +378,7 @@ AC_CHECK_FUNCS([ioperm iopl], [have_io=yes])
 AC_CHECK_FUNCS([futimens], [have_futimens=yes])
 AC_CHECK_FUNCS([inotify_init1], [have_inotify_init1=yes])
 AC_CHECK_FUNCS([open_memstream], [have_open_memstream=yes],[have_open_memstream=no])
+AC_CHECK_FUNCS([reboot], [have_reboot=yes],[have_reboot=no])
 
 dnl lib/mononotic.c may require -lrt
 AC_CHECK_FUNCS([clock_gettime], [],
@@ -1420,6 +1421,11 @@ AM_CONDITIONAL([BUILD_DMESG], [test "x$build_dmesg" = xyes])
 
 UL_BUILD_INIT([ctrlaltdel], [check])
 UL_REQUIRES_LINUX([ctrlaltdel])
+dnl we assume reboot() to be the 1-argument variant, because even considering
+dnl widely used alternative C libraries like uclibc, dietlibc and musl,
+dnl reboot() with multiple arguments is yet only found in glibc versions
+dnl earlier than 2.x.
+UL_REQUIRES_HAVE([ctrlaltdel], [reboot])
 AM_CONDITIONAL([BUILD_CTRLALTDEL], [test "x$build_ctrlaltdel" = xyes])
 
 UL_BUILD_INIT([fsfreeze], [check])
diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c
index 4388925..4a69584 100644
--- a/sys-utils/ctrlaltdel.c
+++ b/sys-utils/ctrlaltdel.c
@@ -10,13 +10,17 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include "linux_reboot.h"
+#include <unistd.h>
+#include <sys/reboot.h>
 #include "nls.h"
 #include "c.h"
 #include "closestream.h"
 #include "pathnames.h"
 #include "path.h"
 
+#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
+#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
+
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
 	fprintf(out, USAGE_HEADER);
@@ -67,7 +71,7 @@ static int set_cad(const char *arg)
 		warnx(_("unknown argument: %s"), arg);
 		return EXIT_FAILURE;
 	}
-	if (my_reboot(cmd) < 0) {
+	if (reboot(cmd) < 0) {
 		warnx("reboot");
 		return EXIT_FAILURE;
 	}
-- 
2.6.3


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

* [PATCH v2 2/2] Remove now useless linux_reboot.h.
  2015-11-17  8:54 [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Casper Ti. Vector
                   ` (3 preceding siblings ...)
  2015-11-19  2:52 ` [PATCH v2 1/2] ctrlaltdel: use reboot() provided by libc, assuming it is 1-adic Casper Ti. Vector
@ 2015-11-19  2:56 ` Casper Ti. Vector
  4 siblings, 0 replies; 8+ messages in thread
From: Casper Ti. Vector @ 2015-11-19  2:56 UTC (permalink / raw)
  To: util-linux

---
 include/Makemodule.am  |  1 -
 include/linux_reboot.h | 72 --------------------------------------------------
 2 files changed, 73 deletions(-)
 delete mode 100644 include/linux_reboot.h

diff --git a/include/Makemodule.am b/include/Makemodule.am
index f0bb898..fcda908 100644
--- a/include/Makemodule.am
+++ b/include/Makemodule.am
@@ -19,7 +19,6 @@ dist_noinst_HEADERS += \
 	include/exitcodes.h \
 	include/fileutils.h \
 	include/ismounted.h \
-	include/linux_reboot.h \
 	include/linux_version.h \
 	include/list.h \
 	include/loopdev.h \
diff --git a/include/linux_reboot.h b/include/linux_reboot.h
deleted file mode 100644
index 9cebc67..0000000
--- a/include/linux_reboot.h
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef _LINUX_REBOOT_H
-#define _LINUX_REBOOT_H
-
-/*
- * Magic values required to use _reboot() system call.
- */
-
-#define	LINUX_REBOOT_MAGIC1	0xfee1dead
-#define	LINUX_REBOOT_MAGIC2	672274793
-#define	LINUX_REBOOT_MAGIC2A	85072278
-#define	LINUX_REBOOT_MAGIC2B	369367448
-
-
-/*
- * Commands accepted by the _reboot() system call.
- *
- * RESTART     Restart system using default command and mode.
- * HALT        Stop OS and give system control to ROM monitor, if any.
- * CAD_ON      Ctrl-Alt-Del sequence causes RESTART command.
- * CAD_OFF     Ctrl-Alt-Del sequence sends SIGINT to init task.
- * POWER_OFF   Stop OS and remove all power from system, if possible.
- * RESTART2    Restart system using given command string.
- */
-
-#define	LINUX_REBOOT_CMD_RESTART	0x01234567
-#define	LINUX_REBOOT_CMD_HALT		0xCDEF0123
-#define	LINUX_REBOOT_CMD_CAD_ON		0x89ABCDEF
-#define	LINUX_REBOOT_CMD_CAD_OFF	0x00000000
-#define	LINUX_REBOOT_CMD_POWER_OFF	0x4321FEDC
-#define	LINUX_REBOOT_CMD_RESTART2	0xA1B2C3D4
-
-/* Including <unistd.h> makes sure that on a glibc system
-   <features.h> is included, which again defines __GLIBC__ */
-#include <unistd.h>
-#include "linux_reboot.h"
-
-#define USE_LIBC
-
-#ifdef USE_LIBC
-
-/* libc version */
-#if defined __GLIBC__ && __GLIBC__ >= 2
-#  include <sys/reboot.h>
-#  define REBOOT(cmd) reboot(cmd)
-#else
-extern int reboot(int, int, int);
-#  define REBOOT(cmd) reboot(LINUX_REBOOT_MAGIC1,LINUX_REBOOT_MAGIC2,(cmd))
-#endif
-static inline int my_reboot(int cmd) {
-	return REBOOT(cmd);
-}
-
-#else /* no USE_LIBC */
-
-/* direct syscall version */
-#include <linux/unistd.h>
-
-#ifdef _syscall3
-_syscall3(int,  reboot,  int,  magic, int, magic_too, int, cmd);
-#else
-/* Let us hope we have a 3-argument reboot here */
-extern int reboot(int, int, int);
-#endif
-
-static inline int my_reboot(int cmd) {
-	return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd);
-}
-
-#endif
-
-
-#endif /*  _LINUX_REBOOT_H  */
-- 
2.6.3


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

* Re: [PATCH v2 1/2] ctrlaltdel: use reboot() provided by libc, assuming it is 1-adic.
  2015-11-19  2:52 ` [PATCH v2 1/2] ctrlaltdel: use reboot() provided by libc, assuming it is 1-adic Casper Ti. Vector
@ 2015-11-19 11:12   ` Karel Zak
  2015-11-19 11:38     ` Casper Ti. Vector
  0 siblings, 1 reply; 8+ messages in thread
From: Karel Zak @ 2015-11-19 11:12 UTC (permalink / raw)
  To: Casper Ti. Vector; +Cc: util-linux

On Thu, Nov 19, 2015 at 10:52:14AM +0800, Casper Ti. Vector wrote:
>  2 files changed, 12 insertions(+), 2 deletions(-)
>  2 files changed, 73 deletions(-)

75 deletions, cool :-) Applied, thanks.

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

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

* Re: [PATCH v2 1/2] ctrlaltdel: use reboot() provided by libc, assuming it is 1-adic.
  2015-11-19 11:12   ` Karel Zak
@ 2015-11-19 11:38     ` Casper Ti. Vector
  0 siblings, 0 replies; 8+ messages in thread
From: Casper Ti. Vector @ 2015-11-19 11:38 UTC (permalink / raw)
  To: util-linux

:)

On Thu, Nov 19, 2015 at 12:12:45PM +0100, Karel Zak wrote:
> 75 deletions, cool :-) Applied, thanks.

-- 
My current OpenPGP key:
RSA4096/0x227E8CAAB7AA186C (expires: 2020.10.19)
7077 7781 B859 5166 AE07 0286 227E 8CAA B7AA 186C


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

end of thread, other threads:[~2015-11-19 11:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17  8:54 [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Casper Ti. Vector
2015-11-17  9:05 ` [PATCH 2/2] linux_reboot.h: remove code that is unused anyway Casper Ti. Vector
2015-11-17 21:04 ` [PATCH 1/2] linux_reboot.h: support 1-argument reboot() from alternative libc Christoph Hellwig
2015-11-18 12:59 ` Karel Zak
2015-11-19  2:52 ` [PATCH v2 1/2] ctrlaltdel: use reboot() provided by libc, assuming it is 1-adic Casper Ti. Vector
2015-11-19 11:12   ` Karel Zak
2015-11-19 11:38     ` Casper Ti. Vector
2015-11-19  2:56 ` [PATCH v2 2/2] Remove now useless linux_reboot.h Casper Ti. Vector

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.