Skip to content

Conversation

evverx
Copy link
Contributor

@evverx evverx commented Jul 9, 2020

Closes #4093

infra/utils.py Outdated

Returns:
Container name or None if not in a container.
"""
with open('/proc/self/cgroup') as file_handle:
if 'docker' not in file_handle.read():
if b'docker' not in subprocess.run('systemd-detect-virt -c', shell=True, stdout=subprocess.PIPE).stdout:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you so much! you rock!

can you please do
result = subprocess.run('systemd-detect-virt -c', shell=True, stdout=subprocess.PIPE)
if b'docker' in result.stdout:

Copy link
Contributor

Choose a reason for hiding this comment

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

stdout=subprocess.PIPE can be skipped as well i think

Copy link
Contributor

@jonathanmetzman jonathanmetzman Jul 9, 2020

Choose a reason for hiding this comment

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

b'docker' in subprocess.run(['systemd-detect-virt', '-c'], stdout=subprocess.PIPE).stdout should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://docs.python.org/3/library/subprocess.html#subprocess.run, run doesn't capture stdout by default. Another option would be to pass capture_output=True to it but it was added relatively recently so I don't expect it to be available on Ubuntu (where python-3.5 is still used).

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just subprocess.check_output
This is equivalent to:
run(..., check=True, stdout=PIPE).stdout

Copy link
Contributor Author

@evverx evverx Jul 9, 2020

Choose a reason for hiding this comment

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

systemd-detect-virt -c returns 1 when it isn't run in containers, which makes check_output throw exceptions left and right. I don't think it's desirable given that that code can be run elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok then, please move this to a local var, that line is too long. rest lgtm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I replaced shell=True with ['systemd-detect-virt', '-c'] as @jonathanmetzman suggested.

I'll add result=... shortly

@evverx evverx force-pushed the systemd-detect-virt branch 2 times, most recently from 906221d to c563c92 Compare July 9, 2020 19:41
@inferno-chromium
Copy link
Contributor

Minor lint failure in presubmit in https://github.com/google/oss-fuzz/pull/4101/checks?check_run_id=855435834

-  result = subprocess.run(['systemd-detect-virt', '-c'], stdout=subprocess.PIPE).stdout
+  result = subprocess.run(['systemd-detect-virt', '-c'],
+                          stdout=subprocess.PIPE).stdout

@evverx evverx force-pushed the systemd-detect-virt branch from c563c92 to 69cb2fe Compare July 9, 2020 19:48
@inferno-chromium inferno-chromium merged commit ec269ac into google:master Jul 9, 2020
@evverx
Copy link
Contributor Author

evverx commented Jul 9, 2020

The presubmit check is still failing unfortunately with

************* Module utils
infra/utils.py:96:11: W1510: Using subprocess.run without explicitly set `check` is not recommended. (subprocess-run-check)

-----------------------------------
Your code has been rated at 9.81/10

@inferno-chromium
Copy link
Contributor

The presubmit check is still failing unfortunately with

************* Module utils
infra/utils.py:96:11: W1510: Using subprocess.run without explicitly set `check` is not recommended. (subprocess-run-check)

-----------------------------------
Your code has been rated at 9.81/10

it is ok, we will fix it sometime later.

evverx added a commit to evverx/oss-fuzz that referenced this pull request Jul 9, 2020
"check" is omitted intentionally there.

A follow-up to google#4101
@evverx evverx deleted the systemd-detect-virt branch July 9, 2020 20:52
@evverx
Copy link
Contributor Author

evverx commented Jul 9, 2020

it is ok, we will fix it sometime later

Until then it would probably make sense to ignore subprocess-run-check there. I've just opened #4102.

inferno-chromium pushed a commit that referenced this pull request Jul 9, 2020
"check" is omitted intentionally there.

A follow-up to #4101
tdf-gerrit pushed a commit to LibreOffice/core that referenced this pull request Apr 10, 2021
Drop the older container detection attempts because they are not
reliable to detect being run as root in a container in github actions.

<cloph> google/oss-fuzz#4093 (comment) "It appears some GitHub actions are run with docker.service (where docker is in /proc/self/cgroup) while the zstd actions are run with containerd.service where /proc/self/cgroup looks like […]"
<cloph> google/oss-fuzz#4101 → probably also just use systemd-detect-virt instead of the grepping ourselves...

if we're root and systemd-detect-virt doesn't exist or it claims
we're not in a container then continue to abort the build

using LIB_FUZZING_ENGINE for the oss-fuzz specific case worked fine,
but lets try something a little more generic.

Change-Id: I59711b01dfcd052b5af899ad41ae5890f849eacb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113738
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[zstd] CIFuzz failing to build
3 participants