Deleted Added
full compact
exec.c (218242) exec.c (218306)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/bin/sh/exec.c 218242 2011-02-03 23:38:11Z jilles $");
39__FBSDID("$FreeBSD: head/bin/sh/exec.c 218306 2011-02-04 22:47:55Z jilles $");
40
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <unistd.h>
44#include <fcntl.h>
45#include <errno.h>
40
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <unistd.h>
44#include <fcntl.h>
45#include <errno.h>
46#include <paths.h>
46#include <stdlib.h>
47
48/*
49 * When commands are first encountered, they are entered in a hash table.
50 * This ensures that a full path search will not have to be done for them
51 * on each invocation.
52 *
53 * We should investigate converting to a linear search, even though that

--- 46 unchanged lines hidden (view full) ---

100static struct tblentry *cmdlookup(const char *, int);
101static void delete_cmd_entry(void);
102
103
104
105/*
106 * Exec a program. Never returns. If you change this routine, you may
107 * have to change the find_command routine as well.
47#include <stdlib.h>
48
49/*
50 * When commands are first encountered, they are entered in a hash table.
51 * This ensures that a full path search will not have to be done for them
52 * on each invocation.
53 *
54 * We should investigate converting to a linear search, even though that

--- 46 unchanged lines hidden (view full) ---

101static struct tblentry *cmdlookup(const char *, int);
102static void delete_cmd_entry(void);
103
104
105
106/*
107 * Exec a program. Never returns. If you change this routine, you may
108 * have to change the find_command routine as well.
109 *
110 * The argv array may be changed and element argv[-1] should be writable.
108 */
109
110void
111shellexec(char **argv, char **envp, const char *path, int idx)
112{
113 char *cmdname;
114 int e;
115

--- 26 unchanged lines hidden (view full) ---

142static void
143tryexec(char *cmd, char **argv, char **envp)
144{
145 int e;
146
147 execve(cmd, argv, envp);
148 e = errno;
149 if (e == ENOEXEC) {
111 */
112
113void
114shellexec(char **argv, char **envp, const char *path, int idx)
115{
116 char *cmdname;
117 int e;
118

--- 26 unchanged lines hidden (view full) ---

145static void
146tryexec(char *cmd, char **argv, char **envp)
147{
148 int e;
149
150 execve(cmd, argv, envp);
151 e = errno;
152 if (e == ENOEXEC) {
150 initshellproc();
151 setinputfile(cmd, 0);
152 commandname = arg0 = savestr(argv[0]);
153 setparam(argv + 1);
154 exraise(EXSHELLPROC);
155 /*NOTREACHED*/
153 *argv = cmd;
154 *--argv = _PATH_BSHELL;
155 execve(_PATH_BSHELL, argv, envp);
156 }
157 errno = e;
158}
159
160/*
161 * Do a path search. The variable path (passed by reference) should be
162 * set to the start of the path before the first call; padvance will update
163 * this value as it proceeds. Successive calls to padvance will return

--- 368 unchanged lines hidden (view full) ---

532 }
533 }
534 }
535 INTON;
536}
537
538
539/*
156 }
157 errno = e;
158}
159
160/*
161 * Do a path search. The variable path (passed by reference) should be
162 * set to the start of the path before the first call; padvance will update
163 * this value as it proceeds. Successive calls to padvance will return

--- 368 unchanged lines hidden (view full) ---

532 }
533 }
534 }
535 INTON;
536}
537
538
539/*
540 * Delete all functions.
541 */
542
543#ifdef mkinit
544MKINIT void deletefuncs(void);
545
546SHELLPROC {
547 deletefuncs();
548}
549#endif
550
551void
552deletefuncs(void)
553{
554 struct tblentry **tblp;
555 struct tblentry **pp;
556 struct tblentry *cmdp;
557
558 INTOFF;
559 for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
560 pp = tblp;
561 while ((cmdp = *pp) != NULL) {
562 if (cmdp->cmdtype == CMDFUNCTION) {
563 *pp = cmdp->next;
564 unreffunc(cmdp->param.func);
565 ckfree(cmdp);
566 } else {
567 pp = &cmdp->next;
568 }
569 }
570 }
571 INTON;
572}
573
574
575
576/*
577 * Locate a command in the command hash table. If "add" is nonzero,
578 * add the command to the table if it is not already present. The
579 * variable "lastcmdentry" is set to point to the address of the link
580 * pointing to the entry, so that delete_cmd_entry can delete the
581 * entry.
582 */
583
584static struct tblentry **lastcmdentry;

--- 234 unchanged lines hidden ---
540 * Locate a command in the command hash table. If "add" is nonzero,
541 * add the command to the table if it is not already present. The
542 * variable "lastcmdentry" is set to point to the address of the link
543 * pointing to the entry, so that delete_cmd_entry can delete the
544 * entry.
545 */
546
547static struct tblentry **lastcmdentry;

--- 234 unchanged lines hidden ---