From dan@obluda.cz  Sun Sep 12 02:37:40 2004
Return-Path: <dan@obluda.cz>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id DF17516A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Sep 2004 02:37:40 +0000 (GMT)
Received: from kulesh.obluda.cz (kulesh.obluda.cz [193.179.22.243])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B463A43D48
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Sep 2004 02:37:39 +0000 (GMT)
	(envelope-from dan@obluda.cz)
Received: from kulesh.obluda.cz (localhost.eunet.cz [127.0.0.1])
	by kulesh.obluda.cz (8.13.1/8.13.1) with ESMTP id i8C2bc9q007097
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 12 Sep 2004 04:37:38 +0200 (CEST)
	(envelope-from dan@obluda.cz)
Received: (from root@localhost)
	by kulesh.obluda.cz (8.13.1/8.13.1/Submit) id i8C2bb7V007096
	for FreeBSD-gnats-submit@freebsd.org; Sun, 12 Sep 2004 04:37:37 +0200 (CEST)
	(envelope-from dan@obluda.cz)
Message-Id: <200409120237.i8C2bb7V007096@kulesh.obluda.cz>
Date: Sun, 12 Sep 2004 04:37:37 +0200 (CEST)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] cleanup of the usr.sbin/timed code
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         71618
>Category:       bin
>Synopsis:       [patch] timed(8): cleanup of the usr.sbin/timed code
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 12 02:40:23 GMT 2004
>Closed-Date:    
>Last-Modified:  Mon Dec 29 17:59:55 UTC 2008
>Originator:     Dan Lukes
>Release:        FreeBSD 5.3-BETA3 i386
>Organization:
Obludarium
>Environment:
System: FreeBSD kulesh.obluda.cz 5.3-BETA3 FreeBSD 5.3-BETA3 #8: Sun Sep 5 07:06:40 CEST 2004 dan@kulesh.obluda.cz:/usr/obj/usr/src/sys/Dan i386
src/usr.sbin/timed/timed/readmsg.c,v 1.9 2001/11/20 07:13:40 jhb
src/usr.sbin/timed/timed/master.c,v 1.9 2002/07/11 20:01:36 robert

>Description:
	There are more than 5000 warnings issued during "make buildworld".
Some of them are false positives, but some of them are sign of true errors.

	Nobody is upset by warnings due it's amount, so some errors remain
uncorrected.

	I want to cleanup the code-base from warnings, so warnings will
become "attention mark" again.

usr.sbin/timed/timed/master.c:340: warning: no return statement in function returning non-void
usr.sbin/timed/timed/readmsg.c:501: warning: long int format, int32_t arg (arg 6)
usr.sbin/timed/timed/readmsg.c:501: warning: long int format, int32_t arg (arg 7)
>How-To-Repeat:
	N/A
>Fix:
*** usr.sbin/timed/timed/master.c.ORIG	Mon Jul 15 02:11:08 2002
--- usr.sbin/timed/timed/master.c	Mon Sep  6 02:22:26 2004
***************
*** 337,342 ****
--- 337,343 ----
  		}
  	}
  	goto loop;
+ 	return(0);
  }
  
  
*** usr.sbin/timed/timed/readmsg.c.ORIG	Tue Nov 20 08:13:40 2001
--- usr.sbin/timed/timed/readmsg.c	Mon Sep  6 02:20:20 2004
***************
*** 491,497 ****
  		break;
  
  	case TSP_ADJTIME:
