Skip to content

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

Merged
natoscott merged 3 commits intohtop-dev:masterfrom
natoscott:platform-options
Mar 22, 2021
Merged

Move libcap use to (Linux) platform-specific code#564
natoscott merged 3 commits intohtop-dev:masterfrom
natoscott:platform-options

Conversation

@natoscott
Copy link
Copy Markdown
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
Comment thread htop.c Outdated
Comment thread htop.c Outdated
Comment thread htop.c Outdated
Comment thread htop.c Outdated
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
Comment thread 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread 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
Copy Markdown
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
Copy Markdown
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.

3 participants