From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sa.local.altlinux.org X-Spam-Level: ** X-Spam-Status: No, score=2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DNS_FROM_AHBL_RHSBL,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.0 Message-ID: <553CC974.2070004@gmail.com> Date: Sun, 26 Apr 2015 14:18:12 +0300 From: Alexey Gladkov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Linux console tools development discussion References: <20150422190649.GE3170@euler> In-Reply-To: <20150422190649.GE3170@euler> OpenPGP: id=4CFFD434; url=http://pgp.mit.edu:11371/pks/lookup?op=vindex&fingerprint=on&search=0xA45ABA544CFFD434 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [kbd] [PATCH 5/5] Replace error() by fprintf() and perror() X-BeenThere: kbd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Linux console tools development discussion List-Id: Linux console tools development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Apr 2015 11:17:53 -0000 Archived-At: List-Archive: 22.04.2015 22:06, Felix Janda пишет: > --- > src/kbdinfo.c | 26 ++++++++++++++++---------- > src/setvtrgb.c | 42 ++++++++++++++++++++++++------------------ > src/vlock/auth.c | 2 -- > src/vlock/pam.c | 6 ++---- > src/vlock/username.c | 12 ++++++++---- > src/vlock/vlock.c | 11 ++++++----- > src/vlock/vt.c | 5 ++--- > 7 files changed, 58 insertions(+), 46 deletions(-) This patch does not an equivalent substitute. I think it's better to implement a local version of error(). > diff --git a/src/kbdinfo.c b/src/kbdinfo.c > index e5f122d..dfce591 100644 > --- a/src/kbdinfo.c > +++ b/src/kbdinfo.c > @@ -1,6 +1,4 @@ > #include > -#include > -#include > #include > #include > #include > @@ -74,8 +72,10 @@ main(int argc, char **argv) { > fd = getfd(console); > > if (!strcasecmp("GETMODE", action)) { > - if (ioctl(fd, KDGETMODE, &mode) == -1) > - error(EXIT_FAILURE, errno, "ioctl"); > + if (ioctl(fd, KDGETMODE, &mode) == -1) { > + perror("ioctl"); > + exit(EXIT_FAILURE); > + } > > switch (mode) { > case KD_TEXT: rc = answer("text"); break; > @@ -83,8 +83,10 @@ main(int argc, char **argv) { > } > > } else if (!strcasecmp("GKBMODE", action)) { > - if (ioctl(fd, KDGKBMODE, &mode) == -1) > - error(EXIT_FAILURE, errno, "ioctl"); > + if (ioctl(fd, KDGKBMODE, &mode) == -1) { > + perror("ioctl"); > + exit(EXIT_FAILURE); > + } > > switch (mode) { > case K_RAW: rc = answer("raw"); break; > @@ -94,8 +96,10 @@ main(int argc, char **argv) { > } > > } else if (!strcasecmp("GKBMETA", action)) { > - if (ioctl(fd, KDGKBMETA, &mode) == -1) > - error(EXIT_FAILURE, errno, "ioctl"); > + if (ioctl(fd, KDGKBMETA, &mode) == -1) { > + perror("ioctl"); > + exit(EXIT_FAILURE); > + } > > switch (mode) { > case K_METABIT: rc = answer("metabit"); break; > @@ -103,8 +107,10 @@ main(int argc, char **argv) { > } > > } else if (!strcasecmp("GKBLED", action)) { > - if (ioctl(fd, KDGKBLED, &flags) == -1) > - error(EXIT_FAILURE, errno, "ioctl"); > + if (ioctl(fd, KDGKBLED, &flags) == -1) { > + perror("ioctl"); > + exit(EXIT_FAILURE); > + } > > mode = (flags & 0x7); > > diff --git a/src/setvtrgb.c b/src/setvtrgb.c > index 3fa03a7..e369702 100644 > --- a/src/setvtrgb.c > +++ b/src/setvtrgb.c > @@ -4,8 +4,6 @@ > #include > #include > #include > -#include > -#include > #include "kbd.h" > #include "getfd.h" > #include "nls.h" > @@ -63,26 +61,30 @@ parse_file(FILE *fd, const char *filename) > for (cols = 0; cols < 16; cols++) { > if ((c = fscanf(fd, "%u", &val)) != 1) { > if (c == EOF) > - error(EXIT_FAILURE, errno, "fscanf"); > - > - error(EXIT_FAILURE, 0, _("Error: %s: Invalid value in field %u in line %u."), > - filename, rows + 1, cols + 1); > + perror("fscanf"); > + else > + fprintf(stderr, _("Error: %s: Invalid value in field %u in line %u."), > + filename, rows + 1, cols + 1); > + exit(EXIT_FAILURE); > } > > cmap[rows + cols * 3] = (unsigned char) val; > > - if (cols < 15 && fgetc(fd) != ',') > - error(EXIT_FAILURE, 0, _("Error: %s: Insufficient number of fields in line %u."), > + if (cols < 15 && fgetc(fd) != ',') { > + fprintf(stderr, _("Error: %s: Insufficient number of fields in line %u."), > filename, rows + 1); > + exit(EXIT_FAILURE); > + } > } > > - if ((c = fgetc(fd)) == EOF) > - error(EXIT_FAILURE, 0, _("Error: %s: Line %u has ended unexpectedly.\n"), > - filename, rows + 1); > + if ((c = fgetc(fd)) == EOF) { > + fprintf(stderr, _("Error: %s: Line %u has ended unexpectedly.\n"), filename, rows + 1); > + } else if (c != '\n') { > + fprintf(stderr, _("Error: %s: Line %u is too long.\n"), filename, rows + 1); > + } else > + continue; > > - if (c != '\n') > - error(EXIT_FAILURE, 0, _("Error: %s: Line %u is too long.\n"), > - filename, rows + 1); > + exit(EXIT_FAILURE); > } > } > > @@ -122,8 +124,10 @@ main(int argc, char **argv) { > parse_file(stdin, "stdin"); > > } else { > - if ((f = fopen(file, "r")) == NULL) > - error(EXIT_FAILURE, errno, "fopen"); > + if ((f = fopen(file, "r")) == NULL) { > + perror("fopen"); > + return EXIT_FAILURE; > + } > > parse_file(f, file); > fclose(f); > @@ -132,8 +136,10 @@ main(int argc, char **argv) { > fd = getfd(NULL); > > /* Apply the color map to the tty via ioctl */ > - if (ioctl(fd, PIO_CMAP, colormap) == -1) > - error(EXIT_FAILURE, errno, "ioctl"); > + if (ioctl(fd, PIO_CMAP, colormap) == -1) { > + perror("ioctl"); > + return EXIT_FAILURE; > + } > > close(fd); > > diff --git a/src/vlock/auth.c b/src/vlock/auth.c > index eddce51..4964b30 100644 > --- a/src/vlock/auth.c > +++ b/src/vlock/auth.c > @@ -21,8 +21,6 @@ > Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > */ > > -#include > -#include > #include > #include > #include > diff --git a/src/vlock/pam.c b/src/vlock/pam.c > index ab255db..a178e94 100644 > --- a/src/vlock/pam.c > +++ b/src/vlock/pam.c > @@ -21,8 +21,6 @@ > */ > > #include > -#include > -#include > #include > #include > > @@ -48,7 +46,7 @@ init_pam (const char *username, const char *tty, int log) > if (log) > syslog (LOG_WARNING, "pam_start failed: %m"); > else > - error (EXIT_SUCCESS, errno, "pam_start"); > + perror ("pam_start"); > return 0; > } > > @@ -59,7 +57,7 @@ init_pam (const char *username, const char *tty, int log) > syslog (LOG_WARNING, "pam_set_item: %s", > pam_strerror (pamh, rc)); > else > - error (EXIT_SUCCESS, 0, "pam_set_item: %s", > + fprintf (stderr, "pam_set_item: %s", > pam_strerror (pamh, rc)); > pam_end (pamh, rc); > return 0; > diff --git a/src/vlock/username.c b/src/vlock/username.c > index 9626946..6f3c712 100644 > --- a/src/vlock/username.c > +++ b/src/vlock/username.c > @@ -21,8 +21,6 @@ > */ > > #include > -#include > -#include > #include > #include > #include > @@ -54,11 +52,17 @@ get_username (void) > pw = getpwuid (uid); > > if (!pw) > - error (EXIT_FAILURE, 0, _("unrecognized user")); > + { > + fprintf (stderr, _("unrecognized user")); > + return NULL; > + } > > name = strdup (pw->pw_name); > if (!name) > - error (EXIT_FAILURE, errno, "strdup"); > + { > + perror ("strdup"); > + return NULL; > + } > > endpwent (); > return name; > diff --git a/src/vlock/vlock.c b/src/vlock/vlock.c > index c2c4158..559dd0c 100644 > --- a/src/vlock/vlock.c > +++ b/src/vlock/vlock.c > @@ -22,8 +22,6 @@ > */ > > #include > -#include > -#include > #include > #include > #include > @@ -51,16 +49,19 @@ main (int ac, char *const av[]) > > /* 2nd, find out tty name... */ > tty = ttyname (STDIN_FILENO); > - if (!tty) > + if (!tty) { > /* stdin is not a tty, so no need to try. */ > - error (EXIT_FAILURE, 0, _("stdin is not a tty")); > + fprintf (stderr, _("stdin is not a tty")); > + exit (EXIT_FAILURE); > + } > > /* ... and strip its /dev/ prefix. */ > if (!strncmp (tty, dev_prefix, sizeof (dev_prefix) - 1)) > tty += sizeof (dev_prefix) - 1; > > /* 3rd, get username for PAM. */ > - username = get_username (); > + if (!(username = get_username ())) > + exit (EXIT_FAILURE); > > /* 4th, initialize system logger. */ > openlog ("vlock", LOG_PID, LOG_AUTH); > diff --git a/src/vlock/vt.c b/src/vlock/vt.c > index 4e5282b..96ec9a1 100644 > --- a/src/vlock/vt.c > +++ b/src/vlock/vt.c > @@ -23,7 +23,6 @@ > > #include > #include > -#include > #include > #include > #include > @@ -136,7 +135,7 @@ init_vt (const char *tty) > vfd = open (dev_tty, O_RDWR); > if (vfd < 0) > { > - error (EXIT_SUCCESS, errno, "could not open %s", dev_tty); > + fprintf (stderr, "could not open %s: %s", dev_tty, strerror(errno)); > return 0; > } > > @@ -187,7 +186,7 @@ init_vt (const char *tty) > /* Set mode of active vt. */ > if (ioctl (vfd, VT_SETMODE, &vtm) < 0) > { > - error (EXIT_SUCCESS, errno, "ioctl VT_SETMODE"); > + perror ("ioctl VT_SETMODE"); > return 0; > } > } > -- Rgrds, legion