DragonFly BSD
DragonFly submit List (threaded) for 2005-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Patch to getty (WARNS=6)


From: "Kevin M. Kilbride" <kmk@xxxxxxx>
Date: Thu, 24 Feb 2005 20:48:02 -0800

This patch brings getty into WARNS=6 compliance under both GCC 2.95 and GCC 3.4. It depends upon the patch posted prior to 'constify' the getcap facility.

diff -u libexec/getty_orig/chat.c libexec/getty/chat.c
--- libexec/getty_orig/chat.c    2004-03-25 16:30:12.000000000 -0800
+++ libexec/getty/chat.c    2005-02-23 12:15:05.000000000 -0800
@@ -32,6 +32,8 @@
#include <sys/resource.h>
#include <sys/ttydefaults.h>
#include <sys/utsname.h>
+#include <sys/socket.h>
+
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -42,10 +44,9 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
-#include <time.h>
#include <termios.h>
+#include <time.h>
#include <unistd.h>
-#include <sys/socket.h>

#include "extern.h"

@@ -71,7 +72,7 @@
static int    getdigit (unsigned char **, int, int);
static char   **read_chat (char **);
static char   *cleanchr (char **, unsigned char);
-static char   *cleanstr (const unsigned char *, int);
+static const char *cleanstr (const unsigned char *, int);
static const char *result (int);
static int    chat_expect (const char *);
static int    chat_send (char const *);
@@ -85,7 +86,7 @@
 */

