Skip to content
New issue

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

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

Already on GitHub? # to your account

cleanup(libscap): Allow retries after encountering SCAP_EOF #1809

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

geraldcombs
Copy link
Contributor

Call gzclearerr if gzread returns fewer bytes than expected. This lets us "tail" a file being written by another process.

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

return gzread(((reader_handle_t*)r->handle)->m_file, buf, len);
int readsize = gzread(((reader_handle_t*)r->handle)->m_file, buf, len);

if (readsize < (int)len)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't all of this be handled by the client program?

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 don't think so, at least with the current API. I'm trying to use sinsp::open_savefile() + sinsp::next() to read events from a file which is simultaneously being written by another process. The problem is that EOF handling in zlib is sticky; it changes its internal state when it reaches the end of input which in turn causes subsequent sinsp::next() calls to fail with SCAP_EOF even after more data has been written to the file.

The gzread documentation recommends using gzclearerr in this case. I don't think I can do so from the client side because we don't appear expose the gzFile handle.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification, LGTM!

@FedeDP
Copy link
Contributor

FedeDP commented Apr 23, 2024

/milestone TBD

@poiana poiana added this to the TBD milestone Apr 23, 2024
Call gzclearerr if gzread returns fewer bytes than expected. This lets
us "tail" a file being written by another process.

Signed-off-by: Gerald Combs <gerald@wireshark.org>
Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

/approve

/milestone 0.17.0

@poiana poiana modified the milestones: TBD, 0.17.0 Apr 24, 2024
@poiana poiana added the lgtm label Apr 24, 2024
@poiana
Copy link
Contributor

poiana commented Apr 24, 2024

LGTM label has been added.

Git tree hash: a3841cf57628ac62d83d8928fb0fe41122b1cfcb

@jasondellaluce
Copy link
Contributor

/milestone TBD

@poiana poiana modified the milestones: 0.17.0, TBD Apr 24, 2024
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Apr 24, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, geraldcombs, jasondellaluce

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [FedeDP,jasondellaluce]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@FedeDP
Copy link
Contributor

FedeDP commented Apr 24, 2024

/milestone 0.17.0

@poiana poiana modified the milestones: TBD, 0.17.0 Apr 24, 2024
@poiana poiana merged commit 13d73bf into falcosecurity:master Apr 24, 2024
39 of 40 checks passed
@Andreagit97 Andreagit97 removed this from the 0.17.0 milestone May 2, 2024
@Andreagit97 Andreagit97 added this to the 0.16.0 milestone May 2, 2024
@Andreagit97 Andreagit97 mentioned this pull request May 2, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants