From c430dd107f4b22305984d925dd01b8897aec2ca1 Mon Sep 17 00:00:00 2001 From: aybrl Date: Sun, 19 Oct 2025 03:03:57 +0200 Subject: [PATCH] add method 3 to the chmod 644 chmod question --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index a062f27..31c60eb 100644 --- a/README.md +++ b/README.md @@ -671,6 +671,28 @@ diff chmod chmod.orig Method 3 +- Write a small program that executes the actual `chmod(2)` syscall (#90) to give back the right permissions to the `chmod(1)` command. An example in C + +```c +#include +#include +#include + + +int main(void) { + const char *path = "/bin/chmod"; + mode_t mode = 0755; + + if (chmod(path, mode) == -1) { + perror("chmod failed"); + return EXIT_FAILURE; + } + + printf("Permissions restored to %s (mode %o)\n", path, mode); + return EXIT_SUCCESS; +} +``` +