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

Go's syscall package FreeBSD is missing S_IRWXG and S_IRWXO #2079

Closed
wants to merge 2 commits into from

Conversation

janl
Copy link

@janl janl commented Jul 29, 2018

This patch adds a _freebsd.go file that builds instead of the regular
one only on Freebsd (to the best of my cross-platform Go abilities).

It imports the C constants S_IRWXG and S_IRWXO and uses them instead
of syscall.S_IRWXG and syscall.S_IRWXO.

Closes #2078

The relevant diff is:

--- pkg/secrets/check_right.go	2018-07-29 16:56:36.000000000 +0200
+++ pkg/secrets/check_right_freebsd.go	2018-07-29 16:56:36.000000000 +0200
@@ -3,10 +3,17 @@
 // This product includes software developed at Datadog (https://www.datadoghq.com/).
 // Copyright 2018 Datadog, Inc.
 
-// +build !windows,!freebsd
+// +build freebsd
 
 package secrets
 
+// temporary fix until go gets S_IRWXG and S_IRWXO
+
+/*
+#include <sys/stat.h>
+*/
+import "C"
+
 import (
 	"fmt"
 	"os/user"
@@ -20,7 +27,7 @@
 	}
 
 	// checking that group and others don't have any rights
-	if stat.Mode&(syscall.S_IRWXG|syscall.S_IRWXO) != 0 {
+	if stat.Mode&(C.S_IRWXG|C.S_IRWXO) != 0 {
 		return fmt.Errorf("invalid executable '%s', 'groups' or 'others' have rights on it", path)
 	}

@janl janl requested a review from a team as a code owner July 29, 2018 14:52
@janl janl changed the title Go’s syscall package FreeBSD is missing S_IRWXG and S_IRWXO Go's syscall package FreeBSD is missing S_IRWXG and S_IRWXO Jul 29, 2018
janl added 2 commits July 29, 2018 16:56
This patch adds a _freebsd.go file that builds instead of the regular
one *only* on Freebsd (to the best of my cross-platform Go abilities).

It imports the C constants S_IRWXG and S_IRWXO and uses them instead
of syscall.S_IRWXG and syscall.S_IRWXO.

Closes DataDog#2078
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2018 Datadog, Inc.

// +build freebsd
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line might be double the trouble, but doesn’t hurt either

gopherbot pushed a commit to golang/sys that referenced this pull request Aug 8, 2018
I found this during DataDog/datadog-agent#2079

Change-Id: I51d57e7e3cedb8b23e720bc03f38504dc0ad063d
GitHub-Last-Rev: 4e1c193
GitHub-Pull-Request: #13
Reviewed-on: https://go-review.googlesource.com/126620
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@janl
Copy link
Author

janl commented Aug 14, 2018

ping cc @masci <3

@olivielpeau
Copy link
Member

Hi @janl, thanks for opening this PR! (and for the detailed explanation of the root cause)

The one downside I see to your PR is that it adds a dependency on cgo in a "core" part of the Agent, which will prevent the core of the Agent from being cross-compiled using the regular go toolchain. We want to keep the ability to do so in order to easily ship minimal Agents for all the platforms that go supports at some point in the future (we call this minimal Agent the "puppy" Agent, we don't have docs for it right now, but there's some info on #346 if you're interested).

Anyway, do you plan to use the features provided in the secrets package (documented here: https://github.com/DataDog/datadog-agent/blob/master/docs/agent/secrets.md) in your build of the Agent on FreeBSD? It's a beta feature that we only support on Linux for now.

If you don't plan to, I'd suggest removing the secrets package entirely from the FreeBSD build (by modifying the build tag on the files of the secrets package to !windows,!freebsd), and use a "placeholder" file for freebsd similar to what's done for Windows.

Let me know what you think!

@olivielpeau olivielpeau added the [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead.. label Aug 14, 2018
@janl
Copy link
Author

janl commented Aug 15, 2018

@olivielpeau thanks for the detailed and thoughtful reply. I didn’t realise secrets was something non-essential to be enabled at build time. That’s definitely good enough for me for now.

That said, an alternative patch could be a bit more “risky”. These constants are ancient Unix 25+year old constants and likely to have the same bitmask values everywhere. Given that this patch introduces a FreeBSD-only compilation path, you could be open to accept using the raw bitmask values in the two places needed. The FreeBSD-only complication path could be removed once you require a go version that this is fixed in.

If you’re interested, I can amend the patch.

@olivielpeau
Copy link
Member

@janl Using the raw bitmask values sounds good to me, if you could amend your patch this way that'd be great, thanks 👍. Could you also leave a FIXME comment as a reminder to update it once your patch on golang is shipped in go stable?

@irabinovitch
Copy link
Contributor

@janl Thanks again for your contributions here. Were you still interested in working through the changes olivielpeau suggested?

@irabinovitch
Copy link
Contributor

@janl Thanks again for your contributions here. It sounds like you might have gotten busy with other projects. Should we close this PR and revisit at a future date?

@arapulido
Copy link
Contributor

Thanks again @janl for your contributions here. Any chance you will be able to work on the changes suggested by @olivielpeau or shall we close for now and revisit later?

@janl janl closed this Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead..
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build fails on FreeBSD (11.2)
4 participants