[PATCH] Use tiny, fast and thread-safe ntplib module instead of ntpdate

Vratislav Podzimek vpodzime at redhat.com
Tue Jul 30 08:35:46 UTC 2013


On Mon, 2013-07-29 at 11:57 -0700, Brian C. Lane wrote:
> On Fri, Jul 26, 2013 at 01:41:04PM +0200, Vratislav Podzimek wrote:
> > ntpdate is quite a big and slow binary that is not further developed and
> > basically nobody but us uses it. ntplib is a tiny, fast and thread-safe module
> > provided by the python-ntplib package containing only the tiny module.
> 
> Nice find!
> 
> > +    settimeofday(&tv, NULL);
> 
> Should we be checking the rc and raising an error if it fails?
Good point, I've added the check and also modified the function a bit to
get rid of the temporary 'int secs' variable. It could cause problems
because 'time_t' may be bigger than 'int'. For the same reason I've
changed the format string for ParseTuple to "L" (long long). This is how
the function looks now:

static PyObject * doSetSystemTime(PyObject *s, PyObject  *args) {
    struct timeval tv;
    tv.tv_usec = 0;

    if (!PyArg_ParseTuple(args, "L", &(tv.tv_sec)))
        return NULL;

    if (settimeofday(&tv, NULL) != 0)
        PyErr_SetFromErrno(PyExc_SystemError);

    Py_INCREF(Py_None);
    return Py_None;
}

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list