From fbcf5b1464a592c7e04a5a20161b8afc3b573ffa Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Sun, 11 Dec 2022 12:55:24 +0100 Subject: [PATCH 01/13] fix(Makefile): unzip -f flag --- Makefile | 2 +- config.mk | 2 +- feuille.1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b5878a6..3852e58 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ cosmopolitan: curl -sO "https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.2.zip" ;\ \ printf "%-8s cosmopolitan-amalgamation-2.2.zip\n" "unzip" ;\ - unzip -qf cosmopolitan-amalgamation-2.2.zip -d cosmopolitan ;\ + unzip -q cosmopolitan-amalgamation-2.2.zip -d cosmopolitan ;\ \ rm -rf cosmopolitan-amalgamation-* ;\ fi diff --git a/config.mk b/config.mk index d6b25f7..9a9df30 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # feuille version -VERSION = 2.1.0 +VERSION = 2.1.1 # paths (customize them to fit your system) PREFIX = /usr/local diff --git a/feuille.1 b/feuille.1 index f90ddb6..91f2138 100644 --- a/feuille.1 +++ b/feuille.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "feuille" "1" "November 2022" "feuille 2.1.0" "" +.TH "feuille" "1" "November 2022" "feuille 2.1.1" "" .hy .SH NAME .PP From 5c93649473fe7b91c3379c481146a9f41d583bd3 Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Sun, 11 Dec 2022 14:38:36 +0100 Subject: [PATCH 02/13] fix(Makefile): minor tweaks --- .gitignore | 1 + Makefile | 40 +++++++++++++++++++++++++--------------- config.mk | 2 +- feuille.1 | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index ad9f5f6..d7968c9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ cosmopolitan feuille feuille.com +feuille.com.dbg cgi/feuille.cgi diff --git a/Makefile b/Makefile index 3852e58..be133e4 100644 --- a/Makefile +++ b/Makefile @@ -10,18 +10,21 @@ TARGET$(COSMO) = feuille SRC = feuille.c util.c server.c bin.c OBJ = $(SRC:%.c=%.o) + all: $(TARGET) feuille.1 cgi run: $(TARGET) ./$(TARGET) + clean: @printf "%-8s $(OBJ)\n" "rm" @rm -f $(OBJ) distclean: - @printf "%-8s feuille feuille.com $(OBJ)\n" "rm" - @rm -f feuille feuille.com $(OBJ) + @printf "%-8s feuille feuille.com feuille.com.dbg $(OBJ)\n" "rm" + @rm -f feuille feuille.com feuille.com.dbg $(OBJ) + install: $(TARGET) feuille.1 @echo "installing executable file to $(PREFIX)/bin" @@ -34,26 +37,25 @@ install: $(TARGET) feuille.1 @cp -f feuille.1 $(MAN)/man1 @chmod 644 $(MAN)/man1/feuille.1 -uninstall: $(PREFIX)/bin/$(TARGET) $(MAN)/man1/feuille.1 +uninstall: @echo "removing executable file from $(PREFIX)/bin" @rm -f "$(PREFIX)/bin/$(TARGET)" @echo "removing manpage from $(MAN)/man1" @rm -f $(MAN)/man1/feuille.1 -feuille.1: feuille.1.md config.mk - @printf "%-8s feuille.1.md -o feuille.1\n" "pandoc" - @sed "s/{VERSION}/$(VERSION)/g" feuille.1.md | pandoc -s -t man -o feuille.1 +# manpage +feuille.1: feuille.1.md config.mk + @printf "%-8s $@.md -o $@\n" "pandoc" + @sed "s/{VERSION}/$(VERSION)/g" $@.md | pandoc -s -t man -o $@ + +# standard libc feuille: $(OBJ) - @printf "%-8s $(OBJ) -o feuille\n" "$(CC)" - @$(CC) $(OBJ) -o feuille $(LDFLAGS) + @printf "%-8s $(OBJ) -o $@\n" "$(CC)" + @$(CC) $(OBJ) -o $@ $(LDFLAGS) # cosmopolitan libc -feuille.com: cosmopolitan feuille - @printf "%-8s feuille -o feuille.com\n" "objcopy" - @objcopy -S -O binary feuille feuille.com - cosmopolitan: @if [ ! -d cosmopolitan ]; then \ printf "%-8s https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.2.zip\n" "curl" ;\ @@ -65,6 +67,14 @@ cosmopolitan: rm -rf cosmopolitan-amalgamation-* ;\ fi +feuille.com.dbg: $(OBJ) + @printf "%-8s $(OBJ) -o $@\n" "$(CC)" + @$(CC) $(OBJ) -o $@ $(LDFLAGS) + +feuille.com: cosmopolitan feuille.com.dbg + @printf "%-8s $@.dbg -o $@\n" "objcopy" + @objcopy -S -O binary $@.dbg $@ + # CGI script ADDR = 127.0.0.1 PORT = 9999 @@ -73,9 +83,9 @@ cgi: cgi/feuille.cgi cgi/feuille.cgi: cgi/feuille.cgi.c @printf "%-8s cgi/feuille.cgi.c -o cgi/feuille.cgi\n" "$(CC)" - @$(CC) cgi/feuille.cgi.c -o cgi/feuille.cgi -std=c99 -O3 -static -Wall -Wextra \ - -DADDR=\"$(ADDR)\" -DPORT=$(PORT) \ - $(INCS) $(LIBS) + @$(CC) $@.c -o $@ -std=c99 -O3 -static -Wall -Wextra \ + -DADDR=\"$(ADDR)\" -DPORT=$(PORT) \ + $(INCS) $(LIBS) .SUFFIXES: .c .o .c.o: diff --git a/config.mk b/config.mk index 9a9df30..1fd8299 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # feuille version -VERSION = 2.1.1 +VERSION = 2.1.2 # paths (customize them to fit your system) PREFIX = /usr/local diff --git a/feuille.1 b/feuille.1 index 91f2138..5452e7f 100644 --- a/feuille.1 +++ b/feuille.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "feuille" "1" "November 2022" "feuille 2.1.1" "" +.TH "feuille" "1" "November 2022" "feuille 2.1.2" "" .hy .SH NAME .PP From 48c211fc64a6c280f9877218f8f9f3629acf6940 Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Mon, 12 Dec 2022 20:54:21 +0100 Subject: [PATCH 03/13] fix(README.md): broken link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71f0379..bee1674 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ That sould be it. Have fun! * Works on nearly all POSIX-compliant OSes * Can be run in the background and as a service * IPv6-enabled -* Now with 100% more (Cosmopolitan libc)[http://justine.lol/cosmopolitan/] support! +* Now with 100% more [Cosmopolitan libc](http://justine.lol/cosmopolitan/) support! ## Installation @@ -196,7 +196,7 @@ $ sudo make install ``` You can also build using the -(Cosmopolitan libc)[http://justine.lol/cosmopolitan/], which will +[Cosmopolitan libc](http://justine.lol/cosmopolitan/], which will make an executable capable of running on Linux, OpenBSD, FreeBSD, Mac... out of the box. To do so, build with the `COSMO` flag. It will produce `feuille` and `feuille.com`, the former being the From 67cbd21fc4820fe11d4964899ec42efa1e97a51f Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Mon, 12 Dec 2022 20:55:15 +0100 Subject: [PATCH 04/13] fix(README.md): broken link (again) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bee1674..1db4fe4 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ $ sudo make install ``` You can also build using the -[Cosmopolitan libc](http://justine.lol/cosmopolitan/], which will +[Cosmopolitan libc](http://justine.lol/cosmopolitan/), which will make an executable capable of running on Linux, OpenBSD, FreeBSD, Mac... out of the box. To do so, build with the `COSMO` flag. It will produce `feuille` and `feuille.com`, the former being the From bd471e41130a774e2408844dcd2ba7509b6b23b5 Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Mon, 12 Dec 2022 20:56:14 +0100 Subject: [PATCH 05/13] fix(README.md): cosmopolitan libc --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1db4fe4..1eacab0 100644 --- a/README.md +++ b/README.md @@ -199,8 +199,8 @@ You can also build using the [Cosmopolitan libc](http://justine.lol/cosmopolitan/), which will make an executable capable of running on Linux, OpenBSD, FreeBSD, Mac... out of the box. To do so, build with the `COSMO` flag. -It will produce `feuille` and `feuille.com`, the former being the -debug binary, and the former the portable one. +It will produce `feuille.com.dbg` and `feuille.com`, the former being +the debug binary, and the latter the portable one. If you wish to make a debug build, you can set `DEBUG` to whatever comes to your mind. From 40dfb78ef2a6d76ec2f8c2a5d13cc5df95f55f04 Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Sun, 18 Dec 2022 23:46:35 +0100 Subject: [PATCH 06/13] style(feuille.c): padding --- feuille.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feuille.c b/feuille.c index 27d2b94..7b58278 100644 --- a/feuille.c +++ b/feuille.c @@ -389,11 +389,11 @@ int main(int argc, char *argv[]) if (setgid(gid) != 0 || getgid() != gid) die(1, "could not switch to group for user `%s'.\n", settings.user); - #ifndef COSMOPOLITAN +#ifndef COSMOPOLITAN /* initgroups doesn't work on cosmopolitan libc yet */ if (initgroups(settings.user, gid) != 0) die(1, "could not initialize other groups for user `%s'.\n", settings.user); - #endif +#endif /* switching user */ if (setuid(uid) != 0 || getuid() != uid) From 47e6204e08de4f771b4f64f7381bf25b31dafd52 Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Thu, 22 Dec 2022 19:32:37 +0100 Subject: [PATCH 07/13] fix(README.md): small nitpick (thanks random lainon) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1eacab0..43a52b4 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,8 @@ That sould be it. Have fun! ## Description * Focuses on speed, - * Multi-threaded (using `fork`) + * Handles multiple requests at once (using a pool of `fork`'ed + workers) * Only does what it needs to do * code quality, From c2c5440b21373f92338f734ab4f47aea5d2dbda8 Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Sun, 25 Dec 2022 01:03:02 +0100 Subject: [PATCH 08/13] fix: use `#pragma once' instead of guards --- arg.h | 5 +---- bin.h | 5 +---- config.mk | 2 +- feuille.1 | 2 +- feuille.h | 5 +---- server.h | 5 +---- util.h | 5 +---- 7 files changed, 7 insertions(+), 22 deletions(-) diff --git a/arg.h b/arg.h index 9c4d1bb..fef64f7 100644 --- a/arg.h +++ b/arg.h @@ -31,8 +31,7 @@ * by 20h */ -#ifndef _ARG_H_ -#define _ARG_H_ +#pragma once #ifndef COSMOPOLITAN #include @@ -79,5 +78,3 @@ extern char *argv0; (brk_ = 1, (argv[0][i_+1] != '\0')?\ (&argv[0][i_+1]) :\ (argc--, argv++, argv[0]))) - -#endif diff --git a/bin.h b/bin.h index fddb7f0..dbb9a0c 100644 --- a/bin.h +++ b/bin.h @@ -11,8 +11,7 @@ * . */ -#ifndef _BIN_H_ -#define _BIN_H_ +#pragma once #include "feuille.h" @@ -21,5 +20,3 @@ int write_paste(char *, unsigned long, char *); char *generate_id(int); char *create_url(char *); - -#endif diff --git a/config.mk b/config.mk index 1fd8299..e09c7ce 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # feuille version -VERSION = 2.1.2 +VERSION = 2.1.4 # paths (customize them to fit your system) PREFIX = /usr/local diff --git a/feuille.1 b/feuille.1 index 5452e7f..b8d1600 100644 --- a/feuille.1 +++ b/feuille.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "feuille" "1" "November 2022" "feuille 2.1.2" "" +.TH "feuille" "1" "November 2022" "feuille 2.1.4" "" .hy .SH NAME .PP diff --git a/feuille.h b/feuille.h index fa87e0c..4894ada 100644 --- a/feuille.h +++ b/feuille.h @@ -11,8 +11,7 @@ * . */ -#ifndef _FEUILLE_H_ -#define _FEUILLE_H_ +#pragma once typedef struct Settings { char *address; @@ -32,5 +31,3 @@ typedef struct Settings { } Settings; extern Settings settings; - -#endif diff --git a/server.h b/server.h index d72b18a..48e6796 100644 --- a/server.h +++ b/server.h @@ -11,8 +11,7 @@ * . */ -#ifndef _SERVER_H_ -#define _SERVER_H_ +#pragma once #include "feuille.h" @@ -23,5 +22,3 @@ void close_connection(int); unsigned long read_paste(int, char **); int send_response(int, char *); - -#endif diff --git a/util.h b/util.h index f074d15..5daeff1 100644 --- a/util.h +++ b/util.h @@ -11,11 +11,8 @@ * . */ -#ifndef _UTIL_H_ -#define _UTIL_H_ +#pragma once void die(int, char *, ...); void error(char *, ...); void verbose(int, char *, ...); - -#endif From 0b7db033c51ef691ad89958e0e9a49b88fb8b86c Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Thu, 29 Dec 2022 17:05:05 +0100 Subject: [PATCH 09/13] style(feuille.c): padding --- feuille.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/feuille.c b/feuille.c index 7b58278..6e2fc28 100644 --- a/feuille.c +++ b/feuille.c @@ -41,20 +41,20 @@ char *argv0; /* default settings */ Settings settings = { - .address = "0.0.0.0", - .url = "http://localhost", - .output = "/var/www/feuille", - .user = "www", + .address = "0.0.0.0", + .url = "http://localhost", + .output = "/var/www/feuille", + .user = "www", - .id_length = 4, - .worker_count = 4, - .port = 9999, - .timeout = 2, - .max_size = 1048576, /* = 1MiB = 1024 * 1024 */ - .buffer_size = 131072, /* = 128KiB = 1024 * 128 */ + .id_length = 4, + .worker_count = 4, + .port = 9999, + .timeout = 2, + .max_size = 1048576, /* = 1MiB = 1024 * 1024 */ + .buffer_size = 131072, /* = 128KiB = 1024 * 128 */ - .verbose = 0, - .foreground = 0 + .verbose = 0, + .foreground = 0 }; /* functions declarations */ From 6468c286528e83e9038e2d72a493200c725091c1 Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Tue, 14 Feb 2023 13:47:11 +0100 Subject: [PATCH 10/13] fix(README.md): Description in ToC --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 43a52b4..edcf858 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ code quality, and security. Table of Contents
  1. Usage
  2. +
  3. Description
  4. Installation
      From c52d52df2a17cd62c8ffd96005f0715440c04bae Mon Sep 17 00:00:00 2001 From: Tom MTT Date: Thu, 23 Feb 2023 17:44:40 +0100 Subject: [PATCH 11/13] fix(config.mk): typo --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index e09c7ce..48af386 100644 --- a/config.mk +++ b/config.mk @@ -41,4 +41,4 @@ CFLAGS$(DEBUG) = -O3 -Wall -Wextra -Wno-sign-compare $(CCFLAGS) LDFLAGS$(DEBUG) = -s $(CLDFLAGS) # static build (uncomment) -#LD_FLAGS += -static +#LDFLAGS += -static From bceed896bb4ad7bf285307e6bfcd0962cb500a64 Mon Sep 17 00:00:00 2001 From: "Tom MTT." Date: Wed, 15 Nov 2023 14:17:43 +0100 Subject: [PATCH 12/13] fix(.gitignore): ignore .ccls-cache --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d7968c9..133de78 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ feuille.com feuille.com.dbg cgi/feuille.cgi + +.ccls-cache From 9f641dccda5c73193620727603826bd8b001d5eb Mon Sep 17 00:00:00 2001 From: "Tom MTT." Date: Wed, 15 Nov 2023 14:19:10 +0100 Subject: [PATCH 13/13] docs(feuille.1): typo --- feuille.1 | 2 +- feuille.1.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/feuille.1 b/feuille.1 index b8d1600..5906b17 100644 --- a/feuille.1 +++ b/feuille.1 @@ -45,7 +45,7 @@ The difference is minimal, no need to worry about it. Default: \f[V]131072\f[R]B (128KiB) .TP \f[B]-f\f[R] -Makes \f[B]feuille\f[R] run in the forground. +Makes \f[B]feuille\f[R] run in the foreground. Default: disabled .TP \f[B]-h\f[R] diff --git a/feuille.1.md b/feuille.1.md index aecc491..2664d5a 100644 --- a/feuille.1.md +++ b/feuille.1.md @@ -30,7 +30,7 @@ and IPv6 addresses (won't work on OpenBSD). : Default: `131072`B (128KiB) **-f** -: Makes **feuille** run in the forground. +: Makes **feuille** run in the foreground. : Default: disabled **-h**