Subject: Re: shell scripts in an emulation environment
To: Jonathan Stone <jonathan@DSG.Stanford.EDU>
From: Matthias Drochner <drochner@zelux6.zel.kfa-juelich.de>
List: tech-kern
Date: 01/29/1998 20:25:42
Excerpts from netbsd: 28-Jan-98 Jonathan Stone@DSG.Stanf (983)

> Two years ago I proposed rewriting the emul path-prefixing as a
> single, data-driven service.  Just put the string name of an emul into
> the in-kernel structure for an emul. Create CHECK_ALT_EXISTS which
> pulls the emul name from the calling process' struct emul, rather than
> a hardcoded version for each number.

The arguments still have to be repacked, and special semantics
applied in some cases. To have a common function per syscall
would be not bad, but it wouldn't save much code imo.

For the script interpreter problem, here is a patch for review
and discussion.
The resource management is a bit ugly (as it is in the whole
exec code).
(I've dropped the idea to put the emulation lookup into check_exec().
This is not the right place to care about the allocation of space for
the new path, and it would impose more penalty on native execs.)

best regards
Matthias

Index: sys/proc.h
===================================================================
RCS file: /cvsroot/src/sys/sys/proc.h,v
retrieving revision 1.55
diff -r1.55 proc.h
94a95
> 	char	*(*e_altname) __P((struct proc *, char *, int));
Index: kern/exec_script.c
===================================================================
RCS file: /cvsroot/src/sys/kern/exec_script.c,v
retrieving revision 1.18
diff -r1.18 exec_script.c
75a76
> 	char *emulshellname = 0;
197a199,201
> 	if (p->p_emul->e_altname &&
> 	    (emulshellname = (*p->p_emul->e_altname)(p, shellname, 0)))
> 		epp->ep_ndp->ni_dirp = emulshellname;
243a248,250
> 		if (emulshellname)
> 			(void)(*p->p_emul->e_altname)(p, emulshellname, 1);
> 
280a288,290
> 
> 	if (emulshellname)
> 		(void)(*p->p_emul->e_altname)(p, emulshellname, 1);
Index: compat/linux/linux_exec.c
===================================================================
RCS file: /cvsroot/src/sys/compat/linux/linux_exec.c,v
retrieving revision 1.26
diff -r1.26 linux_exec.c
83a84,85
> char *linux_altname __P((struct proc *, char *, int));
> 
96a99
> 	linux_altname,
111a115
> 	linux_altname,
579a584,603
> }
> 
> char *
> linux_altname(p, name, flags)
> 	struct proc *p;
> 	char *name;
> 	int flags;
> {
> 	int res;
> 	char *emulpath;
> 
> 	if (flags == 0) {
> 		res = emul_find(p, 0, linux_emul_path, name,
> 				&emulpath, 0);
> 		if (res == 0)
> 			return(emulpath);
> 	} else
> 		free(name, M_TEMP);
> 
> 	return(0);