summaryrefslogtreecommitdiffstats
path: root/fish
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-08-19 10:01:07 +0200
committerJim Meyering <meyering@redhat.com>2009-08-19 13:27:13 +0200
commit6aa44937d5ee9accb0025cd8536c5adafd24ef23 (patch)
tree62014a3f86ebe36b9ed36a11c7e565e5b48a8d4c /fish
parent0f7656f2870fd5f1644e54438e7639fa2dcbc747 (diff)
downloadlibguestfs-6aa44937d5ee9accb0025cd8536c5adafd24ef23.tar.gz
libguestfs-6aa44937d5ee9accb0025cd8536c5adafd24ef23.tar.xz
libguestfs-6aa44937d5ee9accb0025cd8536c5adafd24ef23.zip
guestfish: detect more failed syscalls
* fish/fish.c (issue_command): Detect/diagnose more failed syscalls.
Diffstat (limited to 'fish')
-rw-r--r--fish/fish.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/fish/fish.c b/fish/fish.c
index 830617b1..987df596 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -750,8 +750,14 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
if (pipecmd) {
int fd[2];
- fflush (stdout);
- pipe (fd);
+ if (fflush (stdout) == EOF) {
+ perror ("failed to flush standard output");
+ return -1;
+ }
+ if (pipe (fd) < 0) {
+ perror ("pipe failed");
+ return -1;
+ }
pid = fork ();
if (pid == -1) {
perror ("fork");
@@ -760,7 +766,10 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
if (pid == 0) { /* Child process. */
close (fd[1]);
- dup2 (fd[0], 0);
+ if (dup2 (fd[0], 0) < 0) {
+ perror ("dup2 of stdin failed");
+ _exit (1);
+ }
r = system (pipecmd);
if (r == -1) {
@@ -770,9 +779,16 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
_exit (WEXITSTATUS (r));
}
- stdout_saved_fd = dup (1);
+ if ((stdout_saved_fd = dup (1)) < 0) {
+ perror ("failed to dup stdout");
+ return -1;
+ }
close (fd[0]);
- dup2 (fd[1], 1);
+ if (dup2 (fd[1], 1) < 0) {
+ perror ("failed to dup stdout");
+ close (stdout_saved_fd);
+ return -1;
+ }
close (fd[1]);
}
@@ -823,13 +839,22 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
/* Always flush stdout after every command, so that messages, results
* etc appear immediately.
*/
- fflush (stdout);
+ if (fflush (stdout) == EOF) {
+ perror ("failed to flush standard output");
+ return -1;
+ }
if (pipecmd) {
close (1);
- dup2 (stdout_saved_fd, 1);
+ if (dup2 (stdout_saved_fd, 1) < 0) {
+ perror ("failed to dup2 standard output");
+ r = -1;
+ }
close (stdout_saved_fd);
- waitpid (pid, NULL, 0);
+ if (waitpid (pid, NULL, 0) < 0) {
+ perror ("waiting for command to complete");
+ r = -1;
+ }
}
return r;