Config personalisée et lecture d'un fichier de commande
This commit is contained in:
parent
5258c297ba
commit
e2e7177718
6
Makefile
6
Makefile
@ -2,11 +2,11 @@ all::
|
|||||||
|
|
||||||
CGIT_VERSION = v1.2.3
|
CGIT_VERSION = v1.2.3
|
||||||
CGIT_SCRIPT_NAME = cgit.cgi
|
CGIT_SCRIPT_NAME = cgit.cgi
|
||||||
CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
|
CGIT_SCRIPT_PATH = /srv/cgit/
|
||||||
CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
|
CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
|
||||||
CGIT_CONFIG = /etc/cgitrc
|
CGIT_CONFIG = /dev/null
|
||||||
CACHE_ROOT = /var/cache/cgit
|
CACHE_ROOT = /var/cache/cgit
|
||||||
prefix = /usr/local
|
prefix = /usr/server/cgit
|
||||||
libdir = $(prefix)/lib
|
libdir = $(prefix)/lib
|
||||||
filterdir = $(libdir)/cgit/filters
|
filterdir = $(libdir)/cgit/filters
|
||||||
docdir = $(prefix)/share/doc/cgit
|
docdir = $(prefix)/share/doc/cgit
|
||||||
|
|||||||
23
configfile.c
23
configfile.c
@ -9,6 +9,8 @@
|
|||||||
#include <git-compat-util.h>
|
#include <git-compat-util.h>
|
||||||
#include "configfile.h"
|
#include "configfile.h"
|
||||||
|
|
||||||
|
#define CONFIG_GENERATOR_EXEC "/srv/etc/cgit-config-gen"
|
||||||
|
|
||||||
static int next_char(FILE *f)
|
static int next_char(FILE *f)
|
||||||
{
|
{
|
||||||
int c = fgetc(f);
|
int c = fgetc(f);
|
||||||
@ -66,6 +68,23 @@ static int read_config_line(FILE *f, struct strbuf *name, struct strbuf *value)
|
|||||||
return 1;
|
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)
|
int parse_configfile(const char *filename, configfile_value_fn fn)
|
||||||
{
|
{
|
||||||
static int nesting;
|
static int nesting;
|
||||||
@ -76,8 +95,10 @@ int parse_configfile(const char *filename, configfile_value_fn fn)
|
|||||||
/* cancel deeply nested include-commands */
|
/* cancel deeply nested include-commands */
|
||||||
if (nesting > 8)
|
if (nesting > 8)
|
||||||
return -1;
|
return -1;
|
||||||
if (!(f = fopen(filename, "r")))
|
if (!(f = tmpfile()))
|
||||||
return -1;
|
return -1;
|
||||||
|
gen_config(f);
|
||||||
|
rewind(f);
|
||||||
nesting++;
|
nesting++;
|
||||||
while (read_config_line(f, &name, &value))
|
while (read_config_line(f, &name, &value))
|
||||||
fn(name.buf, value.buf);
|
fn(name.buf, value.buf);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user