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

cmd/snap-confine: workaround time_t size differences between architectures #15113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bboozzoo
Copy link
Contributor

The following error was observed when building for armhf:

snap-confine/snap-confine.c: In function ‘log_startup_stage’: snap-confine/snap-confine.c:280:60: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘__time64_t’ {aka ‘long long int’} [-Werror=format=]
  280 |     debug("-- snap startup {\"stage\":\"%s\", \"time\":\"%lu.%06lu\"}", stage, tv.tv_sec, tv.tv_usec);
      |                                                          ~~^                   ~~~~~~~~~
      |                                                            |                     |
      |                                                            long unsigned int     __time64_t {aka long long int}
      |                                                          %llu
snap-confine/snap-confine.c:280:66: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__suseconds64_t’ {aka ‘long long int’} [-Werror=format=]
  280 |     debug("-- snap startup {\"stage\":\"%s\", \"time\":\"%lu.%06lu\"}", stage, tv.tv_sec, tv.tv_usec);
      |                                                              ~~~~^                        ~~~~~~~~~~
      |                                                                  |                          |
      |                                                                  long unsigned int          __suseconds64_t {aka long long int}
      |                                                              %06llu
cc1: all warnings being treated as errors

Use proper formatting macros and check for time_t size.

Thanks for helping us make a better snapd!
Have you signed the license agreement and read the contribution guide?

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.07%. Comparing base (a272aac) to head (df56019).
Report is 36 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15113      +/-   ##
==========================================
- Coverage   78.07%   78.07%   -0.01%     
==========================================
  Files        1182     1188       +6     
  Lines      157743   158027     +284     
==========================================
+ Hits       123154   123375     +221     
- Misses      26943    26987      +44     
- Partials     7646     7665      +19     
Flag Coverage Δ
unittests 78.07% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -277,7 +278,14 @@ static void log_startup_stage(const char *stage) {
}
struct timeval tv;
gettimeofday(&tv, NULL);
debug("-- snap startup {\"stage\":\"%s\", \"time\":\"%lu.%06lu\"}", stage, tv.tv_sec, tv.tv_usec);
/* TODO ifdef on __TIMESIZE ? */
Copy link
Contributor

Choose a reason for hiding this comment

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

It would go to the else if __TIMESIZE is not defined, right? So 32 bits. Is it really the default we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tweaked to #if __TIMESIZE == 32

@bboozzoo bboozzoo force-pushed the bboozzoo/time_t-size branch from 84cf191 to d48f15c Compare February 21, 2025 09:22
Copy link

github-actions bot commented Feb 21, 2025

Mon Feb 24 14:24:08 UTC 2025
The following results are from: https://github.com/canonical/snapd/actions/runs/13493536630

Failures:

Executing:

  • google-arm:ubuntu-20.04-arm-64:tests/main/progress
  • google-arm:ubuntu-20.04-arm-64:tests/main/default-tracks
  • google:ubuntu-25.04-64:tests/main/security-device-cgroups-helper
  • google:ubuntu-25.04-64:tests/main/security-device-cgroups-required-or-optional
  • google:ubuntu-25.04-64:tests/main/snap-ns-forward-compat
  • google:ubuntu-25.04-64:tests/main/snap-user-service-socket-activation
  • google:ubuntu-25.04-64:tests/main/security-device-cgroups:kmsg
  • google:ubuntu-25.04-64:tests/main/security-device-cgroups-strict-enforced
  • google:ubuntu-25.04-64:tests/main/security-device-cgroups-serial-port
  • google:ubuntu-25.04-64:tests/main/security-device-cgroups-self-manage
  • google:ubuntu-25.04-64:tests/main/cgroup-devices-v2
  • google:ubuntu-25.04-64:tests/main/security-device-cgroups:uinput
  • google:ubuntu-22.04-64:tests/unit/go:clang
  • google:ubuntu-16.04-64:tests/main/microk8s-smoke:edge

Restoring:

  • google:ubuntu-25.04-64:tests/main/security-device-cgroups-strict-enforced

@bboozzoo bboozzoo force-pushed the bboozzoo/time_t-size branch from d48f15c to 6a678fb Compare February 21, 2025 10:21
Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@@ -277,7 +278,13 @@ static void log_startup_stage(const char *stage) {
}
struct timeval tv;
gettimeofday(&tv, NULL);
debug("-- snap startup {\"stage\":\"%s\", \"time\":\"%lu.%06lu\"}", stage, tv.tv_sec, tv.tv_usec);
#if __TIMESIZE == 32
Copy link
Collaborator

@ernestl ernestl Feb 21, 2025

Choose a reason for hiding this comment

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

Is this not sufficient and simple? #15111

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rebased and updated with explicit int64_t and formatting macros

…tures

The following error was observed when building for armhf:

snap-confine/snap-confine.c: In function ‘log_startup_stage’:
snap-confine/snap-confine.c:280:60: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘__time64_t’ {aka ‘long long int’} [-Werror=format=]
  280 |     debug("-- snap startup {\"stage\":\"%s\", \"time\":\"%lu.%06lu\"}", stage, tv.tv_sec, tv.tv_usec);
      |                                                          ~~^                   ~~~~~~~~~
      |                                                            |                     |
      |                                                            long unsigned int     __time64_t {aka long long int}
      |                                                          %llu
snap-confine/snap-confine.c:280:66: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__suseconds64_t’ {aka ‘long long int’} [-Werror=format=]
  280 |     debug("-- snap startup {\"stage\":\"%s\", \"time\":\"%lu.%06lu\"}", stage, tv.tv_sec, tv.tv_usec);
      |                                                              ~~~~^                        ~~~~~~~~~~
      |                                                                  |                          |
      |                                                                  long unsigned int          __suseconds64_t {aka long long int}
      |                                                              %06llu
cc1: all warnings being treated as errors

Use proper formatting macros and check for time_t size.

Signed-off-by: Maciej Borzecki <[email protected]>
Copy link
Collaborator

@ernestl ernestl left a comment

Choose a reason for hiding this comment

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

Thanks

@ernestl ernestl closed this Feb 24, 2025
@ernestl ernestl reopened this Feb 24, 2025
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.

5 participants