From: Camm Maguire Date: Wed, 18 Dec 2019 20:14:09 +0000 (+0000) Subject: Version_2_6_13pre70 X-Git-Tag: archive/raspbian/2.6.12-91+rpi1^2~18 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2af2cd232c6489ac34f7528c376f73d7ec01da91;p=gcl.git Version_2_6_13pre70 Gbp-Pq: Name Version_2_6_13pre70 --- diff --git a/h/linux.h b/h/linux.h index 474f7f31..3c94d8dc 100644 --- a/h/linux.h +++ b/h/linux.h @@ -132,17 +132,10 @@ do { int c = 0; \ #include #include -#define GET_FULL_PATH_SELF(a_) do { \ - static char q[PATH_MAX]; \ - const char *s="/proc/self/exe"; \ - struct stat ss; \ - if (stat(s,&ss)) \ - (a_)=argv[0]; \ - else { \ - if (!realpath(s,q)) \ - error("realpath error"); \ - (a_)=q; \ - } \ +#define GET_FULL_PATH_SELF(a_) do { \ + static char q[PATH_MAX]; \ + massert(which("/proc/self/exe",q) || which(argv[0],q)); \ + (a_)=q; \ } while(0) diff --git a/o/main.c b/o/main.c index de77f741..e9dda787 100755 --- a/o/main.c +++ b/o/main.c @@ -460,18 +460,49 @@ DEFUN_NEW("EQUAL-TAIL-RECURSION-CHECK",object,fSequal_tail_recursion_check,SI,1, RETURN1((object)(w-u)); } +static int +mbin(const char *s,char *o) { + + struct stat ss; + + if (!stat(s,&ss) && (ss.st_mode&S_IFMT)==S_IFREG && !access(s,R_OK|X_OK)) { + massert(realpath(s,o)); + return 1; + } + + return 0; + +} + +static int +which(const char *n,char *o) { + + char *s; + + if (strchr(n,'/')) + return mbin(n,o); + + massert(snprintf(FN1,sizeof(FN1),"%s",getenv("PATH"))>1); + for (s=NULL;(s=strtok(s ? NULL : FN1,":"));) { + + massert(snprintf(FN2,sizeof(FN2),"%s/%s",s,n)); + if (mbin(FN2,o)) + return 1; + + } + + return 0; + +} + + int main(int argc, char **argv, char **envp) { -#ifdef GET_FULL_PATH_SELF GET_FULL_PATH_SELF(kcl_self); -#else - kcl_self = argv[0]; -#endif - *argv=kcl_self; - + #ifdef CAN_UNRANDOMIZE_SBRK #include #include