samba-bugs at samba.org
2020-Mar-27 15:47 UTC
[Bug 14328] New: usleep() is obsolete, use nanosleep()
https://bugzilla.samba.org/show_bug.cgi?id=14328 Bug ID: 14328 Summary: usleep() is obsolete, use nanosleep() Product: rsync Version: 3.1.3 Hardware: All OS: All Status: NEW Severity: normal Priority: P5 Component: core Assignee: wayne at opencoder.net Reporter: devzero at web.de QA Contact: rsync-qa at samba.org by chance i came across https://polyverse.com/weakness-report/centos/7/obsolete/cwe-676/379/ and indeed http://man7.org/linux/man-pages/man3/usleep.3.html is telling: 4.3BSD, POSIX.1-2001. POSIX.1-2001 declares this function obsolete; use nanosleep(2) instead. POSIX.1-2008 removes the specification of usleep(). recent rsync 3.1.3 is still using usleep: # grep -r usleep * config.h.in:/* Define to 1 if you have the `usleep' function. */ configure.ac: initgroups utimensat posix_fallocate attropen setvbuf usleep) configure.sh: initgroups utimensat posix_fallocate attropen setvbuf usleep OLDNEWS: - Use usleep() for our msleep() function if it is available. util2.c: usleep(t*1000); for my curiosity, that went into rsync @2014, which is not too long ago: https://git.samba.org/rsync.git/?p=rsync.git;a=commit;h=5546dab32970955e77ef7a5886bcd8fb765a25bf http://man7.org/linux/man-pages/man2/nanosleep.2.html is telling: Compared to sleep(3) and usleep(3), nanosleep() has the following advantages: it provides a higher resolution for specifying the sleep interval; POSIX.1 explicitly specifies that it does not interact with signals; and it makes the task of resuming a sleep that has been interrupted by a signal handler easier. also mind this one, as usleep return value is NOT being checked at the moment : http://www.programmersought.com/article/5824721961/ 2, pay attention Be sure to pay attention to the return value when using these functions. Sometimes the sleep function is interrupted by the system, and the result is not as expected. while (nanosleep(&ts, &ts) == -1 && errno == EINTR) {} so - usleep is being used to define msleep() and that being used several times in rsync source i'm not sure if this could be a source of bugs, but i remember there are some "rsync sits around doing nothing after larger transfers" and perhaps there is a relation to this.... # grep -r msleep * cleanup.c: msleep(100); clientserver.c: msleep(400); io.c: msleep(20); main.c: msleep(20); main.c: msleep(20); OLDNEWS: - Use usleep() for our msleep() function if it is available. OLDNEWS: - Fix an issue in the msleep() function if time jumps backwards. options.c: msleep(20); proto.h:int msleep(int t); rsync.c: msleep(400); util2.c:int msleep(int t) -- You are receiving this mail because: You are the QA Contact for the bug.
samba-bugs at samba.org
2020-Apr-05 17:07 UTC
[Bug 14328] usleep() is obsolete, use nanosleep()
https://bugzilla.samba.org/show_bug.cgi?id=14328 Wayne Davison <wayne at opencoder.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #1 from Wayne Davison <wayne at opencoder.net> --- Thanks for the suggestion. I've made nanosleep() the preferred means of implementing msleep(). -- You are receiving this mail because: You are the QA Contact for the bug.
Apparently Analagous Threads
- [PATCH] Use nanosleep instead of usleep when waiting the hardware.
- patch: Replace many usleep and some sleep calls with nanosleep
- supporting --fake-super on opensolaris (zfs) destination
- [PATCH] Solais has nanosleep, too.
- Build errors on AIX 4.2.1: nanosleep