Bug 8105 - source3/utils/net_time.c uses settimeofday...
Summary: source3/utils/net_time.c uses settimeofday...
Status: RESOLVED WORKSFORME
Alias: None
Product: Samba 3.6
Classification: Unclassified
Component: Build environment (show other bugs)
Version: 3.6.8
Hardware: IA64 Other
: P5 normal
Target Milestone: ---
Assignee: Björn Jacke
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-24 16:51 UTC by Joachim Schmitz (mail address dead)
Modified: 2012-09-18 15:08 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Schmitz (mail address dead) 2011-04-24 16:51:42 UTC
without checking via configugre and pre-processer (HAVE_SETTIMEOFDAY) whether this does exist in the given platform.
Comment 1 Björn Jacke 2011-04-26 08:08:57 UTC
On 2011-04-24 at 18:51 +0200 samba-bugs@samba.org sent off:
> https://bugzilla.samba.org/show_bug.cgi?id=8105
> 
>            Summary: source3/utils/net_time.c uses settimeofday...
>            Product: Samba 3.6
>            Version: 3.6.0pre2
>           Platform: IA64
>         OS/Version: Other
>             Status: NEW
>           Severity: normal
>           Priority: P5
>          Component: Build environment
>         AssignedTo: bj@sernet.de
>         ReportedBy: schmitz@hp.com
>          QAContact: samba-qa@samba.org
> 
> 
> without checking via configugre and pre-processer (HAVE_SETTIMEOFDAY) whether
> this does exist in the given platform.

just out of interest - which systems do you have which do not have
settimeofday() ?
Comment 2 Joachim Schmitz (mail address dead) 2011-04-26 08:21:42 UTC
HP NonStop doesn't have settimeofday()
Comment 3 Björn Jacke 2011-04-26 08:34:56 UTC
> HP NonStop doesn't have settimeofday()

but gettimeofday() exists ? How about clock_settime() ?
Comment 4 Joachim Schmitz (mail address dead) 2011-04-26 08:39:14 UTC
gettimeofday() does exist, clock_settime() does not.
Comment 5 Björn Jacke 2011-04-26 08:55:35 UTC
> --- Comment #4 from Joachim Schmitz <schmitz@hp.com> 2011-04-26 08:39:14 UTC ---
> gettimeofday() does exist, clock_settime() does not.

interesting ... can you find out which function is being used to set the
system clock on that OS ?
Comment 6 Joachim Schmitz (mail address dead) 2011-04-26 09:19:17 UTC
I'm affraid only a prorietary one, nothing that would be portable in any form or shape. We have a SETSYSTEMCLOCK(), see http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c02734252/c02734252.pdf

For now my 'fix' is this:
diff -u ./source3/utils/net_time.c.orig ./source3/utils/net_time.c
--- ./source3/utils/net_time.c.orig     2011-04-12 09:03:35.000000000 -0500
+++ ./source3/utils/net_time.c  2011-04-24 10:10:28.000000000 -0500
@@ -115,7 +115,12 @@

        if (tv.tv_sec == 0) return -1;

+#ifdef HAVE_SETTIMEOFDAY /* ToDo: Needs a proper check in configure! */
        result = settimeofday(&tv,NULL);
+#else
+       result = -1;
+       errno = ENOSYS;
+#endif

        if (result)
                d_fprintf(stderr, _("setting system clock failed.  Error was (%s)\n"),


Without the corresponding check in configure...
Comment 7 Björn Jacke 2011-04-26 09:38:47 UTC
> I'm affraid only a prorietary one, nothing that would be portable in any form
> or shape. We have a SETSYSTEMCLOCK(), see
> http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c02734252/c02734252.pdf

could you add a libreplace wrapper which implements settimeofday() using
setsystemclock()? You may have a look at the clock_gettime() replacement hooks
in lib/replace/ to see where you need to start.
Comment 8 Joachim Schmitz (mail address dead) 2011-05-13 13:14:20 UTC
(In reply to comment #7)
> > I'm affraid only a prorietary one, nothing that would be portable in any form
> > or shape. We have a SETSYSTEMCLOCK(), see
> > http://bizsupport2.austin.hp.com/bc/docs/support/SupportManual/c02734252/c02734252.pdf
> could you add a libreplace wrapper which implements settimeofday() using
> setsystemclock()? You may have a look at the clock_gettime() replacement hooks
> in lib/replace/ to see where you need to start.

I've now created the following (as I said earlier: most probably nobody outsite HP NonStop would be able to use it):

#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
#include <cextdecs.h(SETSYSTEMCLOCK,COMPUTETIMESTAMP)>
#include <tal.h>

int
settimeofday(const struct timeval* tv, const struct timezone *tz)
{
        long long julian_gmt;
        short date_n_time[8] = { 1970, 1, 1, 0, 0, 0, 0, 0}; /* the 'Epoch' */

        if (tz != NULL || tv == NULL) {
                errno = EINVAL; /* invalid argument */
                return -1;
        }

        /* usecs since the 'Epoch' */
        julian_gmt  = (tv->tv_sec * 1000000LL) + tv->tv_usec;
        /* correction to match Guardian timestamps */
        julian_gmt += COMPUTETIMESTAMP(date_n_time);

        if (_status_lt(SETSYSTEMCLOCK(julian_gmt, 7))) { /* set absolute GMT */
                errno = EPERM; /* insufficient privilege */
                return -1;
        }
        return 0;
}


As far as I'm concerned this problem is fixed, for me at least.
However: there may well be other plattforms that don't have a settimeofday() ...

bye, Jojo
Comment 9 Joachim Schmitz (mail address dead) 2012-09-18 15:08:09 UTC
There hasn#t happaned anything on this ffor more than a year, and as it works for me, I'll close this issue