From: Felix Janda <felix.janda@posteo.de>
To: kbd@lists.altlinux.org
Subject: [kbd] [PATCH 5/5] Replace error() by fprintf() and perror()
Date: Wed, 22 Apr 2015 21:06:49 +0200 [thread overview]
Message-ID: <20150422190649.GE3170@euler> (raw)
---
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(-)
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 <stdio.h>
-#include <errno.h>
-#include <error.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
@@ -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 <getopt.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
-#include <errno.h>
-#include <error.h>
#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 <errno.h>
-#include <error.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
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 <stdio.h>
-#include <errno.h>
-#include <error.h>
#include <stdlib.h>
#include <syslog.h>
@@ -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 <stdio.h>
-#include <errno.h>
-#include <error.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -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 <stdio.h>
-#include <errno.h>
-#include <error.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -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 <stdio.h>
#include <errno.h>
-#include <error.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -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;
}
}
--
2.0.5
next reply other threads:[~2015-04-22 19:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 19:06 Felix Janda [this message]
2015-04-26 11:18 ` [kbd] [PATCH 5/5] Replace error() by fprintf() and perror() Alexey Gladkov
2015-04-28 22:08 ` Alexey Gladkov
2015-04-29 18:11 ` Felix Janda
2015-04-30 19:21 ` Alexey Gladkov
2015-04-30 20:36 ` Felix Janda
2015-05-04 18:38 ` Alexey Gladkov
[not found] ` <20150504195148.GA3967@euler>
2015-05-04 23:10 ` Alexey Gladkov
2015-05-06 19:34 ` Felix Janda
2015-05-11 22:00 ` Alexey Gladkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150422190649.GE3170@euler \
--to=felix.janda@posteo.de \
--cc=kbd@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.