Include strerror(errno) in error messages after failed system calls.

Fix a warning.
This commit is contained in:
Martin Cracauer 1999-11-29 19:11:01 +00:00
parent 886530ab78
commit 6c48b6cf75
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53891
10 changed files with 21 additions and 15 deletions

View File

@ -342,7 +342,7 @@ getpwd()
INTOFF;
if (pipe(pip) < 0)
error("Pipe call failed");
error("Pipe call failed: %s", strerror(errno));
jp = makejob((union node *)NULL, 1);
if (forkshell(jp, (union node *)NULL, FORK_NOJOB) == 0) {
(void) close(pip[0]);

View File

@ -51,6 +51,7 @@ static const char rcsid[] =
#include "options.h"
#include "output.h"
#include "error.h"
#include "nodes.h" /* show.h needs nodes.h */
#include "show.h"
#include "trap.h"
#include <signal.h>

View File

@ -45,6 +45,7 @@ static const char rcsid[] =
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h> /* For WIFSIGNALED(status) */
#include <errno.h>
/*
* Evaluate a command.
@ -488,7 +489,7 @@ evalpipe(n)
if (lp->next) {
if (pipe(pip) < 0) {
close(prevfd);
error("Pipe call failed");
error("Pipe call failed: %s", strerror(errno));
}
}
if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
@ -556,7 +557,7 @@ evalbackcmd(n, result)
} else {
exitstatus = 0;
if (pipe(pip) < 0)
error("Pipe call failed");
error("Pipe call failed: %s", strerror(errno));
jp = makejob(n, 1);
if (forkshell(jp, n, FORK_NOJOB) == 0) {
FORCEINTON;
@ -728,7 +729,7 @@ evalcommand(cmd, flags, backcmd)
if (flags & EV_BACKCMD) {
mode = FORK_NOJOB;
if (pipe(pip) < 0)
error("Pipe call failed");
error("Pipe call failed: %s", strerror(errno));
}
if (forkshell(jp, cmd, mode) != 0)
goto parent; /* at end of routine */

View File

@ -383,7 +383,7 @@ setinputfile(fname, push)
INTOFF;
if ((fd = open(fname, O_RDONLY)) < 0)
error("Can't open %s", fname);
error("Can't open %s: %s", fname, strerror(errno));
if (fd < 10) {
fd2 = copyfd(fd, 10);
close(fd);

View File

@ -594,7 +594,7 @@ forkshell(jp, n, mode)
if (pid == -1) {
TRACE(("Fork failed, errno=%d\n", errno));
INTON;
error("Cannot fork");
error("Cannot fork: %s", strerror(errno));
}
if (pid == 0) {
struct job *p;
@ -636,7 +636,8 @@ forkshell(jp, n, mode)
! fd0_redirected_p ()) {
close(0);
if (open("/dev/null", O_RDONLY) != 0)
error("Can't open /dev/null");
error("Can't open /dev/null: %s",
strerror(errno));
}
}
#else
@ -647,7 +648,8 @@ forkshell(jp, n, mode)
! fd0_redirected_p ()) {
close(0);
if (open("/dev/null", O_RDONLY) != 0)
error("Can't open /dev/null");
error("Can't open /dev/null: %s",
strerror(errno));
}
}
#endif

View File

@ -300,7 +300,7 @@ readcmdfile(name)
if ((fd = open(name, O_RDONLY)) >= 0)
setinputfd(fd, 1);
else
error("Can't open %s", name);
error("Can't open %s: %s", name, strerror(errno));
INTON;
cmdloop(0);
popfile();

View File

@ -66,6 +66,7 @@ static const char rcsid[] =
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
/*
@ -478,7 +479,7 @@ ckfopen(file, mode)
FILE *fp;
if ((fp = fopen(file, mode)) == NULL) {
fprintf(stderr, "Can't open %s\n", file);
fprintf(stderr, "Can't open %s: %s\n", file, strerror(errno));
exit(2);
}
return fp;

View File

@ -56,6 +56,7 @@ static const char rcsid[] =
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef __STDC__
#include <stdarg.h>
#else
@ -123,7 +124,7 @@ main(argc, argv)
if (argc != 3)
error("usage: mknodes file");
if ((infp = fopen(argv[1], "r")) == NULL)
error("Can't open %s", argv[1]);
error("Can't open %s: %s", argv[1], strerror(errno));
while (readline()) {
if (line[0] == ' ' || line[0] == '\t')
parsefield();
@ -232,9 +233,9 @@ output(file)
char *p;
if ((patfile = fopen(file, "r")) == NULL)
error("Can't open %s", file);
error("Can't open %s: %s", file, strerror(errno));
if ((hfile = fopen("nodes.h", "w")) == NULL)
error("Can't create nodes.h");
error("Can't create nodes.h: %s", strerror(errno));
if ((cfile = fopen("nodes.c", "w")) == NULL)
error("Can't create nodes.c");
fputs(writer, hfile);

View File

@ -246,7 +246,7 @@ openhere(redir)
int len = 0;
if (pipe(pip) < 0)
error("Pipe call failed");
error("Pipe call failed: %s", strerror(errno));
if (redir->type == NHERE) {
len = strlen(redir->nhere.doc->narg.text);
if (len <= PIPESIZE) {

View File

@ -420,7 +420,7 @@ opentrace() {
scopy("./trace", s);
#endif /* not_this_way */
if ((tracefile = fopen(s, "a")) == NULL) {
fprintf(stderr, "Can't open %s\n", s);
fprintf(stderr, "Can't open %s: %s\n", s, strerror(errno));
return;
}
#ifdef O_APPEND