[PATCH] libexec/getty WARNS=6 cleanup
Joe Talbott
josepht at cstone.net
Thu Apr 28 07:54:47 PDT 2005
Here's a patch for libexec/getty for your review.
Joe
Index: Makefile
===================================================================
RCS file: /home/dcvs/src/libexec/getty/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- Makefile 17 Jun 2003 04:27:07 -0000 1.2
+++ Makefile 27 Apr 2005 20:44:44 -0000
@@ -9,6 +9,7 @@
MAN= gettytab.5 ttys.5 getty.8
# for the paranoid:
#CFLAGS+= -Wall -Wstrict-prototypes -Wno-unused -Wwrite-strings
+WARNS?= 6
.include <bsd.prog.mk>
Index: chat.c
===================================================================
RCS file: /home/dcvs/src/libexec/getty/chat.c,v
retrieving revision 1.4
diff -u -r1.4 chat.c
--- chat.c 26 Mar 2004 00:30:12 -0000 1.4
+++ chat.c 27 Apr 2005 20:44:44 -0000
@@ -85,7 +85,7 @@
*/
static void
-chat_alrm(int signo)
+chat_alrm(int signo __unused)
{
int on = 1;
Index: init.c
===================================================================
RCS file: /home/dcvs/src/libexec/getty/init.c,v
retrieving revision 1.2
diff -u -r1.2 init.c
--- init.c 17 Jun 2003 04:27:07 -0000 1.2
+++ init.c 28 Apr 2005 14:20:31 -0000
@@ -51,100 +51,100 @@
static char datefmt[] = "%+";
struct gettystrs gettystrs[] = {
- { "nx" }, /* next table */
- { "cl" }, /* screen clear characters */
- { "im" }, /* initial message */
- { "lm", loginmsg }, /* login message */
- { "er", &tmode.c_cc[VERASE] }, /* erase character */
- { "kl", &tmode.c_cc[VKILL] }, /* kill character */
- { "et", &tmode.c_cc[VEOF] }, /* eof chatacter (eot) */
- { "pc", nullstr }, /* pad character */
- { "tt" }, /* terminal type */
- { "ev" }, /* enviroment */
- { "lo", loginprg }, /* login program */
- { "hn", hostname }, /* host name */
- { "he" }, /* host name edit */
- { "in", &tmode.c_cc[VINTR] }, /* interrupt char */
- { "qu", &tmode.c_cc[VQUIT] }, /* quit char */
- { "xn", &tmode.c_cc[VSTART] }, /* XON (start) char */
- { "xf", &tmode.c_cc[VSTOP] }, /* XOFF (stop) char */
- { "bk", &tmode.c_cc[VEOL] }, /* brk char (alt \n) */
- { "su", &tmode.c_cc[VSUSP] }, /* suspend char */
- { "ds", &tmode.c_cc[VDSUSP] }, /* delayed suspend */
- { "rp", &tmode.c_cc[VREPRINT] },/* reprint char */
- { "fl", &tmode.c_cc[VDISCARD] },/* flush output */
- { "we", &tmode.c_cc[VWERASE] }, /* word erase */
- { "ln", &tmode.c_cc[VLNEXT] }, /* literal next */
- { "Lo" }, /* locale for strftime() */
- { "pp" }, /* ppp login program */
- { "if" }, /* sysv-like 'issue' filename */
- { "ic" }, /* modem init-chat */
- { "ac" }, /* modem answer-chat */
- { "al" }, /* user to auto-login */
- { "df", datefmt}, /* format for strftime() */
- { 0 }
+ { "nx", 0, 0 }, /* next table */
+ { "cl", 0, 0 }, /* screen clear characters */
+ { "im", 0, 0 }, /* initial message */
+ { "lm", loginmsg, 0 }, /* login message */
+ { "er", &tmode.c_cc[VERASE], 0 }, /* erase character */
+ { "kl", &tmode.c_cc[VKILL], 0 }, /* kill character */
+ { "et", &tmode.c_cc[VEOF], 0 }, /* eof chatacter (eot) */
+ { "pc", nullstr, 0 }, /* pad character */
+ { "tt", 0, 0 }, /* terminal type */
+ { "ev", 0, 0 }, /* enviroment */
+ { "lo", loginprg, 0 }, /* login program */
+ { "hn", hostname, 0 }, /* host name */
+ { "he", 0, 0 }, /* host name edit */
+ { "in", &tmode.c_cc[VINTR], 0 }, /* interrupt char */
+ { "qu", &tmode.c_cc[VQUIT], 0 }, /* quit char */
+ { "xn", &tmode.c_cc[VSTART], 0 }, /* XON (start) char */
+ { "xf", &tmode.c_cc[VSTOP], 0 }, /* XOFF (stop) char */
+ { "bk", &tmode.c_cc[VEOL], 0 }, /* brk char (alt \n) */
+ { "su", &tmode.c_cc[VSUSP], 0 }, /* suspend char */
+ { "ds", &tmode.c_cc[VDSUSP], 0 }, /* delayed suspend */
+ { "rp", &tmode.c_cc[VREPRINT], 0 },/* reprint char */
+ { "fl", &tmode.c_cc[VDISCARD], 0 },/* flush output */
+ { "we", &tmode.c_cc[VWERASE], 0 }, /* word erase */
+ { "ln", &tmode.c_cc[VLNEXT], 0 }, /* literal next */
+ { "Lo", 0, 0 }, /* locale for strftime() */
+ { "pp", 0, 0 }, /* ppp login program */
+ { "if", 0, 0 }, /* sysv-like 'issue' filename */
+ { "ic", 0, 0 }, /* modem init-chat */
+ { "ac", 0, 0 }, /* modem answer-chat */
+ { "al", 0, 0 }, /* user to auto-login */
+ { "df", datefmt, 0}, /* format for strftime() */
+ { 0, 0, 0 }
};
struct gettynums gettynums[] = {
- { "is" }, /* input speed */
- { "os" }, /* output speed */
- { "sp" }, /* both speeds */
- { "nd" }, /* newline delay */
- { "cd" }, /* carriage-return delay */
- { "td" }, /* tab delay */
- { "fd" }, /* form-feed delay */
- { "bd" }, /* backspace delay */
- { "to" }, /* timeout */
- { "f0" }, /* output flags */
- { "f1" }, /* input flags */
- { "f2" }, /* user mode flags */
- { "pf" }, /* delay before flush at 1st prompt */
- { "c0" }, /* output c_flags */
- { "c1" }, /* input c_flags */
- { "c2" }, /* user mode c_flags */
- { "i0" }, /* output i_flags */
- { "i1" }, /* input i_flags */
- { "i2" }, /* user mode i_flags */
- { "l0" }, /* output l_flags */
- { "l1" }, /* input l_flags */
- { "l2" }, /* user mode l_flags */
- { "o0" }, /* output o_flags */
- { "o1" }, /* input o_flags */
- { "o2" }, /* user mode o_flags */
- { "de" }, /* delay before sending 1st prompt */
- { "rt" }, /* reset timeout */
- { "ct" }, /* chat script timeout */
- { "dc" }, /* debug chat script value */
- { 0 }
+ { "is", 0, 0, 0 }, /* input speed */
+ { "os", 0, 0, 0 }, /* output speed */
+ { "sp", 0, 0, 0 }, /* both speeds */
+ { "nd", 0, 0, 0 }, /* newline delay */
+ { "cd", 0, 0, 0 }, /* carriage-return delay */
+ { "td", 0, 0, 0 }, /* tab delay */
+ { "fd", 0, 0, 0 }, /* form-feed delay */
+ { "bd", 0, 0, 0 }, /* backspace delay */
+ { "to", 0, 0, 0 }, /* timeout */
+ { "f0", 0, 0, 0 }, /* output flags */
+ { "f1", 0, 0, 0 }, /* input flags */
+ { "f2", 0, 0, 0 }, /* user mode flags */
+ { "pf", 0, 0, 0 }, /* delay before flush at 1st prompt */
+ { "c0", 0, 0, 0 }, /* output c_flags */
+ { "c1", 0, 0, 0 }, /* input c_flags */
+ { "c2", 0, 0, 0 }, /* user mode c_flags */
+ { "i0", 0, 0, 0 }, /* output i_flags */
+ { "i1", 0, 0, 0 }, /* input i_flags */
+ { "i2", 0, 0, 0 }, /* user mode i_flags */
+ { "l0", 0, 0, 0 }, /* output l_flags */
+ { "l1", 0, 0, 0 }, /* input l_flags */
+ { "l2", 0, 0, 0 }, /* user mode l_flags */
+ { "o0", 0, 0, 0 }, /* output o_flags */
+ { "o1", 0, 0, 0 }, /* input o_flags */
+ { "o2", 0, 0, 0 }, /* user mode o_flags */
+ { "de", 0, 0, 0 }, /* delay before sending 1st prompt */
+ { "rt", 0, 0, 0 }, /* reset timeout */
+ { "ct", 0, 0, 0 }, /* chat script timeout */
+ { "dc", 0, 0, 0 }, /* debug chat script value */
+ { 0, 0, 0, 0 }
};
struct gettyflags gettyflags[] = {
- { "ht", 0 }, /* has tabs */
- { "nl", 1 }, /* has newline char */
- { "ep", 0 }, /* even parity */
- { "op", 0 }, /* odd parity */
- { "ap", 0 }, /* any parity */
- { "ec", 1 }, /* no echo */
- { "co", 0 }, /* console special */
- { "cb", 0 }, /* crt backspace */
- { "ck", 0 }, /* crt kill */
- { "ce", 0 }, /* crt erase */
- { "pe", 0 }, /* printer erase */
- { "rw", 1 }, /* don't use raw */
- { "xc", 1 }, /* don't ^X ctl chars */
- { "lc", 0 }, /* terminal las lower case */
- { "uc", 0 }, /* terminal has no lower case */
- { "ig", 0 }, /* ignore garbage */
- { "ps", 0 }, /* do port selector speed select */
- { "hc", 1 }, /* don't set hangup on close */
- { "ub", 0 }, /* unbuffered output */
- { "ab", 0 }, /* auto-baud detect with '\r' */
- { "dx", 0 }, /* set decctlq */
- { "np", 0 }, /* no parity at all (8bit chars) */
- { "mb", 0 }, /* do MDMBUF flow control */
- { "hw", 0 }, /* do CTSRTS flow control */
- { "nc", 0 }, /* set clocal (no carrier) */
- { "pl", 0 }, /* use PPP instead of login(1) */
- { 0 }
+ { "ht", 0, 0, 0, 0 }, /* has tabs */
+ { "nl", 1, 0, 0, 0 }, /* has newline char */
+ { "ep", 0, 0, 0, 0 }, /* even parity */
+ { "op", 0, 0, 0, 0 }, /* odd parity */
+ { "ap", 0, 0, 0, 0 }, /* any parity */
+ { "ec", 1, 0, 0, 0 }, /* no echo */
+ { "co", 0, 0, 0, 0 }, /* console special */
+ { "cb", 0, 0, 0, 0 }, /* crt backspace */
+ { "ck", 0, 0, 0, 0 }, /* crt kill */
+ { "ce", 0, 0, 0, 0 }, /* crt erase */
+ { "pe", 0, 0, 0, 0 }, /* printer erase */
+ { "rw", 1, 0, 0, 0 }, /* don't use raw */
+ { "xc", 1, 0, 0, 0 }, /* don't ^X ctl chars */
+ { "lc", 0, 0, 0, 0 }, /* terminal las lower case */
+ { "uc", 0, 0, 0, 0 }, /* terminal has no lower case */
+ { "ig", 0, 0, 0, 0 }, /* ignore garbage */
+ { "ps", 0, 0, 0, 0 }, /* do port selector speed select */
+ { "hc", 1, 0, 0, 0 }, /* don't set hangup on close */
+ { "ub", 0, 0, 0, 0 }, /* unbuffered output */
+ { "ab", 0, 0, 0, 0 }, /* auto-baud detect with '\r' */
+ { "dx", 0, 0, 0, 0 }, /* set decctlq */
+ { "np", 0, 0, 0, 0 }, /* no parity at all (8bit chars) */
+ { "mb", 0, 0, 0, 0 }, /* do MDMBUF flow control */
+ { "hw", 0, 0, 0, 0 }, /* do CTSRTS flow control */
+ { "nc", 0, 0, 0, 0 }, /* set clocal (no carrier) */
+ { "pl", 0, 0, 0, 0 }, /* use PPP instead of login(1) */
+ { 0, 0, 0, 0, 0 }
};
Index: main.c
===================================================================
RCS file: /home/dcvs/src/libexec/getty/main.c,v
retrieving revision 1.4
diff -u -r1.4 main.c
--- main.c 26 Mar 2004 00:30:12 -0000 1.4
+++ main.c 27 Apr 2005 20:44:44 -0000
@@ -142,7 +142,7 @@
jmp_buf timeout;
static void
-dingdong(int signo)
+dingdong(int signo __unused)
{
alarm(0);
longjmp(timeout, 1);
@@ -151,7 +151,7 @@
jmp_buf intrupt;
static void
-interrupt(int signo)
+interrupt(int signo __unused)
{
longjmp(intrupt, 1);
}
@@ -160,20 +160,23 @@
* Action to take when getty is running too long.
*/
static void
-timeoverrun(int signo)
+timeoverrun(int signo __unused)
{
syslog(LOG_ERR, "getty exiting due to excessive running time");
exit(1);
}
+extern char **environ;
+extern char editedhost[];
+
int
main(int argc, char **argv)
{
- extern char **environ;
- const char *tname;
- int first_sleep = 1, first_time = 1;
+ const char * volatile tname;
+ volatile int first_sleep = 1;
+ volatile int first_time = 1;
struct rlimit limit;
- int rval;
+ volatile int rval = 0;
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
@@ -187,10 +190,10 @@
/*
* Limit running time to deal with broken or dead lines.
*/
- (void)signal(SIGXCPU, timeoverrun);
+ signal(SIGXCPU, timeoverrun);
limit.rlim_max = RLIM_INFINITY;
limit.rlim_cur = GETTY_TIMEOUT;
- (void)setrlimit(RLIMIT_CPU, &limit);
+ setrlimit(RLIMIT_CPU, &limit);
gettable("default", defent);
gendefaults();
@@ -225,34 +228,34 @@
setdefttymode(tname);
if (getty_chat(IC, CT, DC) > 0) {
syslog(LOG_ERR, "modem init problem on %s", ttyn);
- (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
+ tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(1);
}
}
if (AC) {
int i, rfds;
- struct timeval timeout;
+ struct timeval tout;
if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
exit(1);
setdefttymode(tname);
rfds = 1 << 0; /* FD_SET */
- timeout.tv_sec = RT;
- timeout.tv_usec = 0;
+ tout.tv_sec = RT;
+ tout.tv_usec = 0;
i = select(32, (fd_set*)&rfds, (fd_set*)NULL,
- (fd_set*)NULL, RT ? &timeout : NULL);
+ (fd_set*)NULL, RT ? &tout : NULL);
if (i < 0) {
syslog(LOG_ERR, "select %s: %m", ttyn);
} else if (i == 0) {
syslog(LOG_NOTICE, "recycle tty %s", ttyn);
- (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
+ tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(0); /* recycle for init */
}
i = getty_chat(AC, CT, DC);
if (i > 0) {
syslog(LOG_ERR, "modem answer problem on %s", ttyn);
- (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
+ tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(1);
}
} else { /* maybe blocking open */
@@ -290,7 +293,7 @@
if (first_sleep && DE) {
sleep(DE);
/* remove any noise */
- (void)tcflush(STDIN_FILENO, TCIOFLUSH);
+ tcflush(STDIN_FILENO, TCIOFLUSH);
}
first_sleep = 0;
@@ -328,7 +331,7 @@
if (setjmp(timeout)) {
cfsetispeed(&tmode, B0);
cfsetospeed(&tmode, B0);
- (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
+ tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
exit(1);
}
if (TO) {
@@ -338,9 +341,8 @@
if (AL) {
const char *p = AL;
char *q = name;
- int n = sizeof name;
- while (*p && q < &name[sizeof name - 1]) {
+ while (*p && q < &name[sizeof(name) - 1]) {
if (isupper(*p))
upper = 1;
else if (islower(*p))
@@ -356,7 +358,7 @@
alarm(0);
limit.rlim_max = RLIM_INFINITY;
limit.rlim_cur = RLIM_INFINITY;
- (void)setrlimit(RLIMIT_CPU, &limit);
+ setrlimit(RLIMIT_CPU, &limit);
execle(PP, "ppplogin", ttyn, (char *) 0, env);
syslog(LOG_ERR, "%s: %m", PP);
exit(1);
@@ -394,7 +396,7 @@
limit.rlim_max = RLIM_INFINITY;
limit.rlim_cur = RLIM_INFINITY;
- (void)setrlimit(RLIMIT_CPU, &limit);
+ setrlimit(RLIMIT_CPU, &limit);
execle(LO, "login", AL ? "-fp" : "-p", name,
(char *) 0, env);
syslog(LOG_ERR, "%s: %m", LO);
@@ -409,22 +411,23 @@
}
static int
-opentty(const char *ttyn, int flags)
+opentty(const char *tname, int flags)
{
- int i, j = 0;
+ int i = 0;
+ int j = 0;
int failopenlogged = 0;
- while (j < 10 && (i = open(ttyn, flags)) == -1)
+ while (j < 10 && (i = open(tname, flags)) == -1)
{
if (((j % 10) == 0) && (errno != ENXIO || !failopenlogged)) {
- syslog(LOG_ERR, "open %s: %m", ttyn);
+ syslog(LOG_ERR, "open %s: %m", tname);
failopenlogged = 1;
}
j++;
sleep(60);
}
if (i == -1) {
- syslog(LOG_ERR, "open %s: %m", ttyn);
+ syslog(LOG_ERR, "open %s: %m", tname);
return 0;
}
else {
@@ -435,7 +438,7 @@
return 0;
}
if (login_tty(i) < 0) {
- syslog(LOG_ERR, "login_tty %s: %m", ttyn);
+ syslog(LOG_ERR, "login_tty %s: %m", tname);
close(i);
return 0;
}
@@ -448,7 +451,7 @@
setdefttymode(const char *tname)
{
if (tcgetattr(STDIN_FILENO, &tmode) < 0) {
- syslog(LOG_ERR, "tcgetattr %s: %m", ttyn);
+ syslog(LOG_ERR, "tcgetattr %s: %m", tname);
exit(1);
}
tmode.c_iflag = TTYDEF_IFLAG;
@@ -468,7 +471,7 @@
if (OPset || EPset || APset)
APset++, OPset++, EPset++;
setdefaults();
- (void)tcflush(STDIN_FILENO, TCIOFLUSH); /* clear out the crap */
+ tcflush(STDIN_FILENO, TCIOFLUSH); /* clear out the crap */
ioctl(STDIN_FILENO, FIONBIO, &off); /* turn off non-blocking mode */
ioctl(STDIN_FILENO, FIOASYNC, &off); /* ditto for async mode */
@@ -485,7 +488,7 @@
if (raw)
cfmakeraw(&tmode);
if (tcsetattr(STDIN_FILENO, TCSANOW, &tmode) < 0) {
- syslog(LOG_ERR, "tcsetattr %s: %m", ttyn);
+ syslog(LOG_ERR, "tcsetattr %s: %m", tname);
exit(1);
}
}
@@ -497,8 +500,8 @@
int c;
char *np;
unsigned char cs;
- int ppp_state = 0;
- int ppp_connection = 0;
+ volatile int ppp_state = 0;
+ volatile int ppp_connection = 0;
/*
* Interrupt may happen if we use CBREAK mode
@@ -557,7 +560,7 @@
if (c == EOT || c == CTRL('d'))
exit(1);
- if (c == '\r' || c == '\n' || np >= &name[sizeof name-1]) {
+ if (c == '\r' || c == '\n' || np >= &name[sizeof(name) - 1]) {
putf("\r\n");
break;
}
@@ -690,14 +693,14 @@
static char *
getline(int fd)
{
- int i = 0;
+ size_t i = 0;
static char linebuf[512];
/*
* This is certainly slow, but it avoids having to include
* stdio.h unnecessarily. Issue files should be small anyway.
*/
- while (i < (sizeof linebuf - 3) && read(fd, linebuf+i, 1)==1) {
+ while (i < (sizeof(linebuf) - 3) && read(fd, linebuf+i, 1)==1) {
if (linebuf[i] == '\n') {
/* Don't rely on newline mode, assume raw */
linebuf[i++] = '\r';
@@ -714,7 +717,6 @@
static void
putf(const char *cp)
{
- extern char editedhost[];
time_t t;
char *slash, db[100];
@@ -744,10 +746,10 @@
case 'd': {
t = (time_t)0;
- (void)time(&t);
+ time(&t);
if (Lo)
- (void)setlocale(LC_TIME, Lo);
- (void)strftime(db, sizeof(db), DF, localtime(&t));
+ setlocale(LC_TIME, Lo);
+ strftime(db, sizeof(db), DF, localtime(&t));
puts(db);
break;
Index: subr.c
===================================================================
RCS file: /home/dcvs/src/libexec/getty/subr.c,v
retrieving revision 1.4
diff -u -r1.4 subr.c
--- subr.c 26 Mar 2004 00:30:12 -0000 1.4
+++ subr.c 28 Apr 2005 14:21:30 -0000
@@ -72,7 +72,7 @@
long n;
int l;
char *p;
- char *msg = NULL;
+ const char *msg = NULL;
const char *dba[2];
static int firsttime = 1;
@@ -694,7 +694,7 @@
{ 57600, B57600 },
{ 115200, B115200 },
{ 230400, B230400 },
- { 0 }
+ { 0, 0 }
};
int
@@ -757,7 +757,7 @@
{ "B4800", "std.4800" },
{ "B9600", "std.9600" },
{ "B19200", "std.19200" },
- { 0 }
+ { 0, 0 }
};
const char *
@@ -766,7 +766,7 @@
char c, baud[20];
const char *type = "default";
struct portselect *ps;
- int len;
+ size_t len;
alarm(5*60);
for (len = 0; len < sizeof (baud) - 1; len++) {
More information about the Submit
mailing list