Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interp: Set GID #514

Closed
jjzcru opened this issue Feb 23, 2020 · 3 comments
Closed

Interp: Set GID #514

jjzcru opened this issue Feb 23, 2020 · 3 comments

Comments

@jjzcru
Copy link

jjzcru commented Feb 23, 2020

I know that you can get the PID from the terminal but there is a way to make the process that is going to work with an specificy GID (Group ID)?

Cheers

@mvdan
Copy link
Owner

mvdan commented Feb 23, 2020

Sorry, I don't get what you're trying to do.

@mvdan
Copy link
Owner

mvdan commented Feb 28, 2020

Closing for now.

@sylv-io
Copy link
Contributor

sylv-io commented Sep 6, 2021

Hello there,

I guess I understand the issue. Analog to bash, only UID is provided as environment variable, but not GID.
Other shells like zsh does also export GID.

This issue can be solved with the following patch:

diff --git a/interp/api.go b/interp/api.go
index 6ac3dc34..b7526c56 100644
--- a/interp/api.go
+++ b/interp/api.go
@@ -444,6 +444,13 @@ func (r *Runner) Reset() {
                        Str:      strconv.Itoa(os.Getuid()),
                })
        }
+       if !r.writeEnv.Get("GID").IsSet() {
+               r.setVar("GID", nil, expand.Variable{
+                       Kind:     expand.String,
+                       ReadOnly: true,
+                       Str:      strconv.Itoa(os.Getgid()),
+               })
+       }
        r.setVarString("PWD", r.Dir)
        r.setVarString("IFS", " \t\n")
        r.setVarString("OPTIND", "1")

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

No branches or pull requests

3 participants