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

Move libcap use to (Linux) platform-specific code #564

Merged
merged 3 commits into from
Mar 22, 2021

Conversation

natoscott
Copy link
Member

The libcap code is Linux-specific so move it all below
the linux/ platform subdirectory. As this feature has
custom command-line long options I provide a mechanism
whereby each platform can add custom long options that
augment the main htop options. We'll make use this of
this with the pcp/ platform in due course to implement
the --host and --archive options there.

Related to #536

@natoscott natoscott requested a review from cgzones March 17, 2021 03:30
htop.c Outdated Show resolved Hide resolved
htop.c Outdated Show resolved Hide resolved
htop.c Outdated Show resolved Hide resolved
htop.c Outdated Show resolved Hide resolved
natoscott added a commit to natoscott/htop that referenced this pull request Mar 17, 2021
Follow up on the two items of feedback from cgzones review.

Related to htop-dev#564
natoscott added a commit to natoscott/htop that referenced this pull request Mar 17, 2021
Follow up on the two items of feedback from cgzones review,
and resolve a build failure picked up by CI on Mac OS X.

Related to htop-dev#564
linux/Platform.h Outdated
Comment on lines 33 to 37
#define PLATFORM_LONG_OPTIONS_USAGE \
" --drop-capabilities[=none|basic|strict] Drop Linux capabilities when running as root\n" \
" none - do not drop any capabilities\n" \
" basic (default) - drop all capabilities not needed by htop\n" \
" strict - drop all capabilities except those needed for core functionality\n"
Copy link
Member

Choose a reason for hiding this comment

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

Prone to format string issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess. Any better alternative you can suggest?

Copy link
Member

Choose a reason for hiding this comment

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

One could split the printf() call in htop.c:printHelpFlag() into

printf("%s " VERSION "\n"
         COPYRIGHT "\n"
         "Released under the GNU GPLv2.\n\n"
         "-C --no-color                   Use a monochrome color scheme\n"
         ...
         "-V --version                    Print version info\n",
         name);

Platform_printLongOptionsUsage(name);

printf("\n"
         "Long options may be passed with a single dash.\n\n"
         "Press F1 inside %s for online help.\n"
         "See 'man %s' for more information.\n",
         name, name);

but I am also fine with the current implementation, relying on -Wformat to alert on format string issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cgzones nice - I like that, it's cleaner and more flexible. Will implement shortly and then merge, I think that's the last thing here.

htop.c Outdated
Comment on lines 62 to 64
"Press F1 inside %s for online help.\n"
"See 'man %s' for more information.\n",
name, name, name);
Copy link
Member

Choose a reason for hiding this comment

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

Why not use positional arguments here? Allows for re-use of the same argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good idea! Trying it out though, I get...

htop.c: In function ‘printHelpFlag’:
htop.c:64:10: warning: ISO C does not support %n$ operand number formats [-Wformat=]
   64 |          name);
      |          ^~~~

natoscott added a commit to natoscott/htop that referenced this pull request Mar 22, 2021
The libcap code is Linux-specific so move it all below
the linux/ platform subdirectory.  As this feature has
custom command-line long options I provide a mechanism
whereby each platform can add custom long options that
augment the main htop options.  We'll make use this of
this with the pcp/ platform in due course to implement
the --host and --archive options there.

Related to htop-dev#536
Follow up on the two items of feedback from cgzones review,
and resolve a build failure picked up by CI on Mac OS X.

Related to htop-dev#564
@natoscott natoscott merged commit 6fd5b05 into htop-dev:master Mar 22, 2021
@natoscott natoscott deleted the platform-options branch March 22, 2021 06:25
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.

None yet

3 participants