- Always call exec_free_args() in kern_execve() instead of doing it in all

the callers if the exec either succeeds or fails early.
- Move the code to call exit1() if the exec fails after the vmspace is
  gone to the bottom of kern_execve() to cut down on some code duplication.
This commit is contained in:
John Baldwin 2006-02-06 22:06:54 +00:00
parent 809f984b21
commit 8917b8d28c
10 changed files with 9 additions and 33 deletions

View File

@ -81,7 +81,6 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}

View File

@ -1246,7 +1246,6 @@ osf1_execve(td, uap)
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}

View File

@ -205,7 +205,6 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}

View File

@ -324,7 +324,6 @@ freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
uap->argv, uap->envv);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}

View File

@ -175,7 +175,6 @@ svr4_sys_execv(td, uap)
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}
@ -195,7 +194,6 @@ svr4_sys_execve(td, uap)
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}

View File

@ -207,7 +207,6 @@ ibcs2_execv(td, uap)
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}
@ -227,7 +226,6 @@ ibcs2_execve(td, uap)
free(path, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}

View File

@ -122,7 +122,6 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
free(newpath, M_TEMP);
if (error == 0)
error = kern_execve(td, &eargs, NULL);
exec_free_args(&eargs);
return (error);
}

View File

@ -86,6 +86,7 @@ static int sysctl_kern_usrstack(SYSCTL_HANDLER_ARGS);
static int sysctl_kern_stackprot(SYSCTL_HANDLER_ARGS);
static int do_execve(struct thread *td, struct image_args *args,
struct mac *mac_p);
static void exec_free_args(struct image_args *);
/* XXX This should be vm_size_t. */
SYSCTL_PROC(_kern, KERN_PS_STRINGS, ps_strings, CTLTYPE_ULONG|CTLFLAG_RD,
@ -181,12 +182,8 @@ execve(td, uap)
error = exec_copyin_args(&args, uap->fname, UIO_USERSPACE,
uap->argv, uap->envv);
if (error == 0)
error = kern_execve(td, &args, NULL);
exec_free_args(&args);
return (error);
}
@ -218,12 +215,8 @@ __mac_execve(td, uap)
error = exec_copyin_args(&args, uap->fname, UIO_USERSPACE,
uap->argv, uap->envv);
if (error == 0)
error = kern_execve(td, &args, uap->mac_p);
exec_free_args(&args);
return (error);
#else
return (ENOSYS);
@ -776,19 +769,6 @@ do_execve(td, args, mac_p)
p->p_flag &= ~P_INEXEC;
PROC_UNLOCK(p);
if (imgp->vmspace_destroyed) {
/* sorry, no more process anymore. exit gracefully */
#ifdef MAC
mac_execve_exit(imgp);
if (interplabel != NULL)
mac_vnode_label_free(interplabel);
#endif
VFS_UNLOCK_GIANT(vfslocked);
exec_free_args(args);
exit1(td, W_EXITCODE(0, SIGABRT));
/* NOT REACHED */
error = 0;
}
done2:
#ifdef MAC
mac_execve_exit(imgp);
@ -796,6 +776,13 @@ do_execve(td, args, mac_p)
mac_vnode_label_free(interplabel);
#endif
VFS_UNLOCK_GIANT(vfslocked);
exec_free_args(args);
if (error && imgp->vmspace_destroyed) {
/* sorry, no more process anymore. exit gracefully */
exit1(td, W_EXITCODE(0, SIGABRT));
/* NOT REACHED */
}
return (error);
}
@ -1036,7 +1023,7 @@ exec_copyin_args(struct image_args *args, char *fname,
return (0);
}
void
static void
exec_free_args(struct image_args *args)
{

View File

@ -266,7 +266,6 @@ kse_thr_interrupt(struct thread *td, struct kse_thr_interrupt_args *uap)
args.argv, args.envp);
if (error == 0)
error = kern_execve(td, &iargs, NULL);
exec_free_args(&iargs);
if (error == 0) {
PROC_LOCK(p);
SIGSETOR(td->td_siglist, args.sigpend);

View File

@ -76,7 +76,6 @@ void exec_setregs(struct thread *, u_long, u_long, u_long);
int exec_shell_imgact(struct image_params *);
int exec_copyin_args(struct image_args *, char *, enum uio_seg,
char **, char **);
void exec_free_args(struct image_args *);
#endif
#endif /* !_SYS_IMGACT_H_ */