Patchwork initscripts: add usleep support from RHEL

login
register
mail settings
Submitter Ming Liu
Date July 2, 2014, 7:33 a.m.
Message ID <1404286429-13962-1-git-send-email-ming.liu@windriver.com>
Download mbox | patch
Permalink /patch/74803/
State New
Headers show

Comments

Ming Liu - July 2, 2014, 7:33 a.m.
Add usleep in to support sleeping some number of microseconds.

Signed-off-by: Ming Liu <ming.liu@windriver.com>
---
 .../initscripts/initscripts-1.0/usleep.1           | 25 +++++++
 .../initscripts/initscripts-1.0/usleep.c           | 82 ++++++++++++++++++++++
 meta/recipes-core/initscripts/initscripts_1.0.bb   | 13 +++-
 3 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-core/initscripts/initscripts-1.0/usleep.1
 create mode 100644 meta/recipes-core/initscripts/initscripts-1.0/usleep.c
Chris Larson - July 2, 2014, 5:37 p.m.
On Wed, Jul 2, 2014 at 12:33 AM, Ming Liu <ming.liu@windriver.com> wrote:

> Add usleep in to support sleeping some number of microseconds.
>
> Signed-off-by: Ming Liu <ming.liu@windriver.com>
>

Maybe it's just me, but initscripts seems like a horrible place to put this.
Ross Burton - July 2, 2014, 7:08 p.m.
On 2 July 2014 18:37, Christopher Larson <clarson@kergoth.com> wrote:
>> Add usleep in to support sleeping some number of microseconds.
>>
>> Signed-off-by: Ming Liu <ming.liu@windriver.com>
>
>
> Maybe it's just me, but initscripts seems like a horrible place to put this.

Agreed.  Also is there a rationale for adding this?

Ross
Saul Wold - July 2, 2014, 7:39 p.m.
On 07/02/2014 10:37 AM, Christopher Larson wrote:
> On Wed, Jul 2, 2014 at 12:33 AM, Ming Liu <ming.liu@windriver.com> wrote:
>
>> Add usleep in to support sleeping some number of microseconds.
>>
>> Signed-off-by: Ming Liu <ming.liu@windriver.com>
>>
>
> Maybe it's just me, but initscripts seems like a horrible place to put this.
>
>
>
It's not just you!  Not sure why it's being added here and I don't see 
any usage of it, so more information is required.

Sau!
Ming Liu - July 3, 2014, 2:26 a.m.
On 07/03/2014 03:39 AM, Saul Wold wrote:
> On 07/02/2014 10:37 AM, Christopher Larson wrote:
>> On Wed, Jul 2, 2014 at 12:33 AM, Ming Liu <ming.liu@windriver.com> 
>> wrote:
>>
>>> Add usleep in to support sleeping some number of microseconds.
>>>
>>> Signed-off-by: Ming Liu <ming.liu@windriver.com>
>>>
>>
>> Maybe it's just me, but initscripts seems like a horrible place to 
>> put this.
>>
>>
>>
> It's not just you!  Not sure why it's being added here and I don't see 
> any usage of it, so more information is required.
Why I've sent this is because I noticed there was no usleep binary in 
any of the packages in oe repositories, and I assumed that the end user 
might like to use it in their rootfs, so I migrated it from initscripts 
package of RHEL. Anyway, if all you guys think it's not necessary and 
not appropriate, I will not insist it, we could just ignore my proposal. :)

the best,
thank you
>
> Sau!
>
>
Chris Larson - July 3, 2014, 3:45 a.m.
On Wed, Jul 2, 2014 at 7:26 PM, Ming Liu <ming.liu@windriver.com> wrote:

> On 07/03/2014 03:39 AM, Saul Wold wrote:
>
>> On 07/02/2014 10:37 AM, Christopher Larson wrote:
>>
>>> On Wed, Jul 2, 2014 at 12:33 AM, Ming Liu <ming.liu@windriver.com>
>>> wrote:
>>>
>>>  Add usleep in to support sleeping some number of microseconds.
>>>>
>>>> Signed-off-by: Ming Liu <ming.liu@windriver.com>
>>>>
>>>>
>>> Maybe it's just me, but initscripts seems like a horrible place to put
>>> this.
>>>
>>>
>>>
>>>  It's not just you!  Not sure why it's being added here and I don't see
>> any usage of it, so more information is required.
>>
> Why I've sent this is because I noticed there was no usleep binary in any
> of the packages in oe repositories, and I assumed that the end user might
> like to use it in their rootfs, so I migrated it from initscripts package
> of RHEL. Anyway, if all you guys think it's not necessary and not
> appropriate, I will not insist it, we could just ignore my proposal. :)


