From 30b2e94ae8b59a50d9b9708a09fd8eb4ea19431b Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 7 Nov 2010 15:20:18 +0100 Subject: [PATCH] talkd(8): Reduce diffs with FreeBSD and raise WARNS to 6. --- libexec/talkd/Makefile | 1 - libexec/talkd/announce.c | 23 ++++++-------------- libexec/talkd/extern.h | 40 ++++++++++++++++++++++++++++++++++ libexec/talkd/print.c | 24 ++++++++++----------- libexec/talkd/process.c | 33 ++++++++-------------------- libexec/talkd/table.c | 46 ++++++++++++++++------------------------ libexec/talkd/talkd.8 | 1 - libexec/talkd/talkd.c | 16 ++++++-------- 8 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 libexec/talkd/extern.h diff --git a/libexec/talkd/Makefile b/libexec/talkd/Makefile index f9fa4b6433..b85e7e87f7 100644 --- a/libexec/talkd/Makefile +++ b/libexec/talkd/Makefile @@ -6,7 +6,6 @@ PROG= ntalkd SRCS= talkd.c announce.c process.c table.c print.c ttymsg.c MAN= talkd.8 -WARNS?= 1 CFLAGS+=-I${.CURDIR}/../../usr.bin/wall diff --git a/libexec/talkd/announce.c b/libexec/talkd/announce.c index d3299d7872..f3fd058e63 100644 --- a/libexec/talkd/announce.c +++ b/libexec/talkd/announce.c @@ -32,7 +32,6 @@ * * @(#)announce.c 8.3 (Berkeley) 4/28/95 * $FreeBSD: src/libexec/talkd/announce.c,v 1.11.2.3 2001/10/18 12:30:42 des Exp $ - * $DragonFly: src/libexec/talkd/announce.c,v 1.4 2008/08/23 22:26:56 swildner Exp $ */ #include @@ -53,12 +52,11 @@ #include #include +#include "extern.h" #include "ttymsg.h" extern char hostname[]; -int print_mesg (char *, CTL_MSG *, char *); - /* * Announce an invitation to talk. */ @@ -68,9 +66,7 @@ int print_mesg (char *, CTL_MSG *, char *); * a talk is requested. */ int -announce(request, remote_machine) - CTL_MSG *request; - char *remote_machine; +announce(CTL_MSG *request, const char *remote_machine) { char full_tty[32]; struct stat stbuf; @@ -90,18 +86,13 @@ announce(request, remote_machine) * Build a block of characters containing the message. * It is sent blank filled and in a single block to * try to keep the message in one piece if the recipient - * in in vi at the time + * in vi at the time */ int -print_mesg(tty, request, remote_machine) - char *tty; - CTL_MSG *request; - char *remote_machine; +print_mesg(const char *tty, CTL_MSG *request, const char *remote_machine) { - struct timeval clock; + struct timeval now; time_t clock_sec; - struct timezone zone; - struct tm *localtime(); struct tm *localclock; struct iovec iovec; char line_buf[N_LINES][N_CHARS]; @@ -112,8 +103,8 @@ print_mesg(tty, request, remote_machine) i = 0; max_size = 0; - gettimeofday(&clock, &zone); - clock_sec = clock.tv_sec; + gettimeofday(&now, NULL); + clock_sec = now.tv_sec; localclock = localtime(&clock_sec); (void)snprintf(line_buf[i], N_CHARS, " "); sizes[i] = strlen(line_buf[i]); diff --git a/libexec/talkd/extern.h b/libexec/talkd/extern.h new file mode 100644 index 0000000000..015ae6b692 --- /dev/null +++ b/libexec/talkd/extern.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2002 M. Warner Losh. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/libexec/talkd/extern.h,v 1.3 2003/04/03 05:13:27 jmallett Exp $ + */ + +int announce(CTL_MSG *, const char *); +int delete_invite(unsigned int); +void do_announce(CTL_MSG *, CTL_RESPONSE *); +CTL_MSG *find_match(CTL_MSG *request); +CTL_MSG *find_request(CTL_MSG *request); +int find_user(const char *name, char *tty); +void insert_table(CTL_MSG *, CTL_RESPONSE *); +int new_id(void); +int print_mesg(const char *, CTL_MSG *, const char *); +void print_request(const char *, CTL_MSG *); +void print_response(const char *, CTL_RESPONSE *); +void process_request(CTL_MSG *mp, CTL_RESPONSE *rp); +void timeout(int sig); diff --git a/libexec/talkd/print.c b/libexec/talkd/print.c index f1ab80195a..102ad73dbd 100644 --- a/libexec/talkd/print.c +++ b/libexec/talkd/print.c @@ -32,47 +32,47 @@ * * @(#)print.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/libexec/talkd/print.c,v 1.9 1999/08/28 00:10:16 peter Exp $ - * $DragonFly: src/libexec/talkd/print.c,v 1.2 2003/06/17 04:27:08 dillon Exp $ */ /* debug print routines */ +#include #include #include #include #include #include -static char *types[] = +#include "extern.h" + +static const char *types[] = { "leave_invite", "look_up", "delete", "announce" }; #define NTYPES (sizeof (types) / sizeof (types[0])) -static char *answers[] = +static const char *answers[] = { "success", "not_here", "failed", "machine_unknown", "permission_denied", "unknown_request", "badversion", "badaddr", "badctladdr" }; #define NANSWERS (sizeof (answers) / sizeof (answers[0])) void -print_request(cp, mp) - char *cp; - register CTL_MSG *mp; +print_request(const char *cp, CTL_MSG *mp) { - char tbuf[80], *tp; + const char *tp; + char tbuf[80]; if (mp->type > NTYPES) { (void)snprintf(tbuf, sizeof(tbuf), "type %d", mp->type); tp = tbuf; } else tp = types[mp->type]; - syslog(LOG_DEBUG, "%s: %s: id %lu, l_user %s, r_user %s, r_tty %s", + syslog(LOG_DEBUG, "%s: %s: id %u, l_user %s, r_user %s, r_tty %s", cp, tp, mp->id_num, mp->l_name, mp->r_name, mp->r_tty); } void -print_response(cp, rp) - char *cp; - register CTL_RESPONSE *rp; +print_response(const char *cp, CTL_RESPONSE *rp) { - char tbuf[80], *tp, abuf[80], *ap; + const char *tp, *ap; + char tbuf[80], abuf[80]; if (rp->type > NTYPES) { (void)snprintf(tbuf, sizeof(tbuf), "type %d", rp->type); diff --git a/libexec/talkd/process.c b/libexec/talkd/process.c index a6014c256e..3c7257ebdb 100644 --- a/libexec/talkd/process.c +++ b/libexec/talkd/process.c @@ -32,7 +32,6 @@ * * @(#)process.c 8.2 (Berkeley) 11/16/93 * $FreeBSD: src/libexec/talkd/process.c,v 1.9 1999/08/28 00:10:16 peter Exp $ - * $DragonFly: src/libexec/talkd/process.c,v 1.3 2003/11/14 03:54:31 dillon Exp $ */ /* @@ -55,25 +54,16 @@ #include #include #include +#include + +#include "extern.h" -int announce (CTL_MSG *, char *); -int delete_invite (int); -void do_announce (CTL_MSG *, CTL_RESPONSE *); -CTL_MSG *find_request(); -CTL_MSG *find_match(); -int find_user (char *, char *); -void insert_table (CTL_MSG *, CTL_RESPONSE *); -int new_id (void); -void print_request (char *, CTL_MSG *); -void print_response (char *, CTL_RESPONSE *); +extern int debug; void -process_request(mp, rp) - register CTL_MSG *mp; - register CTL_RESPONSE *rp; +process_request(CTL_MSG *mp, CTL_RESPONSE *rp) { - register CTL_MSG *ptr; - extern int debug; + CTL_MSG *ptr; char *s; rp->vers = TALK_VERSION; @@ -147,9 +137,7 @@ process_request(mp, rp) } void -do_announce(mp, rp) - register CTL_MSG *mp; - CTL_RESPONSE *rp; +do_announce(CTL_MSG *mp, CTL_RESPONSE *rp) { struct hostent *hp; CTL_MSG *ptr; @@ -161,7 +149,7 @@ do_announce(mp, rp) rp->answer = result; return; } -#define satosin(sa) ((struct sockaddr_in *)(sa)) +#define satosin(sa) ((struct sockaddr_in *)(void *)(sa)) hp = gethostbyaddr(&satosin(&mp->ctl_addr)->sin_addr, sizeof (struct in_addr), AF_INET); if (hp == NULL) { @@ -189,14 +177,11 @@ do_announce(mp, rp) } } -#include - /* * Search utmp for the local user */ int -find_user(name, tty) - char *name, *tty; +find_user(const char *name, char *tty) { struct utmp ubuf; int status; diff --git a/libexec/talkd/table.c b/libexec/talkd/table.c index 9ab5cfe550..0bd2e6469f 100644 --- a/libexec/talkd/table.c +++ b/libexec/talkd/table.c @@ -32,7 +32,6 @@ * * @(#)table.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/libexec/talkd/table.c,v 1.7 1999/08/28 00:10:17 peter Exp $ - * $DragonFly: src/libexec/talkd/table.c,v 1.3 2003/11/14 03:54:31 dillon Exp $ */ /* @@ -53,11 +52,12 @@ #include #include +#include "extern.h" + #define MAX_ID 16000 /* << 2^15 so I don't have sign troubles */ extern int debug; struct timeval tp; -struct timezone txp; typedef struct table_entry TABLE_ENTRY; @@ -68,26 +68,21 @@ struct table_entry { TABLE_ENTRY *last; }; -TABLE_ENTRY *table = NULL; +static void delete(TABLE_ENTRY *); -void delete (TABLE_ENTRY *); -CTL_MSG *find_request(); -CTL_MSG *find_match(); -int new_id (void); -void print_request (char *, CTL_MSG *); +TABLE_ENTRY *table = NULL; /* * Look in the table for an invitation that matches the current * request looking for an invitation */ CTL_MSG * -find_match(request) - register CTL_MSG *request; +find_match(CTL_MSG *request) { - register TABLE_ENTRY *ptr; + TABLE_ENTRY *ptr; time_t current_time; - gettimeofday(&tp, &txp); + gettimeofday(&tp, NULL); current_time = tp.tv_sec; if (debug) print_request("find_match", request); @@ -115,13 +110,12 @@ find_match(request) * one as find_match does */ CTL_MSG * -find_request(request) - register CTL_MSG *request; +find_request(CTL_MSG *request) { - register TABLE_ENTRY *ptr; + TABLE_ENTRY *ptr; time_t current_time; - gettimeofday(&tp, &txp); + gettimeofday(&tp, NULL); current_time = tp.tv_sec; /* * See if this is a repeated message, and check for @@ -153,14 +147,12 @@ find_request(request) } void -insert_table(request, response) - CTL_MSG *request; - CTL_RESPONSE *response; +insert_table(CTL_MSG *request, CTL_RESPONSE *response) { - register TABLE_ENTRY *ptr; + TABLE_ENTRY *ptr; time_t current_time; - gettimeofday(&tp, &txp); + gettimeofday(&tp, NULL); current_time = tp.tv_sec; request->id_num = new_id(); response->id_num = htonl(request->id_num); @@ -183,7 +175,7 @@ insert_table(request, response) * Generate a unique non-zero sequence number */ int -new_id() +new_id(void) { static int current_id = 0; @@ -198,10 +190,9 @@ new_id() * Delete the invitation with id 'id_num' */ int -delete_invite(id_num) - int id_num; +delete_invite(unsigned int id_num) { - register TABLE_ENTRY *ptr; + TABLE_ENTRY *ptr; ptr = table; if (debug) @@ -222,9 +213,8 @@ delete_invite(id_num) /* * Classic delete from a double-linked list */ -void -delete(ptr) - register TABLE_ENTRY *ptr; +static void +delete(TABLE_ENTRY *ptr) { if (debug) diff --git a/libexec/talkd/talkd.8 b/libexec/talkd/talkd.8 index f30c7f0156..aa51da8c52 100644 --- a/libexec/talkd/talkd.8 +++ b/libexec/talkd/talkd.8 @@ -31,7 +31,6 @@ .\" .\" @(#)talkd.8 8.2 (Berkeley) 12/11/93 .\" $FreeBSD: src/libexec/talkd/talkd.8,v 1.3.2.2 2001/08/16 10:44:21 ru Exp $ -.\" $DragonFly: src/libexec/talkd/talkd.8,v 1.3 2006/05/26 19:39:38 swildner Exp $ .\" .Dd December 11, 1993 .Dt TALKD 8 diff --git a/libexec/talkd/talkd.c b/libexec/talkd/talkd.c index 112f0ca736..b1e91832ec 100644 --- a/libexec/talkd/talkd.c +++ b/libexec/talkd/talkd.c @@ -33,7 +33,6 @@ * @(#) Copyright (c) 1983, 1993 The Regents of the University of California. All rights reserved. * @(#)talkd.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/libexec/talkd/talkd.c,v 1.11.2.1 2001/10/18 12:30:42 des Exp $ - * $DragonFly: src/libexec/talkd/talkd.c,v 1.3 2003/11/14 03:54:31 dillon Exp $ */ /* @@ -57,6 +56,8 @@ #include #include +#include "extern.h" + CTL_MSG request; CTL_RESPONSE response; @@ -64,20 +65,15 @@ int sockt; int debug = 0; long lastmsgtime; -char hostname[MAXHOSTNAMELEN]; +char hostname[MAXHOSTNAMELEN]; #define TIMEOUT 30 #define MAXIDLE 120 -void process_request (CTL_MSG *, CTL_RESPONSE *); -void timeout(); - int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { - register CTL_MSG *mp = &request; + CTL_MSG *mp = &request; int cc; #ifdef NOTDEF @@ -121,7 +117,7 @@ main(argc, argv) } void -timeout() +timeout(int sig __unused) { int save_errno = errno; -- 2.41.0