- Move the prototype of ttymsg() into ttymsg.h. syslogd and talkd
also use this, and they shouldn't have to have their own prototypes. - Silence warnings about constness and signedness in ttymsg(). This includes changing the return value to a `const char *', and changing the types of `left' and `wret' (both byte counts) to ssize_t. Reviewed by: bde
This commit is contained in:
parent
8b0bff44c7
commit
728d043e5b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83242
@ -51,6 +51,8 @@ static const char rcsid[] =
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "ttymsg.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display the contents of a uio structure on a terminal. Used by wall(1),
|
* Display the contents of a uio structure on a terminal. Used by wall(1),
|
||||||
* syslogd(8), and talkd(8). Forks and finishes in child if write would block,
|
* syslogd(8), and talkd(8). Forks and finishes in child if write would block,
|
||||||
@ -58,17 +60,18 @@ static const char rcsid[] =
|
|||||||
* error; string is not newline-terminated. Various "normal" errors are
|
* error; string is not newline-terminated. Various "normal" errors are
|
||||||
* ignored (exclusive-use, lack of permission, etc.).
|
* ignored (exclusive-use, lack of permission, etc.).
|
||||||
*/
|
*/
|
||||||
char *
|
const char *
|
||||||
ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout)
|
ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout)
|
||||||
{
|
{
|
||||||
struct iovec localiov[7];
|
struct iovec localiov[7];
|
||||||
int cnt, fd, left, wret;
|
ssize_t left, wret;
|
||||||
|
int cnt, fd;
|
||||||
static char device[MAXNAMLEN] = _PATH_DEV;
|
static char device[MAXNAMLEN] = _PATH_DEV;
|
||||||
static char errbuf[1024];
|
static char errbuf[1024];
|
||||||
int forked;
|
int forked;
|
||||||
|
|
||||||
forked = 0;
|
forked = 0;
|
||||||
if (iovcnt > sizeof(localiov) / sizeof(localiov[0]))
|
if (iovcnt > (int)(sizeof(localiov) / sizeof(localiov[0])))
|
||||||
return ("too many iov's (change code in wall/ttymsg.c)");
|
return ("too many iov's (change code in wall/ttymsg.c)");
|
||||||
|
|
||||||
strlcpy(device + sizeof(_PATH_DEV) - 1, line, sizeof(device));
|
strlcpy(device + sizeof(_PATH_DEV) - 1, line, sizeof(device));
|
||||||
@ -91,7 +94,7 @@ ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout)
|
|||||||
return (errbuf);
|
return (errbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (cnt = left = 0; cnt < iovcnt; ++cnt)
|
for (cnt = 0, left = 0; cnt < iovcnt; ++cnt)
|
||||||
left += iov[cnt].iov_len;
|
left += iov[cnt].iov_len;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -105,7 +108,7 @@ ttymsg(struct iovec *iov, int iovcnt, const char *line, int tmout)
|
|||||||
iovcnt * sizeof(struct iovec));
|
iovcnt * sizeof(struct iovec));
|
||||||
iov = localiov;
|
iov = localiov;
|
||||||
}
|
}
|
||||||
for (cnt = 0; wret >= iov->iov_len; ++cnt) {
|
for (cnt = 0; (size_t)wret >= iov->iov_len; ++cnt) {
|
||||||
wret -= iov->iov_len;
|
wret -= iov->iov_len;
|
||||||
++iov;
|
++iov;
|
||||||
--iovcnt;
|
--iovcnt;
|
||||||
|
3
usr.bin/wall/ttymsg.h
Normal file
3
usr.bin/wall/ttymsg.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/* $FreeBSD$ */
|
||||||
|
|
||||||
|
const char *ttymsg(struct iovec *, int, const char *, int);
|
@ -67,9 +67,10 @@ static const char rcsid[] =
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utmp.h>
|
#include <utmp.h>
|
||||||
|
|
||||||
|
#include "ttymsg.h"
|
||||||
|
|
||||||
static void makemsg(char *);
|
static void makemsg(char *);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
char *ttymsg(struct iovec *, int, const char *, int);
|
|
||||||
|
|
||||||
#define IGNOREUSER "sleeper"
|
#define IGNOREUSER "sleeper"
|
||||||
|
|
||||||
@ -92,7 +93,8 @@ main(int argc, char *argv[])
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct wallgroup *g;
|
struct wallgroup *g;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
char *p, **np;
|
char **np;
|
||||||
|
const char *p;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
char line[sizeof(utmp.ut_line) + 1];
|
char line[sizeof(utmp.ut_line) + 1];
|
||||||
char username[sizeof(utmp.ut_name) + 1];
|
char username[sizeof(utmp.ut_name) + 1];
|
||||||
|
Loading…
Reference in New Issue
Block a user