summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorBjörn Jacke <bj@sernet.de>2010-12-14 13:28:49 +0100
committerBjoern Jacke <bj@sernet.de>2010-12-14 15:31:03 +0100
commit4fd57cbe1ba35d3b3deb01b2eb6aba1d0aa4ddfd (patch)
tree88f46c430195508565c9dc6314e20f17309691dd /source3/utils
parenta55f5e7080587ae7cc3b2e64ef2fbd467cc24842 (diff)
downloadsamba-4fd57cbe1ba35d3b3deb01b2eb6aba1d0aa4ddfd.tar.gz
samba-4fd57cbe1ba35d3b3deb01b2eb6aba1d0aa4ddfd.tar.bz2
samba-4fd57cbe1ba35d3b3deb01b2eb6aba1d0aa4ddfd.zip
s3/net: don't use external "date" to make "net time set" more portable
the "date" syntax is different for example on *BSD Autobuild-User: Björn Jacke <bj@sernet.de> Autobuild-Date: Tue Dec 14 15:31:03 CET 2010 on sn-devel-104
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_time.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c
index d9b6f27551..a02387f6aa 100644
--- a/source3/utils/net_time.c
+++ b/source3/utils/net_time.c
@@ -103,26 +103,22 @@ int net_time_usage(struct net_context *c, int argc, const char **argv)
return -1;
}
-/* try to set the system clock using /bin/date */
+/* try to set the system clock */
static int net_time_set(struct net_context *c, int argc, const char **argv)
{
- time_t t = nettime(c, NULL);
- char *cmd;
+ struct timeval tv;
int result;
- if (t == 0) return -1;
+ tv.tv_sec = nettime(c, NULL);
+ tv.tv_usec=0;
+
+ if (tv.tv_sec == 0) return -1;
+
+ result = settimeofday(&tv,0);
- /* yes, I know this is cheesy. Use "net time system" if you want to
- roll your own. I'm putting this in as it works on a large number
- of systems and the user has a choice in whether its used or not */
- if (asprintf(&cmd, "/bin/date %s", systime(t)) == -1) {
- return -1;
- }
- result = system(cmd);
if (result)
- d_fprintf(stderr, _("%s failed. Error was (%s)\n"),
- cmd, strerror(errno));
- free(cmd);
+ d_fprintf(stderr, _("setting system clock failed. Error was (%s)\n"),
+ strerror(errno));
return result;
}