First stab at better error reporting on too many arguments to execve.

darcs-hash:20071015093615-75c98-2137b887ca3c97bc3e4234e2fd14a1391b4cc85a.gz
This commit is contained in:
liljencrantz 2007-10-15 19:36:15 +10:00
parent 0bea4c46e3
commit 4163040e56

59
exec.c
View File

@ -439,9 +439,12 @@ static void launch_process( process_t *p )
// debug( 1, L"exec '%ls'", p->argv[0] );
char **argv = wcsv2strv( (const wchar_t **) p->argv);
char **envv = env_export_arr( 0 );
execve ( wcs2str(p->actual_cmd),
wcsv2strv( (const wchar_t **) p->argv),
env_export_arr( 0 ) );
argv,
envv );
err = errno;
@ -482,19 +485,59 @@ static void launch_process( process_t *p )
p->actual_cmd = L"/bin/sh";
execve ( wcs2str(p->actual_cmd),
wcsv2strv( (const wchar_t **) p->argv),
env_export_arr( 0 ) );
argv,
envv );
}
}
debug( 0,
_( L"Failed to execute process '%ls'" ),
p->actual_cmd );
errno = err;
debug( 0,
_( L"Failed to execute process '%ls'. Reason:" ),
p->actual_cmd );
switch( errno )
{
case E2BIG:
{
size_t sz = 0;
char **p;
for(p=argv; *p; p++)
{
sz += strlen(*p)+1;
}
for(p=envv; *p; p++)
{
sz += strlen(*p)+1;
}
#ifdef ARG_MAX
debug( 0,
L"The total size of the argument and environment lists (%d bytes) exceeds the system limit of %d bytes.",
sz,
ARG_MAX );
#else
debug( 0,
L"The total size of the argument and environment lists (%d bytes) exceeds the system limit.",
sz );
#endif
debug( 0,
L"Please try running the command again with fewer arguments.");
exit(1);
break;
}
default:
{
wperror( L"execve" );
FATAL_EXIT();
}
}
}