From: Mika Laitio Date: Mon, 4 Oct 2010 06:23:08 +0000 (+0300) Subject: copy headers with make install, start integrating sysout methods to use libplp X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=6d5562f5000da6d6c4cb9d7b32b29ad7dbbd6366;p=libplpha.git copy headers with make install, start integrating sysout methods to use libplp --- diff --git a/src/Makefile.am b/src/Makefile.am index 40b9e27..4eebd16 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,3 +8,9 @@ libplpha_la_SOURCES = \ libplpha_la_LDFLAGS = $(SRC_LIBS) $(all_libraries) -version-info 1:0:0 -no-undefined AM_CPPFLAGS = $(SRC_CFLAGS) DISTCLEANFILES = Makefile.in + +libplphaincludedir=$(includedir)/plp/ha +libplphainclude_HEADERS = process_listener.h \ + launcher.h \ + process_parser.h \ + servicedir_listener.h \ No newline at end of file diff --git a/src/launcher.c b/src/launcher.c index 07f22cc..8b831a9 100644 --- a/src/launcher.c +++ b/src/launcher.c @@ -9,6 +9,8 @@ #include #include +#include + int launch_new_process(char *param_arr[]) { int ret_val; int child_pid; @@ -23,7 +25,7 @@ int launch_new_process(char *param_arr[]) { //execvp(param_arr[0], param_arr); // first parameter must contain a full path to executable execv(param_arr[0], param_arr); - printf("Failed to execute\n"); + log_error("Failed to launch new process\n"); exit(-1); } else { diff --git a/src/process_listener.c b/src/process_listener.c index 81ef446..57b03c2 100644 --- a/src/process_listener.c +++ b/src/process_listener.c @@ -13,6 +13,8 @@ #include #include +#include + #include "process_listener.h" static pthread_t _listener_thread; @@ -26,14 +28,14 @@ static void *process_listener_thread(void *thread_args_pointer) while(_continue) { closed_pid = wait(&status); if (closed_pid >= 0) { - printf("process closed: %d, status: %d\n", closed_pid, status); + log_info("process closed: %d, status: %d\n", closed_pid, status); } } pthread_exit(NULL); } void start_process_listener() { - printf("listen_closed_processes()\n"); + log_debug("start_process_listener()\n"); _listener_thread = 0; _continue = true; diff --git a/src/process_parser.c b/src/process_parser.c index 2dffdda..dcc4af8 100644 --- a/src/process_parser.c +++ b/src/process_parser.c @@ -10,6 +10,7 @@ #include #include +#include #include "common.h" #include "process_parser.h" @@ -47,7 +48,7 @@ t_process_arg_list *parse_command_line_args(char *cmd_line_param) { len++; } ret_val->arg_arr[ret_val->count] = strndup(start, len); - printf("ret_val[%d] = %s\n", ret_val->count, ret_val->arg_arr[ret_val->count]); + log_debug("ret_val[%d] = %s\n", ret_val->count, ret_val->arg_arr[ret_val->count]); ret_val->count = ret_val->count + 1; } else { @@ -120,10 +121,11 @@ t_process_info_list *get_process_config_list() { option = uci_lookup_option(ctx, section, "ExecStart"); switch (option->type) { case UCI_TYPE_STRING: - printf("config file: %s name: %s, value: %s\n", *config_file, option->e.name, option->v.string); + log_info("config file: %s name: %s, value: %s\n", *config_file, option->e.name, option->v.string); add_process_config(ret_val, option); break; default: + log_error("config file: can not parse parameter value"); break; } } @@ -141,12 +143,12 @@ t_process_info_list *get_process_config_list() { free(config_list); } else { - printf("Failed to read service configurations from directory: %s\n", CONST_SERVICE_DIRECTORY_LOCATION); + log_error("Failed to read service configurations from directory: %s\n", CONST_SERVICE_DIRECTORY_LOCATION); } uci_free_context(ctx); } else { - printf("Failed to read service configurations from directory: %s\n Memory allocation error.", CONST_SERVICE_DIRECTORY_LOCATION); + log_error("Failed to read service configurations from directory: %s\n Memory allocation error.", CONST_SERVICE_DIRECTORY_LOCATION); } return ret_val; } diff --git a/src/process_parser.h b/src/process_parser.h index 7f2d0db..e57c810 100644 --- a/src/process_parser.h +++ b/src/process_parser.h @@ -5,8 +5,8 @@ * Author: lamikr */ -#ifndef INIT_PARSER_H_ -#define INIT_PARSER_H_ +#ifndef PROCESS_PARSER_H_ +#define PROCESS_PARSER_H_ #include "process_info.h" @@ -14,4 +14,4 @@ t_process_info_list *get_process_config_list(); void release_process_config_list(t_process_info_list *list_param); void release_process_config_arg_list(t_process_arg_list *arg_list_param); -#endif /* INIT_PARSER_H_ */ +#endif /* PROCESS_PARSER_H_ */ diff --git a/src/servicedir_listener.c b/src/servicedir_listener.c index d3d42b2..9b667da 100644 --- a/src/servicedir_listener.c +++ b/src/servicedir_listener.c @@ -15,6 +15,8 @@ #include #include +#include + #include "common.h" #include "servicedir_listener.h" @@ -55,49 +57,49 @@ static void *servicedir_listener_thread(void *thread_args_pointer) CONST_SERVICE_DIRECTORY_LOCATION, IN_CREATE | IN_ATTRIB | IN_MODIFY | IN_DELETE); if (_dir_handle >= 0) { - printf("Waiting service directory file events\n"); + log_info("Waiting service directory file events\n"); while (_listener_stop_requested == false) { ii = 0; - printf("Waiting service directory file event\n"); + log_debug("Waiting service directory file event\n"); b_count = read(_inotify_handle, buffer, buffer_max_size); - printf("Service directory file event received\n"); + log_debug("Service directory file event received\n"); if (b_count >= 0) { while (ii < b_count) { event = (struct inotify_event *)&buffer[ii]; - printf("event length = %d\n", event->len); + log_debug("event length = %d\n", event->len); if (event->len) { if (event->mask & IN_CREATE) { if ((event->mask & IN_ISDIR) == 0) { - printf("file create event: %s\n", event->name); + log_info("file create event: %s\n", event->name); } else { - printf("sub-directory create event: %s, no need to process\n", event->name); + log_debug("sub-directory create event: %s, no need to process\n", event->name); } } else if (event->mask & IN_ATTRIB) { if ((event->mask & IN_ISDIR) == 0) { - printf("file attribute change event: %s\n", event->name); + log_info("file attribute change event: %s\n", event->name); } else { - printf("sub-directory attribute change event: %s, no need to process\n", event->name); + log_debug("sub-directory attribute change event: %s, no need to process\n", event->name); } } else if (event->mask & IN_MODIFY) { if ((event->mask & IN_ISDIR) == 0) { - printf("file modify event: %s\n", event->name); + log_info("file modify event: %s\n", event->name); } else { - printf("sub-directory modify event: %s, no need to process\n", event->name); + log_debug("sub-directory modify event: %s, no need to process\n", event->name); } } else if (event->mask & IN_DELETE) { if ((event->mask & IN_ISDIR) == 0) { - printf("file delete event: %s\n", event->name); + log_info("file delete event: %s\n", event->name); } else { - printf("sub-directory delete event: %s, no need to process\n", event->name); + log_debug("sub-directory delete event: %s, no need to process\n", event->name); } } } @@ -105,10 +107,10 @@ static void *servicedir_listener_thread(void *thread_args_pointer) } } else { - printf("Failed to initialize service directory listener: %s, event read failed.\n", CONST_SERVICE_DIRECTORY_LOCATION); + log_error("Failed to initialize service directory listener: %s, event read failed.\n", CONST_SERVICE_DIRECTORY_LOCATION); } } - printf("Closing service directory listener: %s, close request received.\n", CONST_SERVICE_DIRECTORY_LOCATION); + log_info("Closing service directory listener: %s, close request received.\n", CONST_SERVICE_DIRECTORY_LOCATION); pthread_mutex_lock(&_listener_mutex); if ((_inotify_handle > 0) && (_dir_handle)) { inotify_rm_watch(_inotify_handle, _dir_handle); @@ -117,7 +119,7 @@ static void *servicedir_listener_thread(void *thread_args_pointer) pthread_mutex_unlock(&_listener_mutex); } else { - printf("Failed to initialize service directory listener: %s, event listener start-up error.\n", CONST_SERVICE_DIRECTORY_LOCATION); + log_error("Failed to initialize service directory listener: %s, event listener start-up error.\n", CONST_SERVICE_DIRECTORY_LOCATION); } pthread_mutex_lock(&_listener_mutex); if (_inotify_handle > 0) { @@ -127,7 +129,7 @@ static void *servicedir_listener_thread(void *thread_args_pointer) pthread_mutex_unlock(&_listener_mutex); } else { - printf("Failed to initialize service directory listener: %s\n", CONST_SERVICE_DIRECTORY_LOCATION); + log_error("Failed to initialize service directory listener: %s\n", CONST_SERVICE_DIRECTORY_LOCATION); } if (buffer != NULL) { free(buffer); @@ -135,14 +137,14 @@ static void *servicedir_listener_thread(void *thread_args_pointer) } } else { - printf("Failed to initialize service directory listener: %s, buffer allocation error.\n", CONST_SERVICE_DIRECTORY_LOCATION); + log_error("Failed to initialize service directory listener: %s, buffer allocation error.\n", CONST_SERVICE_DIRECTORY_LOCATION); } _listener_running = false; pthread_exit(NULL); } void start_servicedir_listener() { - printf("listen_closed_processes()\n"); + log_debug("listen_closed_processes()\n"); init_servicedir_listener(); if (_listener_running == false) { _listener_thread = 0; diff --git a/src_test/Makefile.am b/src_test/Makefile.am index 5310373..6b54771 100644 --- a/src_test/Makefile.am +++ b/src_test/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = test_ha test_client test_client2 +noinst_PROGRAMS = test_ha test_client test_client2 test_ha_SOURCES = test_ha.c test_ha_LDADD = $(SRC_LIBS) ../src/.libs/libplpha.a diff --git a/src_test/test_client.c b/src_test/test_client.c index cd2bafe..c2abc75 100644 --- a/src_test/test_client.c +++ b/src_test/test_client.c @@ -15,11 +15,11 @@ int main(int argc, char** argv) { - int sleep_time = 2; - + int sleep_time; t_process_arg_list *ret_val; - int ii; + int ii; + sleep_time = 2; ret_val = calloc(1, sizeof(t_process_arg_list)); for (ii = 0; ii < 1; ii++) { if (ret_val->arg_arr == NULL) {