Hi!

----

Attached is a small toy patch
("usr_bin_sleep_uses_libshell_b_sleep_patch001.diff.txt") which switches
/usr/bin/sleep over to use libshell.so's builtin "sleep" version and may
be usefull as blueprint to switch other commands over to use the builtin
versions, too.

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.mainz at nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
-------------- next part --------------
Index: src/cmd/sleep/sleep.c
===================================================================
--- src/cmd/sleep/sleep.c       (revision 263)
+++ src/cmd/sleep/sleep.c       (working copy)
@@ -30,83 +30,14 @@
 **             sleep time
 */
 
-#include       <stdio.h>
-#include       <signal.h>
-#include       <locale.h>
-#include       <unistd.h>
-#include       <limits.h>
-#include       <stdlib.h>
+#include <ast/shell.h>
 
-static void catch_sig(int sig);
+/* From libshell/common/include/builtins.h */
+extern int b_sleep(int, char*[],void*);
 
 int
 main(int argc, char **argv)
 {
-       unsigned long n;
-       unsigned long leftover;
-       int     c;
-       char    *s;
-
-       n = 0;
-       (void) setlocale(LC_ALL, "");
-#if !defined(TEXT_DOMAIN)      /* Should be defined by cc -D */
-#define        TEXT_DOMAIN "SYS_TEST"  /* Use this only if it weren't */
-#endif
-       (void) textdomain(TEXT_DOMAIN);
-       while ((c = getopt(argc, argv, "")) != -1)
-               switch (c) {
-               case '?':
-               (void) fprintf(stderr, gettext("usage: sleep time\n"));
-               (void) exit(2);
-               }
-       argc -= optind-1;
-       argv += optind-1;
-       if (argc < 2) {
-               (void) fprintf(stderr, gettext("usage: sleep time\n"));
-               (void) exit(2);
-       }
-
-       /*
-       * XCU4: utility must terminate with zero exit status upon receiving
-       * SIGALRM signal
-       */
-
-       signal(SIGALRM, catch_sig);
-       s = argv[1];
-       while (c = *s++) {
-               if (c < '0' || c > '9') {
-                       (void) fprintf(stderr,
-                               gettext("sleep: bad character in argument\n"));
-                       (void) exit(2);
-               }
-               n = n*10 + c - '0';
-       }
-
-       /*
-       * to fix - sleep fails silently when on "long sleep" BUG: 1164064.
-       * logic is to repeatedly sleep for unslept remaining time after sleep
-       * of USHRT_MAX seconds, via reset and repeat call to sleep()
-       * library routine until there is none remaining time to sleep.
-       *
-       * The fix for 1164064 introduced bug 1263997 : This is a fix for 
-       * these problems.
-       */
-
-       leftover = 0;
-        while (n != 0) {
-                if (n >= USHRT_MAX) {
-                        leftover = n - USHRT_MAX;
-                        leftover += sleep(USHRT_MAX);
-                }
-                else {
-                        leftover = sleep(n);
-                }
-                n = leftover;
-        }
-       return (0);
+       return b_sleep(argc, argv, sh_init(argc, argv, (Shinit_f)0));
 }
 
-static void
-catch_sig(int sig)
-{
-}
Index: src/cmd/sleep/Makefile
===================================================================
--- src/cmd/sleep/Makefile      (revision 263)
+++ src/cmd/sleep/Makefile      (working copy)
@@ -33,6 +33,13 @@
 
 .KEEP_STATE:
 
+CFLAGS += -I$(ROOT)/usr/include/ast -D_BLD_DLL -D_BLD_ast -D_PACKAGE_ast
+LDLIBS += -lshell -last
+
+# silence common libast&co. warnings (upstream will handle this later) ...
+# ... about |#pragma prototyped| ...
+CERRWARN += -erroff=E_UNRECOGNIZED_PRAGMA_IGNORED
+
 all: $(PROG)
 
 install: all $(ROOTPROG)
Index: src/lib/libshell/spec/shell.spec
===================================================================
--- src/lib/libshell/spec/shell.spec    (revision 263)
+++ src/lib/libshell/spec/shell.spec    (working copy)
@@ -41,8 +41,9 @@
 #      printf "end\n\n" ; 
 #    done
 #
-#  Note: |sh_waitnotify| and |sh_openmax| are two exceptions which
+#  Note 1: |sh_waitnotify| and |sh_openmax| are two exceptions which
 #  require manual editing of the script results. See comments below.
+#  Note 2: |b_sleep| was exported for /usr/bin/sleep
 # )
 
 function       sh_bltin_tree
@@ -286,5 +287,9 @@
 version                SUNWprivate_1.1
 end
 
+function       b_sleep
+declaration    int     b_sleep(int, char*[],void*);
+version                SUNWprivate_1.1
+end
 
 #EOF.

Reply via email to