Merge commit 'jrollins/master'
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 11 Apr 2008 17:20:55 +0000 (13:20 -0400)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 11 Apr 2008 17:20:55 +0000 (13:20 -0400)
gnutls-helpers.c
gpg2ssh.c

index 50b611446a32145c12edb5ba91bc149a93968705..5a567e2940ef9376f35a535382f31107e0b0e640 100644 (file)
@@ -20,6 +20,7 @@ void err(const char* fmt, ...) {
   va_start(ap, fmt);
   vfprintf(stderr, fmt, ap);
   va_end(ap);
+  fflush(stderr);
 }
 
 void logfunc(int level, const char* string) {
@@ -286,6 +287,10 @@ int create_writing_pipe(pid_t* pid, const char* path, char* const argv[]) {
     }
     execv(path, argv);
     err("exec %s failed (error: %d \"%s\")\n", path, errno, strerror(errno));
+    /* close the open file descriptors */
+    close(p[0]);
+    close(0);
+
     exit(1);
   } else { /* this is the parent */
     close(p[0]); /* close unused read end */
index f696f659cc903d8938f9cdb21efd14b5118a389c..615554990161f4bff2aefeac390a693ec7011d2f 100644 (file)
--- a/gpg2ssh.c
+++ b/gpg2ssh.c
@@ -48,6 +48,7 @@ int main(int argc, char* argv[]) {
   char* const args[] = {"/usr/bin/base64", "--wrap=0", NULL};
   const char* algoname;
   int mpicount;
+  int pipestatus;
 
   init_gnutls();
   
@@ -258,23 +259,27 @@ int main(int argc, char* argv[]) {
 
   snprintf(output_data, sizeof(output_data), "%s %s ", userid, algoname);
 
-  write(1, output_data, strlen(output_data));
-
   pipefd = create_writing_pipe(&child_pid, args[0], args);
   if (pipefd < 0) {
     err("failed to create a writing pipe (returned %d)\n", pipefd);
     return pipefd;
   }
     
+  write(1, output_data, strlen(output_data));
+
   if (0 != write_data_fd_with_length(pipefd, all, mpicount)) {
     err("was not able to write out RSA key data\n");
     return 1;
   }
   close(pipefd);
-  if (child_pid != waitpid(child_pid, NULL, 0)) {
+  if (child_pid != waitpid(child_pid, &pipestatus, 0)) {
     err("could not wait for child process to return for some reason.\n");
     return 1;
   }
+  if (pipestatus != 0) {
+    err("base64 pipe died with return code %d\n", pipestatus);
+    return pipestatus;
+  }
 
   write(1, "\n", 1);