libc: add pexec() to execute a command in $PATH
This commit is contained in:
@ -601,6 +601,7 @@ extern int jehanne_brk(void*);
|
|||||||
extern int jehanne_execl(const char*, ...);
|
extern int jehanne_execl(const char*, ...);
|
||||||
extern int jehanne_forgivewkp(int64_t);
|
extern int jehanne_forgivewkp(int64_t);
|
||||||
extern pid_t jehanne_fork(void);
|
extern pid_t jehanne_fork(void);
|
||||||
|
extern int jehanne_pexec(const char* cmd, char* args[]);
|
||||||
extern int32_t jehanne_readn(int, void*, int32_t);
|
extern int32_t jehanne_readn(int, void*, int32_t);
|
||||||
extern void* jehanne_segbrk(uint32_t);
|
extern void* jehanne_segbrk(uint32_t);
|
||||||
#define sbrk(incr) jehanne_segbrk(incr)
|
#define sbrk(incr) jehanne_segbrk(incr)
|
||||||
@ -674,4 +675,3 @@ extern char *argv0;
|
|||||||
|
|
||||||
/* this is used by segbrk and brk, it's a really bad idea to redefine it */
|
/* this is used by segbrk and brk, it's a really bad idea to redefine it */
|
||||||
extern char end[];
|
extern char end[];
|
||||||
|
|
||||||
|
41
sys/src/lib/c/9sys/pexec.c
Normal file
41
sys/src/lib/c/9sys/pexec.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Jehanne.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
|
||||||
|
*
|
||||||
|
* Jehanne is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 2 of the License.
|
||||||
|
*
|
||||||
|
* Jehanne is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#include <envvars.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
jehanne_pexec(const char *f, char *args[])
|
||||||
|
{
|
||||||
|
char *epath, *path, *entries[33];
|
||||||
|
int n, i;
|
||||||
|
|
||||||
|
if(f[0] == '/' || (epath = jehanne_getenv(ENV_PATH)) == nil)
|
||||||
|
return exec(f, (const char**)args);
|
||||||
|
|
||||||
|
n = jehanne_getfields(epath, entries, nelem(entries), 1, ":");
|
||||||
|
for(i = 0; i < n; ++i){
|
||||||
|
path = jehanne_smprint("%s/%s", entries[i], f);
|
||||||
|
exec(path, args);
|
||||||
|
jehanne_free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
jehanne_free(epath);
|
||||||
|
return -1;
|
||||||
|
}
|
@ -60,6 +60,7 @@
|
|||||||
"9sys/nsec.c",
|
"9sys/nsec.c",
|
||||||
"9sys/nulldir.c",
|
"9sys/nulldir.c",
|
||||||
"9sys/ocreate.c",
|
"9sys/ocreate.c",
|
||||||
|
"9sys/pexec.c",
|
||||||
"9sys/pipe.c",
|
"9sys/pipe.c",
|
||||||
"9sys/postnote.c",
|
"9sys/postnote.c",
|
||||||
"9sys/privalloc.c",
|
"9sys/privalloc.c",
|
||||||
|
Reference in New Issue
Block a user