Skip to content

Commit 1245051

Browse files
authored
Merge pull request #93 from K900/revert-default-path
Partially revert "remvoe dead code"
2 parents e0bb4ca + 416a246 commit 1245051

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/args.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@ impl Args {
194194
explode("The handoff function returned");
195195
}
196196

197+
/// Creates a new environment variable.
198+
pub fn add_env<F>(&mut self, name: &str, value_len: usize, f: F) -> Result<*const u8, ()>
199+
where
200+
F: FnOnce(&mut [u8]),
201+
{
202+
if self.extra_env.is_some() {
203+
return Err(());
204+
}
205+
206+
let name_len = name.len();
207+
let whole_len = name_len + 1 + value_len;
208+
let new_buf = new_slice_leak(whole_len + 1).unwrap();
209+
new_buf[..name_len].copy_from_slice(name.as_bytes());
210+
new_buf[name_len] = b'=';
211+
new_buf[whole_len] = 0;
212+
213+
f(&mut new_buf[name_len + 1..whole_len]);
214+
215+
self.extra_env = Some(new_buf.as_ptr());
216+
Ok(new_buf.as_ptr())
217+
}
218+
197219
pub fn iter_env(&mut self) -> Option<EnvIter> {
198220
if self.env_iterated {
199221
return None;

src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ extern "C" fn real_main() -> ! {
152152
} else {
153153
log::info!("Neither LD_LIBRARY_PATH or NIX_LD_LIBRARY_PATH exist - Setting default");
154154

155+
args
156+
.add_env(
157+
"LD_LIBRARY_PATH",
158+
DEFAULT_NIX_LD_LIBRARY_PATH.len(),
159+
|buf| {
160+
buf.copy_from_slice(DEFAULT_NIX_LD_LIBRARY_PATH);
161+
},
162+
)
163+
.unwrap();
164+
155165
// If the entry trampoline is available on the platform, LD_LIBRARY_PATH
156166
// will be replaced with an empty LD_LIBRARY_PATH when ld.so launches
157167
// the actual program.

0 commit comments

Comments
 (0)