/** * @file zos-sleep.c * @brief A `sleep` that takes fractions, for the z/OS test runs. * * /bin/sleep on z/OS rejects "0.3" ("Improper sleep interval * specification"), and tests/zash/jobs.sh and tests/scripts/parallel.sh * order background jobs with sub-second sleeps. `make zos-check` builds * this and puts its directory in front of PATH; Linux never builds it, * because its own sleep is already fine. */ #include #include #include int main(int argc, char **argv) { struct timespec ts = {0, 0}; if (argc < 2) return 1; for (int i = 1; i < argc; i++) { char *end = NULL; double seconds = strtod(argv[i], &end); if (end == argv[i] || *end != '\0' || seconds < 0) return 1; long whole = (long)seconds; ts.tv_sec += (time_t)whole; ts.tv_nsec += (long)((seconds - (double)whole) * 1e9); } ts.tv_sec += (time_t)(ts.tv_nsec / 1000000000L); ts.tv_nsec %= 1000000000L; while (nanosleep(&ts, &ts) < 0) { if (errno != EINTR) return 1; } return 0; }