build: remove use of usleep gnulib module in favour of g_usleep

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.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-10-02 18:01:11 +01:00
parent c4d18e8b3e
commit 27cb4c1a53
31 changed files with 41 additions and 42 deletions

View File

@ -90,7 +90,6 @@ timegm
ttyname_r
uname
unsetenv
usleep
verify
vsnprintf
waitpid

View File

@ -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++) {

View File

@ -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:

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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,

View File

@ -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);

View File

@ -1095,7 +1095,7 @@ virLXCProcessReadLogOutputData(virDomainObjPtr vm,
goto cleanup;
}
usleep(100*1000);
g_usleep(100*1000);
retries--;
}

View File

@ -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')",

View File

@ -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);
}
}

View File

@ -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;

View File

@ -1650,7 +1650,7 @@ qemuMonitorJSONStartCPUs(qemuMonitorPtr mon)
virJSONValueFree(reply);
reply = NULL;
usleep(250000);
g_usleep(250000);
} while (++i <= timeout);
virJSONValueFree(cmd);

View File

@ -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",

View File

@ -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)

View File

@ -749,7 +749,7 @@ int virNetSocketNewConnectUNIX(const char *path,
daemonLaunched = true;
}
usleep(10000);
g_usleep(10000);
}
localAddr.len = sizeof(localAddr.data);

View File

@ -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,

View File

@ -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;
}

View File

@ -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;

View File

@ -4387,7 +4387,7 @@ virFileWaitForExists(const char *path,
if (tries == 0 || errno != ENOENT)
return -1;
usleep(ms * 1000);
g_usleep(ms * 1000);
}
return 0;

View File

@ -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) {

View File

@ -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) {

View File

@ -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,

View File

@ -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) {

View File

@ -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,

View File

@ -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,

View File

@ -448,6 +448,6 @@ virTimeBackOffWait(virTimeBackOffVar *var)
VIR_DEBUG("sleeping for %llu ms", next);
usleep(next * 1000);
g_usleep(next * 1000);
return 1;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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)

View File

@ -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 &&

View File

@ -1945,7 +1945,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
break;
}
usleep(500 * 1000);
g_usleep(500 * 1000);
}
/* print 100% completed */