Commit b12b6a188e50c3bad1f866bb7f8cdb42a8b0d56c

Authored by ths
1 parent ffb04fcf

Option to drop LD_PRELOAD from emulated environment, by Lauri Leukkunen.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2985 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 34 additions and 9 deletions
linux-user/main.c
@@ -1666,11 +1666,12 @@ void usage(void) @@ -1666,11 +1666,12 @@ void usage(void)
1666 "usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] [-cpu model] program [arguments...]\n" 1666 "usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] [-cpu model] program [arguments...]\n"
1667 "Linux CPU emulator (compiled for %s emulation)\n" 1667 "Linux CPU emulator (compiled for %s emulation)\n"
1668 "\n" 1668 "\n"
1669 - "-h print this help\n"  
1670 - "-g port wait gdb connection to port\n"  
1671 - "-L path set the elf interpreter prefix (default=%s)\n"  
1672 - "-s size set the stack size in bytes (default=%ld)\n"  
1673 - "-cpu model select CPU (-cpu ? for list)\n" 1669 + "-h print this help\n"
  1670 + "-g port wait gdb connection to port\n"
  1671 + "-L path set the elf interpreter prefix (default=%s)\n"
  1672 + "-s size set the stack size in bytes (default=%ld)\n"
  1673 + "-cpu model select CPU (-cpu ? for list)\n"
  1674 + "-drop-ld-preload drop LD_PRELOAD for target process\n"
1674 "\n" 1675 "\n"
1675 "debug options:\n" 1676 "debug options:\n"
1676 #ifdef USE_CODE_COPY 1677 #ifdef USE_CODE_COPY
@@ -1702,7 +1703,9 @@ int main(int argc, char **argv) @@ -1702,7 +1703,9 @@ int main(int argc, char **argv)
1702 int optind; 1703 int optind;
1703 const char *r; 1704 const char *r;
1704 int gdbstub_port = 0; 1705 int gdbstub_port = 0;
1705 - 1706 + int drop_ld_preload = 0, environ_count = 0;
  1707 + char **target_environ, **wrk, **dst;
  1708 +
1706 if (argc <= 1) 1709 if (argc <= 1)
1707 usage(); 1710 usage();
1708 1711
@@ -1774,6 +1777,8 @@ int main(int argc, char **argv) @@ -1774,6 +1777,8 @@ int main(int argc, char **argv)
1774 #endif 1777 #endif
1775 _exit(1); 1778 _exit(1);
1776 } 1779 }
  1780 + } else if (!strcmp(r, "drop-ld-preload")) {
  1781 + drop_ld_preload = 1;
1777 } else 1782 } else
1778 #ifdef USE_CODE_COPY 1783 #ifdef USE_CODE_COPY
1779 if (!strcmp(r, "no-code-copy")) { 1784 if (!strcmp(r, "no-code-copy")) {
@@ -1802,11 +1807,31 @@ int main(int argc, char **argv) @@ -1802,11 +1807,31 @@ int main(int argc, char **argv)
1802 env = cpu_init(); 1807 env = cpu_init();
1803 global_env = env; 1808 global_env = env;
1804 1809
1805 - if (loader_exec(filename, argv+optind, environ, regs, info) != 0) {  
1806 - printf("Error loading %s\n", filename);  
1807 - _exit(1); 1810 + wrk = environ;
  1811 + while (*(wrk++))
  1812 + environ_count++;
  1813 +
  1814 + target_environ = malloc((environ_count + 1) * sizeof(char *));
  1815 + if (!target_environ)
  1816 + abort();
  1817 + for (wrk = environ, dst = target_environ; *wrk; wrk++) {
  1818 + if (drop_ld_preload && !strncmp(*wrk, "LD_PRELOAD=", 11))
  1819 + continue;
  1820 + *(dst++) = strdup(*wrk);
  1821 + }
  1822 + dst = NULL; /* NULL terminate target_environ */
  1823 +
  1824 + if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
  1825 + printf("Error loading %s\n", filename);
  1826 + _exit(1);
  1827 + }
  1828 +
  1829 + for (wrk = target_environ; *wrk; wrk++) {
  1830 + free(*wrk);
1808 } 1831 }
1809 1832
  1833 + free(target_environ);
  1834 +
1810 if (loglevel) { 1835 if (loglevel) {
1811 page_dump(logfile); 1836 page_dump(logfile);
1812 1837