so://phie

soso

My pretty neat website
git clone git://soophie.de/soso

feat: Made port configurable with environment variable SOSO_PORT


commit: c850ce8e76b8e8edd09804b8b84a940a1dbd7f88
parent: dc8c1848e143bc9c11abeaba2740de148a39c6ca
author: Sophie <info@soophie.de>
time: 2026-10-08 22:49

diff --git a/src/main.c b/src/main.c

index 2aa0013..cc34490 100644

--- a/src/main.c

+++ b/src/main.c

1@@ -14,7 +14,7 @@

2 #define UTIL_IMPL

3 #include "util.h" // IWYU pragma: keep

4

5-#define PORT 8087

6+#define SOSO_PORT "SOSO_PORT"

7

8 #include "module/page.h"

9 #include "module/default.h"

10@@ -208,15 +208,26 @@ int main(void) {

11 sigint_action.sa_flags = 0;

12 sigemptyset(&sigint_action.sa_mask);

13 sigaction(SIGSEGV, &sigint_action, NULL);

14+ char *port_str = getenv(SOSO_PORT);

15+ if (!port_str) {

16+ printf("no port specified! set environment variable SOSO_PORT.\n");

17+ return 1;

18+ }

19+ char *end = NULL;

20+ int port = strtoimax(port_str, &end, 10);

21+ if (end == port_str || *end != '\0') {

22+ printf("invalid port specified! set environment variable SOSO_PORT.\n");

23+ return 1;

24+ }

25 tpee_t *tpee = tpee_init();

26- if (tpee_bind(tpee, "0.0.0.0", PORT, NULL, 0) != TPEE_ERR_OK) {

27+ if (tpee_bind(tpee, "0.0.0.0", port, NULL, 0) != TPEE_ERR_OK) {

28 printf("failed to bind port!\n");

29 return 1;

30 }

31 git_libgit2_init();

32 git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 0);

33 if (tpee_listen(tpee) == TPEE_ERR_OK) {

34- printf("ready and listening (pid: %d)\n", getpid());

35+ printf("ready and listening (pid: %d, port: %d)\n", getpid(), port);

36 pause();

37 }

38 git_libgit2_shutdown();

39

40