I have an excellent idea for a start-up company, "Arguments, Inc.".
The core technology is:
No, that's a really great way to make Dr Memory unhappy.
Really.
The right way is to feed the arguments in through a stream if they're
more than 10k or whatever.
(y'all are spoiled, kid, when I thought of this solution we had 1k
shared between argv and envp)
First, modify libc so that in between _start and main you get something
like this:
_main(int argc, char **argv, char **envp)
{
/* Look for environment variable "ARGFD" and remove it from the
environment */
int envhead, envtail;
int argfd = -1;
for(envhead = envtail = 0; envp[envihead]; envhead++)
{
if(strncmp(envp[envhead],"ARGFD=",6) == 0)
argfd = atoi(envp[envhead] + 6);
else
{
if(envhead != envtail) envp[envtail] = envp[envhead];
envtail++;
}
}
if(envhead != envtail) envp[envtail] = 0;
/* Reading argv from a file descriptor? */
if(argfd >= 0)
{
/* insert code to read null-terminated or counted strings from
argfd and build up as big an
* argv as you want
*/
close(argfd);
}
return main(argc, argv, envp);
}
* No fucking fancy newfangled crap using ptrace, and associated
complexity and unreliability.
* You can use some other sentinel to tell it to read the args from a
file descriptor, like wrapping the info in argv[0], there's plenty of
out of band places to pass args.
* It's easy enough to make it thread-safe.
* Programs written to know about "stdcmd" or whatever you want to call
it can read the arguments as a stream, getting even more efficiency and
a basically unlimited argument length.
* You can use "find ... -print0 | env ARGFD=0 command..." and eliminate
xargs AND you can feed gcc with it.
* It can be injected into existing dynamically linked programs using
LD_LIBRARY_foo or equivalent, or simply mofifying glibc.
* It's about ten billion times more portable than anything involving
ptrace.
* I published this idea on Usenet 20 years ago, and there's prior art
in Intel's "ISIS" operating system... which was incidentally one of the
precursors of CP/M and MS-DOS, so it's pretty patent-resistant.
* It would take you a few hours at the most to implement it, right now,
if you really thought the argument limit was hateful enough.
"This is Worker speaking. Read Me Doctor Memory."