[source] rdate-1.2

bridged with qdn.public.qnxrtp.porting
Post Reply
Guest

[source] rdate-1.2

Post by Guest » Thu Jun 19, 2003 5:04 pm

This update will also update the RTC when resetting the date.

"make package" will create an installable *.qpr .

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2003-06-20 01:29 JST by <kabe#sra-tohoku.co.jp>.
# Source directory was `/autofs/home/kabe'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1661 -rw-rw-r-- rdate-1.2/COPYING
# 728 -rw-rw-r-- rdate-1.2/Makefile
# 2316 -rw-rw-r-- rdate-1.2/README
# 2522 -rw-rw-r-- rdate-1.2/adjtime.c
# 2564 -rw-rw-r-- rdate-1.2/rdate.8
# 6222 -rw-rw-r-- rdate-1.2/rdate.c
# 3995 -rw-rw-r-- rdate-1.2/rdate.qpg
#
echo=echo
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh04098; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= rdate-1.2/COPYING ==============
if test ! -d 'rdate-1.2'; then
$echo 'x -' 'creating directory' 'rdate-1.2'
mkdir 'rdate-1.2'
fi
if test -f 'rdate-1.2/COPYING' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'rdate-1.2/COPYING' '(file already exists)'
else
$echo 'x -' extracting 'rdate-1.2/COPYING' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'rdate-1.2/COPYING' &&
/*
X * Copyright (c) 1994 Christos Zoulas
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X * notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X * notice, this list of conditions and the following disclaimer in the
X * documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X * must display the following acknowledgement:
X * This product includes software developed by Christos Zoulas.
X * 4. The name of the author may not be used to endorse or promote products
X * derived from this software without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X */
SHAR_EOF
(set 20 03 03 14 00 32 15 'rdate-1.2/COPYING'; eval "$shar_touch") &&
chmod 0664 'rdate-1.2/COPYING' ||
$echo 'restore of' 'rdate-1.2/COPYING' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'rdate-1.2/COPYING:' 'MD5 check failed'
47202fddd430ddb4f93d4f0bde8f216a rdate-1.2/COPYING
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rdate-1.2/COPYING'`"
test 1661 -eq "$shar_count" ||
$echo 'rdate-1.2/COPYING:' 'original size' '1661,' 'current size' "$shar_count!"
fi
fi
# ============= rdate-1.2/Makefile ==============
if test -f 'rdate-1.2/Makefile' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'rdate-1.2/Makefile' '(file already exists)'
else
$echo 'x -' extracting 'rdate-1.2/Makefile' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'rdate-1.2/Makefile' &&
# $Id: Makefile,v 1.13 2003/06/19 15:21:58 kabe Exp $
X
PROG= rdate
X
MAN= rdate.8
X
LDLIBS=-lsocket
CCLINK=$(CC)
X
OBJS = rdate.o adjtime.o
X
$(PROG): $(OBJS)
X $(CCLINK) -o $@ $(OBJS) $(LDLIBS)
X
clean::
X $(RM) $(PROG)
X $(RM) *.o a.out core *~ #~
X $(RM) $(PROG).use
X $(RM) history.qrs
X
X
BINDIR=/opt/sbin
MANDIR=/opt/man
install: $(PROG)
X mkdir -p $(DESTDIR)$(BINDIR)
X cp -p $(PROG) $(DESTDIR)$(BINDIR)
X MAN8=`expr $(MAN) : '.*\.\([^.]*\)$$'`; \
X mkdir -p $(DESTDIR)$(MANDIR)/man$$MAN8; \
X cp -p $(MAN) $(DESTDIR)$(MANDIR)/man$$MAN8
X
### QNX package thingies
package: $(PROG).qpg
X $(MAKE) CFLAGS="-O2 -Wall"
X $(MAKE) install DESTDIR=./DIST
X packager -u $(PROG).qpg
X
clean::
X $(RM) -r ./DIST
distclean:: clean
X $(RM) *.qpr *.qpm *.qpk
SHAR_EOF
(set 20 03 06 20 00 21 58 'rdate-1.2/Makefile'; eval "$shar_touch") &&
chmod 0664 'rdate-1.2/Makefile' ||
$echo 'restore of' 'rdate-1.2/Makefile' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'rdate-1.2/Makefile:' 'MD5 check failed'
a101a3f7597051bb732300236e182457 rdate-1.2/Makefile
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rdate-1.2/Makefile'`"
test 728 -eq "$shar_count" ||
$echo 'rdate-1.2/Makefile:' 'original size' '728,' 'current size' "$shar_count!"
fi
fi
# ============= rdate-1.2/README ==============
if test -f 'rdate-1.2/README' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'rdate-1.2/README' '(file already exists)'
else
$echo 'x -' extracting 'rdate-1.2/README' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'rdate-1.2/README' &&
README for QNXRTP ported rdate
X
X This is an QNXRTP/Momentics port of the rdate utility,
X which is derived from NetBSD rdate.
X
CHANGES from original
X * Neutrino lacks adjtime() system call, so a custom implementation
X wrapping ClockAdjust() NTO call is provided.
X You could plop in the adjtime.c for other programs
X demanding adjtime().
X * Also sets RTC to the retrieved date.
X
INSTALL:
X make
X make install DESTDIR=/usr
X
PACKAGING:
X make package
X
X Touching rdate.qpg (package generator file) may be needed if you
X changed something.
X
X
CREDITS:
X Chistos Zoulas: Original NetBSD rdate implementation
X kabe@sra-tohoku.co.jp: adjtime.c, QNX packaging
X
/*
X * Copyright (c) 1994 Christos Zoulas
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X * notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X * notice, this list of conditions and the following disclaimer in the
X * documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X * must display the following acknowledgement:
X * This product includes software developed by Christos Zoulas.
X * 4. The name of the author may not be used to endorse or promote products
X * derived from this software without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X */
SHAR_EOF
(set 20 03 06 20 01 10 46 'rdate-1.2/README'; eval "$shar_touch") &&
chmod 0664 'rdate-1.2/README' ||
$echo 'restore of' 'rdate-1.2/README' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'rdate-1.2/README:' 'MD5 check failed'
e807e883d95bfa4ec6454ee97c9fd573 rdate-1.2/README
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rdate-1.2/README'`"
test 2316 -eq "$shar_count" ||
$echo 'rdate-1.2/README:' 'original size' '2316,' 'current size' "$shar_count!"
fi
fi
# ============= rdate-1.2/adjtime.c ==============
if test -f 'rdate-1.2/adjtime.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'rdate-1.2/adjtime.c' '(file already exists)'
else
$echo 'x -' extracting 'rdate-1.2/adjtime.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'rdate-1.2/adjtime.c' &&
/*
X * adjtime() for QNXNTO
X *
X */
static const char * const _rcsid="$Id: adjtime.c,v 1.12 2002/09/02 01:10:25 kabe Exp $";
X
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdint.h>
X
#if __QNXNTO__
#include <sys/neutrino.h>
#define UNSIGNED_TV_SEC
#endif
X
#if defined(__QNXNTO__) && !defined(HAVE_ADJTIME)
int
adjtime(struct timeval *delta, struct timeval * const olddelta)
{
X int retval = 0;
X struct _clockadjust newadjust;
X struct _clockadjust oldadjust;
X
#ifdef DEBUG
X /* in RTP, time_t (uint32) tv_sec, suseconds_t (int32) tv_usec */
X if (delta) fprintf(stderr,"adjtime: %ld:%ld\n", (long)delta->tv_sec, (long)delta->tv_usec);
#endif
X
X if (delta) {
X int64_t nto_delta; /* nanosecs */
X struct _clockperiod nto_period;
X long tickadj; /*nanosec*/
X
X /* XXX typeof(tv.tv_sec)==time_t COULD BE UNSIGNED! */
X nto_delta =
#ifdef UNSIGNED_TV_SEC
X (int64_t)(signed long)delta->tv_sec * 1000000000LL +
#else
X (int64_t)delta->tv_sec * 1000000000LL +
#endif
X (int64_t)delta->tv_usec * 1000LL;
X
#ifdef DEBUG
X fprintf(stderr,"adjtime: delta=%lldns\n", nto_delta);
#endif
X
X /* get current tick length */
X ClockPeriod(CLOCK_REALTIME, NULL, &nto_period, 0);
X
X /* 10% deviation from standard tick */
X tickadj = nto_period.nsec * 10/*percent*/ / 100;
X if (tickadj==0) tickadj=1;
X if (-tickadj < nto_delta && nto_delta < tickadj) {
X /* lesser than 10% (including zero);
X direct bump by one tick */
X tickadj = nto_delta;
X newadjust.tick_nsec_inc = tickadj;
X newadjust.tick_count = 1;
X } else {
X if (nto_delta<0) tickadj = -tickadj;
X newadjust.tick_nsec_inc = tickadj;
X newadjust.tick_count = nto_delta / tickadj; /* possible roundoff error */
X }
#ifdef DEBUG
X fprintf(stderr, "adjtime: Slewing %ld nsec * %lu ticks (range %ld seconds)\n",
X newadjust.tick_nsec_inc, newadjust.tick_count,
X (long)((uint64_t)newadjust.tick_count*nto_period.nsec/1000000000L));
#endif
X retval = ClockAdjust(CLOCK_REALTIME, &newadjust, &oldadjust);
X }
X
X if (olddelta) {
X int64_t d;
X if (!delta)
X retval = ClockAdjust(CLOCK_REALTIME, NULL, &oldadjust);
X /* XXX overflow warning */
X /* but could not if previous adjtime fitted in nto_delta */
X d = (int64_t)oldadjust.tick_nsec_inc * oldadjust.tick_count;
X d /= 1000; /* nanosec to usec */
X olddelta->tv_sec = d / 1000000; /* usec to sec */
X /* beware for negative d;
X * should -1us be {0,-1} or {-1, 999999}? */
X d -= olddelta->tv_sec * 1000000;
X olddelta->tv_usec = d;
X }
X
X return retval;
}
#endif /* __QNXNTO__ */
SHAR_EOF
(set 20 02 09 02 10 10 25 'rdate-1.2/adjtime.c'; eval "$shar_touch") &&
chmod 0664 'rdate-1.2/adjtime.c' ||
$echo 'restore of' 'rdate-1.2/adjtime.c' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'rdate-1.2/adjtime.c:' 'MD5 check failed'
72f392a4616179ebc9fa52894965ce17 rdate-1.2/adjtime.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rdate-1.2/adjtime.c'`"
test 2522 -eq "$shar_count" ||
$echo 'rdate-1.2/adjtime.c:' 'original size' '2522,' 'current size' "$shar_count!"
fi
fi
# ============= rdate-1.2/rdate.8 ==============
if test -f 'rdate-1.2/rdate.8' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'rdate-1.2/rdate.8' '(file already exists)'
else
$echo 'x -' extracting 'rdate-1.2/rdate.8' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'rdate-1.2/rdate.8' &&
X.\" $NetBSD: rdate.8,v 1.9 2002/01/19 11:45:00 wiz Exp $
X.\"
X.\" Copyright (c) 1994 Christos Zoulas
X.\" All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\" notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\" notice, this list of conditions and the following disclaimer in the
X.\" documentation and/or other materials provided with the distribution.
X.\" 3. All advertising materials mentioning features or use of this software
X.\" must display the following acknowledgement:
X.\" This product includes software developed by Christos Zoulas.
X.\" 4. The name of the author may not be used to endorse or promote products
X.\" derived from this software without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
X.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
X.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X.\"
X.Dd April 30, 1994
X.Dt RDATE 8
X.Os
X.Sh NAME
X.Nm rdate
X.Nd set the system's date from a remote host
X.Sh SYNOPSIS
X.Nm
X.Op Fl psa
X.Ar host
X.Sh DESCRIPTION
X.Nm
displays and sets the local date and time from the
host name or address given as the argument. It uses the RFC868
protocol which is usually implemented as a built-in service of
X.Xr inetd 8 .
X.Pp
Available options:
X.Pp
X.Bl -tag -width indent
X.It Fl p
Do not set, just print the remote time
X.It Fl s
Do not print the time.
X.It Fl a
Use the
X.Xr adjtime 2
call to gradually skew the local time to the
remote time rather than just hopping.
X.El
X.Sh FILES
X.Bl -tag -width /var/log/wtmp -compact
X.It Pa /var/log/wtmp
A record of date resets and time changes.
X.El
X.Sh SEE ALSO
X.Xr adjtime 2 ,
X.Xr ClockAdjust 2 ,
X.Xr gettimeofday 2 ,
X.Xr utmp 5 ,
X.Xr inetd 8,
X.Xr ntpd 8
SHAR_EOF
(set 20 02 09 04 05 37 34 'rdate-1.2/rdate.8'; eval "$shar_touch") &&
chmod 0664 'rdate-1.2/rdate.8' ||
$echo 'restore of' 'rdate-1.2/rdate.8' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'rdate-1.2/rdate.8:' 'MD5 check failed'
51da00b0cfb308d367dd1620f5a17cb7 rdate-1.2/rdate.8
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rdate-1.2/rdate.8'`"
test 2564 -eq "$shar_count" ||
$echo 'rdate-1.2/rdate.8:' 'original size' '2564,' 'current size' "$shar_count!"
fi
fi
# ============= rdate-1.2/rdate.c ==============
if test -f 'rdate-1.2/rdate.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'rdate-1.2/rdate.c' '(file already exists)'
else
$echo 'x -' extracting 'rdate-1.2/rdate.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'rdate-1.2/rdate.c' &&
/* $Id: rdate.c,v 1.11 2003/06/19 16:10:46 kabe Exp $ */
X
/*
X * Copyright (c) 1994 Christos Zoulas
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X * notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X * notice, this list of conditions and the following disclaimer in the
X * documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X * must display the following acknowledgement:
X * This product includes software developed by Christos Zoulas.
X * 4. The name of the author may not be used to endorse or promote products
X * derived from this software without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X */
/* Modified for QNXRTP by kabe */
X
/*
X * rdate.c: Set the date from the specified host
X *
X * Uses the rfc868 time protocol at socket 37.
X * Time is returned as the number of seconds since
X * midnight January 1st 1900.
X */
X
#include <sys/cdefs.h>
#ifndef lint
static const char * const _rcsidNetBSD="$NetBSD: rdate.c,v 1.14 2002/07/14 01:01:10 wiz Exp $";
static const char * const _rcsid = "$Id: rdate.c,v 1.11 2003/06/19 16:10:46 kabe Exp $";
#endif /* lint */
X
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
X
#include <netinet/in.h>
X
#include <ctype.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if __NETBSD
#include <util.h>
#endif
X
/* seconds from midnight Jan 1900 - 1970 */
#define DIFFERENCE 2208988800UL
X
static char *gProgname = "";
X
static const char _usage[] __attribute__((section("QNX_usage"),unused)) =
"%C - set system time and date from remote host (time server port 37)\n"
"\n"
"Options:\n"
"%C [\033[1m-psa\033[0m] \033[4mhost\033[0m\n"
" \033[1m-p\033[0m just print, don't set\n"
" \033[1m-s\033[0m just set, don't print\n"
" \033[1m-a\033[0m use adjtime for gradual change instead of instant change\n"
" \033[1m-r\033[0m do not set RTC (default is to also set RTC)\n"
"";
X
int
main(int argc, char *argv[])
{
X int pr = 0, silent = 0, s;
X int slidetime = 0;
X int adjustment;
X int nosetrtc = 0;
X time_t tim;
X char *hname, *emsg;
X struct addrinfo hints, *res, *res0;
X int c;
X int error;
X
X gProgname=strrchr(argv[0], '/');
X if (NULL == gProgname) {
X gProgname = argv[0];
X } else {
X gProgname++; /* skip '/' */
X }
X
X adjustment = 0;
X while ((c = getopt(argc, argv, "psar")) != -1)
X switch (c) {
X case 'p':
X pr++;
X break;
X
X case 's':
X silent++;
X break;
X
X case 'a':
X slidetime++;
X break;
X
X case 'r':
X nosetrtc++;
X break;
X
X default:
X return 1;
X }
X
X if (argc - 1 != optind) {
X fprintf(stderr, "Usage: %s [-psa] host\n", gProgname);
X return 1;
X }
X hname = argv[optind];
X
X memset(&hints, 0, sizeof (hints));
X hints.ai_family = PF_UNSPEC;
X hints.ai_socktype = SOCK_STREAM;
X hints.ai_flags = AI_CANONNAME;
X error = getaddrinfo(hname, "time", &hints, &res0);
X if (error)
X errx(1, "%s: %s", gai_strerror(error), hname);
X
X for (res = res0, s = -1; res != NULL; res = res->ai_next) {
X s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
X if (s < 0) {
X emsg = "socket";
X continue;
X }
X
X if (connect(s, res->ai_addr, res->ai_addrlen)) {
X close(s);
X s = -1;
X emsg = "connect";
X continue;
X }
X
X break;
X }
X freeaddrinfo(res0);
X if (s < 0)
X err(1, "%s", emsg);
X
X if (read(s, &tim, sizeof(time_t)) != sizeof(time_t))
X err(1, "Could not read data");
X
X (void) close(s);
X tim = ntohl(tim) - DIFFERENCE;
X
X if (!pr) {
X struct timeval tv;
X if (!slidetime) {
X void qnx_setrtc(void);
X logwtmp("|", "date", "");
X tv.tv_sec = tim;
X tv.tv_usec = 0;
X if (settimeofday(&tv, NULL) == -1)
X err(1, "Could not set time of day");
X if (!nosetrtc) qnx_setrtc();
X logwtmp("{", "date", "");
X } else {
X struct timeval tv_current;
X if (gettimeofday(&tv_current, NULL) == -1)
X err(1, "Could not get local time of day");
X /* XXX typeof(tv.tv_sec)==time_t COULD BE UNSIGNED! */
X adjustment = tv.tv_sec = tim - tv_current.tv_sec;
X tv.tv_usec = 0;
X if (adjtime(&tv, NULL) == -1)
X err(1, "Could not adjust time of day");
X }
X }
X
X if (!silent) {
X (void) fputs(ctime(&tim), stdout);
X if (slidetime)
X (void) fprintf(stdout,
X "%s: adjust local clock by %d seconds\n",
X gProgname, adjustment);
X }
X return 0;
}
X
/*
X * Set RTC from current system time.
X *
X * Consults the "rtc -l hw" line in /etc/rc.d/rc.rtc,
X * convert it to "rtc -s -l hw" and invoke it.
X * (-l indicates RTC is in localtime; missing -l means RTC is GMT)
X */
#include <process.h>
void
qnx_setrtc(void)
{
X FILE *fp;
X char buf[128];
X
X fp = fopen("/etc/rc.d/rc.rtc", "r");
X if (!fp) {
X warn("/etc/rc.d/rc.rtc");
X return;
X }
X while (fgets(buf, sizeof buf, fp)) {
X char *p = strtok(buf, " \t");
X if (p[0] == '#') continue;
X if (!strcmp(p, "rtc")) {
X char *argv[16];
X int argc=0;
X argv[argc++] = p;
X /* insert "-s" to make it into "rtc -s -l hw" */
X argv[argc++] = "-s";
X for (argc; argc<16-1 && (p = strtok(NULL, " \t\r\n")); )
X argv[argc++] = p;
X argv[argc] = NULL;
X
X spawnvp(P_WAIT, "rtc", argv);
X break;
X }
X }
X fclose(fp);
}
SHAR_EOF
(set 20 03 06 20 01 10 46 'rdate-1.2/rdate.c'; eval "$shar_touch") &&
chmod 0664 'rdate-1.2/rdate.c' ||
$echo 'restore of' 'rdate-1.2/rdate.c' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'rdate-1.2/rdate.c:' 'MD5 check failed'
2b8f845fb20ff8ce404ec7e86f2e908c rdate-1.2/rdate.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rdate-1.2/rdate.c'`"
test 6222 -eq "$shar_count" ||
$echo 'rdate-1.2/rdate.c:' 'original size' '6222,' 'current size' "$shar_count!"
fi
fi
# ============= rdate-1.2/rdate.qpg ==============
if test -f 'rdate-1.2/rdate.qpg' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'rdate-1.2/rdate.qpg' '(file already exists)'
else
$echo 'x -' extracting 'rdate-1.2/rdate.qpg' '(binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 rdate-1.2/rdate.qpg
M/%%01SI'96YE<F%T:6]N/@H@("`\45!'.D]P=&EO;G,^"B`@("`@(#Q14$<Z
M57-E<B!U;F%T=&5N9&5D/2)N;R(@=F5R8F]S:71Y/2(R(B!L:7-T9FEL97,]
M(GEE<R(O/@H@("`@("`\45!'.D1E9F%U;'1S('1Y<&4](G%N>%]P86-K86=E
M(B\^"B`@("`@(#Q14$<Z4V]U<F-E/CPO45!'.E-O=7)C93X*("`@("`@/%%0
M1SI296QE87-E(&YU;6)E<CTB*R(O/@H@("`@("`\45!'.D)U:6QD("\^"B`@
M("`@(#Q14$<Z1FEL95-O<G1I;F<@<W1R:7`](GEE<R(O/@H@("`@("`\45!'
M.E!A8VMA9V4@=&%R9V5T<STB8V]M8FEN92(O/@H@("`@("`\45!'.E)E<&]S
M:71O<GD@9V5N97)A=&4](GEE<R(O/@H@("`@("`\45!'.D9I;F%L1&ER(&1I
M<CTB+B(@+SX*("`@("`@/%%01SI#;&5A;G5P/CPO45!'.D-L96%N=7`^"B`@
M(#PO45!'.D]P=&EO;G,^"@H@("`\45!'.E)E<W!O;G-I8FQE/@H@("`@("`\
M45!'.D-O;7!A;GD^/"]14$<Z0V]M<&%N>3X*("`@("`@/%%01SI$97!A<G1M
M96YT/CPO45!'.D1E<&%R=&UE;G0^"B`@("`@(#Q14$<Z1W)O=7`^/"]14$<Z
M1W)O=7`^"B`@("`@(#Q14$<Z5&5A;3X\+U%01SI496%M/@H@("`@("`\45!'
M.D5M<&QO>65E/CPO45!'.D5M<&QO>65E/@H@("`@("`\45!'.D5M86EL061D
M<F5S<SX\+U%01SI%;6%I;$%D9')E<W,^"B`@(#PO45!'.E)E<W!O;G-I8FQE
M/@H*("`@/%%01SI686QU97,^"B`@("`@(#Q14$<Z1FEL97,^"B`@("`@("`@
M(#Q14$<Z061D('1Y<&4](G1R964B(&9I;&4](D1)4U0O(B!I;G-T86QL/2(O
M(B`O/@H@("`@("`@("`\45!'.D%D9"!F:6QE/2(N+T-/4%E)3D<B(&EN<W1A
M;&P](B\B(&AA;F1L:6YG/2)R97!D871A(B`O/@H@("`@("`\+U%01SI&:6QE
M<SX*"B`@("`@(#Q14$<Z4&%C:V%G949I;'1E<CX*("`@("`@("`@/%%033I0
M86-K86=E36%N:69E<W0^"B`@("`@("`@("`@(#Q14$TZ4&%C:V%G941E<V-R
M:7!T:6]N/@H@("`@("`@("`@("`@("`\45!-.E!A8VMA9V54>7!E/D%P<&QI
M8V%T:6]N/"]14$TZ4&%C:V%G951Y<&4^"B`@("`@("`@("`@("`@(#Q14$TZ
M4&%C:V%G95)E<&]S:71O<GD^/"]14$TZ4&%C:V%G95)E<&]S:71O<GD^"B`@
M("`@("`@("`@("`@(#Q14$TZ1FEL959E<G-I;VX^,2XY/"]14$TZ1FEL959E
M<G-I;VX^"B`@("`@("`@("`@(#PO45!-.E!A8VMA9V5$97-C<FEP=&EO;CX*
M"B`@("`@("`@("`@(#Q14$TZ4')O9'5C=$1E<V-R:7!T:6]N/@H@("`@("`@
M("`@("`@("`\45!-.E!R;V1U8W1.86UE/G)D871E($1A=&4@4WEN8W)O;FEZ
M871I;VX@0V]M;6%N9#PO45!-.E!R;V1U8W1.86UE/@H@("`@("`@("`@("`@
M("`\45!-.E!R;V1U8W1)9&5N=&EF:65R/G)D871E/"]14$TZ4')O9'5C=$ED
M96YT:69I97(^"B`@("`@("`@("`@("`@(#Q14$TZ4')O9'5C=$5M86EL/CPO
M45!-.E!R;V1U8W1%;6%I;#X*("`@("`@("`@("`@("`@/%%033I696YD;W).
M86UE/E!U8FQI8SPO45!-.E9E;F1O<DYA;64^"B`@("`@("`@("`@("`@(#Q1
M4$TZ5F5N9&]R26YS=&%L;$YA;64^<'5B;&EC/"]14$TZ5F5N9&]R26YS=&%L
M;$YA;64^"B`@("`@("`@("`@("`@(#Q14$TZ5F5N9&]R55),/CPO45!-.E9E
M;F1O<E523#X*("`@("`@("`@("`@("`@/%%033I696YD;W)%;6)E9%523#X\
M+U%033I696YD;W)%;6)E9%523#X*("`@("`@("`@("`@("`@/%%033I696YD
M;W)%;6%I;#YK86)E0'-R82UT;VAO:W4N8V\N:G`\+U%033I696YD;W)%;6%I
M;#X*("`@("`@("`@("`@("`@/%%033I!=71H;W).86UE/D-H<FES=&]S(%IO
M=6QA<R`O($YE=$)31#PO45!-.D%U=&AO<DYA;64^"B`@("`@("`@("`@("`@
M(#Q14$TZ075T:&]R55),/CPO45!-.D%U=&AO<E523#X*("`@("`@("`@("`@
M("`@/%%033I!=71H;W)%;6)E9%523#X\+U%033I!=71H;W)%;6)E9%523#X*
M("`@("`@("`@("`@("`@/%%033I!=71H;W)%;6%I;#X\+U%033I!=71H;W)%
M;6%I;#X*("`@("`@("`@("`@("`@/%%033I0<F]D=6-T26-O;E-M86QL/CPO
M45!-.E!R;V1U8W1)8V]N4VUA;&P^"B`@("`@("`@("`@("`@(#Q14$TZ4')O
M9'5C=$EC;VY,87)G93X\+U%033I0<F]D=6-T26-O;DQA<F=E/@H@("`@("`@
M("`@("`@("`\45!-.E!R;V1U8W1$97-C<FEP=&EO;E-H;W)T/F$@8V]M;6%N
M9"!F;W(@<WEN8W)O;FEZ:6YG('1H92!C;&]C:R!T;R!O=&AE<B!M86-H:6YE
M/"]14$TZ4')O9'5C=$1E<V-R:7!T:6]N4VAO<G0^"B`@("`@("`@("`@("`@
M(#Q14$TZ4')O9'5C=$1E<V-R:7!T:6]N3&]N9SYR9&%T92!C;VUM86YD(&-O
M;G-U;'1S('1H92!T:6UE('-E<G9I8V4@*%1#4"!P;W)T(#,W*2!O9B!T:&4@
M;W1H97(@;6%C:&EN92!A;F0@<V5T<R!T:&4@;&]C86P@8VQO8VL@86-C;W)D
M:6YG;'DL('=I=&AI;B`Q('-E8V]N9"!G<F%N=6QA<FET>2X\+U%033I0<F]D
M=6-T1&5S8W)I<'1I;VY,;VYG/@H@("`@("`@("`@("`@("`\45!-.E!R;V1U
M8W1$97-C<FEP=&EO;E523#X\+U%033I0<F]D=6-T1&5S8W)I<'1I;VY54DP^
M"B`@("`@("`@("`@("`@(#Q14$TZ4')O9'5C=$1E<V-R:7!T:6]N16UB9615
M4DP^/"]14$TZ4')O9'5C=$1E<V-R:7!T:6]N16UB96154DP^"B`@("`@("`@
M("`@(#PO45!-.E!R;V1U8W1$97-C<FEP=&EO;CX*"B`@("`@("`@("`@(#Q1
M4$TZ4F5L96%S941E<V-R:7!T:6]N/@H@("`@("`@("`@("`@("`\45!-.E)E
M;&5A<V5697)S:6]N/C$N,F$\+U%033I296QE87-E5F5R<VEO;CX*("`@("`@
M("`@("`@/%%033I296QE87-E1&%T93XR,#`R+S`Y+S`T/"]14$TZ4F5L96%S
M941A=&4^"B`@("`@("`@("`@("`@(#Q14$TZ4F5L96%S955R9V5N8WD^365D
M:75M/"]14$TZ4F5L96%S955R9V5N8WD^"B`@("`@("`@("`@("`@(#Q14$TZ
M4F5L96%S95-T86)I;&ET>3Y3=&%B;&4\+U%033I296QE87-E4W1A8FEL:71Y
M/@H@("`@("`@("`@("`@("`\45!-.E)E;&5A<V5.;W1E36EN;W(^/"]14$TZ
M4F5L96%S94YO=&5-:6YO<CX*("`@("`@("`@("`@("`@/%%033I296QE87-E
M3F]T94UA:F]R/E1H:7,@8V]M;6%N9"!I<R!A(%%.6"!P;W)T(&]F('1H92!.
M971"4T0@<F1A=&4N"F%D:G1I;64H*2!I<R!N;W0@<')O=FED960@:6X@3F5U
M=')I;F\L('-O(&$@8W5S=&]M(&-O9&4@=&\@=')A;G-L871E(&%D:G1I;64H
M*2!T;R!#;&]C:T%D:G5S="@I('=A<R!A9&1E9"X\+U%033I296QE87-E3F]T
M94UA:F]R/@H@("`@("`@("`@("`@("`\45!-.D-O=6YT<GE%>&-L=61E/CPO
M45!-.D-O=6YT<GE%>&-L=61E/@H@("`@("`@("`@("`@("`\45!-.E)E;&5A
M<V5#;W!Y<FEG:'0^0E-$($QI8V5N<V4\+U%033I296QE87-E0V]P>7)I9VAT
M/@H@("`@("`@("`@("`\+U%033I296QE87-E1&5S8W)I<'1I;VX^"@H@("`@
M("`@("`@("`\45!-.D-O;G1E;G1$97-C<FEP=&EO;CX*("`@("`@("`@("`@
M("`@/%%033I#;VYT96YT5&]P:6,@>&UL;75L=&EP;&4](G1R=64B/E-Y<W1E
M;3PO45!-.D-O;G1E;G14;W!I8SX*("`@("`@("`@("`@("`@/%%033I#;VYT
M96YT2V5Y=V]R9#YR9&%T92QD871E+'1I;64@<WEN8W)O;FEZ93PO45!-.D-O
M;G1E;G1+97EW;W)D/@H@("`@("`@("`@("`@("`\45!-.E1A<F=E=$]3/G%N
M>#8\+U%033I487)G971/4SX*("`@("`@("`@("`@("`@/%%033I(;W-T3U,^
M;F]N93PO45!-.DAO<W1/4SX*("`@("`@("`@("`@("`@/%%033I$:7-P;&%Y
M16YV:7)O;FUE;G0@>&UL;75L=&EP;&4](G1R=64B/D-O;G-O;&4\+U%033I$
M:7-P;&%Y16YV:7)O;FUE;G0^"B`@("`@("`@("`@("`@(#Q14$TZ5&%R9V5T
M075D:65N8V4@>&UL;75L=&EP;&4](G1R=64B/D%D;6EN:7-T<F%T;W(\+U%0
M33I487)G971!=61I96YC93X*("`@("`@("`@("`@/"]14$TZ0V]N=&5N=$1E
M<V-R:7!T:6]N/@H*("`@("`@("`@("`@/%%033I,:6-E;G-E57)L/G)E<&1A
M=&$Z+R]#3U!924Y'/"]14$TZ3&EC96YS955R;#X*("`@("`@("`@/"]14$TZ
M4&%C:V%G94UA;FEF97-T/@H@("`@("`\+U%01SI086-K86=E1FEL=&5R/@H*
C("`@/"]14$<Z5F%L=65S/@H\+U%01SI'96YE<F%T:6]N/@IE
`
end
SHAR_EOF
(set 20 03 03 14 00 32 16 'rdate-1.2/rdate.qpg'; eval "$shar_touch") &&
chmod 0664 'rdate-1.2/rdate.qpg' ||
$echo 'restore of' 'rdate-1.2/rdate.qpg' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'rdate-1.2/rdate.qpg:' 'MD5 check failed'
491f7b440dcf646a647ab4b339e3dca1 rdate-1.2/rdate.qpg
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'rdate-1.2/rdate.qpg'`"
test 3995 -eq "$shar_count" ||
$echo 'rdate-1.2/rdate.qpg:' 'original size' '3995,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh04098
exit 0

Post Reply

Return to “qdn.public.qnxrtp.porting”