* [PATCH 2/3] textual: improve error messages
2014-12-07 10:13 [PATCH 1/3] login-utils: use libc error printing facility Sami Kerola
@ 2014-12-07 10:13 ` Sami Kerola
2014-12-07 10:13 ` [PATCH 3/3] line: use util-linux conventions Sami Kerola
2014-12-09 8:22 ` [PATCH 1/3] login-utils: use libc error printing facility Karel Zak
2 siblings, 0 replies; 4+ messages in thread
From: Sami Kerola @ 2014-12-07 10:13 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Use error printing facilities that add command name in front of the error
message, and add explanation that is part of existing translations.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
disk-utils/blockdev.c | 2 +-
disk-utils/mkfs.c | 3 +--
disk-utils/mkfs.cramfs.c | 2 +-
text-utils/more.c | 10 ++++------
4 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c
index efaa0ea..43aaef6 100644
--- a/disk-utils/blockdev.c
+++ b/disk-utils/blockdev.c
@@ -365,7 +365,7 @@ static void do_commands(int fd, char **argv, int d)
}
if (res == -1) {
- perror(bdcms[j].iocname);
+ warn(_("ioctl error on %s"), bdcms[j].iocname);
if (verbose)
printf(_("%s failed.\n"), _(bdcms[j].help));
exit(EXIT_FAILURE);
diff --git a/disk-utils/mkfs.c b/disk-utils/mkfs.c
index dbc938f..8ad6065 100644
--- a/disk-utils/mkfs.c
+++ b/disk-utils/mkfs.c
@@ -147,6 +147,5 @@ int main(int argc, char **argv)
/* Execute the program */
execvp(progname, argv + optind);
- perror(progname);
- return EXIT_FAILURE;
+ err(EXIT_FAILURE, _("failed to execute %s"), progname);
}
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index bae68ec..509b50b 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -328,7 +328,7 @@ static unsigned int parse_directory(struct entry *root_entry, const char *name,
memcpy(endpath, dirent->d_name, namelen + 1);
if (lstat(path, &st) < 0) {
- perror(endpath);
+ warn(_("stat failed %s"), endpath);
warn_skip = 1;
continue;
}
diff --git a/text-utils/more.c b/text-utils/more.c
index a489953..8c0853c 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -591,7 +591,7 @@ FILE *checkf(register char *fs, int *clearfirst)
fflush(stdout);
if (clreol)
cleareol();
- perror(fs);
+ warn(_("stat failed %s"), fs);
return ((FILE *)NULL);
}
if ((stbuf.st_mode & S_IFMT) == S_IFDIR) {
@@ -600,7 +600,7 @@ FILE *checkf(register char *fs, int *clearfirst)
}
if ((f = Fopen(fs, "r")) == NULL) {
fflush(stdout);
- perror(fs);
+ warn(_("cannot open %s"), fs);
return ((FILE *)NULL);
}
if (magic(f, fs)) {
@@ -1781,10 +1781,8 @@ void initterm(void)
int tgrp;
/* Wait until we're in the foreground before we
* save the terminal modes. */
- if ((tgrp = tcgetpgrp(fileno(stdout))) < 0) {
- perror("tcgetpgrp");
- exit(EXIT_FAILURE);
- }
+ if ((tgrp = tcgetpgrp(fileno(stdout))) < 0)
+ err(EXIT_FAILURE, "tcgetpgrp");
if (tgrp != getpgrp(0)) {
kill(0, SIGTTOU);
goto retry;
--
2.1.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 3/3] line: use util-linux conventions
2014-12-07 10:13 [PATCH 1/3] login-utils: use libc error printing facility Sami Kerola
2014-12-07 10:13 ` [PATCH 2/3] textual: improve error messages Sami Kerola
@ 2014-12-07 10:13 ` Sami Kerola
2014-12-09 8:22 ` [PATCH 1/3] login-utils: use libc error printing facility Karel Zak
2 siblings, 0 replies; 4+ messages in thread
From: Sami Kerola @ 2014-12-07 10:13 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
This change add --help and --version print outs, checking at exit the
stdout write was successful, and as a minor thing the command is made to
use wide char functions to read and write inputs.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
text-utils/line.c | 64 ++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 49 insertions(+), 15 deletions(-)
diff --git a/text-utils/line.c b/text-utils/line.c
index 636122e..80daa34 100644
--- a/text-utils/line.c
+++ b/text-utils/line.c
@@ -15,31 +15,65 @@
* See Documentation/deprecated.txt for more information.
*/
-#include <stdio.h>
-#include <unistd.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <unistd.h>
-static int status; /* exit status */
+#include "c.h"
+#include "closestream.h"
+#include "nls.h"
+#include "widechar.h"
-static void
-doline(int fd)
+static void __attribute__((__noreturn__)) usage(FILE *out)
{
- char c;
+ fputs(USAGE_HEADER, out);
+ fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
+ fputs(USAGE_OPTIONS, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
+ fprintf(out, USAGE_MAN_TAIL("line(1)"));
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+ wint_t c;
+ int opt;
+ int status = EXIT_SUCCESS;
+
+ static const struct option longopts[] = {
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+ atexit(close_stdout);
+
+ while ((opt = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+ switch (opt) {
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return EXIT_SUCCESS;
+ case 'h':
+ usage(stdout);
+ default:
+ usage(stderr);
+ }
for (;;) {
- if (read(fd, &c, 1) <= 0) {
- status = 1;
+ c = getwchar();
+ if (c == WEOF) {
+ status = EXIT_FAILURE;
break;
}
if (c == '\n')
break;
- putchar(c);
+ putwchar(c);
}
- putchar('\n');
-}
+ putwchar(L'\n');
-int
-main(void)
-{
- doline(0);
return status;
}
--
2.1.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] login-utils: use libc error printing facility
2014-12-07 10:13 [PATCH 1/3] login-utils: use libc error printing facility Sami Kerola
2014-12-07 10:13 ` [PATCH 2/3] textual: improve error messages Sami Kerola
2014-12-07 10:13 ` [PATCH 3/3] line: use util-linux conventions Sami Kerola
@ 2014-12-09 8:22 ` Karel Zak
2 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2014-12-09 8:22 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Dec 07, 2014 at 10:13:02AM +0000, Sami Kerola wrote:
> login-utils/islocal.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
All three patches applied.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread