mirror of
https://github.com/troglobit/finit.git
synced 2026-10-15 10:29:35 +00:00
Switch to using nanosleep in favour of sleep
The remaining sleep time returned by sleep is not accurate enough to be used as a means to achieve "signal safe"-sleep. nanosleep can be used in similar fashion instead and is granular enough for our purposes. This issue was identified during reboot, when Finit is bombarded with SIGCHLD, aborting the sleep that we do to give daemons a chance to shut down gracefully. The total delay ended up being less than a second when in fact two seconds were the intended delay.
This commit is contained in:
1 parent
997a699b7e
commit
920382518f
1 file changed
+6
-1
+6
-1
@@ -28,6 +28,7 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysinfo.h> /* sysinfo() */
|
||||
#include <lite/lite.h> /* strlcat() */
|
||||
@@ -105,7 +106,11 @@ int strtobytes(char *arg)
|
||||
|
||||
void do_sleep(unsigned int sec)
|
||||
{
|
||||
while ((sec = sleep(sec)))
|
||||
struct timespec requested_sleep = {
|
||||
.tv_sec = sec,
|
||||
.tv_nsec = 0,
|
||||
};
|
||||
while (nanosleep(&requested_sleep, &requested_sleep))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user