The tool itself sounds like it could be of use, but it should likely get
its own recipe in meta-oe until/if something in oe-core actually needs it.
Ming Liu - July 4, 2014, 2:30 a.m.
On 07/03/2014 11:45 AM, Christopher Larson wrote:
>
> On Wed, Jul 2, 2014 at 7:26 PM, Ming Liu <ming.liu@windriver.com 
> <mailto:ming.liu@windriver.com>> wrote:
>
>     On 07/03/2014 03:39 AM, Saul Wold wrote:
>
>         On 07/02/2014 10:37 AM, Christopher Larson wrote:
>
>             On Wed, Jul 2, 2014 at 12:33 AM, Ming Liu
>             <ming.liu@windriver.com <mailto:ming.liu@windriver.com>>
>             wrote:
>
>                 Add usleep in to support sleeping some number of
>                 microseconds.
>
>                 Signed-off-by: Ming Liu <ming.liu@windriver.com
>                 <mailto:ming.liu@windriver.com>>
>
>
>             Maybe it's just me, but initscripts seems like a horrible
>             place to put this.
>
>
>
>         It's not just you!  Not sure why it's being added here and I
>         don't see any usage of it, so more information is required.
>
>     Why I've sent this is because I noticed there was no usleep binary
>     in any of the packages in oe repositories, and I assumed that the
>     end user might like to use it in their rootfs, so I migrated it
>     from initscripts package of RHEL. Anyway, if all you guys think
>     it's not necessary and not appropriate, I will not insist it, we
>     could just ignore my proposal. :)
>
>
> The tool itself sounds like it could be of use, but it should likely 
> get its own recipe in meta-oe until/if something in oe-core actually 
> needs it.
Got it, thanks! I will do that.

the best,
thank you
> -- 
> Christopher Larson
> clarson at kergoth dot com
> Founder - BitBake, OpenEmbedded, OpenZaurus
> Maintainer - Tslib
> Senior Software Engineer, Mentor Graphics

Patch

diff --git a/meta/recipes-core/initscripts/initscripts-1.0/usleep.1 b/meta/recipes-core/initscripts/initscripts-1.0/usleep.1
new file mode 100644
index 0000000..2d7520f
--- /dev/null
+++ b/meta/recipes-core/initscripts/initscripts-1.0/usleep.1
@@ -0,0 +1,25 @@ 
+.TH USLEEP 1 "Red Hat, Inc" \" -*- nroff -*-
+.SH NAME
+usleep \- sleep some number of microseconds
+.SH SYNOPSIS
+.B usleep
+[\fInumber\fP]
+.SH DESCRIPTION
+.B usleep
+sleeps some number of microseconds.  The default is 1.
+.SH OPTIONS
+\fI--usage\fP
+Show short usage message.
+.TP
+\fI--help, -?\fP
+Print help information.
+.TP
+\fI-v, --version\fP
+Print version information.
+.SH BUGS
+Probably not accurate on many machines down to the microsecond.  Count
+on precision only to -4 or maybe -5.
+.SH AUTHOR
+Donald Barnes <djb@redhat.com>
+.br
+Erik Troan <ewt@redhat.com>
diff --git a/meta/recipes-core/initscripts/initscripts-1.0/usleep.c b/meta/recipes-core/initscripts/initscripts-1.0/usleep.c
new file mode 100644
index 0000000..a5e7d9d
--- /dev/null
+++ b/meta/recipes-core/initscripts/initscripts-1.0/usleep.c
@@ -0,0 +1,82 @@ 
+/* 
+ * usleep
+ * 
+ * Written by Donald Barnes <djb@redhat.com> for Red Hat, Inc.
+ * 
+ * Copyright (c) 1997-2003 Red Hat, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "popt.h"
+
+int main(int argc, char **argv) {
+  unsigned long count;
+  poptContext optCon;
+  int showVersion = 0;
+  int showOot = 0;
+  int rc;
+  char * countStr = NULL;
+  struct poptOption options[] = {
+            { "version", 'v', POPT_ARG_NONE, &showVersion, 0, 
+			"Display the version of this program, and exit" },
+            { "oot", 'o', POPT_ARG_NONE, &showOot, 0, 
+			"oot says hey!" },
+	    POPT_AUTOHELP
+            { 0, 0, 0, 0, 0 }
+        };
+
+  optCon = poptGetContext("usleep", argc, argv, options,0);
+  /*poptReadDefaultConfig(optCon, 1);*/
+  poptSetOtherOptionHelp(optCon, "[microseconds]");
+
+  if ((rc = poptGetNextOpt(optCon)) < -1) {
+	fprintf(stderr, "usleep: bad argument %s: %s\n", 
+		poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
+		poptStrerror(rc));
+	return 2;
+  }
+
+  if (showVersion) {
+      printf("usleep version 1.2\n	usleep --help for more info\n");
+      return 0;
+  }
+
+  if (showOot) {
+      printf("oot says hey!\n");
+      return 0;
+  }
+
+  countStr = poptGetArg(optCon);
+
+  if (countStr == NULL) count = 1;
+
+  else if (countStr && poptGetArg(optCon)) {
+      fprintf(stderr, "%s: exactly one argument (number of microseconds) "
+      		"must be used\n", argv[0]);
+      return 2;
+  }
+
+  else count = strtoul(countStr, NULL, 0); 
+
+  usleep(count);
+  return 0;
+} 
diff --git a/meta/recipes-core/initscripts/initscripts_1.0.bb b/meta/recipes-core/initscripts/initscripts_1.0.bb
index 7273a82..456aed4 100644
--- a/meta/recipes-core/initscripts/initscripts_1.0.bb
+++ b/meta/recipes-core/initscripts/initscripts_1.0.bb
@@ -5,7 +5,7 @@  LICENSE = "GPLv2"
 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
 PR = "r155"
 
