mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-29 06:45:54 +03:00
5e4c494636
I don't think there's any situation in which an unwrapped execlineb is useful -- if you want to use different versions of the execlineb tool it'll still prefer ones in PATH. At the same time, implementing the wrapper in this way, as a series of two derivations, meant that we didn't get stdenv goodness for the wrapper. This meant that, for example, the wrapper was not stripped, and so execline ended up with runtime dependencies on gcc and the Linux headers. I don't want to have to reimplement this sort of stuff when it's already in stdenv, and so it makes much more sense to create the wrapper in the mkDerivation call, where all of stdenv's normal magic will find it.
51 lines
1.4 KiB
C
51 lines
1.4 KiB
C
/*
|
||
* A wrapper around execlineb, which provides all execline
|
||
* tools on execlineb’s PATH.
|
||
* It is implemented as a C program, because on non-Linux,
|
||
* nested shebang lines are not supported.
|
||
*/
|
||
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
|
||
#include <skalibs/stralloc.h>
|
||
#include <skalibs/djbunix.h>
|
||
#include <skalibs/strerr2.h>
|
||
#include <skalibs/env.h>
|
||
|
||
#define dienomem() strerr_diefu1sys(111, "stralloc_catb")
|
||
|
||
// macros from outside
|
||
/* const char* EXECLINEB_PATH; */
|
||
/* const char* EXECLINE_BIN_PATH; */
|
||
|
||
int main(int argc, char const* argv[], char const *const *envp)
|
||
{
|
||
PROG = "execlineb-wrapper";
|
||
|
||
char const* path = getenv("PATH");
|
||
stralloc path_modif = STRALLOC_ZERO;
|
||
|
||
// modify PATH if unset or EXECLINEB_BIN_PATH is not yet there
|
||
if ( !path || ! strstr(path, EXECLINE_BIN_PATH())) {
|
||
// prepend our execline path
|
||
if ( ! stralloc_cats(&path_modif, "PATH=")
|
||
|| ! stralloc_cats(&path_modif, EXECLINE_BIN_PATH()) ) dienomem();
|
||
// old path was not empty
|
||
if ( path && path[0] ) {
|
||
if ( ! stralloc_catb(&path_modif, ":", 1)
|
||
|| ! stralloc_cats(&path_modif, path) ) dienomem();
|
||
}
|
||
// append final \0
|
||
if ( ! stralloc_0(&path_modif) ) dienomem();
|
||
}
|
||
|
||
// exec into execlineb and append path_modif to the environment
|
||
xpathexec_r_name(
|
||
EXECLINEB_PATH(),
|
||
argv,
|
||
envp, env_len(envp),
|
||
path_modif.s, path_modif.len
|
||
);
|
||
}
|