-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this invoking one of the utilities with `-h` will display the manpage. Since quark is not a "system utility", we can't expect people to go to the trouble of installing manpages, and typing `man ./quark-mon.8` is a pain. It's also likely that the binary is sent somewhere and thus the man relationship was lost. I had to write a mini-utility to embed the manpage, it's a bit sad that there isn't a `mandoc -T c` to export the manpage as a C struct. Arm64 cross compilation gets a little bit trickier: In order to build quark-mon, quark-btf and quark-test, it needs to build manpage.h, and to build manpage.h it needs to build man-embedder. But it can't build man-embedder for arm64, since we must be able to execute it! We fix it by cheating the order build, we force manpages.h to be evaluated before `all` in the host system. Which pulls man-embedder for the host and generates manpage.h. The only drawback is that man-embedder will stay built for the host system, which is fine since it's a build-system executable.
- Loading branch information
Showing
13 changed files
with
225 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* This code is stashed in the end of manpage.h | ||
*/ | ||
static void | ||
display_man(void) | ||
{ | ||
int fd, status; | ||
char template[] = "/tmp/quark-man-display.XXXXXX"; | ||
pid_t pid; | ||
|
||
fd = mkstemp(template); | ||
if (fd == -1) | ||
err(1, "mkstemp"); | ||
if (qwrite(fd, manpage_bin, sizeof(manpage_bin)) != 0) | ||
err(1, "qwrite"); | ||
close(fd); | ||
|
||
if ((pid = fork()) == -1) | ||
err(1, "fork"); | ||
|
||
/* child */ | ||
if (pid == 0) | ||
exit(execlp("man", "man", template, NULL)); | ||
/* parent */ | ||
if (waitpid(pid, &status, 0) == -1) | ||
err(1, "waitpid"); | ||
if (unlink(template) != 0) | ||
warn("unlink"); | ||
if (WIFEXITED(status)) | ||
exit(WEXITSTATUS(status)); | ||
|
||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* Copyright (c) 2024 Elastic NV */ | ||
|
||
#include <err.h> | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <strings.h> | ||
#include <unistd.h> | ||
|
||
static void | ||
usage(void) | ||
{ | ||
fprintf(stderr, "usage: %s input_file ifdef_name\n", | ||
program_invocation_short_name); | ||
|
||
exit(1); | ||
} | ||
|
||
static int | ||
embed(const char *input_path, const char *ifdef_name) | ||
{ | ||
FILE *input; | ||
int ch, line_wrap; | ||
|
||
if ((input = fopen(input_path, "r")) == NULL) | ||
err(1, "fopen"); | ||
|
||
if (ifdef_name != NULL) | ||
printf("#ifdef %s\n", ifdef_name); | ||
printf("const char manpage_bin[] = {\n"); | ||
|
||
line_wrap = 0; | ||
while ((ch = fgetc(input)) != EOF) { | ||
if (line_wrap == 0) | ||
putchar('\t'); | ||
printf("0x%02x, ", ch); | ||
if (++line_wrap == 10) { | ||
putchar('\n'); | ||
line_wrap = 0; | ||
} | ||
} | ||
if (ferror(input)) | ||
errx(1, "input error"); | ||
fclose(input); | ||
|
||
printf("\n};\n"); | ||
if (ifdef_name != NULL) | ||
printf("#endif /* %s */", ifdef_name); | ||
putchar('\n'); | ||
|
||
return (0); | ||
} | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
if (argc != 3) | ||
usage(); | ||
|
||
return (embed(argv[1], argv[2])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.