ANSIfication, WARNS and lint cleanup.
This commit is contained in:
parent
2be21c5e68
commit
20bee7c8de
@ -32,6 +32,10 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char copyright[] =
|
static const char copyright[] =
|
||||||
"@(#) Copyright (c) 1988 Regents of the University of California.\n\
|
"@(#) Copyright (c) 1988 Regents of the University of California.\n\
|
||||||
@ -39,12 +43,8 @@ static const char copyright[] =
|
|||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
#if 0
|
static const char sccsid[] = "from: @(#)wall.c 5.14 (Berkeley) 3/2/91";
|
||||||
static char sccsid[] = "from: @(#)wall.c 5.14 (Berkeley) 3/2/91";
|
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
|
||||||
"$FreeBSD$";
|
|
||||||
#endif /* not lint */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This program is not related to David Wall, whose Stanford Ph.D. thesis
|
* This program is not related to David Wall, whose Stanford Ph.D. thesis
|
||||||
@ -53,8 +53,9 @@ static const char rcsid[] =
|
|||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
#include <rpc/rpc.h>
|
||||||
|
#include <rpcsvc/rwall.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@ -63,23 +64,17 @@ static const char rcsid[] =
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utmp.h>
|
|
||||||
|
|
||||||
#include <rpc/rpc.h>
|
|
||||||
#include <rpcsvc/rwall.h>
|
|
||||||
|
|
||||||
int mbufsize;
|
|
||||||
char *mbuf;
|
char *mbuf;
|
||||||
|
|
||||||
void makemsg __P((char *));
|
static char notty[] = "no tty";
|
||||||
static void usage __P((void));
|
|
||||||
char *ttymsg __P((struct iovec *, int, char *, int));
|
void makemsg(const char *);
|
||||||
|
static void usage(void);
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
int
|
int
|
||||||
main(argc, argv)
|
main(int argc, char *argv[])
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
{
|
{
|
||||||
char *wallhost, res;
|
char *wallhost, res;
|
||||||
CLIENT *cl;
|
CLIENT *cl;
|
||||||
@ -108,7 +103,8 @@ main(argc, argv)
|
|||||||
|
|
||||||
tv.tv_sec = 15; /* XXX ?? */
|
tv.tv_sec = 15; /* XXX ?? */
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
if (clnt_call(cl, WALLPROC_WALL, xdr_wrapstring, &mbuf, xdr_void, &res, tv) != RPC_SUCCESS) {
|
if (clnt_call(cl, WALLPROC_WALL, xdr_wrapstring, &mbuf, xdr_void,
|
||||||
|
&res, tv) != RPC_SUCCESS) {
|
||||||
/*
|
/*
|
||||||
* An error occurred while calling the server.
|
* An error occurred while calling the server.
|
||||||
* Print error message and die.
|
* Print error message and die.
|
||||||
@ -116,19 +112,18 @@ main(argc, argv)
|
|||||||
errx(1, "%s", clnt_sperror(cl, wallhost));
|
errx(1, "%s", clnt_sperror(cl, wallhost));
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage()
|
usage(void)
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr, "usage: rwall hostname [file]\n");
|
fprintf(stderr, "usage: rwall hostname [file]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
makemsg(fname)
|
makemsg(const char *fname)
|
||||||
char *fname;
|
|
||||||
{
|
{
|
||||||
struct tm *lt;
|
struct tm *lt;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
@ -136,18 +131,24 @@ makemsg(fname)
|
|||||||
time_t now;
|
time_t now;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int fd;
|
int fd;
|
||||||
|
size_t mbufsize;
|
||||||
char *tty, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
|
char *tty, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64];
|
||||||
const char *whom;
|
const char *whom;
|
||||||
|
|
||||||
(void)snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXX", _PATH_TMP);
|
snprintf(tmpname, sizeof(tmpname), "%s/wall.XXXXXX", _PATH_TMP);
|
||||||
if ((fd = mkstemp(tmpname)) == -1 || !(fp = fdopen(fd, "r+")))
|
fd = mkstemp(tmpname);
|
||||||
|
fp = fdopen(fd, "r+");
|
||||||
|
if (fd == -1 || !fp)
|
||||||
err(1, "can't open temporary file");
|
err(1, "can't open temporary file");
|
||||||
(void)unlink(tmpname);
|
unlink(tmpname);
|
||||||
|
|
||||||
if (!(whom = getlogin()))
|
whom = getlogin();
|
||||||
whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
|
if (!whom) {
|
||||||
(void)gethostname(hostname, sizeof(hostname));
|
pw = getpwuid(getuid());
|
||||||
(void)time(&now);
|
whom = pw ? pw->pw_name : "???";
|
||||||
|
}
|
||||||
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
time(&now);
|
||||||
lt = localtime(&now);
|
lt = localtime(&now);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -157,12 +158,12 @@ makemsg(fname)
|
|||||||
* Which means that we may leave a non-blank character
|
* Which means that we may leave a non-blank character
|
||||||
* in column 80, but that can't be helped.
|
* in column 80, but that can't be helped.
|
||||||
*/
|
*/
|
||||||
(void)fprintf(fp, "Remote Broadcast Message from %s@%s\n",
|
fprintf(fp, "Remote Broadcast Message from %s@%s\n",
|
||||||
whom, hostname);
|
whom, hostname);
|
||||||
tty = ttyname(STDERR_FILENO);
|
tty = ttyname(STDERR_FILENO);
|
||||||
if (tty == NULL)
|
if (tty == NULL)
|
||||||
tty = "no tty";
|
tty = notty;
|
||||||
(void)fprintf(fp, " (%s) at %d:%02d ...\n", tty,
|
fprintf(fp, " (%s) at %d:%02d ...\n", tty,
|
||||||
lt->tm_hour, lt->tm_min);
|
lt->tm_hour, lt->tm_min);
|
||||||
|
|
||||||
putc('\n', fp);
|
putc('\n', fp);
|
||||||
@ -175,10 +176,11 @@ makemsg(fname)
|
|||||||
|
|
||||||
if (fstat(fd, &sbuf))
|
if (fstat(fd, &sbuf))
|
||||||
err(1, "can't stat temporary file");
|
err(1, "can't stat temporary file");
|
||||||
mbufsize = sbuf.st_size;
|
mbufsize = (size_t)sbuf.st_size;
|
||||||
if (!(mbuf = malloc((u_int)mbufsize)))
|
mbuf = malloc(mbufsize);
|
||||||
|
if (mbuf == NULL)
|
||||||
err(1, "out of memory");
|
err(1, "out of memory");
|
||||||
if (fread(mbuf, sizeof(*mbuf), mbufsize, fp) != mbufsize)
|
if (fread(mbuf, sizeof(*mbuf), mbufsize, fp) != mbufsize)
|
||||||
err(1, "can't read temporary file");
|
err(1, "can't read temporary file");
|
||||||
(void)close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user