opkg: Don't prompt for user input from stdin if it's not a tty.
authorChris Larson <clarson@mvista.com>
Tue, 6 Oct 2009 01:22:03 +0000 (18:22 -0700)
committerChris Larson <clarson@mvista.com>
Tue, 3 Nov 2009 20:56:13 +0000 (13:56 -0700)
Also fixes a minor memory leak while we're at it, as the code was
strdup'ing the malloc'd string read from stdin without ever
freeing the original.

Signed-off-by: Chris Larson <clarson@mvista.com>
recipes/opkg/opkg.inc
recipes/opkg/opkg/isatty.patch [new file with mode: 0644]

index c146c75..aa91955 100644 (file)
@@ -4,13 +4,14 @@ SECTION = "base"
 LICENSE = "GPL"
 DEPENDS = "curl gpgme"
 PV = "0.1.6+svnr${SRCREV}"
-INC_PR = "r15"
+INC_PR = "r16"
 
 FILESPATHPKG =. "opkg:"
 
 SRC_URI = "svn://opkg.googlecode.com/svn;module=trunk;proto=http \
        file://opkg_unarchive.patch;patch=1;maxrev=201 \
-       file://opkg-intercept-cleanup.patch;patch=1"
+       file://opkg-intercept-cleanup.patch;patch=1 \
+       file://isatty.patch;patch=1"
 
 SRC_URI += "file://configure"
 
diff --git a/recipes/opkg/opkg/isatty.patch b/recipes/opkg/opkg/isatty.patch
new file mode 100644 (file)
index 0000000..c935f15
--- /dev/null
@@ -0,0 +1,64 @@
+Copyright (c) 2009 MontaVista Software, Inc.  All rights reserved.
+
+Don't prompt for user input from stdin if it's not a tty.  Fixes a minor
+memory leak while we're at it, as the code was strdup'ing the malloc'd string
+read from stdin without ever freeing the original.
+---
+ libopkg/libopkg.c      |   13 ++++++++-----
+ libopkg/opkg_install.c |    3 +++
+ libopkg/user.c         |   10 +++++++---
+ 3 files changed, 18 insertions(+), 8 deletions(-)
+
+--- trunk.orig/libopkg/libopkg.c
++++ trunk/libopkg/libopkg.c
+@@ -71,11 +71,14 @@ int default_opkg_status_callback(char *n
+ char* default_opkg_response_callback(char *question)
+ {
+      char *response = NULL;
+-     printf("%s",question);
+-     fflush(stdout);
+-     do {
+-        response = (char *)file_read_line_alloc(stdin);
+-     } while (response == NULL);
++     if (isatty(fileno(stdin)))
++     {
++        printf("%s",question);
++        fflush(stdout);
++        do {
++             response = (char *)file_read_line_alloc(stdin);
++        } while (response == NULL);
++     }
+      return response;
+ }
+--- trunk.orig/libopkg/user.c
++++ trunk/libopkg/user.c
+@@ -44,9 +44,13 @@ char *get_user_response(const char *form
+         len = vsnprintf(question,question_len,format,ap);
+           va_end(ap);
+      } while (len > question_len);
+-     response = strdup(opkg_cb_response(question));
+-     str_chomp(response);
+-     str_tolower(response);
++
++     response = opkg_cb_response(question);
++     if (response)
++     {
++         str_chomp(response);
++         str_tolower(response);
++     }
+      return response;
+ }
+--- trunk.orig/libopkg/opkg_install.c
++++ trunk/libopkg/opkg_install.c
+@@ -1613,6 +1613,9 @@ static int user_prefers_old_conffile(con
+                                      "          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)
++             return 1;
++
+         if (strcmp(response, "y") == 0
+             || strcmp(response, "i") == 0
+             || strcmp(response, "yes") == 0) {