-INHIBIT_DEFAULT_DEPS = "1"
+S = "${WORKDIR}"
 
 SRC_URI = "file://functions \
            file://halt \
@@ -33,6 +33,8 @@  SRC_URI = "file://functions \
            file://GPLv2.patch \
            file://dmesg.sh \
            file://logrotate-dmesg.conf \
+           file://usleep.c \
+           file://usleep.1 \
 "
 
 SRC_URI_append_arm = " file://alignment.sh"
@@ -42,6 +44,7 @@  KERNEL_VERSION = ""
 inherit update-alternatives
 DEPENDS_append = " update-rc.d-native"
 DEPENDS_append = " ${@bb.utils.contains('DISTRO_FEATURES','systemd','systemd-systemctl-native','',d)}"
+DEPENDS_append = " popt"
 
 PACKAGES =+ "${PN}-functions"
 RDEPENDS_${PN} = "${PN}-functions"
@@ -58,6 +61,10 @@  do_configure() {
 	sed -i -e "s:SED_HALTARGS:${HALTARGS}:g" ${WORKDIR}/reboot
 }
 
+do_compile() {
+	${CC} ${CFLAGS} ${LDFLAGS} usleep.c -o usleep -lpopt
+}
+
 do_install () {
 #
 # Create directories and install device independent scripts
@@ -75,6 +82,8 @@  do_install () {
 	install -d ${D}${sysconfdir}/default/volatiles
 	# Holds state information pertaining to urandom
 	install -d ${D}/var/lib/urandom
+	install -d ${D}${base_bindir}
+	install -d ${D}${mandir}/man1
 
 	install -m 0644    ${WORKDIR}/functions		${D}${sysconfdir}/init.d
 	install -m 0755    ${WORKDIR}/bootmisc.sh	${D}${sysconfdir}/init.d
@@ -98,6 +107,8 @@  do_install () {
 	install -m 0644    ${WORKDIR}/volatiles		${D}${sysconfdir}/default/volatiles/00_core
 	install -m 0755    ${WORKDIR}/dmesg.sh		${D}${sysconfdir}/init.d
 	install -m 0644    ${WORKDIR}/logrotate-dmesg.conf ${D}${sysconfdir}/
+	install -m 0755    ${WORKDIR}/usleep            ${D}${base_bindir}
+	install -m 0644    ${WORKDIR}/usleep.1          ${D}${mandir}/man1
 
 	if [ "${TARGET_ARCH}" = "arm" ]; then
 		install -m 0755 ${WORKDIR}/alignment.sh	${D}${sysconfdir}/init.d