Inherit environment variables from PID 1 by reading /proc/1/environ
gist.github.com
gist.github.com
For example, chromium's implementation: https://source.chromium.org/chromium/chromium/src/+/refs/tag...
7ffffffdd000-7ffffffff000 rw-p 00000000 00:00 0 [stack]
Running `call (int) munmap(0x7ffffffdd000, 0x22000)` in gdb did indeed unmap the stack... and the program segfaulted immediately afterwards. But while the process was still in the stopped state and before it finished crashing/exiting, /proc/<pid>/cmdline was a 0-byte file.On Linux, the system call für spawning a process uses a string array for them.
On windows, it's a single string. The string needs to be parsed by the application, making escape sequences in command line arguments implementation defined by the compiler/runtime/etc.
https://nullprogram.com/blog/2022/02/18/
Some examples are here: https://daviddeley.com/autohotkey/parameters/parameters.htm#...
The previous poster overstates things. Environment variables passed to the process by the kernel[1] are NUL-delimited, including a double-NUL (or zero-length pair) to terminate the list of name=value pairs. Neither is there any syntactical ambiguity, as within each NUL-terminated pair the first '=' character delimits the variable name from the value, regardless of whether there are subsequent '=' characters. So there's no real parsing of the name=value content, only locating each NUL character in turn as a C array is built up by the entry code. The only limitation is that neither names nor values can contain the NUL character, and names cannot contain a '=' character.
The process startup code uses the exact same logic for constructing argv as it does for constructing environ/envp as they're both passed by the kernel in the same manner, including the same NUL-delimited structure. In fact, they're written as one long, serial sequence to the stack, above or beneath (depending on stack direction) the initial stack frame setup for the entry point. And usually argv and environ/envp arrays simply hold pointers directly to this memory region, at least initially. On Linux /proc/$$/environ reads out this region, so it won't necessarily reflect a process' actual environment variables once a process starts changing them.
[1] For both Linux and, at least historically, the BSDs.
The Windows (NT) kernel was built to conform to POSIX, although this functionality was removed, then reimplemented and expanded.
'Broad software compatibility was initially achieved with support for several API "personalities", including Windows API, POSIX, and OS/2 APIs – the latter two were phased out starting with Windows XP.'
You can think of a native dictionary as a declarative structure where each of the pairs "happen" simultaneously. A serialized structure is necessarily imperative because it must be an ordered series of bytes that are evaluated in sequence; it must be in order to be written to disk or sent across the network (with /proc being a sort of hybrid, IPC implemented as a virtual filesystem). So we generally need to convert our dictionaries into lists to serialize them.
You might think of something like sending an entire SQLite database as an exception to this rule, but there's an equivalent perspective that it is an example of the rule instead. Lists of key-value pairs and dictionaries of key-value pairs are duals of each other so you're free to take the interpretation you prefer.
I believe the invocation could be:
export $(xargs -0 echo < /proc/1/environ)
It could be dangerous to use echo in this way in some circumstances.I'm likely guessing right that if, for instance, you take the PATH from /proc/pid/1 and install that as your PATH, your CI process may run into trouble, like not being able to find needed utilities.
That you need superuser privileges to get at these variables should be a red flag.
And they want to run CI commands from manual SSH process, so taking PATH (and everything else) from the original CI process is exactly what they want -- this is all part of the game for SSH process to be a real "CI" runner.
I dont fully get this use case yet..
https://www.kernel.org/doc/html/v5.15/admin-guide/kernel-par...
parameters with ‘=’ go into init’s environment