aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-06-24 17:55:11 -0700
committerFuwn <[email protected]>2024-06-24 18:05:22 -0700
commit34e8da2ffea26f3994c84170533c897ef3cfcfa7 (patch)
tree6c2e742fc855c0c0a878c483049c4e09cff026ed
parent105fcb3918a81d661797113ef2a6a4a1515130b5 (diff)
downloadgigi-34e8da2ffea26f3994c84170533c897ef3cfcfa7.tar.xz
gigi-34e8da2ffea26f3994c84170533c897ef3cfcfa7.zip
feat(gigi.c): fallback to default
-rw-r--r--README.md3
-rw-r--r--gigi.c18
2 files changed, 15 insertions, 6 deletions
diff --git a/README.md b/README.md
index 3fa812f..13e0f09 100644
--- a/README.md
+++ b/README.md
@@ -63,7 +63,8 @@ passes any arguments from the Finger request to the executable.
Static mode is enabled by default. A Finger request for `test` will return the
contents of `./gigi/test`. A Finger request of nothing will return the contents
-of `./gigi/default`.
+of `./gigi/default`. The default file is also the fallback file in case the
+requested file does not exist.
To emulate dynamic mode, minus the arguments you can setup a service of some
kind to periodically update the contents of one of the static files.
diff --git a/gigi.c b/gigi.c
index 3f2fd4a..5100706 100644
--- a/gigi.c
+++ b/gigi.c
@@ -176,15 +176,23 @@ void gigi_show(int connection_file_descriptor, const char *arguments) {
snprintf(gigi_show_command, MAXIMUM_COMMAND_LENGTH, "./.gigi/%s",
gigi_show_arguments);
- printf("ok: %s\n", gigi_show_command);
gigi_show_file = fopen(gigi_show_command, "r");
- }
- if (!gigi_show_file) {
- perror("error: could not open gigi show file\n");
+ if (!gigi_show_file) {
+ fprintf(stderr, "error: could not open gigi show file: %s\n",
+ gigi_show_command);
- return;
+ gigi_show_file = fopen("./.gigi/default", "r");
+ }
+
+ if (!gigi_show_file) {
+ perror("error: could not open default gigi show file: default\n");
+
+ return;
+ }
+
+ printf("ok: %s\n", gigi_show_command);
}
while (fgets(gigi_show_message, MAXIMUM_DATA_SIZE, gigi_show_file) != NULL) {