From owner-svn-src-stable-10@FreeBSD.ORG Tue Jan 28 13:29:55 2014 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 15CE39A1; Tue, 28 Jan 2014 13:29:55 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 012B11D74; Tue, 28 Jan 2014 13:29:55 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s0SDTs5p086099; Tue, 28 Jan 2014 13:29:54 GMT (envelope-from ache@svn.freebsd.org) Received: (from ache@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s0SDTsbw086098; Tue, 28 Jan 2014 13:29:54 GMT (envelope-from ache@svn.freebsd.org) Message-Id: <201401281329.s0SDTsbw086098@svn.freebsd.org> From: "Andrey A. Chernov" Date: Tue, 28 Jan 2014 13:29:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r261231 - stable/10/usr.sbin/cron/cron X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jan 2014 13:29:55 -0000 Author: ache Date: Tue Jan 28 13:29:54 2014 New Revision: 261231 URL: http://svnweb.freebsd.org/changeset/base/261231 Log: MFC: r261146 Bad timespec_subtract() calculations produce negative tv_nsec on i386 which cause EINVAL returned from nanosleep() which cause loop in cron_sleep() and making all cron jobs to start about 30 seconds earlier (which cause f.e. logfiles rotation by newsyslog delayed by 1 hour). Use simple and proved calculations from kernel's timespecsub() instead. Modified: stable/10/usr.sbin/cron/cron/cron.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/cron/cron/cron.c ============================================================================== --- stable/10/usr.sbin/cron/cron/cron.c Tue Jan 28 12:48:17 2014 (r261230) +++ stable/10/usr.sbin/cron/cron/cron.c Tue Jan 28 13:29:54 2014 (r261231) @@ -376,30 +376,17 @@ cron_sync(int secres) { } } -static int +static void timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y) { - time_t nsec; - - /* Perform the carry for the later subtraction by updating y. */ - if (x->tv_nsec < y->tv_nsec) { - nsec = (y->tv_nsec - x->tv_nsec) / 10000000 + 1; - y->tv_nsec -= 1000000000 * nsec; - y->tv_sec += nsec; - } - if (x->tv_nsec - y->tv_nsec > 1000000000) { - nsec = (x->tv_nsec - y->tv_nsec) / 1000000000; - y->tv_nsec += 1000000000 * nsec; - y->tv_sec -= nsec; - } - - /* tv_nsec is certainly positive. */ - result->tv_sec = x->tv_sec - y->tv_sec; - result->tv_nsec = x->tv_nsec - y->tv_nsec; - - /* Return True if result is negative. */ - return (x->tv_sec < y->tv_sec); + *result = *x; + result->tv_sec -= y->tv_sec; + result->tv_nsec -= y->tv_nsec; + if (result->tv_nsec < 0) { + result->tv_sec--; + result->tv_nsec += 1000000000; + } } static void