#include <dirent.h>
#include <uci.h>
+#include <plp/log.h>
#include "common.h"
#include "process_parser.h"
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 {
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;
}
}
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;
}
#include <pthread.h>
#include <fcntl.h>
+#include <plp/log.h>
+
#include "common.h"
#include "servicedir_listener.h"
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);
}
}
}
}
}
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);
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) {
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);
}
}
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;