From 4006390a7dfd26ae0f1bac1a35bf0ed0919202e7 Mon Sep 17 00:00:00 2001 From: "Mirar (Pontus Hagland)" <pike@sort.mirar.org> Date: Fri, 29 Sep 2000 14:47:45 +0200 Subject: [PATCH] system.sleep(int) added as wrapper to sleep(3) Rev: src/modules/system/system.c:1.92 Rev: tutorial/tutorial.wmml:1.209 --- src/modules/system/system.c | 24 +++++++++++++++++++++--- tutorial/tutorial.wmml | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/modules/system/system.c b/src/modules/system/system.c index c6418e1e29..c122042983 100644 --- a/src/modules/system/system.c +++ b/src/modules/system/system.c @@ -1,5 +1,5 @@ /* - * $Id: system.c,v 1.91 2000/09/17 19:13:54 grubba Exp $ + * $Id: system.c,v 1.92 2000/09/29 12:47:45 mirar Exp $ * * System-call module for Pike * @@ -15,7 +15,7 @@ #include "system_machine.h" #include "system.h" -RCSID("$Id: system.c,v 1.91 2000/09/17 19:13:54 grubba Exp $"); +RCSID("$Id: system.c,v 1.92 2000/09/29 12:47:45 mirar Exp $"); #ifdef HAVE_WINSOCK_H #include <winsock.h> #endif @@ -1398,7 +1398,6 @@ void f_gethostbyname(INT32 args) } #endif /* HAVE_GETHOSTBYNAME */ - #ifdef GETHOSTBYNAME_MUTEX_EXISTS static void cleanup_after_fork(struct callback *cb, void *arg0, void *arg1) { @@ -1408,6 +1407,23 @@ static void cleanup_after_fork(struct callback *cb, void *arg0, void *arg1) extern void init_passwd(void); + +#ifdef HAVE_SLEEP +/* int sleep(int seconds) */ + +static void f_system_sleep(INT32 args) +{ + INT_TYPE seconds; + get_all_args("setegid", args, "%i", &seconds); + if (seconds<0) seconds=0; /* sleep takes unsinged */ + pop_n_elems(args); + THREADS_ALLOW(); + seconds=(INT_TYPE)sleep( (unsigned int)seconds ); + THREADS_DISALLOW(); + push_int(seconds); +} +#endif /* HAVE_SLEEP */ + /* * Module linkage */ @@ -1648,6 +1664,8 @@ void pike_module_init(void) ADD_FUNCTION("closelog", f_closelog,tFunc(tNone,tVoid), 0); #endif /* HAVE_SYSLOG */ + ADD_FUNCTION("sleep",f_system_sleep,tFunc(tInt,tInt), 0); + init_passwd(); #ifdef GETHOSTBYNAME_MUTEX_EXISTS diff --git a/tutorial/tutorial.wmml b/tutorial/tutorial.wmml index 11b018f54d..8868c56479 100644 --- a/tutorial/tutorial.wmml +++ b/tutorial/tutorial.wmml @@ -6718,6 +6718,26 @@ the fchroot(2) system call. </function> +<function name=sleep title="call the system sleep(3)"> +<man_syntax> +int sleep(int seconds); +</man_syntax> +<man_description> +Calls the system sleep. This is not to be confused with the efun <link +to=sleep>sleep</link>(int|float) that does more elaborate things and +can sleep with better precision (although dependant on a normal +functioning system clock). +</man_description> +<man_note> +The system's sleep function often utilizes the alarm() call and might +not be perfectly thread safe in combination with simultaneous +sleep()'s or alarm()'s. It might also be interrupted by other signals. + +<p>If you don't need it to be independant of the system clock, use the +<link to=sleep>sleep</link>() efun instead. +</man_note> +</function> + <function name=getegid title="get the effective group ID" fullpath> <man_syntax> -- GitLab