]> pilppa.com Git - libplpha.git/commitdiff
copy headers with make install, start integrating sysout methods to use libplp
authorMika Laitio <lamikr@pilppa.org>
Mon, 4 Oct 2010 06:23:08 +0000 (09:23 +0300)
committerMika Laitio <lamikr@pilppa.org>
Mon, 4 Oct 2010 06:23:08 +0000 (09:23 +0300)
src/Makefile.am
src/launcher.c
src/process_listener.c
src/process_parser.c
src/process_parser.h
src/servicedir_listener.c
src_test/Makefile.am
src_test/test_client.c

index 40b9e27fe6083130bc1112858746b3ca2fc4aa89..4eebd162b435b541562e9a21d7b8a3745ee9cd10 100644 (file)
@@ -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
index 07f22ccc7443d464e1d5ebfd6cc15928f8ef2f14..8b831a9ae47ced98960cc8cf1cc46ed2346c200f 100644 (file)
@@ -9,6 +9,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <plp/log.h>
+
 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 {
index 81ef446f1fe253067166b341c653cddf9e38358e..57b03c2b0ec7cdca3335789d6f6039bd257f25ff 100644 (file)
@@ -13,6 +13,8 @@
 #include <pthread.h>
 #include <stdbool.h>
 
+#include <plp/log.h>
+
 #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;
index 2dffddac44e0477028836084c3cd98462db3e8ac..dcc4af82e6209fd0e5897270038c0229773d08cc 100644 (file)
@@ -10,6 +10,7 @@
 #include <dirent.h>
 #include <uci.h>
 
+#include <plp/log.h>
 #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;
 }
index 7f2d0dbfea5c0f7586ff7dfcb8a149d024f5711d..e57c810956311da3925b33c1c348d77a709a72e2 100644 (file)
@@ -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_ */
index d3d42b236f769242ecdf6bcfae59c50a6272ccbe..9b667da852d6dd8d709b81be7513d1fff3f1b1d9 100644 (file)
@@ -15,6 +15,8 @@
 #include <pthread.h>
 #include <fcntl.h>
 
+#include <plp/log.h>
+
 #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;
index 53103731e62d9656a1e1b7180571d1f6fc01b704..6b54771597ecf103b55dc739085ebc6d28dce37b 100644 (file)
@@ -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
index cd2bafe698ebf3b4500391a0b5082d9d274c7ace..c2abc7579c73ab6231aede29d56d6c48d862530f 100644 (file)
 
 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) {