Changeset cba45af in mainline
- Timestamp:
- 2012-08-16T21:01:55Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2bf781a
- Parents:
- e005f92
- Location:
- uspace
- Files:
-
- 1 added
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/log.c
re005f92 rcba45af 62 62 #define MESSAGE_BUFFER_SIZE 4096 63 63 64 static sysarg_t toplog_id; 65 64 66 static int logger_register(async_sess_t *session, const char *prog_name) 65 67 { … … 69 71 } 70 72 71 aid_t reg_msg = async_send_0(exchange, LOGGER_REGISTER, NULL); 73 ipc_call_t answer; 74 aid_t reg_msg = async_send_0(exchange, LOGGER_WRITER_CREATE_TOPLEVEL_LOG, &answer); 72 75 int rc = async_data_write_start(exchange, prog_name, str_size(prog_name)); 73 76 sysarg_t reg_msg_rc; … … 80 83 } 81 84 82 return reg_msg_rc; 85 if (reg_msg_rc != EOK) 86 return reg_msg_rc; 87 88 toplog_id = IPC_GET_ARG1(answer); 89 90 return EOK; 83 91 } 84 92 … … 90 98 } 91 99 92 aid_t reg_msg = async_send_ 2(exchange, LOGGER_MESSAGE,93 ctx, level, NULL);100 aid_t reg_msg = async_send_3(exchange, LOGGER_WRITER_MESSAGE, 101 toplog_id, ctx, level, NULL); 94 102 int rc = async_data_write_start(exchange, message, str_size(message)); 95 103 sysarg_t reg_msg_rc; … … 183 191 184 192 ipc_call_t answer; 185 aid_t reg_msg = async_send_ 0(exchange, LOGGER_CREATE_CONTEXT, &answer);193 aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_SUB_LOG, toplog_id, &answer); 186 194 int rc = async_data_write_start(exchange, name, str_size(name)); 187 195 sysarg_t reg_msg_rc; -
uspace/lib/c/generic/io/logctl.c
re005f92 rcba45af 90 90 return rc; 91 91 92 aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_ NAMESPACE_LEVEL,92 aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_TOP_LOG_LEVEL, 93 93 new_level, NULL); 94 94 rc = async_data_write_start(exchange, namespace, str_size(namespace)); … … 112 112 return rc; 113 113 114 aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_ CONTEXT_LEVEL,114 aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_LOG_LEVEL, 115 115 new_level, NULL); 116 116 rc = async_data_write_start(exchange, namespace, str_size(namespace)); -
uspace/lib/c/include/ipc/logger.h
re005f92 rcba45af 37 37 38 38 typedef enum { 39 LOGGER_CTL_GET_DEFAULT_LEVEL = IPC_FIRST_USER_METHOD, 40 LOGGER_CTL_SET_DEFAULT_LEVEL, 41 LOGGER_CTL_SET_NAMESPACE_LEVEL, 42 LOGGER_CTL_SET_CONTEXT_LEVEL 39 LOGGER_CTL_SET_DEFAULT_LEVEL = IPC_FIRST_USER_METHOD, 40 LOGGER_CTL_SET_TOP_LOG_LEVEL, 41 LOGGER_CTL_SET_LOG_LEVEL 43 42 } logger_control_request_t; 44 43 45 44 typedef enum { 46 LOGGER_REGISTER = IPC_FIRST_USER_METHOD, 47 LOGGER_CREATE_CONTEXT, 48 LOGGER_MESSAGE 49 } logger_sink_request_t; 45 /** Followed by STRING, returns ID to be used for CREATE_SUB_LOG */ 46 LOGGER_WRITER_CREATE_TOPLEVEL_LOG = IPC_FIRST_USER_METHOD, 47 LOGGER_WRITER_CREATE_SUB_LOG, 48 LOGGER_WRITER_MESSAGE 49 } logger_writer_request_t; 50 50 51 51 typedef enum { -
uspace/srv/logger/Makefile
re005f92 rcba45af 34 34 ctl.c \ 35 35 level.c \ 36 logs.c \ 36 37 main.c \ 37 namespace.c \38 38 writer.c 39 39 -
uspace/srv/logger/ctl.c
re005f92 rcba45af 43 43 #include "logger.h" 44 44 45 static int handle_ namespace_level_change(sysarg_t new_level)45 static int handle_toplog_level_change(sysarg_t new_level) 46 46 { 47 void * namespace_name;48 int rc = async_data_write_accept(& namespace_name, true, 0, 0, 0, NULL);47 void *top_name; 48 int rc = async_data_write_accept(&top_name, true, 0, 0, 0, NULL); 49 49 if (rc != EOK) { 50 50 return rc; 51 51 } 52 52 53 logg ing_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name);54 free( namespace_name);55 if ( namespace== NULL)53 logger_toplevel_log_t *toplog = find_or_create_toplevel_log(top_name); 54 free(top_name); 55 if (toplog == NULL) 56 56 return ENOENT; 57 57 58 rc = namespace_change_level(namespace, (log_level_t) new_level); 59 namespace_writer_detach(namespace); 58 toplog->logged_level = new_level; 60 59 61 return rc;60 return EOK; 62 61 } 63 62 64 static int handle_ context_level_change(sysarg_t new_level)63 static int handle_log_level_change(sysarg_t new_level) 65 64 { 66 void * namespace_name;67 int rc = async_data_write_accept(& namespace_name, true, 0, 0, 0, NULL);65 void *top_name; 66 int rc = async_data_write_accept(&top_name, true, 0, 0, 0, NULL); 68 67 if (rc != EOK) { 69 68 return rc; 70 69 } 71 70 72 logg ing_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name);73 free( namespace_name);74 if ( namespace== NULL)71 logger_toplevel_log_t *toplog = find_or_create_toplevel_log(top_name); 72 free(top_name); 73 if (toplog == NULL) 75 74 return ENOENT; 76 75 77 void *context_name; 78 rc = async_data_write_accept(&context_name, true, 0, 0, 0, NULL);79 if (rc != EOK) {80 namespace_writer_detach(namespace);76 77 void *log_name; 78 rc = async_data_write_accept(&log_name, true, 0, 0, 0, NULL); 79 if (rc != EOK) 81 80 return rc; 81 82 rc = ENOENT; 83 for (size_t i = 0; i < toplog->sublog_count; i++) { 84 if (str_cmp(toplog->sublogs[i].name, (const char *) log_name) == 0) { 85 toplog->sublogs[i].logged_level = new_level; 86 rc = EOK; 87 break; 88 } 82 89 } 83 90 84 rc = namespace_change_context_level(namespace, context_name, new_level); 85 free(context_name); 86 namespace_writer_detach(namespace); 91 free(log_name); 87 92 88 93 return rc; … … 101 106 break; 102 107 103 int rc;104 105 108 switch (IPC_GET_IMETHOD(call)) { 106 case LOGGER_CTL_GET_DEFAULT_LEVEL: 107 async_answer_1(callid, EOK, get_default_logging_level()); 108 break; 109 case LOGGER_CTL_SET_DEFAULT_LEVEL: 110 rc = set_default_logging_level(IPC_GET_ARG1(call)); 109 case LOGGER_CTL_SET_DEFAULT_LEVEL: { 110 int rc = set_default_logging_level(IPC_GET_ARG1(call)); 111 111 async_answer_0(callid, rc); 112 112 break; 113 case LOGGER_CTL_SET_NAMESPACE_LEVEL: 114 rc = handle_namespace_level_change(IPC_GET_ARG1(call)); 113 } 114 case LOGGER_CTL_SET_TOP_LOG_LEVEL: { 115 int rc = handle_toplog_level_change(IPC_GET_ARG1(call)); 115 116 async_answer_0(callid, rc); 116 117 break; 117 case LOGGER_CTL_SET_CONTEXT_LEVEL: 118 rc = handle_context_level_change(IPC_GET_ARG1(call)); 118 } 119 case LOGGER_CTL_SET_LOG_LEVEL: { 120 int rc = handle_log_level_change(IPC_GET_ARG1(call)); 119 121 async_answer_0(callid, rc); 120 122 break; 123 } 121 124 default: 122 125 async_answer_0(callid, EINVAL); -
uspace/srv/logger/level.c
re005f92 rcba45af 52 52 { 53 53 if (new_level >= LVL_LIMIT) 54 return E INVAL;54 return ERANGE; 55 55 fibril_mutex_lock(&default_logging_level_guard); 56 56 default_logging_level = new_level; -
uspace/srv/logger/logger.h
re005f92 rcba45af 42 42 #include <bool.h> 43 43 #include <fibril_synch.h> 44 #include <stdio.h> 44 45 45 46 #define NAME "logger" 46 #define MAX_ NAMESPACE_LENGTH 25647 #define MAX_SUBLOGS 64 47 48 #define LOG_LEVEL_USE_DEFAULT (LVL_LIMIT + 1) 48 49 49 typedef struct logging_namespace logging_namespace_t; 50 typedef struct { 51 const char *name; 52 log_level_t logged_level; 53 } logger_sublog_t; 50 54 51 logging_namespace_t *namespace_create(const char *); 52 const char *namespace_get_name(logging_namespace_t *); 53 void namespace_destroy(logging_namespace_t *); 54 logging_namespace_t *namespace_writer_attach(const char *); 55 void namespace_writer_detach(logging_namespace_t *); 55 typedef struct { 56 const char *name; 57 FILE *logfile; 58 log_level_t logged_level; 59 size_t sublog_count; 60 logger_sublog_t sublogs[MAX_SUBLOGS]; 56 61 57 int namespace_change_level(logging_namespace_t *, log_level_t); 62 link_t link; 63 } logger_toplevel_log_t; 58 64 59 bool namespace_has_reader(logging_namespace_t *, sysarg_t, log_level_t);60 void namespace_add_message(logging_namespace_t *, const char *, sysarg_t, log_level_t);61 65 62 int namespace_create_context(logging_namespace_t *, const char *); 63 int namespace_change_context_level(logging_namespace_t *, const char *, log_level_t); 66 logger_toplevel_log_t *find_or_create_toplevel_log(const char *); 67 logger_toplevel_log_t *find_toplevel_log(sysarg_t); 68 bool shall_log_message(logger_toplevel_log_t *, sysarg_t, log_level_t); 69 int add_sub_log(logger_toplevel_log_t *, const char *, sysarg_t *); 64 70 65 71 log_level_t get_default_logging_level(void); -
uspace/srv/logger/writer.c
re005f92 rcba45af 49 49 50 50 51 static logg ing_namespace_t *find_namespace_and_attach_writer(void)51 static logger_toplevel_log_t *handle_create_toplevel_log(void) 52 52 { 53 ipc_call_t call; 54 ipc_callid_t callid = async_get_call(&call); 53 void *name; 54 int rc = async_data_write_accept(&name, true, 1, 0, 0, NULL); 55 if (rc != EOK) 56 return NULL; 55 57 56 if (IPC_GET_IMETHOD(call) != LOGGER_REGISTER) { 57 async_answer_0(callid, EINVAL); 58 return NULL; 59 } 60 61 void *name; 62 int rc = async_data_write_accept(&name, true, 1, MAX_NAMESPACE_LENGTH, 0, NULL); 63 async_answer_0(callid, rc); 64 65 if (rc != EOK) { 66 return NULL; 67 } 68 69 logging_namespace_t *result = namespace_writer_attach((const char *) name); 58 logger_toplevel_log_t *log = find_or_create_toplevel_log(name); 70 59 71 60 free(name); 72 61 73 return result;62 return log; 74 63 } 75 64 76 static int handle_receive_message( logging_namespace_t *namespace, sysarg_t context, int level)65 static int handle_receive_message(sysarg_t toplevel_log_id, sysarg_t log_id, sysarg_t level) 77 66 { 78 bool skip_message = !namespace_has_reader(namespace, context, level); 79 if (skip_message) { 80 /* Abort the actual message buffer transfer. */ 81 ipc_callid_t callid; 82 size_t size; 83 int rc = ENAK; 84 if (!async_data_write_receive(&callid, &size)) 85 rc = EINVAL; 67 logger_toplevel_log_t *log = find_toplevel_log(toplevel_log_id); 68 if (log == NULL) 69 return ENOENT; 86 70 87 async_answer_0(callid, rc); 71 if (log_id > log->sublog_count) 72 return ENOENT; 73 74 void *message; 75 int rc = async_data_write_accept(&message, true, 1, 0, 0, NULL); 76 if (rc != EOK) 88 77 return rc; 78 79 if (!shall_log_message(log, log_id, level)) { 80 free(message); 81 return EOK; 89 82 } 90 83 91 void *message; 92 int rc = async_data_write_accept(&message, true, 0, 0, 0, NULL); 93 if (rc != EOK) { 94 return rc; 95 } 96 97 namespace_add_message(namespace, message, context, level); 84 printf("[%s/%s] %s: %s\n", 85 log->name, log->sublogs[log_id].name, 86 log_level_str(level), 87 (const char *) message); 98 88 99 89 free(message); … … 102 92 } 103 93 104 static int handle_create_ context(logging_namespace_t *namespace, sysarg_t *idx)94 static int handle_create_sub_log(sysarg_t toplevel_log_id, sysarg_t *log_id) 105 95 { 96 logger_toplevel_log_t *log = find_toplevel_log(toplevel_log_id); 97 if (log == NULL) 98 return ENOENT; 99 106 100 void *name; 107 101 int rc = async_data_write_accept(&name, true, 0, 0, 0, NULL); 108 if (rc != EOK) {102 if (rc != EOK) 109 103 return rc; 110 }111 104 112 rc = namespace_create_context(namespace, name);105 rc = add_sub_log(log, name, log_id); 113 106 114 107 free(name); 115 108 116 if (rc < 0) 117 return rc; 118 119 *idx = (sysarg_t) rc; 120 return EOK; 109 return rc; 121 110 } 122 111 123 112 void logger_connection_handler_writer(ipc_callid_t callid) 124 113 { 125 /* First call has to be the registration. */114 /* Acknowledge the connection. */ 126 115 async_answer_0(callid, EOK); 127 logging_namespace_t *namespace = find_namespace_and_attach_writer();128 if (namespace == NULL) {129 fprintf(stderr, NAME ": failed to register namespace.\n");130 return;131 }132 116 133 printf(NAME "/writer: new client %s.\n", namespace_get_name(namespace));117 printf(NAME "/writer: new client.\n"); 134 118 135 119 while (true) { … … 140 124 break; 141 125 142 int rc;143 sysarg_t arg = 0;144 145 126 switch (IPC_GET_IMETHOD(call)) { 146 case LOGGER_CREATE_CONTEXT: 147 rc = handle_create_context(namespace, &arg); 148 async_answer_1(callid, rc, arg); 127 case LOGGER_WRITER_CREATE_TOPLEVEL_LOG: { 128 logger_toplevel_log_t *log = handle_create_toplevel_log(); 129 if (log == NULL) { 130 async_answer_0(callid, ENOMEM); 131 break; 132 } 133 async_answer_1(callid, EOK, (sysarg_t) log); 149 134 break; 150 case LOGGER_MESSAGE: 151 rc = handle_receive_message(namespace, IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 135 } 136 case LOGGER_WRITER_MESSAGE: { 137 int rc = handle_receive_message(IPC_GET_ARG1(call), 138 IPC_GET_ARG2(call), IPC_GET_ARG3(call)); 152 139 async_answer_0(callid, rc); 153 140 break; 141 } 142 case LOGGER_WRITER_CREATE_SUB_LOG: { 143 sysarg_t log_id; 144 int rc = handle_create_sub_log(IPC_GET_ARG1(call), &log_id); 145 async_answer_1(callid, rc, log_id); 146 break; 147 } 154 148 default: 155 149 async_answer_0(callid, EINVAL); … … 158 152 } 159 153 160 printf(NAME "/sink: client %s terminated.\n", namespace_get_name(namespace)); 161 namespace_writer_detach(namespace); 154 // FIXME: destroy created logs 162 155 } 163 156
Note:
See TracChangeset
for help on using the changeset viewer.