Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 4fd4bb8f rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Making things compiles again

parent bd56a177
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!35Adding ini support in lektor
...@@ -73,4 +73,4 @@ void lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg); ...@@ -73,4 +73,4 @@ void lkt_state_send(struct lkt_state *srv, size_t c, struct lkt_message *msg);
long long int *lkt_client_get_mask(struct lkt_state *srv, size_t c); long long int *lkt_client_get_mask(struct lkt_state *srv, size_t c);
/* The server's listen function. */ /* The server's listen function. */
int lkt_listen(struct lkt_config *conf); int lkt_listen(lkt_config_t *conf);
...@@ -318,8 +318,8 @@ main(int argc, char *argv[]) ...@@ -318,8 +318,8 @@ main(int argc, char *argv[])
{ {
int i; int i;
bool ret = true; bool ret = true;
struct lkt_config conf; lkt_config_t conf;
char conf_file[PATH_MAX], *homedir, *xdg_config_home; char conf_file[PATH_MAX], *homedir, *xdg_config_home, kara_dir[PATH_MAX];
struct passwd *pw = getpwuid(getuid()); struct passwd *pw = getpwuid(getuid());
if (argc < 2) if (argc < 2)
...@@ -339,14 +339,17 @@ main(int argc, char *argv[]) ...@@ -339,14 +339,17 @@ main(int argc, char *argv[])
strncat(conf_file, "/lektor/config", PATH_MAX - 1); strncat(conf_file, "/lektor/config", PATH_MAX - 1);
} }
config_default(&conf); if (config_new(conf_file, &conf)) {
if (!config_read(conf_file, &conf)) {
fprintf(stderr, " ! using default configuration file setted by the build because could not read file %s\n", fprintf(stderr, " ! using default configuration file setted by the build because could not read file %s\n",
conf_file); conf_file);
} }
return walk_through(conf.database.kara_dir); if (config_get(conf, "database", "kara_dir", kara_dir, PATH_MAX)) {
fprintf(stderr, " ! failed to get the kara directory\n");
return 10;
}
return walk_through(kara_dir);
} else if (strcmp(argv[1], "--file") == 0) { } else if (strcmp(argv[1], "--file") == 0) {
for (i = 2; i < argc; ++i) for (i = 2; i < argc; ++i)
ret &= walk_single(argv[i]); ret &= walk_single(argv[i]);
......
...@@ -48,7 +48,8 @@ main(int argc, char *argv[]) ...@@ -48,7 +48,8 @@ main(int argc, char *argv[])
struct passwd *pw = getpwuid(getuid()); struct passwd *pw = getpwuid(getuid());
char conf_file[PATH_MAX]; char conf_file[PATH_MAX];
char *homedir, *shell, *user, *xdg_config_home; char *homedir, *shell, *user, *xdg_config_home;
struct lkt_config conf; char *db_path, *kara_dir;
lkt_config_t conf;
sqlite3 *db; sqlite3 *db;
bool is_db_populate = false, bool is_db_populate = false,
is_xdg_malloc = false; is_xdg_malloc = false;
...@@ -100,9 +101,8 @@ normal_launch: ...@@ -100,9 +101,8 @@ normal_launch:
fprintf(stderr, " * Lektor launched by user %s (shell: %s, home: %s)\n", user, shell, homedir); fprintf(stderr, " * Lektor launched by user %s (shell: %s, home: %s)\n", user, shell, homedir);
/* Read configuration */ /* Read configuration */
config_default(&conf);
if (!config_read(conf_file, &conf)) if (!config_new(conf_file, &conf))
fprintf(stderr, " ! Failed to read configuration file %s, using default config\n", conf_file); fprintf(stderr, " ! Failed to read configuration file %s, using default config\n", conf_file);
else { else {
fprintf(stderr, " * Apply config from file %s\n", conf_file); fprintf(stderr, " * Apply config from file %s\n", conf_file);
...@@ -110,20 +110,29 @@ normal_launch: ...@@ -110,20 +110,29 @@ normal_launch:
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
db_path = (char *) calloc(PATH_MAX, sizeof(char));
kara_dir = (char *) calloc(PATH_MAX, sizeof(char));
if (config_get(conf, "database", "db_path", db_path, PATH_MAX)) {
fprintf(stderr, " ! Failed to get database path\n");
goto end;
}
if (config_get(conf, "database", "kara_dir", kara_dir, PATH_MAX)) {
fprintf(stderr, " ! Failed to get kara directory\n");
goto end;
}
/* Populate the db */ /* Populate the db */
if (is_db_populate) { if (is_db_populate) {
sqlite3_open(conf.database.db_path, &db); sqlite3_open(db_path, &db);
database_update(db, conf.database.kara_dir); database_update(db, kara_dir);
sqlite3_close(db); sqlite3_close(db);
goto end; goto end;
} }
/* Autoclean queue */ free(db_path);
if (conf.player.autoclear) { free(kara_dir);
sqlite3_open(conf.database.db_path, &db);
database_queue_clear(db);
sqlite3_close(db);
}
ret = ! (0 == lkt_listen(&conf) ? EXIT_SUCCESS : EXIT_FAILURE); ret = ! (0 == lkt_listen(&conf) ? EXIT_SUCCESS : EXIT_FAILURE);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#ifndef LKT_BACKLOG #ifndef LKT_BACKLOG
#define LKT_BACKLOG 32 #define LKT_BACKLOG 32
...@@ -607,13 +608,50 @@ lkt_client_get_mask(struct lkt_state *srv, size_t c) ...@@ -607,13 +608,50 @@ lkt_client_get_mask(struct lkt_state *srv, size_t c)
} }
int int
lkt_listen(struct lkt_config *conf) lkt_listen(lkt_config_t *conf)
{ {
struct lkt_state srv; struct lkt_state srv;
int autoclear;
memset(&srv, 0, sizeof(struct lkt_state)); memset(&srv, 0, sizeof(struct lkt_state));
sqlite3_open(conf->database.db_path, &srv.db); if (config_get_int(conf, "player", "autoclear", &autoclear)) {
srv.kara_prefix = conf->database.kara_dir; fprintf(stderr, " ! Failed to get queue autoclear property\n");
return 1;
}
char *db_path = (char *) calloc(PATH_MAX, sizeof(char));
char *kara_dir = (char *) calloc(PATH_MAX, sizeof(char));
char *host = (char *) calloc(HOST_NAME_MAX, sizeof(char));
char port[5]; /* Maximal port number is 65535. */
char *player_mod;
if (config_get(conf, "database", "db_path", db_path, PATH_MAX)) {
fprintf(stderr, " ! lkt_listen: Failed to get database path\n");
goto end_free_strings;
}
if (config_get(conf, "database", "kara_dir", kara_dir, PATH_MAX)) {
fprintf(stderr, " ! lkt_listen: Failed to get kara directory\n");
goto end_free_strings;
}
if (config_get(conf, "server", "host", host, HOST_NAME_MAX)) {
fprintf(stderr, " ! lkt_listen: Failed to get the host\n");
goto end_free_strings;
}
if (config_get(conf, "server", "port", port, 5)) {
fprintf(stderr, " ! lkt_listen: Failed to get the port\n");
goto end_free_strings;
}
if (config_get_alloc(conf, "player", "module", &player_mod)) {
fprintf(stderr, " ! lkt_listen: Failed to get the module for the player\n");
goto end_free_strings;
}
sqlite3_open(db_path, &srv.db);
srv.kara_prefix = kara_dir;
database_config_default(srv.db); database_config_default(srv.db);
...@@ -622,16 +660,16 @@ lkt_listen(struct lkt_config *conf) ...@@ -622,16 +660,16 @@ lkt_listen(struct lkt_config *conf)
srv.clients = malloc(srv.fds_max * sizeof(struct lkt_client)); srv.clients = malloc(srv.fds_max * sizeof(struct lkt_client));
memset(srv.clients, 0, srv.fds_max * sizeof(struct lkt_client)); memset(srv.clients, 0, srv.fds_max * sizeof(struct lkt_client));
if ((srv.fds[0].fd = init_listening_socket(conf->server.host, conf->server.port)) < 0) if ((srv.fds[0].fd = init_listening_socket(host, port)) < 0)
return -1; return -1;
srv.fds[0].events = POLLIN; srv.fds[0].events = POLLIN;
srv.fds_len = 1; srv.fds_len = 1;
if (conf->player.autoclear) if (autoclear)
database_queue_clear(srv.db); database_queue_clear(srv.db);
if (!load_module_by_name(conf, conf->player.module_win, &srv.win)) if (!load_module_by_name(conf, player_mod, &srv.win))
return -2; return -2;
if (!srv.win.new(&srv.win)) if (!srv.win.new(&srv.win))
...@@ -648,4 +686,12 @@ lkt_listen(struct lkt_config *conf) ...@@ -648,4 +686,12 @@ lkt_listen(struct lkt_config *conf)
srv.win.free(&srv.win); srv.win.free(&srv.win);
return -1; return -1;
/* End and free strings used to get paths of the database.
There was a failure at some point while getting them. */
end_free_strings:
free(kara_dir);
free(db_path);
free(host);
return -10;
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter