Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
786f4ac3
Vérifiée
Valider
786f4ac3
rédigé
9 avr. 2020
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
WIP: No more segfaults
parent
3f931bac
Branches
Branches contenant la validation
Étiquettes
Étiquettes contenant la validation
1 requête de fusion
!52
Resolve "Use of sqlite to store configuration"
Modifications
4
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
4 fichiers modifiés
inc/ini/ini.h
+2
-2
2 ajouts, 2 suppressions
inc/ini/ini.h
inc/lektor/config.h
+1
-1
1 ajout, 1 suppression
inc/lektor/config.h
src/config.c
+24
-33
24 ajouts, 33 suppressions
src/config.c
src/net/listen.c
+2
-2
2 ajouts, 2 suppressions
src/net/listen.c
avec
29 ajouts
et
38 suppressions
inc/ini/ini.h
+
2
−
2
Voir le fichier @
786f4ac3
...
@@ -73,7 +73,7 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
...
@@ -73,7 +73,7 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
configparser. If allowed, ini_parse() will call the handler with the same
configparser. If allowed, ini_parse() will call the handler with the same
name for each subsequent line parsed. */
name for each subsequent line parsed. */
#ifndef INI_ALLOW_MULTILINE
#ifndef INI_ALLOW_MULTILINE
#define INI_ALLOW_MULTILINE
1
#define INI_ALLOW_MULTILINE
0
#endif
#endif
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
...
@@ -131,7 +131,7 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
...
@@ -131,7 +131,7 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
name and value NULL). Default is to only call the handler on
name and value NULL). Default is to only call the handler on
each name=value pair. */
each name=value pair. */
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
#define INI_CALL_HANDLER_ON_NEW_SECTION
1
#define INI_CALL_HANDLER_ON_NEW_SECTION
0
#endif
#endif
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
inc/lektor/config.h
+
1
−
1
Voir le fichier @
786f4ac3
...
@@ -60,7 +60,7 @@ int config_open(sqlite3 *db);
...
@@ -60,7 +60,7 @@ int config_open(sqlite3 *db);
/* Get the path to the config file that may be red, taking into account the
/* Get the path to the config file that may be red, taking into account the
priority between existing files. The returned path is a path to an existing
priority between existing files. The returned path is a path to an existing
file. If no file is found, returns a non zero value. Returns 1 otherwise. */
file. If no file is found, returns a non zero value. Returns 1 otherwise. */
int
config_detect_file
(
char
*
*
conf
,
size_t
conf_len
);
int
config_detect_file
(
char
*
conf
,
size_t
conf_len
);
/* Create and read the configuration in the conf file and write it into
/* Create and read the configuration in the conf file and write it into
lkt_conf. The type is opaque because it's a C++ class.
lkt_conf. The type is opaque because it's a C++ class.
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/config.c
+
24
−
33
Voir le fichier @
786f4ac3
...
@@ -109,7 +109,7 @@ handler(void *user, const char *section, const char *name, const char *value)
...
@@ -109,7 +109,7 @@ handler(void *user, const char *section, const char *name, const char *value)
}
}
int
int
config_detect_file
(
char
*
*
conf
,
size_t
conf_len
)
config_detect_file
(
char
*
conf
,
size_t
conf_len
)
{
{
bool
is_malloc
=
false
;
bool
is_malloc
=
false
;
struct
passwd
*
pw
=
getpwuid
(
getuid
());
struct
passwd
*
pw
=
getpwuid
(
getuid
());
...
@@ -118,20 +118,13 @@ config_detect_file(char **conf, size_t conf_len)
...
@@ -118,20 +118,13 @@ config_detect_file(char **conf, size_t conf_len)
if
(
conf
==
NULL
)
if
(
conf
==
NULL
)
return
1
;
return
1
;
if
(
*
conf
==
NULL
)
{
memset
(
conf
,
0
,
conf_len
*
sizeof
(
char
));
*
conf
=
(
char
*
)
calloc
(
conf_len
,
sizeof
(
char
));
if
(
!*
conf
)
return
ENOMEM
;
}
memset
(
*
conf
,
0
,
conf_len
*
sizeof
(
char
));
/* Try the current working dir config file. */
/* Try the current working dir config file. */
if
(
getcwd
(
*
conf
,
conf_len
-
1
)
!=
NULL
)
{
if
(
getcwd
(
conf
,
conf_len
-
1
)
!=
NULL
)
{
strncat
(
*
conf
,
"/lektor.ini"
,
conf_len
-
1
);
strncat
(
conf
,
"/lektor.ini"
,
conf_len
-
1
);
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
*
conf
);
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
conf
);
if
(
!
access
(
*
conf
,
R_OK
))
if
(
!
access
(
conf
,
R_OK
))
goto
found
;
goto
found
;
}
}
...
@@ -143,39 +136,39 @@ config_detect_file(char **conf, size_t conf_len)
...
@@ -143,39 +136,39 @@ config_detect_file(char **conf, size_t conf_len)
home
=
pw
->
pw_dir
;
home
=
pw
->
pw_dir
;
if
(
!
home
||
(
strlen
(
home
)
>=
conf_len
))
if
(
!
home
||
(
strlen
(
home
)
>=
conf_len
))
goto
no_config_directory
;
goto
no_config_directory
;
memcpy
(
*
conf
,
home
,
(
strlen
(
home
)
+
1
)
*
sizeof
(
char
));
memcpy
(
conf
,
home
,
(
strlen
(
home
)
+
1
)
*
sizeof
(
char
));
strncat
(
*
conf
,
"/.config/lektor/lektor.ini"
,
conf_len
-
1
);
strncat
(
conf
,
"/.config/lektor/lektor.ini"
,
conf_len
-
1
);
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
*
conf
);
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
conf
);
if
(
!
access
(
*
conf
,
R_OK
|
F_OK
))
if
(
!
access
(
conf
,
R_OK
|
F_OK
))
goto
found
;
goto
found
;
no_config_directory:
no_config_directory:
/* Try the '/opt/lektor' file. */
/* Try the '/opt/lektor' file. */
memcpy
(
*
conf
,
"/opt/lektor/lektor.ini"
,
sizeof
(
"/opt/lektor/lektor.ini"
));
memcpy
(
conf
,
"/opt/lektor/lektor.ini"
,
sizeof
(
"/opt/lektor/lektor.ini"
));
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
*
conf
);
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
conf
);
if
(
!
access
(
*
conf
,
R_OK
))
if
(
!
access
(
conf
,
R_OK
))
goto
found
;
goto
found
;
/* Try the '/usr/local/etc/lektor.ini' file. */
/* Try the '/usr/local/etc/lektor.ini' file. */
memcpy
(
*
conf
,
"/usr/local/etc/lektor.ini"
,
sizeof
(
"/opt/lektor/lektor.ini"
));
memcpy
(
conf
,
"/usr/local/etc/lektor.ini"
,
sizeof
(
"/opt/lektor/lektor.ini"
));
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
*
conf
);
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
conf
);
if
(
!
access
(
*
conf
,
R_OK
))
if
(
!
access
(
conf
,
R_OK
))
goto
found
;
goto
found
;
/* Try the '/etc/lektor.ini' file. */
/* Try the '/etc/lektor.ini' file. */
memcpy
(
*
conf
,
"/etc/lektor.ini"
,
sizeof
(
"/etc/lektor.ini"
));
memcpy
(
conf
,
"/etc/lektor.ini"
,
sizeof
(
"/etc/lektor.ini"
));
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
*
conf
);
fprintf
(
stderr
,
" . config_detect_file: trying %s
\n
"
,
conf
);
if
(
!
access
(
*
conf
,
R_OK
))
if
(
!
access
(
conf
,
R_OK
))
goto
found
;
goto
found
;
/* Error */
/* Error */
fprintf
(
stderr
,
"config_detect_file: an error occured with file %s: %s"
,
fprintf
(
stderr
,
"config_detect_file: an error occured with file %s: %s"
,
*
conf
,
strerror
(
errno
));
conf
,
strerror
(
errno
));
if
(
is_malloc
)
if
(
is_malloc
)
free
(
*
conf
);
free
(
conf
);
return
1
;
return
1
;
found:
found:
fprintf
(
stderr
,
" . config_detect_file: using file %s
\n
"
,
*
conf
);
fprintf
(
stderr
,
" . config_detect_file: using file %s
\n
"
,
conf
);
return
0
;
return
0
;
}
}
...
@@ -198,10 +191,10 @@ config_new(sqlite3 *db, const char *conf)
...
@@ -198,10 +191,10 @@ config_new(sqlite3 *db, const char *conf)
int
int
config_open
(
sqlite3
*
db
)
config_open
(
sqlite3
*
db
)
{
{
char
*
conf_file
=
NULL
;
char
conf_file
[
PATH_MAX
]
;
int
ret
=
1
;
int
ret
=
1
;
if
(
config_detect_file
(
&
conf_file
,
PATH_MAX
))
{
if
(
config_detect_file
(
conf_file
,
PATH_MAX
))
{
fprintf
(
stderr
,
" ! config_open: error while searching for a config file
\n
"
);
fprintf
(
stderr
,
" ! config_open: error while searching for a config file
\n
"
);
goto
error
;
goto
error
;
}
}
...
@@ -213,7 +206,5 @@ config_open(sqlite3 *db)
...
@@ -213,7 +206,5 @@ config_open(sqlite3 *db)
ret
=
0
;
ret
=
0
;
error:
error:
if
(
conf_file
)
free
(
conf_file
);
return
ret
;
return
ret
;
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
src/net/listen.c
+
2
−
2
Voir le fichier @
786f4ac3
...
@@ -716,7 +716,7 @@ lkt_listen(void)
...
@@ -716,7 +716,7 @@ lkt_listen(void)
char
*
host
=
(
char
*
)
calloc
(
HOST_NAME_MAX
,
sizeof
(
char
));
char
*
host
=
(
char
*
)
calloc
(
HOST_NAME_MAX
,
sizeof
(
char
));
char
port
[
7
];
/* Maximal port number is 65535, +2 for '\n' and '\0' */
char
port
[
7
];
/* Maximal port number is 65535, +2 for '\n' and '\0' */
char
player_mod
[
INI_MAX_LINE
];
char
player_mod
[
INI_MAX_LINE
];
char
*
conf_file
;
char
conf_file
[
PATH_MAX
]
;
memset
(
&
srv
,
0
,
sizeof
(
struct
lkt_state
));
memset
(
&
srv
,
0
,
sizeof
(
struct
lkt_state
));
/* Initialize the system. */
/* Initialize the system. */
...
@@ -726,7 +726,7 @@ lkt_listen(void)
...
@@ -726,7 +726,7 @@ lkt_listen(void)
return
1
;
return
1
;
}
}
if
(
config_detect_file
(
&
conf_file
,
PATH_MAX
))
{
if
(
config_detect_file
(
conf_file
,
PATH_MAX
))
{
fprintf
(
stderr
,
" ! error while searching for a config file
\n
"
);
fprintf
(
stderr
,
" ! error while searching for a config file
\n
"
);
return
1
;
return
1
;
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter