Changeset 6e9e12b in mainline
- Timestamp:
- 2012-08-16T09:15:21Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0a6a996
- Parents:
- 669f5cae
- Files:
-
- 1 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
r669f5cae r6e9e12b 165 165 $(USPACE_PATH)/app/killall/killall \ 166 166 $(USPACE_PATH)/app/loc/loc \ 167 $(USPACE_PATH)/app/logview/logview \168 167 $(USPACE_PATH)/app/logset/logset \ 169 168 $(USPACE_PATH)/app/mkfat/mkfat \ -
uspace/Makefile
r669f5cae r6e9e12b 48 48 app/loc \ 49 49 app/logset \ 50 app/logview \51 50 app/mkfat \ 52 51 app/mkexfat \ -
uspace/srv/logger/logger.h
r669f5cae r6e9e12b 45 45 #define MAX_NAMESPACE_LENGTH 256 46 46 47 typedef struct {48 link_t link;49 log_level_t level;50 const char *message;51 } log_message_t;52 53 47 typedef struct logging_namespace logging_namespace_t; 54 55 log_message_t *message_create(const char *, log_level_t);56 void message_destroy(log_message_t *);57 48 58 49 logging_namespace_t *namespace_create(const char *); 59 50 const char *namespace_get_name(logging_namespace_t *); 60 51 void namespace_destroy(logging_namespace_t *); 61 logging_namespace_t *namespace_reader_attach(const char *);62 52 logging_namespace_t *namespace_writer_attach(const char *); 63 void namespace_reader_detach(logging_namespace_t *);64 53 void namespace_writer_detach(logging_namespace_t *); 65 54 … … 67 56 bool namespace_has_reader(logging_namespace_t *, log_level_t); 68 57 void namespace_add_message(logging_namespace_t *, const char *, log_level_t); 69 log_message_t *namespace_get_next_message(logging_namespace_t *);70 58 71 59 log_level_t get_default_logging_level(void); -
uspace/srv/logger/main.c
r669f5cae r6e9e12b 104 104 static int handle_receive_message(logging_namespace_t *namespace, int level) 105 105 { 106 bool skip_message = (level > (int)get_default_logging_level()) &&!namespace_has_reader(namespace, level);106 bool skip_message = !namespace_has_reader(namespace, level); 107 107 if (skip_message) { 108 108 /* Abort the actual message buffer transfer. */ … … 156 156 printf(NAME "/sink: client %s terminated.\n", namespace_get_name(namespace)); 157 157 namespace_writer_detach(namespace); 158 }159 160 161 static logging_namespace_t *find_namespace_and_attach_reader(void)162 {163 ipc_call_t call;164 ipc_callid_t callid = async_get_call(&call);165 166 if (IPC_GET_IMETHOD(call) != LOGGER_CONNECT) {167 async_answer_0(callid, EINVAL);168 return NULL;169 }170 171 void *name;172 int rc = async_data_write_accept(&name, true, 1, MAX_NAMESPACE_LENGTH, 0, NULL);173 174 if (rc != EOK) {175 async_answer_0(callid, rc);176 return NULL;177 }178 179 logging_namespace_t *result = namespace_reader_attach((const char *) name);180 if (result == NULL) {181 rc = ENOENT;182 }183 184 async_answer_0(callid, rc);185 186 free(name);187 188 return result;189 }190 191 192 static int handle_send_message(logging_namespace_t *namespace, int *level)193 {194 ipc_callid_t callid;195 size_t size;196 bool expects_data_read = async_data_read_receive(&callid, &size);197 if (!expects_data_read) {198 return EINVAL;199 }200 201 log_message_t *message = namespace_get_next_message(namespace);202 size_t message_len = str_size(message->message) + 1;203 204 if (size > message_len) {205 size = message_len;206 }207 208 async_data_read_finalize(callid, message->message, size);209 210 *level = (int) message->level;211 message_destroy(message);212 213 return EOK;214 }215 216 217 static void connection_handler_source(logging_namespace_t *namespace)218 {219 printf(NAME "/source: new client for %s.\n", namespace_get_name(namespace));220 221 while (true) {222 ipc_call_t call;223 ipc_callid_t callid = async_get_call(&call);224 225 if (!IPC_GET_IMETHOD(call))226 break;227 228 int rc;229 int message_level = 0;230 231 switch (IPC_GET_IMETHOD(call)) {232 case LOGGER_GET_MESSAGE:233 rc = handle_send_message(namespace, &message_level);234 async_answer_1(callid, rc, message_level);235 break;236 default:237 async_answer_0(callid, EINVAL);238 break;239 }240 }241 242 printf(NAME "/source: client %s terminated.\n", namespace_get_name(namespace));243 namespace_reader_detach(namespace);244 158 } 245 159 … … 265 179 connection_handler_sink(namespace); 266 180 break; 267 case LOGGER_INTERFACE_SOURCE:268 async_answer_0(iid, EOK);269 /* First call has to find existing namespace. */270 namespace = find_namespace_and_attach_reader();271 if (namespace == NULL) {272 fprintf(stderr, NAME ": failed to attach client.\n");273 break;274 }275 connection_handler_source(namespace);276 break;277 181 default: 278 182 async_answer_0(iid, EINVAL); -
uspace/srv/logger/namespace.c
r669f5cae r6e9e12b 44 44 fibril_mutex_t guard; 45 45 size_t writers_count; 46 fibril_condvar_t reader_appeared_cv; 47 bool has_reader; 46 fibril_condvar_t level_changed_cv; 48 47 FILE *logfile; 49 log_level_t l ogfile_level;48 log_level_t level; 50 49 const char *name; 50 51 51 link_t link; 52 prodcons_t messages;53 52 }; 54 53 55 54 static FIBRIL_MUTEX_INITIALIZE(namespace_list_guard); 56 55 static LIST_INITIALIZE(namespace_list); 57 58 log_message_t *message_create(const char *name, log_level_t level)59 {60 log_message_t *message = malloc(sizeof(log_message_t));61 if (message == NULL)62 return NULL;63 64 message->message = str_dup(name);65 if (message->message == NULL) {66 free(message);67 return NULL;68 }69 70 message->level = level;71 link_initialize(&message->link);72 73 return message;74 }75 76 void message_destroy(log_message_t *message)77 {78 assert(message);79 free(message->message);80 free(message);81 }82 56 83 57 static logging_namespace_t *namespace_find_no_lock(const char *name) … … 126 100 } 127 101 128 namespace->l ogfile_level = get_default_logging_level();102 namespace->level = get_default_logging_level(); 129 103 130 104 fibril_mutex_initialize(&namespace->guard); 131 fibril_condvar_initialize(&namespace->reader_appeared_cv); 132 prodcons_initialize(&namespace->messages); 133 namespace->has_reader = false; 105 fibril_condvar_initialize(&namespace->level_changed_cv); 134 106 namespace->writers_count = 0; 135 107 link_initialize(&namespace->link); … … 161 133 162 134 fibril_mutex_lock(&namespace->guard); 163 if (namespace-> has_reader || (namespace->writers_count > 0)) {135 if (namespace->writers_count > 0) { 164 136 fibril_mutex_unlock(&namespace->guard); 165 137 fibril_mutex_unlock(&namespace_list_guard); … … 183 155 } 184 156 185 logging_namespace_t *namespace_reader_attach(const char *name)186 {187 logging_namespace_t *namespace = NULL;188 189 fibril_mutex_lock(&namespace_list_guard);190 191 namespace = namespace_find_no_lock(name);192 193 if (namespace != NULL) {194 fibril_mutex_lock(&namespace->guard);195 namespace->has_reader = true;196 fibril_condvar_broadcast(&namespace->reader_appeared_cv);197 fibril_mutex_unlock(&namespace->guard);198 }199 200 fibril_mutex_unlock(&namespace_list_guard);201 202 return namespace;203 }204 205 157 logging_namespace_t *namespace_writer_attach(const char *name) 206 158 { … … 224 176 } 225 177 226 void namespace_reader_detach(logging_namespace_t *namespace)227 {228 fibril_mutex_lock(&namespace->guard);229 namespace->has_reader = false;230 fibril_condvar_broadcast(&namespace->reader_appeared_cv);231 fibril_mutex_unlock(&namespace->guard);232 233 namespace_destroy_careful(namespace);234 }235 236 178 void namespace_writer_detach(logging_namespace_t *namespace) 237 179 { … … 247 189 { 248 190 fibril_mutex_lock(&namespace->guard); 249 bool has_reader = namespace->has_reader 250 || level <= namespace->logfile_level; 191 bool has_reader = level <= namespace->level; 251 192 fibril_mutex_unlock(&namespace->guard); 252 193 return has_reader; … … 256 197 { 257 198 fibril_mutex_lock(&namespace->guard); 258 bool had_reader = namespace->has_reader;259 while ( had_reader == namespace->has_reader) {260 fibril_condvar_wait(&namespace-> reader_appeared_cv, &namespace->guard);261 } 262 *has_reader_now = namespace->has_reader;199 log_level_t previous_level = namespace->level; 200 while (previous_level == namespace->level) { 201 fibril_condvar_wait(&namespace->level_changed_cv, &namespace->guard); 202 } 203 *has_reader_now = true; 263 204 fibril_mutex_unlock(&namespace->guard); 264 205 } … … 267 208 void namespace_add_message(logging_namespace_t *namespace, const char *message, log_level_t level) 268 209 { 269 if (level <= get_default_logging_level()) {210 if (level <= namespace->level) { 270 211 printf("[%s %d]: %s\n", namespace->name, level, message); 271 }272 if (level <= namespace->logfile_level) {273 212 fprintf(namespace->logfile, "[%d]: %s\n", level, message); 274 213 fflush(namespace->logfile); 275 } 276 277 fibril_mutex_lock(&namespace->guard); 278 if (namespace->has_reader) { 279 log_message_t *msg = message_create(message, level); 280 if (msg != NULL) { 281 prodcons_produce(&namespace->messages, &msg->link); 282 } 283 } 284 fibril_mutex_unlock(&namespace->guard); 285 } 286 287 log_message_t *namespace_get_next_message(logging_namespace_t *namespace) 288 { 289 link_t *message = prodcons_consume(&namespace->messages); 290 291 return list_get_instance(message, log_message_t, link); 214 fflush(stdout); 215 } 292 216 } 293 217
Note:
See TracChangeset
for help on using the changeset viewer.