SVN: rc-scripts/trunk: man/usleep.1 src/Makefile.am src/usleep.c
glen
glen at pld-linux.org
Thu Nov 8 01:42:11 CET 2007
Author: glen
Date: Thu Nov 8 01:42:10 2007
New Revision: 9016
Modified:
rc-scripts/trunk/man/usleep.1
rc-scripts/trunk/src/Makefile.am
rc-scripts/trunk/src/usleep.c
Log:
- update with suse variant from killproc-2.12
(and who's oot? http://lists.rpath.com/pipermail/initscripts-commits/2006-December/000573.html)
Modified: rc-scripts/trunk/man/usleep.1
==============================================================================
--- rc-scripts/trunk/man/usleep.1 (original)
+++ rc-scripts/trunk/man/usleep.1 Thu Nov 8 01:42:10 2007
@@ -1,25 +1,50 @@
-.TH USLEEP 1 "Red Hat, Inc" \" -*- nroff -*-
+.\"
+.\" Copyright 2001 Werner Fink, 2001 SuSE GmbH Nuernberg, Germany.
+.\"
+.\" This program is free software; you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation; either version 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.TH USLEEP 1 "Jan 31, 2001" "Version 1.16" "The SuSE boot concept"
+.UC 1
.SH NAME
-usleep \- sleep some number of microseconds
+Usleep \- sleep for the specified number of microseconds
+.\"
.SH SYNOPSIS
-.B usleep
-[\fInumber\fP]
+.\"
+.B usleep [
+.I usec
+.B ]
+.\"
.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.
+pauses for the number of
+.I usec
+microseconds. The default is
+.B 1
+microsecond. If
+.B 0
+microseconds are specified
+.BR sched_yield (2)
+is called.
+.\"
.SH BUGS
-Probably not accurate on many machines down to the microsecond. Count
-on precision only to -4 or maybe -5.
+The
+.B usleep
+program uses the
+.BR usleep (3)
+function and therefore shows the same weaknesses
+by any system activity.
+\."
+.SH SEE ALSO
+.BR usleep (3),
+.BR sleep (1),
+.BR sleep (3),
+.BR sched_yield (2).
+\."
+.SH COPYRIGHT
+2001 Werner Fink,
+2001 SuSE GmbH Nuernberg, Germany.
.SH AUTHOR
-Donald Barnes <djb at redhat.com>
-.br
-Erik Troan <ewt at redhat.com>
+Werner Fink <werner at suse.de>
Modified: rc-scripts/trunk/src/Makefile.am
==============================================================================
--- rc-scripts/trunk/src/Makefile.am (original)
+++ rc-scripts/trunk/src/Makefile.am Thu Nov 8 01:42:10 2007
@@ -49,7 +49,6 @@
usernetctl_SOURCES = usernetctl.c
usleep_SOURCES = usleep.c
-usleep_LDADD = -lpopt
loglevel_SOURCES = loglevel.c
Modified: rc-scripts/trunk/src/usleep.c
==============================================================================
--- rc-scripts/trunk/src/usleep.c (original)
+++ rc-scripts/trunk/src/usleep.c Thu Nov 8 01:42:10 2007
@@ -1,76 +1,71 @@
-/*
- * usleep
- *
- * Written by Donald Barnes <djb at redhat.com> for Red Hat, Inc.
- *
- * Copyright (c) 1997-2003 Red Hat, Inc. All rights reserved.
+/*
+ * usleep.c Sleep for the specified number of microseconds
*
- * This software may be freely redistributed under the terms of the GNU
- * public license.
+ * Usage: usleep [ microseconds ]
*
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Copyright 2001 Werner Fink, 2001 SuSE GmbH Nuernberg, Germany.
+ * Copyright 2005 Werner Fink, 2005 SUSE LINUX Products GmbH, Germany.
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Author: Werner Fink <werner at suse.de>
*/
-
-#include <unistd.h>
-#include <stdlib.h>
+#ifndef __USE_STRING_INLINES
+# define __USE_STRING_INLINES
+#endif
+#ifdef __NO_STRING_INLINES
+# undef __NO_STRING_INLINES
+#endif
+#include <libgen.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;
-}
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef _POSIX_PRIORITY_SCHEDULING
+# include <sched.h>
+#endif
+#define USAGE "Usage:\t%s [ microseconds ]\n", we_are
+
+static char *we_are;
+int main(int argc, char **argv)
+{
+ unsigned long int usec = 1;
+
+ if (argc > 2)
+ goto err;
+
+ if (argc > 1) {
+ char *endptr;
+ usec = strtoul(argv[1], &endptr, 10);
+ if (*endptr != '\0')
+ goto err;
+ }
+
+ if (usec)
+ usleep(usec);
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ else
+ (void)sched_yield();
+#endif
+ _exit(0);
+
+ /* Do this at the end for speed */
+err:
+ we_are = basename(argv[0]);
+ fprintf(stderr, USAGE);
+
+ if (argc > 1 && *(argv[1]) == '-') {
+ argv[1]++;
+ if (!strcmp(argv[1], "-help") || *(argv[1]) == 'h' || *(argv[1]) == '?') {
+ fprintf(stderr, "Sleep for the specified number of microseconds.\n\n");
+ fprintf(stderr, "Help options:\n");
+ fprintf(stderr, " -h, -?, --help display this help and exit.\n");
+ exit (0);
+ }
+ }
+ exit (1);
+}
More information about the pld-cvs-commit
mailing list