! 		fprintf(fd, "%s %d %-6u (%ld,%ld) %-15s %s\n",
  			tsptype[msg->tsp_type],
  			msg->tsp_vers,
  			msg->tsp_seq,
--- 491,497 ----
  		break;
  
  	case TSP_ADJTIME:
! 		fprintf(fd, "%s %d %-6u (%d,%d) %-15s %s\n",
  			tsptype[msg->tsp_type],
  			msg->tsp_vers,
  			msg->tsp_seq,
>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@freebsd.org>
To: Dan Lukes <dan@obluda.cz>
Cc: bug-followup@freebsd.org
Subject: Re: bin/71618: [PATCH] cleanup of the usr.sbin/timed code
Date: Sun, 12 Sep 2004 21:35:35 +0300

 On 2004-09-12 04:37, Dan Lukes <dan@obluda.cz> wrote:
 > usr.sbin/timed/timed/readmsg.c:501: warning: long int format, int32_t arg (arg 6)
 > usr.sbin/timed/timed/readmsg.c:501: warning: long int format, int32_t arg (arg 7)
 
 > - 		fprintf(fd, "%s %d %-6u (%ld,%ld) %-15s %s\n",
 > + 		fprintf(fd, "%s %d %-6u (%d,%d) %-15s %s\n",
 
 There's no guarantee that an int32_t value will be defined with an `int'.
 This might result in unexpected truncation of the printed value.  A better
 fix, IMHO, would be to change the format to %jd and then cast the value to
 (intmax_t) which should avoid truncation of the value (you'll also have to
 include <stdint.h> for intmax_t to be visible).
 
 There are many other warnings in timed that are exposed if you try to build
 it with an increased WARNS level.  Since you seem to like doing this sort
 of work, can you try the following (and see if you can come up with fixes
 for the warnings this shows)?
 
 	# cd /usr/src/usr.sbin/timed/
 	# make NO_WERROR=1 WARNS?=3
 
 Thank you for your work so far :-)
 

From: Dan Lukes <dan@obluda.cz>
To: Giorgos Keramidas <keramida@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/71618: [PATCH] cleanup of the usr.sbin/timed code
Date: Mon, 13 Sep 2004 03:37:11 +0200 (CEST)

 On Sun, 12 Sep 2004, Giorgos Keramidas wrote:
 
 >> - 		fprintf(fd, "%s %d %-6u (%ld,%ld) %-15s %s\n",
 >> + 		fprintf(fd, "%s %d %-6u (%d,%d) %-15s %s\n",
 >
 > There's no guarantee that an int32_t value will be defined with an `int'.
 > This might result in unexpected truncation of the printed value.  A better
 
  	True. In the fact, I miss the existence of 'j' modifier and intmax_t
 type.
 
 > of work, can you try the following (and see if you can come up with fixes
 > for the warnings this shows)?
 >
 > 	# cd /usr/src/usr.sbin/timed/
 > 	# make NO_WERROR=1 WARNS?=3
 
  	I'm compiling with -Wall -O3.
  	It seems to be more than any WARNS=X
 
  	If there are some warning not corrected by attached patches, then it
 mean I'm don't know how the good way to correct it.
 
 > Thank you for your work so far :-)
 
  	I have a lot of spare time now only ... ;-)
  								Dan

From: Bruce Cran <bruce@cran.org.uk>
To: bug-followup@FreeBSD.org, dan@obluda.cz
Cc:  
Subject: Re: bin/71618: [PATCH] timed(8): cleanup of the usr.sbin/timed code
Date: Thu, 4 Sep 2008 23:40:53 +0100

 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 The attached patches fix a lot of the warnings in usr.sbin/timed with
 high WARNS levels and GCC 4.
 
 -- 
 Bruce Cran
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/x-patch; name=acksend.c.diff
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=acksend.c.diff
 
 --- acksend.c.orig	2008-09-04 23:17:01.000000000 +0100
 +++ acksend.c	2008-09-04 23:17:09.000000000 +0100
 @@ -43,8 +43,6 @@
  
  struct tsp *answer;
  
 -extern u_short sequence;
 -
  void
  xmit(type, seq, addr)
  	int type;
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/x-patch; name=correct.c.diff
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=correct.c.diff
 
 --- correct.c.orig	2008-09-04 23:17:34.000000000 +0100
 +++ correct.c	2008-09-04 23:18:38.000000000 +0100
 @@ -166,8 +166,8 @@
  		}
  	} else {
  		syslog(LOG_WARNING,
 -		       "clock correction %ld sec too large to adjust",
 -		       adj.tv_sec);
 +		       "clock correction %lld sec too large to adjust",
 +		       (long long int)adj.tv_sec);
  		(void) gettimeofday(&now, 0);
  		timevaladd(&now, corr);
  		if (settimeofday(&now, 0) < 0)
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/x-patch; name=globals.h.diff
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=globals.h.diff
 
 --- globals.h.orig	2008-09-04 23:17:14.000000000 +0100
 +++ globals.h	2008-09-04 23:17:25.000000000 +0100
 @@ -55,8 +55,6 @@
  #define	SECHR	(60*60)
  #define	SECDAY	(24*SECHR)
  
 -extern int sock;
 -
  /* Best expected round trip for a measurement.
   * This is essentially the number of milliseconds per CPU tick (CLK_TCK?).
   * All delays shorter than this are usually reported as 0.
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/x-patch; name=master.c.diff
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=master.c.diff
 
 --- master.c.orig	2008-09-04 23:18:49.000000000 +0100
 +++ master.c	2008-09-04 23:21:17.000000000 +0100
 @@ -44,6 +44,7 @@
  #include <sys/types.h>
  #include <sys/times.h>
  #include <setjmp.h>
 +#include <libutil.h>
  #include "pathnames.h"
  
  extern int measure_delta;
 @@ -56,8 +57,6 @@
  
  static void mchgdate(struct tsp *);
  
 -extern void logwtmp(char *, char *, char *);
 -
  /*
   * The main function of `master' is to periodically compute the differences
   * (deltas) between its clock and the clocks of the slaves, to compute the
 @@ -832,8 +831,7 @@
  
  
  void
 -traceoff(msg)
 -	char *msg;
 +traceoff(const char *msg)
  {
  	get_goodgroup(1);
  	setstatus();
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/x-patch; name=readmsg.c.diff
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=readmsg.c.diff
 
 --- readmsg.c.orig	2008-09-04 23:21:26.000000000 +0100
 +++ readmsg.c	2008-09-04 23:39:00.000000000 +0100
 @@ -39,6 +39,7 @@
    "$FreeBSD: src/usr.sbin/timed/timed/readmsg.c,v 1.9 2001/11/20 07:13:40 jhb Exp $";
  #endif /* not lint */
  
 +#include <stdint.h>
  #include "globals.h"
  
  extern char *tsptype[];
 @@ -186,8 +187,8 @@
  			rwait.tv_usec = 1000000/CLK_TCK;
  
  		if (trace) {
 -			fprintf(fd, "readmsg: wait %ld.%6ld at %s\n",
 -				rwait.tv_sec, rwait.tv_usec, date());
 +			fprintf(fd, "readmsg: wait %lld.%6ld at %s\n",
 +			(long long int)rwait.tv_sec, rwait.tv_usec, date());
  			/* Notice a full disk, as we flush trace info.
  			 * It is better to flush periodically than at
  			 * every line because the tracing consists of bursts
 @@ -491,12 +492,12 @@
  		break;
  
  	case TSP_ADJTIME:
 -		fprintf(fd, "%s %d %-6u (%ld,%ld) %-15s %s\n",
 +		fprintf(fd, "%s %d %-6u (%jd,%jd) %-15s %s\n",
  			tsptype[msg->tsp_type],
  			msg->tsp_vers,
  			msg->tsp_seq,
 -			msg->tsp_time.tv_sec,
 -			msg->tsp_time.tv_usec,
 +			(intmax_t)msg->tsp_time.tv_sec,
 +			(intmax_t)msg->tsp_time.tv_usec,
  			inet_ntoa(addr->sin_addr),
  			msg->tsp_name);
  		break;
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/x-patch; name=slave.c.diff
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=slave.c.diff
 
 --- slave.c.orig	2008-09-04 23:28:34.000000000 +0100
 +++ slave.c	2008-09-04 23:32:48.000000000 +0100
 @@ -41,14 +41,14 @@
  
  #include "globals.h"
  #include <setjmp.h>
 +#include <sys/types.h>
 +#include <libutil.h>
  #include "pathnames.h"
  
  extern jmp_buf jmpenv;
  extern int Mflag;
  extern int justquit;
  
 -extern u_short sequence;
 -
  static char master_name[MAXHOSTNAMELEN];
  static struct netinfo *old_slavenet;
  static int old_status;
 @@ -57,13 +57,11 @@
  static void setmaster(struct tsp *);
  static void answerdelay(void);
  
 -extern void logwtmp(char *, char *, char *);
 -
  int
 -slave()
 +slave(void)
  {
  	int tries;
 -	long electiontime, refusetime, looktime, looptime, adjtime;
 +	long electiontime, refusetime, looktime, looptime, adj_time;
  	u_short seq;
  	long fastelection;
  #define FASTTOUT 3
 @@ -75,7 +73,6 @@
  	struct timeval ntime, wait, tmptv;
  	time_t tsp_time_sec;
  	struct tsp *answer;
 -	int timeout();
  	char olddate[32];
  	char newdate[32];
  	struct netinfo *ntp;
 @@ -85,7 +82,9 @@
  	old_slavenet = 0;
  	seq = 0;
  	refusetime = 0;
 -	adjtime = 0;
 +	adj_time = 0;
 +	
 +	memset(&cadr, 0, sizeof(struct in_addr));
  
  	(void)gettimeofday(&ntime, 0);
  	electiontime = ntime.tv_sec + delay2;
 @@ -230,7 +229,7 @@
  			 * is found.
  			 */
  			(void)gettimeofday(&otime, 0);
 -			if (adjtime < otime.tv_sec)
 +			if (adj_time < otime.tv_sec)
  				looptime -= (looptime-otime.tv_sec)/2 + 1;
  
  			setmaster(msg);
 @@ -241,7 +240,7 @@
  			(void)gettimeofday(&ntime, 0);
  			electiontime = ntime.tv_sec + delay2;
  			fastelection = ntime.tv_sec + FASTTOUT;
 -			adjtime = ntime.tv_sec + SAMPLEINTVL*2;
 +			adj_time = ntime.tv_sec + SAMPLEINTVL*2;
  			break;
  
  		case TSP_SETTIME:
 @@ -680,7 +679,7 @@
   * contention and likely collisions.
   */
  static void
 -answerdelay()
 +answerdelay(void)
  {
  	struct timeval timeout;
  
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI
 Content-Type: text/x-patch; name=timed.c.diff
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=timed.c.diff
 
 --- timed.c.orig	2008-09-04 23:33:00.000000000 +0100
 +++ timed.c	2008-09-04 23:34:06.000000000 +0100
 @@ -115,9 +115,7 @@
   * overhauled at Silicon Graphics
   */
  int
 -main(argc, argv)
 -	int argc;
 -	char *argv[];
 +main(int argc, char *argv[])
  {
  	int on;
  	int ret;
 @@ -704,7 +702,7 @@
  }
  
  char *
 -date()
 +date(void)
  {
  	struct	timeval tv;
  	time_t	tv_sec;
 @@ -715,8 +713,7 @@
  }
  
  void
 -addnetname(name)
 -	char *name;
 +addnetname(char *name)
  {
  	register struct nets **netlist = &nets;
  
 @@ -731,9 +728,8 @@
  
  /* note a host as trustworthy */
  static void
 -add_good_host(name, perm)
 -	char *name;
 -	int perm;			/* 1=not part of the netgroup */
 +add_good_host(char *name, int perm)
 +/*	int perm :  1=not part of the netgroup */
  {
  	register struct goodhost *ghp;
  	register struct hostent *hentp;
 
 --MP_/YIDZdtW/+AWSkfJ0mKe0ALI--

From: Dan Lukes <dan@obluda.cz>
To: Bruce Cran <bruce@cran.org.uk>, bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/71618: [PATCH] timed(8): cleanup of the usr.sbin/timed code
Date: Fri, 05 Sep 2008 07:59:44 +0200

 Bruce Cran napsal/wrote, On 09/05/08 00:40:
 > +		       "clock correction %lld sec too large to adjust",
 > +		       (long long int)adj.tv_sec);
 
 
 It seems to be better for me to use '%jd' and (intmax_t)adj.tv_sec
 
 					Dan
>Unformatted:
