Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

htop not working. #1

Open
sergey6661313 opened this issue Jun 27, 2021 · 5 comments
Open

htop not working. #1

sergey6661313 opened this issue Jun 27, 2021 · 5 comments

Comments

@sergey6661313
Copy link

just say:

> htop
Error opening terminal: unknown.
Command returned 256.
@ratfactor
Copy link
Owner

Huh! That must be because I don't pass $TERM. I might experiment with this. Thanks for the issue. :-)

@sschneemelcher
Copy link

Huh! That must be because I don't pass $TERM. I might experiment with this. Thanks for the issue. :-)

This is correct, I tried this, setting the env to something like

const env = [_:null]?[*:0]u8{ "TERM=xterm", null };

makes htop work 😄

@ratfactor
Copy link
Owner

@sschneemelcher Awesome, thanks! 🎉

Note to self (TODO): either pass env to forked process or at least add a comment so others can try it out, then update article and/or readme as needed.

@sskras
Copy link

sskras commented Feb 20, 2023

ping:)

@ratfactor
Copy link
Owner

Okay, so I took a look at this today. The Zig stdlib has std.os.environ:

https://github.com/ziglang/zig/blob/1653a9b2597c66cbcc88ea75d8a4b88c163584a5/lib/std/os.zig#L239

/// See also `getenv`. Populated by startup code before main().
pub var environ: [][*:0]u8 = undefined;

That []*:0]u8 is just sitting there in memory, waiting to be used. But std.os.execvpeZ() wants that environment parameter to be a [*:null]const ?[*:0]const u8.

Passing it anyway gives me this:

src/main.zig:62:78: error: expected type '[*:null]const ?[*:0]const u8', found '[][*:0]u8'
            const result = std.os.execvpeZ(args_ptrs[0].?, &args_ptrs, std.os.environ);
                                                                       ~~~~~~^~~~~~~~
/home/dave/zig/lib/std/os.zig:1857:12: note: parameter type declared here
    envp: [*:null]const ?[*:0]const u8,
          ~^~~~~~~~~~~~~~~~~~~~~~~~~~~

Which is no surprise.

I'm not sure that it would be possible to "add" a null termination to the array through casting alone. It seems like we would need to allocate space and copy the whole environment array in order to add the null termination? I'd love to not have to do that!

I also found std.c.environ, which looks almost exactly right ([*:null]?[*:0]u8), but it requires that zigish be built with libc:

/home/dave/zig/lib/std/c.zig:122:30: error: dependency on libc must be explicitly specified in the build command
pub extern "c" var environ: [*:null]?[*:0]u8;
                            ~^~~~~~~~~~~~~~~

which feels like serious overkill!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants