make-3.81-long-cmdline.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. http://bugs.gentoo.org/301116
  2. tweaked a little to avoid regenerating autotools
  3. 2009-07-29 Ralf Wildenhues <Ralf.Wildenhues <at> gmx.de>
  4. * configure.in: Check for sys/user.h and linux/binfmts.h
  5. headers.
  6. * job.c: Include them if available.
  7. (construct_command_argv_internal): When constructing the command
  8. line with 'sh -c', use multiple arguments together with eval
  9. expansion to evade the Linux per-argument length limit
  10. MAX_ARG_STRLEN if it is defined.
  11. Problem reported against Automake by Xan Lopez <xan <at> gnome.org>.
  12. --- job.c.orig 2010-01-15 18:36:53.000000000 +0200
  13. +++ job.c 2010-01-15 18:41:09.000000000 +0200
  14. @@ -29,6 +29,15 @@
  15. #include <string.h>
  16. +#if defined(__linux__) /* defined (HAVE_LINUX_BINFMTS_H) && defined (HAVE_SYS_USER_H) */
  17. +#include <sys/user.h>
  18. +#include <unistd.h>
  19. +#ifndef PAGE_SIZE
  20. +#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
  21. +#endif
  22. +#include <linux/binfmts.h>
  23. +#endif
  24. +
  25. /* Default shell to use. */
  26. #ifdef WINDOWS32
  27. #include <windows.h>
  28. @@ -2697,9 +2702,19 @@
  29. #endif
  30. unsigned int line_len = strlen (line);
  31. +#ifdef MAX_ARG_STRLEN
  32. + static char eval_line[] = "eval\\ \\\"set\\ x\\;\\ shift\\;\\ ";
  33. +#define ARG_NUMBER_DIGITS 5
  34. +#define EVAL_LEN (sizeof(eval_line)-1 + shell_len + 4 \
  35. + + (7 + ARG_NUMBER_DIGITS) * 2 * line_len / (MAX_ARG_STRLEN - 2))
  36. +#else
  37. +#define EVAL_LEN 0
  38. +#endif
  39. char *new_line = (char *) alloca (shell_len + (sizeof (minus_c) - 1)
  40. - + (line_len * 2) + 1);
  41. + + (line_len*2) + 1 + EVAL_LEN);
  42. +
  43. char *command_ptr = NULL; /* used for batch_mode_shell mode */
  44. + char *args_ptr;
  45. # ifdef __EMX__ /* is this necessary? */
  46. if (!unixy_shell)
  47. @@ -2712,6 +2727,30 @@
  48. bcopy (minus_c, ap, sizeof (minus_c) - 1);
  49. ap += sizeof (minus_c) - 1;
  50. command_ptr = ap;
  51. +
  52. +#if !defined (WINDOWS32) && defined (MAX_ARG_STRLEN)
  53. + if (unixy_shell && line_len > MAX_ARG_STRLEN)
  54. + {
  55. + unsigned j;
  56. + memcpy (ap, eval_line, sizeof (eval_line) - 1);
  57. + ap += sizeof (eval_line) - 1;
  58. + for (j = 1; j <= 2 * line_len / (MAX_ARG_STRLEN - 2); j++)
  59. + ap += sprintf (ap, "\\$\\{%u\\}", j);
  60. + *ap++ = '\\';
  61. + *ap++ = '"';
  62. + *ap++ = ' ';
  63. + /* Copy only the first word of SHELL to $0. */
  64. + for (p = shell; *p != '\0'; ++p)
  65. + {
  66. + if (isspace ((unsigned char)*p))
  67. + break;
  68. + *ap++ = *p;
  69. + }
  70. + *ap++ = ' ';
  71. + }
  72. +#endif
  73. + args_ptr = ap;
  74. +
  75. for (p = line; *p != '\0'; ++p)
  76. {
  77. if (restp != NULL && *p == '\n')
  78. @@ -2760,6 +2799,14 @@
  79. }
  80. #endif
  81. *ap++ = *p;
  82. +
  83. +#if !defined (WINDOWS32) && defined (MAX_ARG_STRLEN)
  84. + if (unixy_shell && line_len > MAX_ARG_STRLEN && (ap - args_ptr > MAX_ARG_STRLEN - 2))
  85. + {
  86. + *ap++ = ' ';
  87. + args_ptr = ap;
  88. + }
  89. +#endif
  90. }
  91. if (ap == new_line + shell_len + sizeof (minus_c) - 1)
  92. /* Line was empty. */