summaryrefslogtreecommitdiff
path: root/usr/src/lib/libshell/common/bltins/sleep.c
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2019-12-19 12:40:51 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2019-12-19 12:40:51 +0000
commit1b4b6f23c2256de6934b89b05c0a77a44b84f817 (patch)
tree38a41ef900c089f777207f357f041d5814dfd532 /usr/src/lib/libshell/common/bltins/sleep.c
parentdfbd50d8db03bb9bc7350af3a750cd017d66d0c0 (diff)
parent7b2eb3f3c068e560c7357b0f314172448bb8d1e0 (diff)
downloadillumos-joyent-1b4b6f23c2256de6934b89b05c0a77a44b84f817.tar.gz
[illumos-gate merge]
commit 7b2eb3f3c068e560c7357b0f314172448bb8d1e0 12057 Writing part of the string to stderr makes zlogin exit commit d2dd27964b9dfc03118548f9509e4706787c2a69 12088 Cannot build iasl with bison 3.5 [-Werror=char-subscripts] commit bf74bfd433cc5106d2fffc63678efb6ba4a3694c 12090 loader.efi: efi_readkey_ex needs to check the key despite the shift status or toggle status commit 5947648b7f5c085635051e1f7aa083a309542467 12069 Backport sh_delay() and tvsleep() from ksh-2020.0.0 commit fc5c75cf5edb072564020725faa0c4313714f09f 12051 re-enable ZFS trim by default commit 8b35e52344673c75ba6a446ced1fb5c36b52a242 12070 sata SSDs attached to sata ports can't trim commit 2ed5f78a049996104f9dcce38d0c0c1735dd0e7a 12091 loader: biosdisk.c: Use symbolic names for int13 calls commit bf6cb86ec437546144857d9aa94ef222ec6763c0 12082 libpctx: cast between incompatible function types commit c94f4b0313ed735fc39e1b15e1fa48c0e6e3730f 12081 libldap5: cast between incompatible function types commit 3c19a1689122901345a6089d081aa2de4a1096da 12079 audit_plugins: cast between incompatible function types commit adbb29bd77dbfbbf129b5e3bd6ccc5bd4074fd79 12073 loader: devopen dereference after free commit fdf04373777e703cebbbce0f774ae970eb6030f7 12072 loader: vdisk dereference after free
Diffstat (limited to 'usr/src/lib/libshell/common/bltins/sleep.c')
-rw-r--r--usr/src/lib/libshell/common/bltins/sleep.c114
1 files changed, 31 insertions, 83 deletions
diff --git a/usr/src/lib/libshell/common/bltins/sleep.c b/usr/src/lib/libshell/common/bltins/sleep.c
index 6121cfe62b..8938dc536c 100644
--- a/usr/src/lib/libshell/common/bltins/sleep.c
+++ b/usr/src/lib/libshell/common/bltins/sleep.c
@@ -1,22 +1,22 @@
/***********************************************************************
-* *
-* This software is part of the ast package *
-* Copyright (c) 1982-2010 AT&T Intellectual Property *
-* and is licensed under the *
-* Common Public License, Version 1.0 *
-* by AT&T Intellectual Property *
-* *
-* A copy of the License is available at *
-* http://www.opensource.org/licenses/cpl1.0.txt *
-* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
-* *
-* Information and Software Systems Research *
-* AT&T Research *
-* Florham Park NJ *
-* *
-* David Korn <dgk@research.att.com> *
-* *
-***********************************************************************/
+ * *
+ * This software is part of the ast package *
+ * Copyright (c) 1982-2013 AT&T Intellectual Property *
+ * and is licensed under the *
+ * Eclipse Public License, Version 1.0 *
+ * by AT&T Intellectual Property *
+ * *
+ * A copy of the License is available at *
+ * http://www.eclipse.org/org/documents/epl-v10.html *
+ * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+ * *
+ * Information and Software Systems Research *
+ * AT&T Research *
+ * Florham Park NJ *
+ * *
+ * David Korn <dgkorn@gmail.com> *
+ * *
+ ***********************************************************************/
#pragma prototyped
/*
* sleep delay
@@ -156,70 +156,18 @@ unsigned int sleep(unsigned int sec)
return(0);
}
-/*
- * delay execution for time <t>
- */
+//
+// Delay execution for time <t>.
+//
+void sh_delay(double t) {
+ Shell_t *shp = sh_getinterp();
+ int n = (int)t;
+ Tv_t ts, tx;
-void sh_delay(double t)
-{
- register int n = (int)t;
- Shell_t *shp = &sh;
-#ifdef _lib_poll
- struct pollfd fd;
- if(t<=0)
- return;
- else if(n > 30)
- {
- sleep(n);
- t -= n;
- }
- if(n=(int)(1000*t))
- {
- if(!shp->waitevent || (*shp->waitevent)(-1,(long)n,0)==0)
- poll(&fd,0,n);
- }
-#else
-# if defined(_lib_select) && defined(_mem_tv_usec_timeval)
- struct timeval timeloc;
- if(t<=0)
- return;
- if(n=(int)(1000*t) && shp->waitevent && (*shp->waitevent)(-1,(long)n,0))
- return;
- n = (int)t;
- timeloc.tv_sec = n;
- timeloc.tv_usec = 1000000*(t-(double)n);
- select(0,(fd_set*)0,(fd_set*)0,(fd_set*)0,&timeloc);
-# else
-# ifdef _lib_select
- /* for 9th edition machines */
- if(t<=0)
- return;
- if(n > 30)
- {
- sleep(n);
- t -= n;
- }
- if(n=(int)(1000*t))
- {
- if(!shp->waitevent || (*shp->waitevent)(-1,(long)n,0)==0)
- select(0,(fd_set*)0,(fd_set*)0,n);
- }
-# else
- struct tms tt;
- if(t<=0)
- return;
- sleep(n);
- t -= n;
- if(t)
- {
- clock_t begin = times(&tt);
- if(begin==0)
- return;
- t *= shp->lim.clk_tck;
- n += (t+.5);
- while((times(&tt)-begin) < n);
- }
-# endif
-# endif
-#endif /* _lib_poll */
+ ts.tv_sec = n;
+ ts.tv_nsec = 1000000000 * (t - (double)n);
+ while (tvsleep(&ts, &tx) < 0 && errno == EINTR) {
+ if (shp->trapnote & (SH_SIGSET | SH_SIGTRAP)) return;
+ ts = tx;
+ }
}