diff mbox series

[oe,meta-oe,V2] ledmon: control hard disk led for RAID arrays

Message ID 20190410043244.12131-1-raj.khem@gmail.com
State Accepted
Commit a12a37659db90a5534349f81fbe3744431f75b1d
Headers show
Series [oe,meta-oe,V2] ledmon: control hard disk led for RAID arrays | expand

Commit Message

Khem Raj April 10, 2019, 4:32 a.m. UTC
From: Liwei Song <liwei.song@windriver.com>


Enable LED support for Intel Virtual RAID On CPU.
Fix build with musl

Signed-off-by: Liwei Song <liwei.song@windriver.com>

Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 ...ad-of-on_exit-for-musl-compatibility.patch | 53 +++++++++++++++++++
 ...include-sys-select.h-and-sys-types.h.patch | 43 +++++++++++++++
 meta-oe/recipes-bsp/ledmon/ledmon_git.bb      | 34 ++++++++++++
 3 files changed, 130 insertions(+)
 create mode 100644 meta-oe/recipes-bsp/ledmon/ledmon/0001-use-atexit-insead-of-on_exit-for-musl-compatibility.patch
 create mode 100644 meta-oe/recipes-bsp/ledmon/ledmon/0002-include-sys-select.h-and-sys-types.h.patch
 create mode 100644 meta-oe/recipes-bsp/ledmon/ledmon_git.bb

-- 
2.21.0

-- 
_______________________________________________
Openembedded-devel mailing list
Openembedded-devel@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-devel

Comments

Adrian Bunk April 15, 2019, 11:44 a.m. UTC | #1
On Tue, Apr 09, 2019 at 09:32:44PM -0700, Khem Raj wrote:
>...

> +musl does not support on_exit which is used in clean up.

> +Instead use atexit with is supported by musl and glibc.


The functions have different signatures, and this patch introduces bugs 
for cases that use the parameters of on_exit.

int on_exit(void (*function)(int , void *), void *arg);
int atexit(void (*function)(void));

Example:

>...

> +-	if (on_exit(_ledmon_status, &terminate))

> ++	if (atexit(_ledmon_status))

>...


static void _ledmon_status(int status, void *ignore)
{
        if (*((int *)ignore) != 0)
                log_info("exit status is %s.", strstatus(status));
        else if (status != STATUS_SUCCESS)
                log_error("parent exit status is %s.", strstatus(status));
}

With the bogus atexit change no parameters are passed to _ledmon_status,
and the function uses (and dereferenes) whatever garbage is currently
in the stack/registers where function parameters are expected.

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed

-- 
_______________________________________________
Openembedded-devel mailing list
Openembedded-devel@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-devel
Khem Raj April 15, 2019, 2:29 p.m. UTC | #2
On Mon, Apr 15, 2019 at 4:44 AM Adrian Bunk <bunk@stusta.de> wrote:

> On Tue, Apr 09, 2019 at 09:32:44PM -0700, Khem Raj wrote:

> >...

> > +musl does not support on_exit which is used in clean up.

> > +Instead use atexit with is supported by musl and glibc.

>

> The functions have different signatures, and this patch introduces bugs

> for cases that use the parameters of on_exit.

>

> int on_exit(void (*function)(int , void *), void *arg);

> int atexit(void (*function)(void));

>

> Example:

>

> >...

> > +-    if (on_exit(_ledmon_status, &terminate))

> > ++    if (atexit(_ledmon_status))

> >...

>

> static void _ledmon_status(int status, void *ignore)

> {

>         if (*((int *)ignore) != 0)

>                 log_info("exit status is %s.", strstatus(status));

>         else if (status != STATUS_SUCCESS)

>                 log_error("parent exit status is %s.", strstatus(status));

> }

>

> With the bogus atexit change no parameters are passed to _ledmon_status,

> and the function uses (and dereferenes) whatever garbage is currently

> in the stack/registers where function parameters are expected.



Thanks for looking into it and This is correct somehow I overlooked it i
will send a follow up to not rely on arguments for on_exit

>

>

> cu

> Adrian

>

> --

>

>        "Is there not promise of rain?" Ling Tan asked suddenly out

>         of the darkness. There had been need of rain for many days.

>        "Only a promise," Lao Er said.

>                                        Pearl S. Buck - Dragon Seed

>

>

-- 
_______________________________________________
Openembedded-devel mailing list
Openembedded-devel@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-devel
diff mbox series

Patch

