The usleep function was missing on older mingw versions, but we can rely
on it existing everywhere these days. It may only support times upto 1
second in duration though, so we'll prefer to use g_usleep instead.
The commandhelper program is not changed since that can't link to glib.
Fortunately it doesn't need to build on Windows platforms either.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
bootstrap.conf | 1 -
src/hyperv/hyperv_driver.c | 2 +-
src/hyperv/hyperv_wmi.c | 4 ++--
src/locking/lock_daemon.c | 2 +-
src/locking/lock_driver_sanlock.c | 2 +-
src/lxc/lxc_controller.c | 2 +-
src/lxc/lxc_driver.c | 2 +-
src/lxc/lxc_process.c | 2 +-
src/network/bridge_driver.c | 2 +-
src/nwfilter/nwfilter_dhcpsnoop.c | 4 ++--
src/nwfilter/nwfilter_learnipaddr.c | 2 +-
src/qemu/qemu_monitor_json.c | 2 +-
src/qemu/qemu_process.c | 2 +-
src/qemu/qemu_tpm.c | 2 +-
src/rpc/virnetsocket.c | 2 +-
src/security/security_manager.c | 2 +-
src/storage/storage_util.c | 4 ++--
src/util/vircgroup.c | 2 +-
src/util/virfile.c | 2 +-
src/util/virnetdev.c | 2 +-
src/util/virnetdevip.c | 2 +-
src/util/virnetdevmacvlan.c | 2 +-
src/util/virnetdevvportprofile.c | 2 +-
src/util/virpci.c | 8 ++++----
src/util/virprocess.c | 4 ++--
src/util/virtime.c | 2 +-
src/vbox/vbox_common.c | 2 +-
tests/commandtest.c | 6 +++---
tests/eventtest.c | 4 ++--
tests/fdstreamtest.c | 4 ++--
tools/virsh-domain.c | 2 +-
31 files changed, 41 insertions(+), 42 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index 241dce50c2..1b5a68b873 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -90,7 +90,6 @@ timegm
ttyname_r
uname
unsetenv
-usleep
verify
vsnprintf
waitpid
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 0e2c6c55ef..ceaf528dd3 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1415,7 +1415,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
/* simulate holdtime by sleeping */
if (holdtime > 0)
- usleep(holdtime * 1000);
+ g_usleep(holdtime * 1000);
/* release the keys */
for (i = 0; i < nkeycodes; i++) {
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 0f39bd4431..c2c1f082e1 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -909,7 +909,7 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr
params,
case MSVM_CONCRETEJOB_JOBSTATE_SHUTTING_DOWN:
hypervFreeObject(priv, (hypervObject *)job);
job = NULL;
- usleep(100 * 1000); /* sleep 100 ms */
+ g_usleep(100 * 1000); /* sleep 100 ms */
timeout -= 100;
continue;
case MSVM_CONCRETEJOB_JOBSTATE_COMPLETED:
@@ -1418,7 +1418,7 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr
domain,
hypervFreeObject(priv, (hypervObject *)concreteJob);
concreteJob = NULL;
- usleep(100 * 1000);
+ g_usleep(100 * 1000);
continue;
case MSVM_CONCRETEJOB_JOBSTATE_COMPLETED:
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index a5a3a97e99..c12cb4ea0f 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -657,7 +657,7 @@ virLockDaemonClientFree(void *opaque)
VIR_WARN("Failed to kill off pid %lld",
(unsigned long long)priv->clientPid);
}
- usleep(200 * 1000);
+ g_usleep(200 * 1000);
}
}
}
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index 85a23c7642..7ebd63913e 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -376,7 +376,7 @@ virLockManagerSanlockSetupLockspace(virLockManagerSanlockDriverPtr
driver)
#else
/* fall back to polling */
VIR_DEBUG("Sleeping for %dms", LOCKSPACE_SLEEP);
- usleep(LOCKSPACE_SLEEP * 1000);
+ g_usleep(LOCKSPACE_SLEEP * 1000);
#endif
VIR_DEBUG("Retrying to add lockspace (left %d)", retries);
goto retry;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 37851bf284..9097655b4d 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -574,7 +574,7 @@ static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
while (!virFileExists(pidpath)) {
/* wait for 100ms before checking again, but don't do it for ever */
if (errno == ENOENT && loops < 10) {
- usleep(100 * 1000);
+ g_usleep(100 * 1000);
loops++;
} else {
virReportSystemError(errno,
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index a69589e50c..c0bbeb09e8 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2965,7 +2965,7 @@ static int lxcFreezeContainer(virDomainObjPtr vm)
* decide that the freezing has been complete only with
* the state actually transit to "FROZEN".
*/
- usleep(check_interval * 1000);
+ g_usleep(check_interval * 1000);
r = virCgroupGetFreezerState(priv->cgroup, &state);
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index cbdc7b1268..318b4c1653 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -1095,7 +1095,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
goto cleanup;
}
- usleep(100*1000);
+ g_usleep(100*1000);
retries--;
}
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index c05157c3ca..d10665efa3 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1034,7 +1034,7 @@ networkKillDaemon(pid_t pid,
* than modifications to domains, this seems a reasonable
* tradeoff in exchange for less code disruption.
*/
- usleep(20 * 1000);
+ g_usleep(20 * 1000);
}
VIR_WARN("Timed out waiting after SIG%s to %s process %d "
"(network '%s')",
diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index 2af8cfdd32..c82457989e 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -1273,7 +1273,7 @@ virNWFilterSnoopRatePenalty(virNWFilterSnoopPcapConfPtr pc,
unsigned long long now;
if (virTimeMillisNowRaw(&now) < 0) {
- usleep(PCAP_FLOOD_TIMEOUT_MS); /* 1 ms */
+ g_usleep(PCAP_FLOOD_TIMEOUT_MS); /* 1 ms */
pc->penaltyTimeoutAbs = 0;
} else {
/* don't listen to the fd for 1 ms */
@@ -2010,7 +2010,7 @@ virNWFilterSnoopJoinThreads(void)
while (virAtomicIntGet(&virNWFilterSnoopState.nThreads) != 0) {
VIR_WARN("Waiting for snooping threads to terminate: %u",
virAtomicIntGet(&virNWFilterSnoopState.nThreads));
- usleep(1000 * 1000);
+ g_usleep(1000 * 1000);
}
}
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index cd66e3ea7d..34b8d7fcd9 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -812,7 +812,7 @@ virNWFilterLearnThreadsTerminate(bool allowNewThreads)
threadsTerminate = true;
while (virHashSize(pendingLearnReq) != 0)
- usleep((PKT_TIMEOUT_MS * 1000) / 3);
+ g_usleep((PKT_TIMEOUT_MS * 1000) / 3);
if (allowNewThreads)
threadsTerminate = false;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index a6facdc09b..dbc32acb5e 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1650,7 +1650,7 @@ qemuMonitorJSONStartCPUs(qemuMonitorPtr mon)
virJSONValueFree(reply);
reply = NULL;
- usleep(250000);
+ g_usleep(250000);
} while (++i <= timeout);
virJSONValueFree(cmd);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3b45b2f641..c6fac01ada 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7611,7 +7611,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
retry:
if ((ret = qemuRemoveCgroup(vm)) < 0) {
if (ret == -EBUSY && (retries++ < 5)) {
- usleep(200*1000);
+ g_usleep(200*1000);
goto retry;
}
VIR_WARN("Failed to remove cgroup for %s",
diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index 1d68803a28..31fdfa995f 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -884,7 +884,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
rc = qemuTPMEmulatorGetPid(cfg->swtpmStateDir, shortName, &pid);
if (rc < 0) {
timeout -= 50;
- usleep(50 * 1000);
+ g_usleep(50 * 1000);
continue;
}
if (rc == 0 && pid == (pid_t)-1)
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index a469907779..bd5fa96751 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -749,7 +749,7 @@ int virNetSocketNewConnectUNIX(const char *path,
daemonLaunched = true;
}
- usleep(10000);
+ g_usleep(10000);
}
localAddr.len = sizeof(localAddr.data);
diff --git a/src/security/security_manager.c b/src/security/security_manager.c
index 7c905f0785..7f187c9068 100644
--- a/src/security/security_manager.c
+++ b/src/security/security_manager.c
@@ -1349,7 +1349,7 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr mgr
ATTRIBUTE_UNUSED,
if (retries && (errno == EACCES || errno == EAGAIN)) {
/* File is locked. Try again. */
retries--;
- usleep(1000);
+ g_usleep(1000);
continue;
} else {
virReportSystemError(errno,
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 6165dd43b2..be084119f4 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1940,7 +1940,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
if (virDirOpenQuiet(&dh, def->target.path) < 0) {
opentries++;
if (loop && errno == ENOENT && opentries < 50) {
- usleep(100 * 1000);
+ g_usleep(100 * 1000);
goto reopen;
}
virReportSystemError(errno,
@@ -1975,7 +1975,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
}
if (!direrr && loop && ++retry < 100) {
- usleep(100 * 1000);
+ g_usleep(100 * 1000);
goto retry;
}
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 4f9d80666d..70d41c4ba5 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2656,7 +2656,7 @@ virCgroupKillPainfully(virCgroupPtr group)
if (ret <= 0)
break;
- usleep(200 * 1000);
+ g_usleep(200 * 1000);
}
VIR_DEBUG("Complete %d", ret);
return ret;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index bb844c64e5..dead335c62 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -4387,7 +4387,7 @@ virFileWaitForExists(const char *path,
if (tries == 0 || errno != ENOENT)
return -1;
- usleep(ms * 1000);
+ g_usleep(ms * 1000);
}
return 0;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 5c0e9723b9..5fef0b79aa 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -2304,7 +2304,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf,
* wait, then upcoming operations on the VF may fail.
*/
while (retries-- > 0 && !virNetDevExists(linkdev))
- usleep(1000);
+ g_usleep(1000);
}
if (pfDevOrig && setMACrc == 0) {
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index e2009fd829..e9d1ce0831 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -465,7 +465,7 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
/* Parse response. */
dad = virNetDevIPParseDadStatus(resp, recvbuflen, addrs, count);
if (dad)
- usleep(1000 * 10);
+ g_usleep(1000 * 10);
}
/* Check timeout. */
if (dad) {
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index e8a9b052b6..efd81c3aa0 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -404,7 +404,7 @@ virNetDevMacVLanTapOpen(const char *ifname,
tapfd[i] = fd;
} else if (retries-- > 0) {
/* may need to wait for udev to be done */
- usleep(20000);
+ g_usleep(20000);
} else {
/* However, if haven't succeeded, quit. */
virReportSystemError(errno,
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index a5ecd783f2..048f891920 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -999,7 +999,7 @@ virNetDevVPortProfileOpCommon(const char *ifname, int ifindex,
break;
}
- usleep(STATUS_POLL_INTERVL_USEC);
+ g_usleep(STATUS_POLL_INTERVL_USEC);
}
if (status == PORT_PROFILE_RESPONSE_INPROGRESS) {
diff --git a/src/util/virpci.c b/src/util/virpci.c
index ee78151e74..9b828b7781 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -833,11 +833,11 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev,
virPCIDeviceWrite16(parent, parentfd, PCI_BRIDGE_CONTROL,
ctl | PCI_BRIDGE_CTL_RESET);
- usleep(200 * 1000); /* sleep 200ms */
+ g_usleep(200 * 1000); /* sleep 200ms */
virPCIDeviceWrite16(parent, parentfd, PCI_BRIDGE_CONTROL, ctl);
- usleep(200 * 1000); /* sleep 200ms */
+ g_usleep(200 * 1000); /* sleep 200ms */
if (virPCIDeviceWrite(dev, cfgfd, 0, config_space, PCI_CONF_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -881,12 +881,12 @@ virPCIDeviceTryPowerManagementReset(virPCIDevicePtr dev, int cfgfd)
virPCIDeviceWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL,
ctl | PCI_PM_CTRL_STATE_D3hot);
- usleep(10 * 1000); /* sleep 10ms */
+ g_usleep(10 * 1000); /* sleep 10ms */
virPCIDeviceWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL,
ctl | PCI_PM_CTRL_STATE_D0);
- usleep(10 * 1000); /* sleep 10ms */
+ g_usleep(10 * 1000); /* sleep 10ms */
if (virPCIDeviceWrite(dev, cfgfd, 0, &config_space[0], PCI_CONF_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 66834d37d3..b1544af730 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -177,7 +177,7 @@ virProcessAbort(pid_t pid)
} else if (ret == 0) {
VIR_DEBUG("trying SIGTERM to child process %d", pid);
kill(pid, SIGTERM);
- usleep(10 * 1000);
+ g_usleep(10 * 1000);
while ((ret = waitpid(pid, &status, WNOHANG)) == -1 &&
errno == EINTR);
if (ret == pid) {
@@ -399,7 +399,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int
extradelay)
goto cleanup; /* process is dead */
}
- usleep(200 * 1000);
+ g_usleep(200 * 1000);
}
virReportSystemError(EBUSY,
diff --git a/src/util/virtime.c b/src/util/virtime.c
index 86993e4e8d..6f978d7c64 100644
--- a/src/util/virtime.c
+++ b/src/util/virtime.c
@@ -448,6 +448,6 @@ virTimeBackOffWait(virTimeBackOffVar *var)
VIR_DEBUG("sleeping for %llu ms", next);
- usleep(next * 1000);
+ g_usleep(next * 1000);
return 1;
}
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d3b8fb625f..748133933c 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7932,7 +7932,7 @@ vboxDomainSendKey(virDomainPtr dom,
/* since VBOX does not support holdtime, simulate it by sleeping and
then sending the release key scancodes */
if (holdtime > 0)
- usleep(holdtime * 1000);
+ g_usleep(holdtime * 1000);
rc = gVBoxAPI.UIKeyboard.PutScancodes(keyboard, nkeycodes, keyUpCodes,
&codesStored);
diff --git a/tests/commandtest.c b/tests/commandtest.c
index 2aaddef3d1..2ec3434f1e 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -262,7 +262,7 @@ static int test4(const void *unused ATTRIBUTE_UNUSED)
goto cleanup;
}
while (kill(pid, 0) != -1)
- usleep(100*1000);
+ g_usleep(100*1000);
ret = checkoutput("test4", NULL);
@@ -751,7 +751,7 @@ static int test18(const void *unused ATTRIBUTE_UNUSED)
}
while (kill(pid, SIGINT) != -1)
- usleep(100*1000);
+ g_usleep(100*1000);
ret = 0;
@@ -1052,7 +1052,7 @@ static int test25(const void *unused ATTRIBUTE_UNUSED)
goto cleanup;
}
- usleep(10 * 1000);
+ g_usleep(10 * 1000);
} else {
break;
}
diff --git a/tests/eventtest.c b/tests/eventtest.c
index f426469d21..f04b416ad2 100644
--- a/tests/eventtest.c
+++ b/tests/eventtest.c
@@ -382,7 +382,7 @@ mymain(void)
startJob();
pthread_mutex_unlock(&eventThreadMutex);
sched_yield();
- usleep(100 * 1000);
+ g_usleep(100 * 1000);
pthread_mutex_lock(&eventThreadMutex);
virEventPollRemoveHandle(handles[1].watch);
if (finishJob("Interrupted during poll", -1, -1) != EXIT_SUCCESS)
@@ -448,7 +448,7 @@ mymain(void)
startJob();
pthread_mutex_unlock(&eventThreadMutex);
sched_yield();
- usleep(100 * 1000);
+ g_usleep(100 * 1000);
pthread_mutex_lock(&eventThreadMutex);
virEventPollRemoveTimeout(timers[1].timer);
if (finishJob("Interrupted during poll", -1, -1) != EXIT_SUCCESS)
diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c
index 054c405cec..98519e6266 100644
--- a/tests/fdstreamtest.c
+++ b/tests/fdstreamtest.c
@@ -101,7 +101,7 @@ static int testFDStreamReadCommon(const char *scratchdir, bool
blocking)
got = st->driver->streamRecv(st, buf + offset, want);
if (got < 0) {
if (got == -2 && !blocking) {
- usleep(20 * 1000);
+ g_usleep(20 * 1000);
goto reread;
}
virFilePrintf(stderr, "Failed to read stream: %s\n",
@@ -222,7 +222,7 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool
blocking)
got = st->driver->streamSend(st, pattern + offset, want);
if (got < 0) {
if (got == -2 && !blocking) {
- usleep(20 * 1000);
+ g_usleep(20 * 1000);
goto rewrite;
}
if (i == 9 &&
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index fbfdc09c0d..c2e7c2b227 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1945,7 +1945,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
break;
}
- usleep(500 * 1000);
+ g_usleep(500 * 1000);
}
/* print 100% completed */
--
2.21.0