8000 WIP: Change log destination by ltworf · Pull Request #60 · ltworf/weborf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

WIP: Change log destination #60

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Wait for weborf to create socket in testsuite
- Add an icon for qweborf (copied from Oxygen)
- Appstream metainfo file for qweborf
- Add logfd option to weborf

0.17
- Fix MOVE and COPY methods to support relative URI
Expand Down
19 changes: 19 additions & 0 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "options.h"

#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <stdio.h>
Expand Down Expand Up @@ -48,6 +49,7 @@ weborf_configuration_t weborf_conf = {
.basedir=BASEDIR,
.uid = ROOTUID,
.gid = ROOTGID,
.log_fd = -1,
.daemonize = false,
#ifdef HAVE_LIBSSL
.sslctx = NULL,
Expand Down Expand Up @@ -114,6 +116,16 @@ static void configuration_set_default_index() {
weborf_conf.indexes_l = 1;
}

static void configuration_set_logging(char *optarg) {
int fd = atoi(optarg);
if (fcntl(fd, F_GETFL) == -1) {
fprintf(stderr, "%d invalid file descriptor\n", fd);
syslog(LOG_ERR, "%d invalid file descriptor\n", fd);
exit(1);
}
weborf_conf.log_fd = fd;
}

static void configuration_set_cgi(char *optarg) {
if (!optarg || strlen(optarg) == 0) {
weborf_conf.cgi_paths.len = 0; //count of indexes
Expand Down Expand Up @@ -248,6 +260,7 @@ void configuration_load(int argc, char *argv[]) {
{"tar", no_argument,0,'t'},
{"cert", required_argument, 0, 'S'},
{"key", required_argument, 0, 'K'},
{"logfd", required_argument, 0, '\0'},
{0, 0, 0, 0}
};

Expand All @@ -270,6 +283,12 @@ void configuration_load(int argc, char *argv[]) {
break;

switch (c) {
case '\0':
switch(option_index) {
case 21:
configuration_set_logging(optarg);
};
break;
case 'k':
print_capabilities();
break;
Expand Down
1 change: 1 addition & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ typedef struct {
char* authsock; //Executable that will authenticate
uid_t uid; //Uid to use after bind
gid_t gid; //gid to use after bind
int log_fd; //fd to use to print the logs. -1 for syslog
#ifdef SEND_MIMETYPES
bool send_content_type; //True if we want to send the content type
#endif
Expand Down
1 change: 1 addition & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ void help() {
" -S, --cert the certificate to use\n"
" -K, --key the private key to use with the certificate\n"
" -Y, --yesexec enables CGI\n"
" --logfd file descriptor number to use for the logs\n"
"\n"
"Report bugs here https://bugs.launchpad.net/weborf\n"
"or to " PACKAGE_BUGREPORT "\n");
Expand Down
7 changes: 6 additions & 1 deletion weborf.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH Weborf 1 "Nov 11, 2020" "Minimal webserver"
.TH Weborf 1 "Feb 27, 2022" "Minimal webserver"
.SH NAME
weborf
\- Minimal webserver
Expand Down Expand Up @@ -107,6 +107,11 @@ Must be followed by a valid gid, different from 0. Weborf will use this user to
.TP
.B \-d
Runs weborf as a daemon. It will not terminate when its father process terminates, and it will leave the shell free to receive commands.

.TP
.B \-\-logfd
Must be followed by an open file descriptor number that weborf will use to send the logs, instead of using syslog.

.SS

.SH SCRIPTING
Expand Down
0