static void
-chat_alrm(int signo)
+chat_alrm(__attribute__((unused)) int signo)
{
    int on = 1;

@@ -280,18 +281,18 @@
 * clean a string for display (ctrl/meta characters)
 */

-static char *
+static const char *
cleanstr(const unsigned char *s, int l)
{
    static unsigned char * tmp = NULL;
    static int tmplen = 0;

-    if (tmplen < l * 4 + 1)
-        tmp = realloc(tmp, tmplen = l * 4 + 1);
+    if (tmplen < l * 4 + 3)
+        tmp = realloc(tmp, tmplen = l * 4 + 3);

    if (tmp == NULL) {
        tmplen = 0;
-        return (char *)"(mem alloc error)";
+        return "(mem alloc error)";
    } else {
        int i = 0;
        char * p = tmp;
diff -u libexec/getty_orig/init.c libexec/getty/init.c
--- libexec/getty_orig/init.c    2003-06-16 21:27:07.000000000 -0700
+++ libexec/getty/init.c    2005-02-23 08:44:43.000000000 -0800
@@ -41,6 +41,7 @@
 * Melbourne getty.
 */
#include <termios.h>
+
#include "extern.h"
#include "gettytab.h"
#include "pathnames.h"
@@ -51,100 +52,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 }
};
diff -u libexec/getty_orig/main.c libexec/getty/main.c
--- libexec/getty_orig/main.c    2004-03-25 16:30:12.000000000 -0800
+++ libexec/getty/main.c    2005-02-23 12:15:45.000000000 -0800
@@ -42,6 +42,7 @@
#include <sys/resource.h>
#include <sys/ttydefaults.h>
#include <sys/utsname.h>
+
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -136,13 +137,15 @@
static void    setttymode (const char *, int);
static void    setdefttymode (const char *);
static int    opentty (const char *, int);
+extern char    **environ;
+extern char    editedhost[];

int main (int, char **);

jmp_buf timeout;

static void
-dingdong(int signo)
+dingdong(__attribute__((unused)) int signo)
{
    alarm(0);
    longjmp(timeout, 1);
@@ -151,7 +154,7 @@
jmp_buf    intrupt;

static void
-interrupt(int signo)
+interrupt(__attribute__((unused)) int signo)
{
    longjmp(intrupt, 1);
}
@@ -160,7 +163,7 @@
 * Action to take when getty is running too long.
 */
static void
-timeoverrun(int signo)
+timeoverrun(__attribute__((unused)) int signo)
{
    syslog(LOG_ERR, "getty exiting due to excessive running time");
    exit(1);
@@ -169,11 +172,10 @@
int
main(int argc, char **argv)
{
-    extern    char **environ;
-    const char *tname;
-    int first_sleep = 1, first_time = 1;
+    const char * volatile tname = "default";
+    volatile int first_sleep = 1, first_time = 1;
    struct rlimit limit;
-    int rval;
+    volatile int rval = 0;

    signal(SIGINT, SIG_IGN);
    signal(SIGQUIT, SIG_IGN);
@@ -182,7 +184,7 @@
    gethostname(hostname, sizeof(hostname) - 1);
    hostname[sizeof(hostname) - 1] = '\0';
    if (hostname[0] == '\0')
-        strcpy(hostname, "Amnesiac");
+        strncpy(hostname, "Amnesiac", MAXHOSTNAMELEN);

    /*
     * Limit running time to deal with broken or dead lines.
@@ -194,7 +196,6 @@

    gettable("default", defent);
    gendefaults();
-    tname = "default";
    if (argc > 1)
        tname = argv[1];

@@ -206,9 +207,9 @@
     * J. Gettys - MIT Project Athena.
     */
    if (argc <= 2 || strcmp(argv[2], "-") == 0)
-        strcpy(ttyn, ttyname(STDIN_FILENO));
+        strncpy(ttyn, ttyname(STDIN_FILENO), sizeof(ttyn));
    else {
-        strcpy(ttyn, dev);
+        strncpy(ttyn, dev, sizeof(ttyn));
        strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
        if (strcmp(argv[0], "+") != 0) {
        chown(ttyn, 0, 0);
@@ -231,17 +232,17 @@
        }

        if (AC) {
-            int i, rfds;
-            struct timeval timeout;
+            int i;
+            fd_set rfds;
+            struct timeval timeout_val;

            if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
                exit(1);
                setdefttymode(tname);
-                rfds = 1 << 0;    /* FD_SET */
-                timeout.tv_sec = RT;
-                timeout.tv_usec = 0;
-                i = select(32, (fd_set*)&rfds, (fd_set*)NULL,
-                           (fd_set*)NULL, RT ? &timeout : NULL);
+            FD_SET(1, &rfds);
+                timeout_val.tv_sec = RT;
+                timeout_val.tv_usec = 0;
+                i = select(32, &rfds, 0, 0, (RT ? &timeout_val : 0));
                if (i < 0) {
                syslog(LOG_ERR, "select %s: %m", ttyn);
            } else if (i == 0) {
@@ -338,7 +339,6 @@
        if (AL) {
            const char *p = AL;
            char *q = name;
-            int n = sizeof name;

            while (*p && q < &name[sizeof name - 1]) {
                if (isupper(*p))
@@ -409,22 +409,22 @@
}

static int
-opentty(const char *ttyn, int flags)
+opentty(const char *ttynm, int flags)
{
-    int i, j = 0;
+    int i = 0, j = 0;
    int failopenlogged = 0;

-    while (j < 10 && (i = open(ttyn, flags)) == -1)
+    while (j < 10 && (i = open(ttynm, flags)) == -1)
    {
        if (((j % 10) == 0) && (errno != ENXIO || !failopenlogged)) {
-            syslog(LOG_ERR, "open %s: %m", ttyn);
+            syslog(LOG_ERR, "open %s: %m", ttynm);
            failopenlogged = 1;
        }
        j++;
        sleep(60);
    }
    if (i == -1) {
-        syslog(LOG_ERR, "open %s: %m", ttyn);
+        syslog(LOG_ERR, "open %s: %m", ttynm);
        return 0;
    }
    else {
@@ -435,7 +435,7 @@
                return 0;
            }
            if (login_tty(i) < 0) {
-                syslog(LOG_ERR, "login_tty %s: %m", ttyn);
+                syslog(LOG_ERR, "login_tty %s: %m", ttynm);
                close(i);
                return 0;
            }
@@ -497,8 +497,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
@@ -690,7 +690,7 @@
static char *
getline(int fd)
{
-    int i = 0;
+    unsigned i = 0;
    static char linebuf[512];

    /*
@@ -714,7 +714,6 @@
static void
putf(const char *cp)
{
-    extern char editedhost[];
    time_t t;
    char *slash, db[100];

diff -u libexec/getty_orig/subr.c libexec/getty/subr.c
--- libexec/getty_orig/subr.c    2004-03-25 16:30:12.000000000 -0800
+++ libexec/getty/subr.c    2005-02-23 12:25:13.000000000 -0800
@@ -39,17 +39,19 @@
 * Melbourne getty.
 */
#define COMPAT_43
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+
#ifdef DEBUG
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <termios.h>
#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <syslog.h>

#include "gettytab.h"
#include "pathnames.h"
@@ -72,7 +74,7 @@
    long n;
    int l;
    char *p;
-    char *msg = NULL;
+    const char *msg = NULL;
    const char *dba[2];

    static int firsttime = 1;
@@ -105,7 +107,7 @@
        firsttime = 0;
    }

-    switch (cgetent(&buf, (char **)dba, (char *)name)) {
+    switch (cgetent(&buf, dba, name)) {
    case 1:
        msg = "%s: couldn't resolve 'tc=' in gettytab '%s'";
    case 0:
@@ -130,7 +132,7 @@
    }

    for (sp = gettystrs; sp->field; sp++) {
-        if ((l = cgetstr(buf, (char*)sp->field, &p)) >= 0) {
+        if ((l = cgetstr(buf, sp->field, &p)) >= 0) {
            if (sp->value) {
                /* prefer existing value */
                if (strcmp(p, sp->value) != 0)
@@ -148,7 +150,7 @@
    }

    for (np = gettynums; np->field; np++) {
-        if (cgetnum(buf, (char*)np->field, &n) == -1)
+        if (cgetnum(buf, np->field, &n) == -1)
            np->set = 0;
        else {
            np->set = 1;
@@ -157,7 +159,7 @@
    }

    for (fp = gettyflags; fp->field; fp++) {
-        if (cgetcap(buf, (char *)fp->field, ':') == NULL)
+        if (cgetcap(buf, fp->field, ':') == NULL)
            fp->set = 0;
        else {
            fp->set = 1;
@@ -694,7 +696,7 @@
    { 57600, B57600 },
    { 115200, B115200 },
    { 230400, B230400 },
-    { 0 }
+    { 0, 0 }
};

int
@@ -757,7 +759,7 @@
    { "B4800",    "std.4800" },
    { "B9600",    "std.9600" },
    { "B19200",    "std.19200" },
-    { 0 }
+    { 0, 0 }
};

const char *
@@ -766,7 +768,7 @@
    char c, baud[20];
    const char *type = "default";
    struct portselect *ps;
-    int len;
+    unsigned len;

    alarm(5*60);
    for (len = 0; len < sizeof (baud) - 1; len++) {
@@ -797,17 +799,16 @@
const char *
autobaud(void)
{
-    int rfds;
+    fd_set rfds;
    struct timeval timeout;
    char c;
    const char *type = "9600-baud";

    (void)tcflush(0, TCIOFLUSH);
-    rfds = 1 << 0;
+    FD_SET(1, &rfds);
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
-    if (select(32, (fd_set *)&rfds, (fd_set *)NULL,
-        (fd_set *)NULL, &timeout) <= 0)
+    if (select(32, &rfds, 0, 0, &timeout) <= 0)
        return (type);
    if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char))
        return (type);




[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]