From 20ca41c3c3aa98cef7b1e0f1c1f183be4b7b768e Mon Sep 17 00:00:00 2001 From: Camm Maguire Date: Sun, 13 Nov 2022 12:55:14 +0000 Subject: [PATCH] TODO: Put a short summary on the line above and replace this paragraph with a longer explanation of this change. Complete the meta-information with other relevant fields (see below for details). To make it easier, the information below has been extracted from the changelog. Adjust it or drop it. gcl (2.6.12-78) unstable; urgency=medium * rebuild against latest compilers and tools * Version_2_6_13pre69 Gbp-Pq: Name Version_2_6_13pre70 --- h/linux.h | 15 ++++----------- o/main.c | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 17 deletions(-) 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 -- 2.30.2