Date: Sun, 27 Mar 2016 06:52:40 +0000 (UTC) From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r297304 - stable/10/sys/compat/linux Message-ID: <201603270652.u2R6qegd017949@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dchagin Date: Sun Mar 27 06:52:40 2016 New Revision: 297304 URL: https://svnweb.freebsd.org/changeset/base/297304 Log: MFC r296502, r296543, r296546, r297060: 1. Limit secs to INT32_MAX / 2 to avoid errors from kern_setitimer(). Assert that kern_setitimer() returns 0. Remove bogus cast of secs. Fix style(9) issues. 2. Increment the return value if the remaining tv_usec value more than 500000 as a Linux does. Modified: stable/10/sys/compat/linux/linux_misc.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/compat/linux/linux_misc.c ============================================================================== --- stable/10/sys/compat/linux/linux_misc.c Sun Mar 27 06:43:05 2016 (r297303) +++ stable/10/sys/compat/linux/linux_misc.c Sun Mar 27 06:52:40 2016 (r297304) @@ -198,24 +198,27 @@ linux_alarm(struct thread *td, struct li if (ldebug(alarm)) printf(ARGS(alarm, "%u"), args->secs); #endif - secs = args->secs; + /* + * Linux alarm() is always successfull. Limit secs to INT32_MAX / 2 + * to match kern_setitimer()'s limit to avoid error from it. + * + * XXX. Linux limit secs to INT_MAX on 32 and does not limit on 64-bit + * platforms. + */ + if (secs > INT32_MAX / 2) + secs = INT32_MAX / 2; - if (secs > INT_MAX) - secs = INT_MAX; - - it.it_value.tv_sec = (long) secs; + it.it_value.tv_sec = secs; it.it_value.tv_usec = 0; - it.it_interval.tv_sec = 0; - it.it_interval.tv_usec = 0; + timevalclear(&it.it_interval); error = kern_setitimer(td, ITIMER_REAL, &it, &old_it); - if (error) - return (error); - if (timevalisset(&old_it.it_value)) { - if (old_it.it_value.tv_usec != 0) - old_it.it_value.tv_sec++; - td->td_retval[0] = old_it.it_value.tv_sec; - } + KASSERT(error == 0, ("kern_setitimer returns %d", error)); + + if ((old_it.it_value.tv_sec == 0 && old_it.it_value.tv_usec > 0) || + old_it.it_value.tv_usec >= 500000) + old_it.it_value.tv_sec++; + td->td_retval[0] = old_it.it_value.tv_sec; return (0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603270652.u2R6qegd017949>