Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 7386 Details for
Bug 13897
Simple distcc wrapper with toggle
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Fixed wrapper.c
wrapper.c (text/plain), 6.11 KB, created by
Eric Andresen
on 2003-01-16 13:56:40 UTC
(
hide
)
Description:
Fixed wrapper.c
Filename:
MIME Type:
Creator:
Eric Andresen
Created:
2003-01-16 13:56:40 UTC
Size:
6.11 KB
patch
obsolete
>/* > * Copyright 1999-2003 Gentoo Technologies, Inc. > * Distributed under the terms of the GNU General Public License v2 > * Author: Martin Schlemmer <azarah@gentoo.org> > * $Header: /home/cvsroot/gentoo-x86/sys-devel/gcc-config/files/wrapper.c,v 1.3 2003/01/15 22:28:10 azarah Exp $ > */ > >#define _REENTRANT >#define _GNU_SOURCE > >#include <stdio.h> >#include <stdlib.h> >#include <sys/types.h> >#include <sys/stat.h> >#include <sys/param.h> >#include <unistd.h> >#include <wait.h> >#include <libgen.h> >#include <string.h> > > >int main(int argc, char **argv) >{ > FILE *inpipe = NULL; > struct stat sbuf; > char wrapperbin[MAXPATHLEN + 1], wrapfullname[MAXPATHLEN + 1]; > char *wrappername = NULL; > char *buffer = NULL, *token = NULL, *tmpstr = NULL, *state = NULL; > int ret = 0; > char *newargs[argc + 1]; > > wrapperbin[0] = '\0'; > > /* What should we find ? */ > wrappername = strdupa(basename(argv[0])); > > /* cc calls gcc ... */ > if (0 == strcmp(wrappername, "cc")) > sprintf(wrappername, "%s", "gcc"); > > buffer = (char *) malloc(16); > /* Check if we're supposed to use distcc or not... */ > sprintf(buffer, "/etc/.usedistcc"); > ret = stat(buffer, &sbuf); > if ((0 == ret) && (sbuf.st_mode & S_IFREG)) > { > /* Using distcc, strip the path.. > * Assumes that distccd server's are using restricted PATH's > */ > argv[0] = wrappername; > /* Pull in cached gcc-config --get-path-bin from last > * source /etc/profile... > */ > if (buffer) > { > free(buffer); > buffer = NULL; > } > > if (getenv("GCCBINPATH")) > { > buffer = strdup((char *) getenv("GCCBINPATH")); > setenv("PATH", buffer, 1); > } else { >/* Just get it from gcc-config instead.. > printf("Oops! GCCBINPATH not set. Please make sure that you have\n" > "the following line in your /etc/profile\n" > "[ -f /etc/profile.d/distcc ] && source /etc/profile.d/distcc\n"); > exit(1); >*/ > /* GCCBINPATH not set.. get it from gcc-config */ > > inpipe = popen("/usr/bin/gcc-config --get-bin-path", "r"); > if (NULL == inpipe) > { > fprintf(stderr, "Oops! GCCBINPATH not set and could not run /usr/bin/gcc-config!\n" > "Please make sure that you have the following line in your /etc/profile\n" > "[ -f /etc/profile.d/distcc ] && source /etc/profile.d/distcc\n"); > exit(1); > } > > buffer = (char *)malloc(MAXPATHLEN + 1); > if (fgets(buffer, MAXPATHLEN, inpipe) == 0) > { > fprintf(stderr, "Could not get compiler binary path!\n"); > > if (buffer) > { > free(buffer); > buffer = NULL; > } > > pclose(inpipe); > > exit(1); > } > /* just use wrapfullname to hold path temp */ > sscanf(buffer, "%s", wrapfullname); > setenv("PATH", wrapfullname, 1); > pclose(inpipe); > } > > int j = 1; > > while (j <= argc) > { > newargs[j] = argv[j - 1]; > j++; > } > > newargs[0] = "/usr/bin/distcc"; > > /* Ok, do it ... */ > if (execv(newargs[0], newargs) < 0) > { > fprintf(stderr, "Could not run/locate %s!\n", newargs[0]); > exit(1); > } > > } else { > > /* What is the full name of our wrapper? */ > snprintf(wrapfullname, strlen("/usr/bin/") + strlen(wrappername) + 1, > "%s%s", "/usr/bin/", wrappername); > > if (buffer) > { > free(buffer); > buffer = NULL; > } > > buffer = strdup((char *) getenv("PATH")); > token = strtok_r(buffer, ":", &state); > ret = 0; > /* Find the first file with suitable name in PATH */ > while ((NULL != token) && (strlen(token) > 0)) > { > > tmpstr = (char *) malloc(strlen(token) + strlen(wrappername) + 2); > snprintf(tmpstr, strlen(token) + strlen(wrappername) + 2, > "%s/%s", token, wrappername); > > /* Does it exist and is a file? */ > ret = stat(tmpstr, &sbuf); > /* It exists, and are not our wrapper, and its not in /usr/bin ... */ > if ((0 == ret) && (sbuf.st_mode & S_IFREG) && > (0 != strcmp(tmpstr, wrapfullname)) > && (0 == strstr(tmpstr, "/usr/bin"))) > { > > strncpy(wrapperbin, tmpstr, MAXPATHLEN); > > if (tmpstr) > { > free(tmpstr); > tmpstr = NULL; > } > > break; > } > > token = strtok_r(NULL, ":", &state); > } > > if (buffer) > { > free(buffer); > buffer = NULL; > } > /* Did we get a valid binary to execute? */ > if (wrapperbin[0] == '\0') > { > /* It is our wrapper, so get the CC path, and execute the real binary in > * there ... */ > > inpipe = popen("/usr/bin/gcc-config --get-bin-path", "r"); > if (NULL == inpipe) > { > fprintf(stderr, "Could not run /usr/bin/gcc-config!\n"); > exit(1); > } > > buffer = (char *)malloc(MAXPATHLEN + 1); > > if (fgets(buffer, MAXPATHLEN, inpipe) == 0) > { > fprintf(stderr, "Could not get compiler binary path!\n"); > > if (buffer) > { > free(buffer); > buffer = NULL; > } > > pclose(inpipe); > > exit(1); > } > > sscanf(buffer, "%s", wrapperbin); > strncat(wrapperbin, "/", MAXPATHLEN - strlen(wrapperbin)); > strncat(wrapperbin, wrappername, MAXPATHLEN - strlen(wrapperbin)); > > pclose(inpipe); > > if (buffer) > { > free(buffer); > buffer = NULL; > } > } > > /* Set argv[0] to the correct binary, else gcc do not find internal > * headers, etc (bug #8132). */ > argv[0] = wrapperbin; > > /* Ok, do it ... */ > if (execv(argv[0], argv) < 0) > { > fprintf(stderr, "Could not run/locate %s!\n", argv[0]); > exit(1); > } > } > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 13897
:
7287
|
7321
|
7352
|
7355
|
7359
|
7386
|
7476
|
7483
|
7491
|
7602
|
7767
|
7768
|
7900
|
7982
|
8056