scst: Use nanosleep for userspace polling delays

Retain the 50 ms and 100 ms polling intervals and the existing
signal-interruption behavior while replacing the obsolete usleep
interface.

Cppcheck reports usleepCalled:

  Obsolescent function 'usleep' called. It is recommended to use
  'nanosleep' or 'setitimer' instead.
This commit is contained in:
Gleb Chesnokov
2026-10-21 22:12:25 +03:00
parent 70b0a59c82
commit c43ebb355b
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -28,6 +28,7 @@
#include <netdb.h>
#include <ifaddrs.h>
#include <unistd.h>
#include <time.h>
#include "iscsid.h"
@@ -376,7 +377,7 @@ int target_del(u32 tid, u32 cookie)
/* We have not yet received session(s) removal event(s), so keep waiting */
log_debug(1, "Target %d has sessions, keep waiting", tid);
usleep(50000);
nanosleep(&(const struct timespec){ .tv_nsec = 50000000 }, NULL);
}
/*
+2 -1
View File
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <time.h>
#include <syslog.h>
#include <signal.h>
#include <syslog.h>
@@ -196,7 +197,7 @@ static int wait_until_finished(pid_t pid, unsigned long deadline, int *status, i
}
break;
}
usleep(100*1000);
nanosleep(&(const struct timespec){ .tv_nsec = 100000000 }, NULL);
time(&end);
elapsed = difftime(end, start);
} while (elapsed < deadline);