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 1666 "usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] [-cpu model] program [arguments...]\n"
1667 1667 "Linux CPU emulator (compiled for %s emulation)\n"
1668 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 1675 "\n"
1675 1676 "debug options:\n"
1676 1677 #ifdef USE_CODE_COPY
... ... @@ -1702,7 +1703,9 @@ int main(int argc, char **argv)
1702 1703 int optind;
1703 1704 const char *r;
1704 1705 int gdbstub_port = 0;
1705   -
  1706 + int drop_ld_preload = 0, environ_count = 0;
  1707 + char **target_environ, **wrk, **dst;
  1708 +
1706 1709 if (argc <= 1)
1707 1710 usage();
1708 1711  
... ... @@ -1774,6 +1777,8 @@ int main(int argc, char **argv)
1774 1777 #endif
1775 1778 _exit(1);
1776 1779 }
  1780 + } else if (!strcmp(r, "drop-ld-preload")) {
  1781 + drop_ld_preload = 1;
1777 1782 } else
1778 1783 #ifdef USE_CODE_COPY
1779 1784 if (!strcmp(r, "no-code-copy")) {
... ... @@ -1802,11 +1807,31 @@ int main(int argc, char **argv)
1802 1807 env = cpu_init();
1803 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 1835 if (loglevel) {
1811 1836 page_dump(logfile);
1812 1837  
... ...