From 8fd3da3832a019a1acca61ad682baeb48e2acb7b Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 18:35:12 +0200 Subject: [PATCH 01/16] Make libgridinit-utils static instead of shared. No one uses it. --- lib/CMakeLists.txt | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index dd03f5f..d7cde54 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,7 +1,7 @@ include_directories(BEFORE .) -add_library(gridinit-utils SHARED +add_library(gridinit-utils STATIC uid.c common.c limits.c @@ -12,13 +12,3 @@ add_library(gridinit-utils SHARED target_link_libraries(gridinit-utils ${GLIB2_LIBRARIES}) - -set_target_properties(gridinit-utils PROPERTIES - PUBLIC_HEADER "gridinit-utils.h" - SOVERSION ${ABI_VERSION}) - -install(TARGETS gridinit-utils - LIBRARY DESTINATION ${LD_LIBDIR} - PUBLIC_HEADER DESTINATION include - RUNTIME DESTINATION bin) - From d2aed69030375bf117d273b3070bf63785272b40 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 18:37:31 +0200 Subject: [PATCH 02/16] Remove the useless test CLI tool --- main/CMakeLists.txt | 6 --- main/test_cmd.c | 114 -------------------------------------------- 2 files changed, 120 deletions(-) delete mode 100644 main/test_cmd.c diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 812a4d3..fafd919 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -24,12 +24,6 @@ target_link_libraries(gridinit_cmd gridinit-internals ${GLIB2_LIBRARIES} ${LIBEVENT_LIBRARIES}) -add_executable(gridinit_testcmd - test_cmd.c) -target_link_libraries(gridinit_testcmd - gridinit-utils gridinit-internals - ${GLIB2_LIBRARIES}) - install(TARGETS gridinit gridinit_cmd LIBRARY DESTINATION ${LD_LIBDIR} PUBLIC_HEADER DESTINATION include diff --git a/main/test_cmd.c b/main/test_cmd.c deleted file mode 100644 index 8488616..0000000 --- a/main/test_cmd.c +++ /dev/null @@ -1,114 +0,0 @@ -/* -gridinit, a monitor for non-daemon processes. -Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -#include -#include -#include -#include - -#include - -#include "../lib/gridinit-utils.h" - -static void -dump_limits(void) -{ - gint64 limit; - - g_print("\nLIMITS:\n"); - supervisor_limit_get(SUPERV_LIMIT_THREAD_STACK, &limit); - g_print("\tSUPERV_LIMIT_THREAD_STACK = %"G_GINT64_FORMAT"\n", limit); - - supervisor_limit_get(SUPERV_LIMIT_MAX_FILES, &limit); - g_print("\tSUPERV_LIMIT_MAX_FILES = %"G_GINT64_FORMAT"\n", limit); - - supervisor_limit_get(SUPERV_LIMIT_CORE_SIZE, &limit); - g_print("\tSUPERV_LIMIT_CORE_SIZE = %"G_GINT64_FORMAT"\n", limit); -} - -static void -dump_environment(void) -{ - gchar **env, **p_env; - const gchar *value; - - g_print("\nENVIRONMENT:\n"); - if (!(env = g_listenv())) - return; - - for (p_env=env ; *p_env ; p_env++) { - value = g_getenv(*p_env); - g_print("\t%s=%s\n", *p_env, value); - } - - g_strfreev(env); -} - -static void -dump_cwd(void) -{ - gchar *dir; - - dir = g_get_current_dir(); - g_print("Current directory: %s\n", dir); - g_free(dir); -} - -static void -my_sleep(gdouble sleep_time) -{ - GTimer *timer; - - g_print("\nSleeping %f seconds\n", sleep_time); - - timer = g_timer_new(); - while (g_timer_elapsed(timer, NULL) < sleep_time) - sleep(1); - - g_print("Sleeped %f seconds\n", g_timer_elapsed(timer, NULL)); - g_timer_destroy(timer); -} - -static void -reopen_output(const gchar *path) -{ - if (!freopen(path, "a", stderr)) - g_printerr("freopen(%s, \"a\", stderr) : %s\n", path, strerror(errno)); - if (!freopen(path, "a", stdout)) - g_printerr("freopen(%s, \"a\", stdout) : %s\n", path, strerror(errno)); -} - -int -main(int argc, char **args) -{ - gdouble sleep_time = 1.0; - - if (argc > 1) - reopen_output(args[1]); - if (argc > 2) - sleep_time = g_ascii_strtod(args[2], NULL); - - dump_cwd(); - dump_limits(); - dump_environment(); - my_sleep(sleep_time); - - return 0; -} - From a93620cb306c95d1370259940c90474397ae14cc Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 18:39:37 +0200 Subject: [PATCH 03/16] Speed the catharsis up --- lib/children.c | 53 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/children.c b/lib/children.c index f996d91..4c6b5d8 100644 --- a/lib/children.c +++ b/lib/children.c @@ -666,29 +666,48 @@ supervisor_children_disable_obsolete(void) return count; } +static inline int +_is_dead(const pid_t needle, pid_t *pincushion, register const int max) +{ + for (register int i=0; i 0) { - FOREACH_CHILD(sd) { - if (sd->pid == pid_dead) { - count++; - _child_notify_death(sd); - if (cb) { - _child_get_info(sd, &ci); - cb(udata, &ci); - } - sd->pid = -1; - break; - } - } + g_assert_nonnull(cb); + + /* Consume a batch of dead children */ + while (pids_idx < 1024 && (pid = waitpid(-1, NULL, WNOHANG)) > 0) + pids[pids_idx++] = pid; + if (!pids_idx) + return 0; + + /* Locate the concerned structures, for each dead child */ + FOREACH_CHILD(sd) { + if (!_is_dead(sd->pid, pids, pids_idx)) + continue; + + count++; + _child_notify_death(sd); + + struct child_info_s ci = {}; + _child_get_info(sd, &ci); + cb(udata, &ci); + + sd->pid = -1; } + return count; } From 26f5c1cd8bd680765175ec5213c109d00ff4dd9b Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 18:41:26 +0200 Subject: [PATCH 04/16] Remove the obsolete ensure_servers function --- main/gridinit.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/main/gridinit.c b/main/gridinit.c index 83ce9cf..5110b79 100644 --- a/main/gridinit.c +++ b/main/gridinit.c @@ -108,8 +108,6 @@ static GHashTable *default_env = NULL; static gboolean _cfg_reload(gboolean services_only, GError **err); -static void servers_ensure(void); - static GOptionEntry entries[] = { {"daemonize", 'd', 0, G_OPTION_ARG_NONE, (gboolean *)&flag_daemon, "Detaches then daemonizes the gridinit", NULL}, @@ -544,9 +542,7 @@ supervisor_signal_handler(int s, short flags, void *udata) case SIGUSR1: flag_more_verbose = ~0; return; - case SIGUSR2: - flag_check_socket = ~0; - return; + case SIGUSR2: /* ignored */ case SIGPIPE: /* ignored */ return; case SIGINT: @@ -919,42 +915,6 @@ servers_clean(void) list_of_servers = NULL; } -/** - * Reopens all the UNIX server sockets bond on paths that changed. - */ -static void -servers_ensure(void) -{ - GList *l; - - flag_check_socket = 0; - TRACE("About to ensure the server sockets"); - - for (l=list_of_servers; l ; l=l->next) { - struct server_sock_s *p_server = l->data; - - NOTICE("Ensuring socket fd=%d bond to [%s]", p_server->fd, p_server->url); - - if (servers_is_unix(p_server) && !servers_is_the_same(p_server)) { - - /* close */ - servers_unmonitor_one(p_server); - - /* reopen */ - p_server->fd = __open_unix_server(p_server->url); - if (p_server->fd < 0) { - WARN("unix: failed to reopen a server bond to [%s] : %s", - p_server->url, strerror(errno)); - } - else if (!servers_monitor_one(p_server)) { - WARN("unix: failed to monitor a server bond to [%s] : %s", - p_server->url, strerror(errno)); - servers_unmonitor_one(p_server); - } - } - } -} - /* Signals management ------------------------------------------------------ */ static void @@ -1984,8 +1944,6 @@ main(int argc, char ** args) if (!flag_running) break; - if (flag_check_socket) - servers_ensure(); if (flag_more_verbose) { NOTICE("Increasing verbosity for 15 minutes"); logger_verbose(); From d850bce6da8ca5bc9851eb0690d8b65904a9bc10 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 21:49:52 +0200 Subject: [PATCH 05/16] Remove the useless command_get_pipe() function --- lib/CMakeLists.txt | 1 - lib/command.c | 103 ------------------------------------------- lib/gridinit-utils.h | 4 -- 3 files changed, 108 deletions(-) delete mode 100644 lib/command.c diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d7cde54..f2dc7b8 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -5,7 +5,6 @@ add_library(gridinit-utils STATIC uid.c common.c limits.c - command.c children.c gridinit-utils.h gridinit-internals.h) diff --git a/lib/command.c b/lib/command.c deleted file mode 100644 index 972818d..0000000 --- a/lib/command.c +++ /dev/null @@ -1,103 +0,0 @@ -/* -gridinit-utils, a helper library for gridinit. -Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - -#include -#include -#include -#include -#include - -#include -#include "./gridinit-utils.h" - -#define IDX_IN 0 -#define IDX_OUT 1 - -static void -dup2_or_exit(int fd1, int fd2) -{ - if (-1 == dup2(fd1, fd2)) { - /*ERROR("dup2(%d,%d) error : %s", fd1, fd2, strerror(errno));*/ - exit(1); - } -} - -static void -run_command(int fd_out, const char *cmd) -{ - gint argc = 0; - gchar **argv = NULL; - - if (!g_shell_parse_argv(cmd, &argc, &argv, NULL)) - exit(1); - - dup2_or_exit(fd_out, fileno(stdout)); - dup2_or_exit(fd_out, fileno(stderr)); - - const char *real_cmd = argv[0]; - if (!g_path_is_absolute(real_cmd)) - real_cmd = g_find_program_in_path(real_cmd); - execv(real_cmd, argv); - g_strfreev(argv); - exit(1); -} - -int -command_get_pipe(const gchar *str_cmd) -{ - typeof(errno) errsav; - int fd[2]; - - if (!str_cmd) { - errno = EINVAL; - return -1; - } - - if (0 != pipe(fd)) { - return -1; - } - - /*TRACE("pipe opened (IN=%d,OUT=%d)", fd[IDX_IN], fd[IDX_OUT]);*/ - - switch (fork()) { - - case -1: /* ERROR */ - errsav = errno; - close(fd[IDX_IN]); - close(fd[IDX_OUT]); - errno = errsav; - return -1; - - case 0: /* CHILD */ - close(fd[IDX_IN]); - /*TRACE("Child writing in fd=%d", fd[IDX_OUT]);*/ - run_command(fd[IDX_OUT], str_cmd); /*never returns on success*/ - return -1;/* makes everybody happy*/ - - default: /* FATHER */ - close(fd[IDX_OUT]); - /*TRACE("Father reading from fd=%d", fd[IDX_IN]);*/ - return fd[IDX_IN]; - } -} - diff --git a/lib/gridinit-utils.h b/lib/gridinit-utils.h index 6d354f0..ce4058f 100644 --- a/lib/gridinit-utils.h +++ b/lib/gridinit-utils.h @@ -153,10 +153,6 @@ int supervisor_children_set_ids(const gchar *key, gint32 uid, gint32 gid); int supervisor_children_set_delay_sigkill(const char *key, time_t delay); -/* Fork and pipe ----------------------------------------------------------- */ - -int command_get_pipe(const gchar *str_cmd); - /* Privileges -------------------------------------------------------------- */ gboolean supervisor_rights_init(const char *user_name, const char *group_name, From 7b51d5ae2cbd7191cc564a53dd21f97dd3eb7ab4 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:10:41 +0200 Subject: [PATCH 06/16] Clean the headers --- CMakeLists.txt | 3 +++ lib/CMakeLists.txt | 4 +--- lib/children.c | 5 ----- lib/common.c | 9 ++------ lib/gridinit-internals.h | 47 ---------------------------------------- lib/gridinit-utils.h | 19 ++++++++++++++++ lib/limits.c | 9 ++------ lib/uid.c | 9 ++------ main/alerting.c | 8 ------- main/cnx.c | 9 +------- main/gridinit.c | 8 ------- main/gridinit_cmd.c | 8 ------- main/utils.c | 8 +------ 13 files changed, 31 insertions(+), 115 deletions(-) delete mode 100644 lib/gridinit-internals.h diff --git a/CMakeLists.txt b/CMakeLists.txt index eb627f1..93664f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,9 @@ set(CMAKE_LIBRARY_PATH "") set(CMAKE_INCLUDE_PATH "") include_directories(AFTER ${GLIB2_INCLUDE_DIRS}) +add_definitions(-DLOG_DOMAIN="gridinit") +add_definitions(-DGRIDINIT_DOMAIN="gridinit") + add_subdirectory(./lib) add_subdirectory(./main) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f2dc7b8..9a9be60 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -5,9 +5,7 @@ add_library(gridinit-utils STATIC uid.c common.c limits.c - children.c - gridinit-utils.h - gridinit-internals.h) + children.c) target_link_libraries(gridinit-utils ${GLIB2_LIBRARIES}) diff --git a/lib/children.c b/lib/children.c index 4c6b5d8..9b23e93 100644 --- a/lib/children.c +++ b/lib/children.c @@ -17,10 +17,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - #include #include #include @@ -33,7 +29,6 @@ along with this program. If not, see . #include #include "./gridinit-utils.h" -#include "./gridinit-internals.h" time_t supervisor_default_delay_KILL = SUPERVISOR_DEFAULT_TIMEOUT_KILL; diff --git a/lib/common.c b/lib/common.c index b58495e..12c2d39 100644 --- a/lib/common.c +++ b/lib/common.c @@ -17,16 +17,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - -#include "./gridinit-utils.h" -#include "./gridinit-internals.h" - #include #include +#include "./gridinit-utils.h" + GError* g_error_printf(const char *dom, int code, const char *fmt, ...) { diff --git a/lib/gridinit-internals.h b/lib/gridinit-internals.h deleted file mode 100644 index 46b73c9..0000000 --- a/lib/gridinit-internals.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -gridinit-utils, a helper library for gridinit. -Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -#ifndef __GRID_SUPERVISOR_INTERNALS_H__ -# define __GRID_SUPERVISOR_INTERNALS_H__ -# include - -#ifndef GRIDINIT_DOMAIN -# define GRIDINIT_DOMAIN "gridinit" -#endif - -# define GRID_LOGLVL_TRACE (32 << G_LOG_LEVEL_USER_SHIFT) -# define GRID_LOGLVL_DEBUG (16 << G_LOG_LEVEL_USER_SHIFT) -# define GRID_LOGLVL_INFO (8 << G_LOG_LEVEL_USER_SHIFT) -# define GRID_LOGLVL_NOTICE (4 << G_LOG_LEVEL_USER_SHIFT) -# define GRID_LOGLVL_WARN (2 << G_LOG_LEVEL_USER_SHIFT) -# define GRID_LOGLVL_ERROR (1 << G_LOG_LEVEL_USER_SHIFT) - -# define FATAL(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) -# define ALERT(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) -# define CRIT(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) -# define ERROR(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) -# define WARN(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_WARN, Format, ##__VA_ARGS__) -# define NOTICE(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_NOTICE, Format, ##__VA_ARGS__) -# define INFO(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_INFO, Format, ##__VA_ARGS__) -# define DEBUG(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_DEBUG, Format, ##__VA_ARGS__) -# define TRACE(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_TRACE, Format, ##__VA_ARGS__) - -GError* g_error_printf(const char *dom, int code, const char *fmt, ...); - -#endif diff --git a/lib/gridinit-utils.h b/lib/gridinit-utils.h index ce4058f..4b80096 100644 --- a/lib/gridinit-utils.h +++ b/lib/gridinit-utils.h @@ -32,6 +32,25 @@ along with this program. If not, see . # include # include +# define GRID_LOGLVL_TRACE (32 << G_LOG_LEVEL_USER_SHIFT) +# define GRID_LOGLVL_DEBUG (16 << G_LOG_LEVEL_USER_SHIFT) +# define GRID_LOGLVL_INFO (8 << G_LOG_LEVEL_USER_SHIFT) +# define GRID_LOGLVL_NOTICE (4 << G_LOG_LEVEL_USER_SHIFT) +# define GRID_LOGLVL_WARN (2 << G_LOG_LEVEL_USER_SHIFT) +# define GRID_LOGLVL_ERROR (1 << G_LOG_LEVEL_USER_SHIFT) + +# define FATAL(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) +# define ALERT(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) +# define CRIT(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) +# define ERROR(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_ERROR, Format, ##__VA_ARGS__) +# define WARN(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_WARN, Format, ##__VA_ARGS__) +# define NOTICE(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_NOTICE, Format, ##__VA_ARGS__) +# define INFO(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_INFO, Format, ##__VA_ARGS__) +# define DEBUG(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_DEBUG, Format, ##__VA_ARGS__) +# define TRACE(Format,...) g_log(GRIDINIT_DOMAIN, GRID_LOGLVL_TRACE, Format, ##__VA_ARGS__) + +GError* g_error_printf(const char *dom, int code, const char *fmt, ...); + extern time_t supervisor_default_delay_KILL; /* Children monitoring ----------------------------------------------------- */ diff --git a/lib/limits.c b/lib/limits.c index d76cb7e..4fecef2 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -17,13 +17,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - -#include "./gridinit-utils.h" -#include "./gridinit-internals.h" - #include #include #include @@ -31,6 +24,8 @@ along with this program. If not, see . #include #include +#include "./gridinit-utils.h" + static const char* get_rlimit_name(enum supervisor_limit_e what) { diff --git a/lib/uid.c b/lib/uid.c index b11f72d..c805f0d 100644 --- a/lib/uid.c +++ b/lib/uid.c @@ -17,13 +17,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif - -#include "./gridinit-utils.h" -#include "./gridinit-internals.h" - #include #include #include @@ -31,6 +24,8 @@ along with this program. If not, see . #include #include +#include "./gridinit-utils.h" + static volatile uid_t effective_uid = 0; static volatile uid_t effective_gid = 0; diff --git a/main/alerting.c b/main/alerting.c index e063fd1..68cca62 100644 --- a/main/alerting.c +++ b/main/alerting.c @@ -17,13 +17,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif -#ifndef LOG_DOMAIN -# define LOG_DOMAIN "gridinit" -#endif - #include #include #include @@ -31,7 +24,6 @@ along with this program. If not, see . #include #include "./gridinit_internals.h" #include "./gridinit_alerts.h" -#include "../lib/gridinit-internals.h" static GModule *module = NULL; static struct gridinit_alert_handle_s *handle = NULL; diff --git a/main/cnx.c b/main/cnx.c index bca43cb..58f347b 100644 --- a/main/cnx.c +++ b/main/cnx.c @@ -17,13 +17,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif -#ifndef LOG_DOMAIN -# define LOG_DOMAIN "gridinit" -#endif - #include #include #include @@ -42,7 +35,7 @@ along with this program. If not, see . #include #include "./gridinit_internals.h" -#include "../lib/gridinit-internals.h" +#include "../lib/gridinit-utils.h" static volatile int backlog_unix = 65536; static volatile int backlog_tcp = 4096; diff --git a/main/gridinit.c b/main/gridinit.c index 5110b79..7b77347 100644 --- a/main/gridinit.c +++ b/main/gridinit.c @@ -17,13 +17,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif -#ifndef LOG_DOMAIN -# define LOG_DOMAIN "gridinit.main" -#endif - #include #include #include @@ -52,7 +45,6 @@ along with this program. If not, see . #include #include "./gridinit_internals.h" #include "./gridinit_alerts.h" -#include "../lib/gridinit-internals.h" #define USERFLAG_PROCESS_DIED 0x00000002 #define USERFLAG_PROCESS_RESTARTED 0x00000004 diff --git a/main/gridinit_cmd.c b/main/gridinit_cmd.c index ac194f3..20c7cf8 100644 --- a/main/gridinit_cmd.c +++ b/main/gridinit_cmd.c @@ -17,13 +17,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif -#ifndef LOG_DOMAIN -# define LOG_DOMAIN "gridinit_cmd" -#endif - #include #include #include @@ -38,7 +31,6 @@ along with this program. If not, see . #include #include "./gridinit_internals.h" -#include "../lib/gridinit-internals.h" #define MINI 0 #define MEDIUM 1 diff --git a/main/utils.c b/main/utils.c index 68ca298..8880084 100644 --- a/main/utils.c +++ b/main/utils.c @@ -17,14 +17,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif -#ifndef LOG_DOMAIN -# define LOG_DOMAIN "gridinit.utils" -#endif - #include + #include "./gridinit_internals.h" #define STR_SKIP_SPACES(s) do {\ From 7fec79df3c705850dcfdbcbda2e1744e269dcd54 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:17:51 +0200 Subject: [PATCH 07/16] Fix the copyright mentions --- lib/children.c | 2 +- lib/common.c | 2 +- lib/gridinit-utils.h | 2 +- lib/limits.c | 2 +- lib/uid.c | 2 +- main/alerting.c | 2 +- main/cnx.c | 2 +- main/gridinit.c | 2 +- main/gridinit_alerts.h | 2 +- main/gridinit_cmd.c | 2 +- main/gridinit_internals.h | 2 +- main/utils.c | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/children.c b/lib/children.c index 9b23e93..2e845c5 100644 --- a/lib/children.c +++ b/lib/children.c @@ -1,7 +1,7 @@ /* gridinit-utils, a helper library for gridinit. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/lib/common.c b/lib/common.c index 12c2d39..8754bb3 100644 --- a/lib/common.c +++ b/lib/common.c @@ -1,7 +1,7 @@ /* gridinit-utils, a helper library for gridinit. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/lib/gridinit-utils.h b/lib/gridinit-utils.h index 4b80096..e1b39d2 100644 --- a/lib/gridinit-utils.h +++ b/lib/gridinit-utils.h @@ -1,7 +1,7 @@ /* gridinit-utils, a helper library for gridinit. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/lib/limits.c b/lib/limits.c index 4fecef2..c63a551 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -1,7 +1,7 @@ /* gridinit-utils, a helper library for gridinit. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/lib/uid.c b/lib/uid.c index c805f0d..1dc6e71 100644 --- a/lib/uid.c +++ b/lib/uid.c @@ -1,7 +1,7 @@ /* gridinit-utils, a helper library for gridinit. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/main/alerting.c b/main/alerting.c index 68cca62..9bee2f2 100644 --- a/main/alerting.c +++ b/main/alerting.c @@ -1,7 +1,7 @@ /* gridinit, a monitor for non-daemon processes. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/main/cnx.c b/main/cnx.c index 58f347b..e02d744 100644 --- a/main/cnx.c +++ b/main/cnx.c @@ -1,7 +1,7 @@ /* gridinit, a monitor for non-daemon processes. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/main/gridinit.c b/main/gridinit.c index 7b77347..fffaa24 100644 --- a/main/gridinit.c +++ b/main/gridinit.c @@ -1,7 +1,7 @@ /* gridinit, a monitor for non-daemon processes. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/main/gridinit_alerts.h b/main/gridinit_alerts.h index 79bdb93..521ad35 100644 --- a/main/gridinit_alerts.h +++ b/main/gridinit_alerts.h @@ -1,7 +1,7 @@ /* gridinit, a monitor for non-daemon processes. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/main/gridinit_cmd.c b/main/gridinit_cmd.c index 20c7cf8..2584d55 100644 --- a/main/gridinit_cmd.c +++ b/main/gridinit_cmd.c @@ -1,7 +1,7 @@ /* gridinit, a monitor for non-daemon processes. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/main/gridinit_internals.h b/main/gridinit_internals.h index 7fce86d..4019c0c 100644 --- a/main/gridinit_internals.h +++ b/main/gridinit_internals.h @@ -1,7 +1,7 @@ /* gridinit, a monitor for non-daemon processes. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as diff --git a/main/utils.c b/main/utils.c index 8880084..408b75b 100644 --- a/main/utils.c +++ b/main/utils.c @@ -1,7 +1,7 @@ /* gridinit, a monitor for non-daemon processes. Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015 OpenIO, modified for OpenIO Software Defined Storage +Copyright (C) 2015-2018 OpenIO SAS This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as From 5663be7ab76338629d9e0042580c39bc033b0f9e Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:26:34 +0200 Subject: [PATCH 08/16] Speed the building process Removing the library allows to parallelize more --- main/CMakeLists.txt | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index fafd919..38f78e5 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -2,26 +2,21 @@ include_directories(BEFORE . ../lib) -add_library(gridinit-internals STATIC - utils.c - cnx.c - gridinit_internals.h) -target_link_libraries(gridinit-internals - ${GLIB2_LIBRARIES}) - add_executable(gridinit gridinit.c alerting.c - gridinit_alerts.h) + utils.c + cnx.c) target_link_libraries(gridinit - gridinit-utils gridinit-internals + gridinit-utils ${GLIB2_LIBRARIES} ${LIBEVENT_LIBRARIES}) add_executable(gridinit_cmd gridinit_cmd.c - format_output.c) + format_output.c + utils.c + cnx.c) target_link_libraries(gridinit_cmd - gridinit-internals ${GLIB2_LIBRARIES} ${LIBEVENT_LIBRARIES}) install(TARGETS gridinit gridinit_cmd From 6e6ce1c9ef7ae1e2c6a8faefa37d1c7a426c8ad0 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:30:45 +0200 Subject: [PATCH 09/16] Gather the useless lib with the rest --- CMakeLists.txt | 1 - lib/CMakeLists.txt | 11 ----------- main/CMakeLists.txt | 11 +++++++++-- {lib => main}/children.c | 0 main/cnx.c | 4 ++-- {lib => main}/common.c | 0 {lib => main}/gridinit-utils.h | 0 {lib => main}/limits.c | 0 {lib => main}/uid.c | 0 9 files changed, 11 insertions(+), 16 deletions(-) delete mode 100644 lib/CMakeLists.txt rename {lib => main}/children.c (100%) rename {lib => main}/common.c (100%) rename {lib => main}/gridinit-utils.h (100%) rename {lib => main}/limits.c (100%) rename {lib => main}/uid.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93664f6..5c868c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,5 @@ include_directories(AFTER ${GLIB2_INCLUDE_DIRS}) add_definitions(-DLOG_DOMAIN="gridinit") add_definitions(-DGRIDINIT_DOMAIN="gridinit") -add_subdirectory(./lib) add_subdirectory(./main) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt deleted file mode 100644 index 9a9be60..0000000 --- a/lib/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ - -include_directories(BEFORE .) - -add_library(gridinit-utils STATIC - uid.c - common.c - limits.c - children.c) - -target_link_libraries(gridinit-utils - ${GLIB2_LIBRARIES}) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 38f78e5..8f0e16f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,6 +1,13 @@ -include_directories(BEFORE . - ../lib) +include_directories(BEFORE .) + +add_library(gridinit-utils STATIC + uid.c + common.c + limits.c + children.c) +target_link_libraries(gridinit-utils + ${GLIB2_LIBRARIES}) add_executable(gridinit gridinit.c diff --git a/lib/children.c b/main/children.c similarity index 100% rename from lib/children.c rename to main/children.c diff --git a/main/cnx.c b/main/cnx.c index e02d744..69ce4bf 100644 --- a/main/cnx.c +++ b/main/cnx.c @@ -34,8 +34,8 @@ along with this program. If not, see . #include -#include "./gridinit_internals.h" -#include "../lib/gridinit-utils.h" +#include "gridinit-utils.h" +#include "gridinit_internals.h" static volatile int backlog_unix = 65536; static volatile int backlog_tcp = 4096; diff --git a/lib/common.c b/main/common.c similarity index 100% rename from lib/common.c rename to main/common.c diff --git a/lib/gridinit-utils.h b/main/gridinit-utils.h similarity index 100% rename from lib/gridinit-utils.h rename to main/gridinit-utils.h diff --git a/lib/limits.c b/main/limits.c similarity index 100% rename from lib/limits.c rename to main/limits.c diff --git a/lib/uid.c b/main/uid.c similarity index 100% rename from lib/uid.c rename to main/uid.c From 6c12a04887db2ea3806fa376d700ad401b6d61b2 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:39:58 +0200 Subject: [PATCH 10/16] Remove the unused support of pluggable alerting --- main/CMakeLists.txt | 1 - main/alerting.c | 109 -------------------------------------- main/gridinit.c | 70 +----------------------- main/gridinit_alerts.h | 53 ------------------ main/gridinit_internals.h | 8 --- 5 files changed, 2 insertions(+), 239 deletions(-) delete mode 100644 main/alerting.c delete mode 100644 main/gridinit_alerts.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 8f0e16f..c0d61d7 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -11,7 +11,6 @@ target_link_libraries(gridinit-utils add_executable(gridinit gridinit.c - alerting.c utils.c cnx.c) target_link_libraries(gridinit diff --git a/main/alerting.c b/main/alerting.c deleted file mode 100644 index 9bee2f2..0000000 --- a/main/alerting.c +++ /dev/null @@ -1,109 +0,0 @@ -/* -gridinit, a monitor for non-daemon processes. -Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015-2018 OpenIO SAS - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -#include -#include -#include - -#include -#include "./gridinit_internals.h" -#include "./gridinit_alerts.h" - -static GModule *module = NULL; -static struct gridinit_alert_handle_s *handle = NULL; - -/* ------------------------------------------------------------------------- */ - -gboolean -gridinit_alerting_configure(const gchar *path, const gchar *symbol, - GHashTable *ht_params, GError **err) -{ - TRACE("trying to configure the alerting with the module [%s] and the symbol [%s]", - path, symbol); - if (!symbol || !path) { - if (err) { - *err = g_error_printf(LOG_DOMAIN, 500, "Invalid parameter"); - } - return FALSE; - } - if (module != NULL) { - if (err) { - *err = g_error_printf(LOG_DOMAIN, 500, "Module already loaded"); - } - return FALSE; - } - - /* Open the module and locate the exported symbol */ - if (NULL == (module = g_module_open (path, 0))) { - if (err) { - *err = g_error_printf(LOG_DOMAIN, 500, - "Cannot load the plug-in from file %s (%s)", - path, g_module_error()); - } - return FALSE; - } - - gpointer pointer = NULL; - if (!g_module_symbol(module, symbol, &pointer) || !pointer) { - if (err) { - *err = g_error_printf(LOG_DOMAIN, 500, - "Cannot get the exported structure (%s) from the plug-in %p (%s)", - symbol, (void*)module, g_module_error()); - } - return FALSE; - } - - handle = pointer; - if (handle->init) { - handle->init(handle->module_data, ht_params); - } - - return TRUE; -} - - -void -gridinit_alerting_send(int event, const char *msg) -{ - if (event == GRIDINIT_EVENT_BROKEN) { - ERROR("Process alert: %s", msg); - } else if (event == GRIDINIT_EVENT_RESTARTED) { - WARN("Process alert: %s", msg); - } else { - NOTICE("Process alert: %s", msg); - } - - if (!module || !handle || !handle->send) - return; - - handle->send(handle->module_data, event, msg); -} - -void -gridinit_alerting_close(void) -{ - if (handle && handle->fini) - handle->fini(handle->module_data); - if (module) - g_module_close(module); - - module = NULL; - handle = NULL; -} - diff --git a/main/gridinit.c b/main/gridinit.c index fffaa24..9bba8a7 100644 --- a/main/gridinit.c +++ b/main/gridinit.c @@ -44,7 +44,6 @@ along with this program. If not, see . #include #include "./gridinit_internals.h" -#include "./gridinit_alerts.h" #define USERFLAG_PROCESS_DIED 0x00000002 #define USERFLAG_PROCESS_RESTARTED 0x00000004 @@ -222,20 +221,17 @@ static void alert_send_deferred(void *udata, struct child_info_s *ci) { (void) udata; - gchar buff[1024]; /* Handle the alerting of broken services */ if ((ci->user_flags & USERFLAG_PROCESS_DIED) && ci->broken) { supervisor_children_del_user_flags(ci->key, USERFLAG_PROCESS_DIED); - g_snprintf(buff, sizeof(buff), "Process broken [%s] %s", ci->key, ci->cmd); - gridinit_alerting_send(GRIDINIT_EVENT_BROKEN, buff); + ERROR("Process broken [%s] %s", ci->key, ci->cmd); } /* Handle the alerting of successfully restarted services */ if (!(ci->user_flags & USERFLAG_PROCESS_DIED) && (ci->user_flags & USERFLAG_PROCESS_RESTARTED)) { supervisor_children_del_user_flags(ci->key, USERFLAG_PROCESS_RESTARTED); - g_snprintf(buff, sizeof(buff), "Process restarted [%s] %s", ci->key, ci->cmd); - gridinit_alerting_send(GRIDINIT_EVENT_RESTARTED, buff); + NOTICE("Process restarted [%s] %s", ci->key, ci->cmd); } } @@ -1271,60 +1267,6 @@ _cfg_section_service(GKeyFile *kf, const gchar *section, GError **err) return rc; } -static gboolean -_cfg_section_alert(GKeyFile *kf, const gchar *section, GError **err) -{ - gchar cfg_plugin[1024], cfg_symbol[128]; - gchar **p_key, **keys; - - bzero(cfg_plugin, sizeof(cfg_plugin)); - bzero(cfg_symbol, sizeof(cfg_symbol)); - - keys = g_key_file_get_keys(kf, section, NULL, err); - if (!keys) - return FALSE; - - for (p_key=keys; *p_key ;p_key++) { - gchar *str; - - str = g_key_file_get_string(kf, section, *p_key, NULL); - - if (!g_ascii_strcasecmp(*p_key, "plugin")) { - if (*cfg_plugin) - NOTICE("Alerting plugin already known : plugin=[%s]", cfg_plugin); - else - g_strlcpy(cfg_plugin, str, sizeof(cfg_plugin)-1); - } - else if (!g_ascii_strcasecmp(*p_key, "symbol")) { - if (*cfg_symbol) - NOTICE("Alerting symbol already known : symbol=[%s]", cfg_symbol); - else - g_strlcpy(cfg_symbol, str, sizeof(cfg_symbol)-1); - } - - g_free(str); - } - - g_strfreev(keys); - - if (!*cfg_symbol || !*cfg_plugin) { - WARN("Missing configuration keys : both \"plugin\" and \"symbol\"" - " must be present in section [%s]", section); - return FALSE; - } - else { - GHashTable *ht_params; - gboolean rc; - ht_params = _cfg_extract_parameters(kf, section, "config.", err); - rc = gridinit_alerting_configure(cfg_plugin, cfg_symbol, ht_params, err); - g_hash_table_destroy(ht_params); - if (!rc) - return FALSE; - } - - return TRUE; -} - static gboolean _cfg_section_default(GKeyFile *kf, const gchar *section, GError **err) { @@ -1489,13 +1431,6 @@ _cfg_reload_file(GKeyFile *kf, gboolean services_only, GError **err) goto label_exit; } } - else if (!services_only && !g_ascii_strcasecmp(*p_group, "alerts")) { - INFO("reconfigure : loading alerting parameters from section [%s]", *p_group); - if (!_cfg_section_alert(kf, *p_group, err)) { - WARN("Invalid alerts section"); - goto label_exit; - } - } else { INFO("reconfigure : ignoring section [%s]", *p_group); } @@ -1986,7 +1921,6 @@ main(int argc, char ** args) signals_clean(); g_free(config_path); - gridinit_alerting_close(); closelog(); return rc; } diff --git a/main/gridinit_alerts.h b/main/gridinit_alerts.h deleted file mode 100644 index 521ad35..0000000 --- a/main/gridinit_alerts.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -gridinit, a monitor for non-daemon processes. -Copyright (C) 2013 AtoS Worldline, original work aside of Redcurrant -Copyright (C) 2015-2018 OpenIO SAS - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -#ifndef __GRIDINIT_ALERTS_H__ -# define __GRIDINIT_ALERTS_H__ -# include -# define GRIDINIT_EVENT_STARTED 1 -# define GRIDINIT_EVENT_RESTARTED 2 -# define GRIDINIT_EVENT_BROKEN 3 - -/** - * @param udata the user data provided in the exported structure - */ -typedef void (*gridinit_alert_handler_f) (void *udata, int event, const char *msg); - -/** - * @param udata the user data provided in the exported structure - */ -typedef void (*gridinit_alert_init_f) (void *udata, GHashTable *params); - -/** - * @param udata the user data provided in the exported structure - */ -typedef void (*gridinit_alert_fini_f) (void *udata); - -/** - * The type of structure that must be exported by the module - * under the name MODULE_HANDLER_gridnit_alert; - */ -struct gridinit_alert_handle_s { - void *module_data; - gridinit_alert_init_f init; - gridinit_alert_fini_f fini; - gridinit_alert_handler_f send; -}; - -#endif diff --git a/main/gridinit_internals.h b/main/gridinit_internals.h index 4019c0c..fa8ee1a 100644 --- a/main/gridinit_internals.h +++ b/main/gridinit_internals.h @@ -86,14 +86,6 @@ int __open_unix_client(const char *path); int __open_inet_server(const char *url); -/* Alerting */ - -gboolean gridinit_alerting_configure(const gchar *path, const gchar *symbol, GHashTable *ht, GError **err); - -void gridinit_alerting_send(int event, const char *msg); - -void gridinit_alerting_close(void); - /* Groups matching */ gboolean gridinit_group_in_set(const gchar *group, const gchar *set); From 905c82e7264a10466ef7405ed00a3d2a09091c5a Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:48:06 +0200 Subject: [PATCH 11/16] Remove the unused __open_inet_server() --- main/cnx.c | 95 ++------------------------------------- main/gridinit_internals.h | 2 - 2 files changed, 3 insertions(+), 94 deletions(-) diff --git a/main/cnx.c b/main/cnx.c index 69ce4bf..d32e206 100644 --- a/main/cnx.c +++ b/main/cnx.c @@ -40,43 +40,12 @@ along with this program. If not, see . static volatile int backlog_unix = 65536; static volatile int backlog_tcp = 4096; -static int -__addr_split(gchar *url_wrk, gchar ** host, gchar ** port) -{ - int len; - gchar *last_semicolon; - - len = strlen(url_wrk); - - if (*url_wrk == '[') { /*[IP]:PORT */ - - last_semicolon = g_strrstr(url_wrk, ":"); - if (!last_semicolon || last_semicolon - url_wrk >= len) - return 0; - - *(last_semicolon - 1) = '\0'; - *port = &(last_semicolon[1]); - *host = &(url_wrk[1]); - return 1; - } - - last_semicolon = g_strrstr(url_wrk, ":"); - if (!last_semicolon || last_semicolon - url_wrk >= len) - return 0; - - *last_semicolon = '\0'; - *port = &(last_semicolon[1]); - *host = &(url_wrk[0]); - return 1; -} - int __open_unix_client(const char *path) { int sock; - struct sockaddr_un local; + struct sockaddr_un local = {}; - memset(&local, 0x00, sizeof(local)); if (!path || strlen(path) >= sizeof(local.sun_path)) { errno = EINVAL; return -1; @@ -116,10 +85,8 @@ __open_unix_client(const char *path) int __open_unix_server(const char *path) { - int sock; - struct sockaddr_un local; + struct sockaddr_un local = {}; - memset(&local, 0x00, sizeof(local)); if (!path || strlen(path) >= sizeof(local.sun_path)) { errno = EINVAL; return -1; @@ -132,7 +99,7 @@ __open_unix_server(const char *path) # define SOCK_FLAGS 0 #endif - sock = socket(PF_UNIX, SOCK_STREAM | SOCK_FLAGS, 0); + int sock = socket(PF_UNIX, SOCK_STREAM | SOCK_FLAGS, 0); if (sock < 0) return -1; @@ -166,59 +133,3 @@ __open_unix_server(const char *path) return -1; } -int -__open_inet_server(const char *url) -{ - gchar url_wrk[512]; - - int sock = -1; - int i_opt = 1; - struct sockaddr_in sin; - gchar *host=NULL, *port=NULL; - - memset(url_wrk, 0x00, sizeof(url_wrk)); - g_strlcpy(url_wrk, url, sizeof(url_wrk)-1); - - if (!__addr_split(url_wrk, &host, &port)) { - errno = EINVAL; - return -1; - } - - sock = socket(PF_INET, SOCK_STREAM, 0); - if (sock < 0) { - /* transmit the errno as is */ - return -1; - } - - /* SO_REUSEADDR */ - i_opt = 1; - if (0 != setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (void*) &i_opt, sizeof(i_opt))) - WARN("Cannot set SO_REUSEADDR flag on socket %d (%s)", sock, strerror(errno)); - - /* bind on the given URL then wait for incoming connections */ - memset(&sin, 0x00, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(atoi(port)); - if (!inet_aton(host, &(sin.sin_addr))) - goto label_error; - - if (-1 == bind(sock, (struct sockaddr *)&sin, sizeof(sin))) - goto label_error; - - if (-1 == listen(sock, backlog_tcp)) - goto label_error; - - errno = 0; - return sock; - -label_error: - if (sock >= 0) { - typeof(errno) errsav; - errsav = errno; - close(sock); - errno = errsav; - } - return -1; -} - - diff --git a/main/gridinit_internals.h b/main/gridinit_internals.h index fa8ee1a..6a5afe3 100644 --- a/main/gridinit_internals.h +++ b/main/gridinit_internals.h @@ -84,8 +84,6 @@ int __open_unix_server(const char *path); int __open_unix_client(const char *path); -int __open_inet_server(const char *url); - /* Groups matching */ gboolean gridinit_group_in_set(const gchar *group, const gchar *set); From 2f60534afdc711d6348d85413808015d05da2e1d Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:53:48 +0200 Subject: [PATCH 12/16] Clean useless/commented code --- main/cnx.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/main/cnx.c b/main/cnx.c index d32e206..13be0a3 100644 --- a/main/cnx.c +++ b/main/cnx.c @@ -37,9 +37,6 @@ along with this program. If not, see . #include "gridinit-utils.h" #include "gridinit_internals.h" -static volatile int backlog_unix = 65536; -static volatile int backlog_tcp = 4096; - int __open_unix_client(const char *path) { @@ -56,12 +53,6 @@ __open_unix_client(const char *path) if (sock < 0) return -1; -#if 0 - /* Got to non-blocking mode */ - if (-1 == fcntl(sock, F_SETFL, O_NONBLOCK)) - goto label_error; -#endif - /* Bind to file */ local.sun_family = AF_UNIX; g_strlcpy(local.sun_path, path, sizeof(local.sun_path)-1); @@ -117,7 +108,7 @@ __open_unix_server(const char *path) goto label_error; /* Listen on that socket */ - if (-1 == listen(sock, backlog_unix)) + if (-1 == listen(sock, 65536)) goto label_error; errno = 0; From c006e842d3c1dfba12983326b167b84af84d7e93 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 22:58:10 +0200 Subject: [PATCH 13/16] Merge gridinit and the useless gridinit-utils lib --- main/CMakeLists.txt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index c0d61d7..e9426be 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,15 +1,10 @@ - include_directories(BEFORE .) -add_library(gridinit-utils STATIC +add_executable(gridinit uid.c common.c limits.c - children.c) -target_link_libraries(gridinit-utils - ${GLIB2_LIBRARIES}) - -add_executable(gridinit + children.c gridinit.c utils.c cnx.c) From 4944b3dcfb3b844f76b5434cfde87b474ef91569 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 23:01:22 +0200 Subject: [PATCH 14/16] Turn static __open_unix_server(), used only once --- main/cnx.c | 55 --------------------------------------- main/gridinit.c | 51 ++++++++++++++++++++++++++++++++++++ main/gridinit_internals.h | 2 -- 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/main/cnx.c b/main/cnx.c index 13be0a3..08ea573 100644 --- a/main/cnx.c +++ b/main/cnx.c @@ -24,9 +24,6 @@ along with this program. If not, see . #include #include #include -#include -#include -#include #include #include #include @@ -34,7 +31,6 @@ along with this program. If not, see . #include -#include "gridinit-utils.h" #include "gridinit_internals.h" int @@ -73,54 +69,3 @@ __open_unix_client(const char *path) return -1; } -int -__open_unix_server(const char *path) -{ - struct sockaddr_un local = {}; - - if (!path || strlen(path) >= sizeof(local.sun_path)) { - errno = EINVAL; - return -1; - } - - /* Create ressources to monitor */ -#ifdef SOCK_CLOEXEC -# define SOCK_FLAGS SOCK_CLOEXEC -#else -# define SOCK_FLAGS 0 -#endif - - int sock = socket(PF_UNIX, SOCK_STREAM | SOCK_FLAGS, 0); - if (sock < 0) - return -1; - -#ifndef SOCK_CLOEXEC -# ifdef FD_CLOEXEC - (void) fcntl(sock, F_SETFD, fcntl(sock, F_GETFD)|FD_CLOEXEC); -# endif -#endif - - /* Bind to file */ - local.sun_family = AF_UNIX; - g_strlcpy(local.sun_path, path, sizeof(local.sun_path)-1); - - if (-1 == bind(sock, (struct sockaddr *)&local, sizeof(local))) - goto label_error; - - /* Listen on that socket */ - if (-1 == listen(sock, 65536)) - goto label_error; - - errno = 0; - return sock; - -label_error: - if (sock >= 0) { - typeof(errno) errsav; - errsav = errno; - close(sock); - errno = errsav; - } - return -1; -} - diff --git a/main/gridinit.c b/main/gridinit.c index 9bba8a7..5fba4e5 100644 --- a/main/gridinit.c +++ b/main/gridinit.c @@ -848,6 +848,57 @@ servers_save_fd(int fd, const char *url) return TRUE; } +static int +__open_unix_server(const char *path) +{ + struct sockaddr_un local = {}; + + if (!path || strlen(path) >= sizeof(local.sun_path)) { + errno = EINVAL; + return -1; + } + + /* Create ressources to monitor */ +#ifdef SOCK_CLOEXEC +# define SOCK_FLAGS SOCK_CLOEXEC +#else +# define SOCK_FLAGS 0 +#endif + + int sock = socket(PF_UNIX, SOCK_STREAM | SOCK_FLAGS, 0); + if (sock < 0) + return -1; + +#ifndef SOCK_CLOEXEC +# ifdef FD_CLOEXEC + (void) fcntl(sock, F_SETFD, fcntl(sock, F_GETFD)|FD_CLOEXEC); +# endif +#endif + + /* Bind to file */ + local.sun_family = AF_UNIX; + g_strlcpy(local.sun_path, path, sizeof(local.sun_path)-1); + + if (-1 == bind(sock, (struct sockaddr *)&local, sizeof(local))) + goto label_error; + + /* Listen on that socket */ + if (-1 == listen(sock, 65536)) + goto label_error; + + errno = 0; + return sock; + +label_error: + if (sock >= 0) { + typeof(errno) errsav; + errsav = errno; + close(sock); + errno = errsav; + } + return -1; +} + /** * Opens a UNIX server socket then manage a server based on it */ diff --git a/main/gridinit_internals.h b/main/gridinit_internals.h index 6a5afe3..8cb8a71 100644 --- a/main/gridinit_internals.h +++ b/main/gridinit_internals.h @@ -80,8 +80,6 @@ along with this program. If not, see . # define CFG_KEY_INHERIT "inherit_env" #endif -int __open_unix_server(const char *path); - int __open_unix_client(const char *path); /* Groups matching */ From 95c2c3647f0870a4fedb8d594ff699bfd63a90a9 Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Wed, 13 Jun 2018 23:25:26 +0200 Subject: [PATCH 15/16] Use glib-2.0 features when possible --- main/utils.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/main/utils.c b/main/utils.c index 408b75b..0394eea 100644 --- a/main/utils.c +++ b/main/utils.c @@ -21,32 +21,17 @@ along with this program. If not, see . #include "./gridinit_internals.h" -#define STR_SKIP_SPACES(s) do {\ - register gchar c;\ - for (; (c = *s) && g_ascii_isspace(c) ;++s);\ -} while (0) - -#define STR_TRIM_TRAILING_SPACES(s) do { \ - register gchar c, *end; \ - for (end = s; *end ;++end); \ - -- end; \ - for (; end > s && (c = *end) && g_ascii_isspace(c) ;--end) *end = '\0'; \ -} while (0) - gboolean gridinit_group_in_set(const gchar *group, const gchar *set) { - gchar **tokens, **token, *g; - - tokens = g_strsplit_set(set, ",", -1); + gchar **tokens = g_strsplit_set(set, ",", -1); if (!tokens) return 0; - for (token=tokens; (g = *token) ;token++) { - STR_SKIP_SPACES(g); - STR_TRIM_TRAILING_SPACES(g); + for (gchar **ptoken=tokens; *ptoken ;ptoken++) { + gchar *g = *ptoken; if (!*g) continue; - if (0 == g_ascii_strcasecmp(g, group)) { + if (0 == g_ascii_strcasecmp(g_strstrip(g), group)) { g_strfreev(tokens); return TRUE; } From 78a76f95f26114afe0c2067dbbace1a6f8b5a87a Mon Sep 17 00:00:00 2001 From: Jean-Francois Smigielski Date: Tue, 11 Sep 2018 14:35:04 +0200 Subject: [PATCH 16/16] cmake: Remove inexistant dependencies --- main/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index e9426be..18f9887 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -9,7 +9,6 @@ add_executable(gridinit utils.c cnx.c) target_link_libraries(gridinit - gridinit-utils ${GLIB2_LIBRARIES} ${LIBEVENT_LIBRARIES}) add_executable(gridinit_cmd