From 6e266e43ddbd99cadc814190c54eb77890f42479 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Tue, 1 Apr 2025 23:44:50 +0800 Subject: feat(www): add cheat-sheet. --- store/home/config/nvim/lua/setup/plugins/cmp.lua | 5 +- www/content/hurd/_index.md | 182 ----------------------- www/content/hurd/todos.md | 54 ------- www/content/notes/cheat-sheet/_index.md | 15 ++ www/content/notes/hurd/_index.md | 182 +++++++++++++++++++++++ www/content/notes/hurd/todos.md | 54 +++++++ www/content/notes/todos.md | 7 + www/content/posts/c-func-ext.md | 80 ++++++++-- www/content/todos.md | 7 - www/layouts/index.html | 21 +-- 10 files changed, 342 insertions(+), 265 deletions(-) delete mode 100644 www/content/hurd/_index.md delete mode 100644 www/content/hurd/todos.md create mode 100644 www/content/notes/cheat-sheet/_index.md create mode 100644 www/content/notes/hurd/_index.md create mode 100644 www/content/notes/hurd/todos.md create mode 100644 www/content/notes/todos.md delete mode 100644 www/content/todos.md diff --git a/store/home/config/nvim/lua/setup/plugins/cmp.lua b/store/home/config/nvim/lua/setup/plugins/cmp.lua index c977943..be9f8ea 100644 --- a/store/home/config/nvim/lua/setup/plugins/cmp.lua +++ b/store/home/config/nvim/lua/setup/plugins/cmp.lua @@ -7,15 +7,12 @@ local function setup() vim.snippet.expand(args.body) end, }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), [''] = cmp.mapping.confirm({ select = true }), }), diff --git a/www/content/hurd/_index.md b/www/content/hurd/_index.md deleted file mode 100644 index b4c727c..0000000 --- a/www/content/hurd/_index.md +++ /dev/null @@ -1,182 +0,0 @@ ---- -title: "Hurd" -date: 2025-03-03T15:34:41+08:00 -lastmod: 2025-03-03T23:28:46+08:00 -layout: single ---- - -{{< mono >}} - -[TODOS](/hurd/todos) - -{{< /mono >}} - -## links - -{{< mono >}} - -| name | link | -| --- | --- | -| kernel-list-archive | | -| debian-list-archive | | -| irc-archive | | -| kernel-home | | -| debian-home | | - -{{< /mono >}} - -refs: - -{{< mono >}} - -| name | link | -| --- | --- | -| c | | -| posix latest | | -| posix 2013 | | -| posix 2008 | | -| glibc | | - -{{< /mono >}} - -## *_MAX patch - -TODO: Move to separate page. - -```c -#include -#include -#include - -static inline char *xreadlink(const char *restrict path) { - char *buffer; - size_t allocated = 128; - ssize_t len; - - while (1) { - buffer = (char *)malloc(allocated); - if (!buffer) { - return NULL; - } - len = readlink(path, buffer, allocated); - if (len < (ssize_t)allocated) { - return buffer; - } - free(buffer); - if (len >= (ssize_t)allocated) { - allocated *= 2; - continue; - } - return NULL; - } -} - -static inline char *xgethostname() { - long max_host_name; - char *buffer; - - max_host_name = sysconf(_SC_HOST_NAME_MAX); - buffer = malloc(max_host_name + 1); - - if (gethostname(buffer, max_host_name + 1)) { - free(buffer); - return NULL; - } - - buffer[max_host_name] = '\0'; - return buffer; -} - -static inline char *xgetcwd() { - char *buffer; - size_t allocated = 128; - - while (1) { - buffer = (char *)malloc(allocated); - if (!buffer) { - return NULL; - } - getcwd(buffer, allocated); - if (buffer) - return buffer; - free(buffer); - if (errno == ERANGE) { - allocated *= 2; - continue; - } - return NULL; - } -} -``` - -## git repos - -{{< link-group >}} -hurd -cru: -upstream: -debian: -{{< /link-group >}} - -{{< link-group >}} -gnumach -cru: -upstream: -debian: -{{< /link-group >}} - -{{< link-group >}} -mig -cru: -upstream: -debian: -{{< /link-group >}} - -{{< link-group >}} -glibc -cru: -upstream: -debian: -mirror: -{{< /link-group >}} - -{{< link-group >}} -web -cru: -upstream: -{{< /link-group >}} - -## cheatsheet - -Start qemu - -```sh -qemu-system-x86_64 -enable-kvm -m 4G -net nic -net user,hostfwd=tcp::3222-:22 -vga vmware -drive cache=writeback,file=[...] -``` - -Configure/Setup network - -```sh -settrans -fgap /servers/socket/2 /hurd/pfinet -i /dev/eth0 -a 10.0.2.15 -g 10.0.2.2 -m 255.255.255.0 -fsysopts /servers/socket/2 /hurd/pfinet -i /dev/eth0 -a 10.0.2.15 -g 10.0.2.2 -m 255.255.255.0 -fsysopts /server/socket/2 -a 10.0.2.15 -g 10.0.2.2 -m 255.255.255.0 -``` - -Setup apt - -```sh -apt-get --allow-unauthenticated --allow-insecure-repositories update -apt-get --allow-unauthenticated upgrade -``` - -## mailing lists / irc - -{{< mono >}} - -| name | address | -| --- | --- | -| hurd | | -| debian | | -| irc | librechat #hurd | - -{{< /mono >}} diff --git a/www/content/hurd/todos.md b/www/content/hurd/todos.md deleted file mode 100644 index f8273fb..0000000 --- a/www/content/hurd/todos.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: "Hurd Todos" -date: 2025-03-03T21:22:35+08:00 -lastmod: 2025-03-03T23:28:46+08:00 -params: - css: - - todos ---- - -## Porting - -### {{< todo name=pam state=working >}} - -{{< link-group >}} -git -cru: -debian: -upstream: -{{< /link-group >}} - -{{< link-group >}} -mail - -{{< /link-group >}} - -### {{< todo name=abseil state=working >}} - -{{< link-group >}} -git -cru: -upstream: -debian: -{{< /link-group >}} - -{{< link-group >}} -mail - - -{{< /link-group >}} - -### {{< todo name=libgav1 state=done >}} - -{{< link-group >}} -git -my: -debian: -upstream: -{{< /link-group >}} - -{{< link-group >}} -misc -mail: -gerrit: -{{< /link-group >}} diff --git a/www/content/notes/cheat-sheet/_index.md b/www/content/notes/cheat-sheet/_index.md new file mode 100644 index 0000000..f379f0b --- /dev/null +++ b/www/content/notes/cheat-sheet/_index.md @@ -0,0 +1,15 @@ +--- +title: "Cheat Sheet" +date: 2025-04-01T23:09:53+08:00 +lastmod: 2025-04-01T23:09:53+08:00 +layout: single +--- + +Update GRUB after `grub` package is updated. Replace `/boot` with your mount +point of the EFI partition in `--efi-directory=/boot`. Replace `GRUB` with your +bootloader id in `--bootloader-id=GRUB`. + +```bash-session +grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB +grub-mkconfig -o /boot/grub/grub.cfg +``` diff --git a/www/content/notes/hurd/_index.md b/www/content/notes/hurd/_index.md new file mode 100644 index 0000000..86b062a --- /dev/null +++ b/www/content/notes/hurd/_index.md @@ -0,0 +1,182 @@ +--- +title: "Hurd" +date: 2025-03-03T15:34:41+08:00 +lastmod: 2025-03-03T23:28:46+08:00 +layout: single +--- + +{{< mono >}} + +[TODOS](/notes/hurd/todos) + +{{< /mono >}} + +## links + +{{< mono >}} + +| name | link | +| --- | --- | +| kernel-list-archive | | +| debian-list-archive | | +| irc-archive | | +| kernel-home | | +| debian-home | | + +{{< /mono >}} + +refs: + +{{< mono >}} + +| name | link | +| --- | --- | +| c | | +| posix latest | | +| posix 2013 | | +| posix 2008 | | +| glibc | | + +{{< /mono >}} + +## *_MAX patch + +TODO: Move to separate page. + +```c +#include +#include +#include + +static inline char *xreadlink(const char *restrict path) { + char *buffer; + size_t allocated = 128; + ssize_t len; + + while (1) { + buffer = (char *)malloc(allocated); + if (!buffer) { + return NULL; + } + len = readlink(path, buffer, allocated); + if (len < (ssize_t)allocated) { + return buffer; + } + free(buffer); + if (len >= (ssize_t)allocated) { + allocated *= 2; + continue; + } + return NULL; + } +} + +static inline char *xgethostname() { + long max_host_name; + char *buffer; + + max_host_name = sysconf(_SC_HOST_NAME_MAX); + buffer = malloc(max_host_name + 1); + + if (gethostname(buffer, max_host_name + 1)) { + free(buffer); + return NULL; + } + + buffer[max_host_name] = '\0'; + return buffer; +} + +static inline char *xgetcwd() { + char *buffer; + size_t allocated = 128; + + while (1) { + buffer = (char *)malloc(allocated); + if (!buffer) { + return NULL; + } + getcwd(buffer, allocated); + if (buffer) + return buffer; + free(buffer); + if (errno == ERANGE) { + allocated *= 2; + continue; + } + return NULL; + } +} +``` + +## git repos + +{{< link-group >}} +hurd +cru: +upstream: +debian: +{{< /link-group >}} + +{{< link-group >}} +gnumach +cru: +upstream: +debian: +{{< /link-group >}} + +{{< link-group >}} +mig +cru: +upstream: +debian: +{{< /link-group >}} + +{{< link-group >}} +glibc +cru: +upstream: +debian: +mirror: +{{< /link-group >}} + +{{< link-group >}} +web +cru: +upstream: +{{< /link-group >}} + +## cheatsheet + +Start qemu + +```sh +qemu-system-x86_64 -enable-kvm -m 4G -net nic -net user,hostfwd=tcp::3222-:22 -vga vmware -drive cache=writeback,file=[...] +``` + +Configure/Setup network + +```sh +settrans -fgap /servers/socket/2 /hurd/pfinet -i /dev/eth0 -a 10.0.2.15 -g 10.0.2.2 -m 255.255.255.0 +fsysopts /servers/socket/2 /hurd/pfinet -i /dev/eth0 -a 10.0.2.15 -g 10.0.2.2 -m 255.255.255.0 +fsysopts /server/socket/2 -a 10.0.2.15 -g 10.0.2.2 -m 255.255.255.0 +``` + +Setup apt + +```sh +apt-get --allow-unauthenticated --allow-insecure-repositories update +apt-get --allow-unauthenticated upgrade +``` + +## mailing lists / irc + +{{< mono >}} + +| name | address | +| --- | --- | +| hurd | | +| debian | | +| irc | librechat #hurd | + +{{< /mono >}} diff --git a/www/content/notes/hurd/todos.md b/www/content/notes/hurd/todos.md new file mode 100644 index 0000000..f8273fb --- /dev/null +++ b/www/content/notes/hurd/todos.md @@ -0,0 +1,54 @@ +--- +title: "Hurd Todos" +date: 2025-03-03T21:22:35+08:00 +lastmod: 2025-03-03T23:28:46+08:00 +params: + css: + - todos +--- + +## Porting + +### {{< todo name=pam state=working >}} + +{{< link-group >}} +git +cru: +debian: +upstream: +{{< /link-group >}} + +{{< link-group >}} +mail + +{{< /link-group >}} + +### {{< todo name=abseil state=working >}} + +{{< link-group >}} +git +cru: +upstream: +debian: +{{< /link-group >}} + +{{< link-group >}} +mail + + +{{< /link-group >}} + +### {{< todo name=libgav1 state=done >}} + +{{< link-group >}} +git +my: +debian: +upstream: +{{< /link-group >}} + +{{< link-group >}} +misc +mail: +gerrit: +{{< /link-group >}} diff --git a/www/content/notes/todos.md b/www/content/notes/todos.md new file mode 100644 index 0000000..1625362 --- /dev/null +++ b/www/content/notes/todos.md @@ -0,0 +1,7 @@ +--- +title: "Todos" +date: 2025-03-03T15:34:53+08:00 +lastmod: 2025-03-03T23:28:46+08:00 +--- + +[Hurd](/notes/hurd/todos) diff --git a/www/content/posts/c-func-ext.md b/www/content/posts/c-func-ext.md index f5ab8fb..f0fce10 100644 --- a/www/content/posts/c-func-ext.md +++ b/www/content/posts/c-func-ext.md @@ -8,16 +8,78 @@ tags: - posix --- -Recently, I've been working on porting libraries to GNU/Hurd. The maintainers of GNU/Hurd -have a strong belief that [`*_MAX` macros on POSIX system interfaces](https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/nframe.html) -are very evil things. This is indeed true as a lot of (old) libraries relying on those macros -to determine the buffer size. In modern programming world, it is definitely a bad -idea to use fixed values for buffer sizes without considering possible overflow, unless -you are certain that size is sufficient. - -When you get rid of some old things, you will always meet compatibility problems. In these -case, old source codes using these macros just do not compile now. So here are some +Recently, I’ve been working on porting some libraries to GNU/Hurd. Many (old) +libraries use [`*_MAX` constants on POSIX system +interfaces](https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/nframe.html) +to calculate buffer sizes. However, the GNU/Hurd maintainers urge against the +blind use of them and refuse to define them in system headers. When old APIs are +gone, compatibility problems come. To make my life easier, I'll put some +reusable code snippets here to help *fix `*_MAX` bugs*. +```c +#include +#include +#include + +static inline char *xreadlink(const char *restrict path) { + char *buffer; + size_t allocated = 128; + ssize_t len; + + while (1) { + buffer = (char *)malloc(allocated); + if (!buffer) { + return NULL; + } + len = readlink(path, buffer, allocated); + if (len < (ssize_t)allocated) { + return buffer; + } + free(buffer); + if (len >= (ssize_t)allocated) { + allocated *= 2; + continue; + } + return NULL; + } +} + +static inline char *xgethostname() { + long max_host_name; + char *buffer; + + max_host_name = sysconf(_SC_HOST_NAME_MAX); + buffer = malloc(max_host_name + 1); + + if (gethostname(buffer, max_host_name + 1)) { + free(buffer); + return NULL; + } + + buffer[max_host_name] = '\0'; + return buffer; +} + +static inline char *xgetcwd() { + char *buffer; + size_t allocated = 128; + while (1) { + buffer = (char *)malloc(allocated); + if (!buffer) { + return NULL; + } + getcwd(buffer, allocated); + if (buffer) + return buffer; + free(buffer); + if (errno == ERANGE) { + allocated *= 2; + continue; + } + return NULL; + } +} +``` diff --git a/www/content/todos.md b/www/content/todos.md deleted file mode 100644 index a790e24..0000000 --- a/www/content/todos.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: "Todos" -date: 2025-03-03T15:34:53+08:00 -lastmod: 2025-03-03T23:28:46+08:00 ---- - -[Hurd](/hurd/todos) diff --git a/www/layouts/index.html b/www/layouts/index.html index 7c608f1..f456e71 100644 --- a/www/layouts/index.html +++ b/www/layouts/index.html @@ -26,23 +26,26 @@

Welcome to my home page! Nice to meet you here! 🥰

-

If you have something interesting to share with me, feel free to email me at - crupest@crupest.life. - You can also create an issue in any of my repos on GitHub to talk anything to me. +

If you have something interesting to share with me, feel free to email me + at crupest@crupest.life. + You can also create an issue in any of my repos + on GitHub to talk + anything to me.


-- cgit v1.2.3