Don't prompt for user input from stdin if it's not a tty.
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Thu, 12 Nov 2009 06:38:44 +0000 (06:38 +0000)
committergraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Thu, 12 Nov 2009 06:38:44 +0000 (06:38 +0000)
Based off a patch by Chris Larson <clarson@mvista.com> for OpenEmbedded.

git-svn-id: http://opkg.googlecode.com/svn/trunk@290 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/opkg_install.c
libopkg/user.c

index a76322d12358aa45ca8bf89374e0b37ec5c0459d..52af71e9aca7812b87650efe2a40d535fe1b3fe3 100644 (file)
@@ -1608,6 +1608,10 @@ static int user_prefers_old_conffile(const char *file_name, const char *backup)
                                       "          D     : show the differences between the versions (if diff is installed)\n"
                                       "     The default action is to keep your current version.\n"
                                       "    *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name);
+
+         if (response == NULL)
+                 return 1;
+
          if (strcmp(response, "y") == 0
              || strcmp(response, "i") == 0
              || strcmp(response, "yes") == 0) {
index 8c960dc8bcdd5207694f5404b713bac2f5c9f7be..dda5013f6338c6fec4940b1b3b0fa7296607603d 100644 (file)
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 */
-#include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
-#include <string.h>
+#include <unistd.h>
 #include "file_util.h"
 #include "str_util.h"
-#include "user.h"
 
 char *get_user_response(const char *format, ...)
 {
@@ -32,6 +30,9 @@ char *get_user_response(const char *format, ...)
        vprintf(format, ap);
        va_end(ap);
 
+       if (isatty(fileno(stdin)))
+               return NULL;
+
        response = (char *)file_read_line_alloc(stdin);
        if (response == NULL)
                return NULL;