diff --git a/meta-oe/recipes-bsp/ledmon/ledmon/0001-use-atexit-insead-of-on_exit-for-musl-compatibility.patch b/meta-oe/recipes-bsp/ledmon/ledmon/0001-use-atexit-insead-of-on_exit-for-musl-compatibility.patch
new file mode 100644
index 0000000000..de5ce9fc83
--- /dev/null
+++ b/meta-oe/recipes-bsp/ledmon/ledmon/0001-use-atexit-insead-of-on_exit-for-musl-compatibility.patch
@@ -0,0 +1,53 @@ 
+From 8aba09b743b4e89ef581a679943ce39a5c7fd4a5 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Tue, 9 Apr 2019 21:25:21 -0700
+Subject: [PATCH 1/2] use atexit insead of on_exit for musl compatibility
+
+musl does not support on_exit which is used in clean up.
+Instead use atexit with is supported by musl and glibc.
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/ledctl.c | 2 +-
+ src/ledmon.c | 4 ++--
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/src/ledctl.c b/src/ledctl.c
+index 2aa1abc..2c97dcf 100644
+--- a/src/ledctl.c
++++ b/src/ledctl.c
+@@ -689,7 +689,7 @@ int main(int argc, char *argv[])
+ 	status = _init_ledctl_conf();
+ 	if (status != STATUS_SUCCESS)
+ 		return status;
+-	if (on_exit(_ledctl_fini, progname))
++	if (atexit(_ledctl_fini))
+ 		exit(STATUS_ONEXIT_ERROR);
+ 	if (_cmdline_parse(argc, argv))
+ 		exit(STATUS_CMDLINE_ERROR);
+diff --git a/src/ledmon.c b/src/ledmon.c
+index 0ea2583..2333c7c 100644
+--- a/src/ledmon.c
++++ b/src/ledmon.c
+@@ -860,7 +860,7 @@ int main(int argc, char *argv[])
+ 	set_invocation_name(argv[0]);
+ 	openlog(progname, LOG_PID | LOG_PERROR, LOG_DAEMON);
+ 
+-	if (on_exit(_ledmon_status, &terminate))
++	if (atexit(_ledmon_status))
+ 		return STATUS_ONEXIT_ERROR;
+ 
+ 	if (_cmdline_parse_non_daemonise(argc, argv) != STATUS_SUCCESS)
+@@ -930,7 +930,7 @@ int main(int argc, char *argv[])
+ 	}
+ 	_ledmon_setup_signals();
+ 
+-	if (on_exit(_ledmon_fini, progname))
++	if (atexit(_ledmon_fini))
+ 		exit(STATUS_ONEXIT_ERROR);
+ 	list_init(&ledmon_block_list, (item_free_t)block_device_fini);
+ 	sysfs_init();
+-- 
+2.21.0
+
diff --git a/meta-oe/recipes-bsp/ledmon/ledmon/0002-include-sys-select.h-and-sys-types.h.patch b/meta-oe/recipes-bsp/ledmon/ledmon/0002-include-sys-select.h-and-sys-types.h.patch
new file mode 100644
index 0000000000..75bf2b4f5e
--- /dev/null
+++ b/meta-oe/recipes-bsp/ledmon/ledmon/0002-include-sys-select.h-and-sys-types.h.patch
@@ -0,0 +1,43 @@ 
+From 2ee8796db5019341b774bcb4f7d0944d89e1845b Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Tue, 9 Apr 2019 21:26:55 -0700
+Subject: [PATCH 2/2] include sys/select.h and sys/types.h
+
+sys/select.h is needed to provide fd_set definition
+sys/types.h is needed for ssize_t
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/dellssd.c | 1 +
+ src/utils.h   | 1 +
+ 2 files changed, 2 insertions(+)
+
+diff --git a/src/dellssd.c b/src/dellssd.c
+index 7b8d431..e97fe45 100644
+--- a/src/dellssd.c
++++ b/src/dellssd.c
+@@ -27,6 +27,7 @@
+ #include <unistd.h>
+ 
+ #include <sys/ioctl.h>
++#include <sys/select.h>
+ #include <linux/ipmi.h>
+ 
+ #if _HAVE_DMALLOC_H
+diff --git a/src/utils.h b/src/utils.h
+index 720447a..c106529 100644
+--- a/src/utils.h
++++ b/src/utils.h
+@@ -21,6 +21,7 @@
+ #define _UTILS_H_INCLUDED_
+ 
+ #include <getopt.h>
++#include <sys/types.h>
+ #include "config_file.h"
+ #include "stdlib.h"
+ #include "stdint.h"
+-- 
+2.21.0
+
diff --git a/meta-oe/recipes-bsp/ledmon/ledmon_git.bb b/meta-oe/recipes-bsp/ledmon/ledmon_git.bb
new file mode 100644
index 0000000000..4376ad3941
--- /dev/null
+++ b/meta-oe/recipes-bsp/ledmon/ledmon_git.bb
@@ -0,0 +1,34 @@ 
+SUMMARY = "Intel(R) Enclosure LED Utilities"
+
+DESCRIPTION = "The utilities are designed primarily to be used on storage servers \
+ utilizing MD devices (aka Linux Software RAID) for RAID arrays.\
+"
+HOMEPAGE = "https://github.com/intel/ledmon"
+
+LICENSE = "GPLv2"
+LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
+"
+
+DEPENDS = "sg3-utils udev"
+
+inherit systemd
+
+SYSTEMD_SERVICE_${PN} = "ledmon.service"
+
+SRC_URI = "git://github.com/intel/ledmon;branch=master \
+           file://0001-use-atexit-insead-of-on_exit-for-musl-compatibility.patch \
+           file://0002-include-sys-select.h-and-sys-types.h.patch \
+          "
+
+SRCREV = "ad1304ca1363d727425a1f23703c523e21feae4f"
+
+COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
+
+S = "${WORKDIR}/git"
+EXTRA_OEMAKE = "CC='${CC}' LDFLAGS='${LDFLAGS}' CFLAGS='${CFLAGS}'"
+
+do_install_append() {
+	install -d ${D}/${systemd_unitdir}/system
+	oe_runmake  DESTDIR=${D}  install
+	oe_runmake  DESTDIR=${D}${systemd_unitdir}/system  install-systemd
+}