]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/ttyutils: add default chardata
authorWerner Fink <werner@suse.de>
Tue, 8 Jan 2013 14:38:40 +0000 (15:38 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 8 Jan 2013 14:42:12 +0000 (15:42 +0100)
this one moves the init_chardata to include/ttyutils.h as well as to
lib/include/ttyutils.c.  Also the macros CTL/CTRL are fixed in
agetty.c and sulogin.c to use the XOR variant CTL.

[kzak@redhat.com: use macro rather than global variable for default
                  chardata]

Signed-off-by: Werner Fink <werner@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/ttyutils.h
login-utils/sulogin-consoles.c
login-utils/sulogin-consoles.h
login-utils/sulogin.c
term-utils/agetty.c

index 3ed7883597c077d08f6ce0a9fab403839e6d09e0..021156d3e71ce3346527756e2cb46012cb2e76d5 100644 (file)
 #include <sys/ioctl.h>
 #endif
 
+/* Some shorthands for control characters. */
+#define CTL(x)         ((x) ^ 0100)    /* Assumes ASCII dialect */
+#define CR             CTL('M')        /* carriage return */
+#define NL             CTL('J')        /* line feed */
+#define BS             CTL('H')        /* back space */
+#define DEL            CTL('?')        /* delete */
+
+/* Defaults for line-editing etc. characters; you may want to change these. */
+#define DEF_ERASE      DEL             /* default erase character */
+#define DEF_INTR       CTL('C')        /* default interrupt character */
+#define DEF_QUIT       CTL('\\')       /* default quit char */
+#define DEF_KILL       CTL('U')        /* default kill char */
+#define DEF_EOF                CTL('D')        /* default EOF char */
+#define DEF_EOL                0
+#define DEF_SWITCH     0               /* default switch char */
+
 /* Storage for things detected while the login name was read. */
 struct chardata {
        int erase;              /* erase character */
@@ -23,6 +39,14 @@ struct chardata {
        int capslock;           /* upper case without lower case */
 };
 
+#define INIT_CHARDATA(ptr) do {              \
+               (ptr)->erase    = DEF_ERASE; \
+               (ptr)->kill     = DEF_KILL;  \
+               (ptr)->eol      = CTRL('r'); \
+               (ptr)->parity   = 0;         \
+               (ptr)->capslock = 0;         \
+       } while (0)
+
 extern int get_terminal_width(void);
 extern int get_terminal_name(const char **path, const char **name, const char **number);
 
index e1d36711c00c11f4aa230fd1489122893946e6b3..b519f7f250ca92c986f12e49c2b94fc5979fff44 100644 (file)
@@ -281,12 +281,6 @@ __attribute__((__nonnull__,__hot__))
 #endif
 int append_console(struct list_head *consoles, const char *name)
 {
-       static const struct chardata initcp = {
-               .erase  = CERASE,
-               .kill   = CKILL,
-               .eol    = CTRL('r'),
-               .parity = 0
-       };
        struct console *restrict tail;
        struct console *last = NULL;
 
@@ -300,6 +294,7 @@ int append_console(struct list_head *consoles, const char *name)
                return -ENOMEM;
 
        INIT_LIST_HEAD(&tail->entry);
+       INIT_CHARDATA(&tail->cp);
 
        list_add_tail(&tail->entry, consoles);
        tail->tty = ((char *) tail) + alignof(struct console);
@@ -311,7 +306,6 @@ int append_console(struct list_head *consoles, const char *name)
        tail->id = last ? last->id + 1 : 0;
        tail->pid = 0;
        memset(&tail->tio, 0, sizeof(tail->tio));
-       memcpy(&tail->cp, &initcp, sizeof(struct chardata));
 
        return 0;
 }
index c2f95eac7984138607ac5cb4c8676642e85610a7..f762e873aac780c1d4ab776b4c8d4dfc6beac372 100644 (file)
@@ -28,8 +28,8 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <termios.h>
-#include <list.h>
 
+#include "list.h"
 #include "ttyutils.h"
 
 struct console {
index 02fa8db57cb52e9fbf1e8716cace399b41c09cbe..cf429fe5c7162e13275e71bb72cd81344b24f84c 100644 (file)
 #include "sulogin-consoles.h"
 #define CONMAX         16
 
-#define BS             CTRL('h')
-#define NL             CTRL('j')
-#define CR             CTRL('m')
-
 static unsigned int timeout;
 static int profile;
 static volatile uint32_t openfd;               /* Remember higher file descriptors */
index c9163caa6bd7f7bd62a7fbcfea71573038328abb..ed97bc5607b919b7115c9811012569aa68c53d83 100644 (file)
 #define LOGIN          "login: "
 #define LOGIN_ARGV_MAX 16              /* Numbers of args for login */
 
-/* Some shorthands for control characters. */
-#define CTL(x)         (x ^ 0100)      /* Assumes ASCII dialect */
-#define        CR              CTL('M')        /* carriage return */
-#define        NL              CTL('J')        /* line feed */
-#define        BS              CTL('H')        /* back space */
-#define        DEL             CTL('?')        /* delete */
-
-/* Defaults for line-editing etc. characters; you may want to change these. */
-#define DEF_ERASE      DEL             /* default erase character */
-#define DEF_INTR       CTL('C')        /* default interrupt character */
-#define DEF_QUIT       CTL('\\')       /* default quit char */
-#define DEF_KILL       CTL('U')        /* default kill char */
-#define DEF_EOF                CTL('D')        /* default EOF char */
-#define DEF_EOL                0
-#define DEF_SWITCH     0               /* default switch char */
-
 /*
  * When multiple baud rates are specified on the command line, the first one
  * we will try is the first one specified.
@@ -178,13 +162,6 @@ struct options {
 #define serial_tty_option(opt, flag)   \
        (((opt)->flags & (F_VCONSOLE|(flag))) == (flag))
 
-/* Initial values for the above. */
-static const struct chardata init_chardata = {
-       .erase = DEF_ERASE,             /* default erase character */
-       .kill  = DEF_KILL,              /* default kill character */
-       .eol   = 13                     /* default eol char */
-};
-
 struct Speedtab {
        long speed;
        speed_t code;
@@ -365,7 +342,7 @@ int main(int argc, char **argv)
                }
        }
 
-       chardata = init_chardata;
+       INIT_CHARDATA(&chardata);
 
        if (options.autolog) {
                debug("doing auto login\n");
@@ -1404,7 +1381,7 @@ static char *get_logname(struct options *op, struct termios *tp, struct chardata
        };
 
        /* Initialize kill, erase, parity etc. (also after switching speeds). */
-       *cp = init_chardata;
+       INIT_CHARDATA(cp);
 
        /*
         * Flush pending input (especially important after parsing or switching