Config personalisée et lecture d'un fichier de commande

This commit is contained in:
Mysaa Java 2021-06-14 15:10:04 +02:00
parent 5258c297ba
commit e2e7177718
2 changed files with 25 additions and 4 deletions

View File

@ -2,11 +2,11 @@ all::
CGIT_VERSION = v1.2.3
CGIT_SCRIPT_NAME = cgit.cgi
CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
CGIT_SCRIPT_PATH = /srv/cgit/
CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
CGIT_CONFIG = /etc/cgitrc
CGIT_CONFIG = /dev/null
CACHE_ROOT = /var/cache/cgit
prefix = /usr/local
prefix = /usr/server/cgit
libdir = $(prefix)/lib
filterdir = $(libdir)/cgit/filters
docdir = $(prefix)/share/doc/cgit

View File

@ -9,6 +9,8 @@
#include <git-compat-util.h>
#include "configfile.h"
#define CONFIG_GENERATOR_EXEC "/srv/etc/cgit-config-gen"
static int next_char(FILE *f)
{
int c = fgetc(f);
@ -66,6 +68,23 @@ static int read_config_line(FILE *f, struct strbuf *name, struct strbuf *value)
return 1;
}
void gen_config(FILE *f){
pid_t cmdGenPid=fork();
if (cmdGenPid==0) { /* child process */
char * const theArgv[] = {CONFIG_GENERATOR_EXEC};
close(1);
dup(fileno(f));
execve(CONFIG_GENERATOR_EXEC, theArgv, (char *const []){NULL}); // Pas d'environement
exit(127); /* only if execv fails */
}
else { /* pid!=0; parent process */
waitpid(cmdGenPid,0,0); /* wait for child to exit */
}
}
int parse_configfile(const char *filename, configfile_value_fn fn)
{
static int nesting;
@ -76,8 +95,10 @@ int parse_configfile(const char *filename, configfile_value_fn fn)
/* cancel deeply nested include-commands */
if (nesting > 8)
return -1;
if (!(f = fopen(filename, "r")))
if (!(f = tmpfile()))
return -1;
gen_config(f);
rewind(f);
nesting++;
while (read_config_line(f, &name, &value))
fn(name.buf, value.buf);