Changeset 494f417 in mainline
- Timestamp:
- 2012-08-16T11:58:46Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7034b443
- Parents:
- eab3d04
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/logset/main.c
reab3d04 r494f417 38 38 #include <io/logctl.h> 39 39 40 static log_level_t parse_log_level_or_die(const char *log_level) 41 { 42 log_level_t result; 43 int rc = log_level_from_str(log_level, &result); 44 if (rc != EOK) { 45 fprintf(stderr, "Unrecognised log level '%s': %s.\n", 46 log_level, str_error(rc)); 47 exit(2); 48 } 49 return result; 50 } 51 52 static void usage(const char *progname) 53 { 54 fprintf(stderr, "Usage:\n"); 55 fprintf(stderr, " %s <default-logging-level>\n", progname); 56 fprintf(stderr, " %s <namespace> <logging-level>\n", progname); 57 } 58 40 59 int main(int argc, char *argv[]) 41 60 { 42 /* The only action is to set default logging level. */ 61 if (argc == 2) { 62 log_level_t new_default_level = parse_log_level_or_die(argv[1]); 63 int rc = logctl_set_default_level(new_default_level); 43 64 44 if (argc < 2) { 45 fprintf(stderr, "Usage: %s <default-logging-level>\n", argv[0]); 65 if (rc != EOK) { 66 fprintf(stderr, "Failed to change default logging level: %s.\n", 67 str_error(rc)); 68 return 2; 69 } 70 } else if (argc == 3) { 71 log_level_t new_level = parse_log_level_or_die(argv[2]); 72 const char *namespace = argv[1]; 73 int rc = logctl_set_namespace_level(namespace, new_level); 74 75 if (rc != EOK) { 76 fprintf(stderr, "Failed to change logging level: %s.\n", 77 str_error(rc)); 78 return 2; 79 } 80 } else { 81 usage(argv[0]); 46 82 return 1; 47 }48 49 log_level_t new_default_level;50 int rc = log_level_from_str(argv[1], &new_default_level);51 if (rc != EOK) {52 fprintf(stderr, "Unrecognised log level '%s': %s.\n",53 argv[1], str_error(rc));54 }55 56 rc = logctl_set_default_level(new_default_level);57 58 if (rc != EOK) {59 fprintf(stderr, "Failed to change default logging level: %s.\n",60 str_error(rc));61 return 2;62 83 } 63 84 -
uspace/lib/c/generic/io/logctl.c
reab3d04 r494f417 77 77 } 78 78 79 int logctl_set_namespace_level(const char *namespace, log_level_t new_level) 80 { 81 int rc = connect_to_logger(); 82 if (rc != EOK) 83 return rc; 84 85 async_exch_t *exchange = async_exchange_begin(logger_session); 86 if (exchange == NULL) 87 return ENOMEM; 88 89 aid_t reg_msg = async_send_1(exchange, LOGGER_CTL_SET_NAMESPACE_LEVEL, 90 new_level, NULL); 91 rc = async_data_write_start(exchange, namespace, str_size(namespace)); 92 sysarg_t reg_msg_rc; 93 async_wait_for(reg_msg, ®_msg_rc); 94 95 async_exchange_end(exchange); 96 97 if (rc != EOK) { 98 return rc; 99 } 100 101 return (int) reg_msg_rc; 102 } 103 79 104 int logctl_get_boot_level(log_level_t *level) 80 105 { -
uspace/lib/c/include/io/logctl.h
reab3d04 r494f417 37 37 38 38 extern int logctl_set_default_level(log_level_t); 39 extern int logctl_set_namespace_level(const char *, log_level_t); 39 40 extern int logctl_get_boot_level(log_level_t *); 40 41 -
uspace/lib/c/include/ipc/logger.h
reab3d04 r494f417 38 38 typedef enum { 39 39 LOGGER_CTL_GET_DEFAULT_LEVEL = IPC_FIRST_USER_METHOD, 40 LOGGER_CTL_SET_DEFAULT_LEVEL 40 LOGGER_CTL_SET_DEFAULT_LEVEL, 41 LOGGER_CTL_SET_NAMESPACE_LEVEL 41 42 } logger_control_request_t; 42 43 -
uspace/srv/logger/logger.h
reab3d04 r494f417 54 54 void namespace_writer_detach(logging_namespace_t *); 55 55 56 int namespace_change_level(logging_namespace_t *, log_level_t); 57 56 58 void namespace_wait_for_reader_change(logging_namespace_t *, bool *); 57 59 bool namespace_has_reader(logging_namespace_t *, log_level_t); -
uspace/srv/logger/main.c
reab3d04 r494f417 48 48 #include "logger.h" 49 49 50 static int handle_namespace_level_change(sysarg_t new_level) 51 { 52 void *namespace_name; 53 int rc = async_data_write_accept(&namespace_name, true, 0, 0, 0, NULL); 54 if (rc != EOK) { 55 return rc; 56 } 57 58 logging_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name); 59 free(namespace_name); 60 if (namespace == NULL) 61 return ENOENT; 62 63 rc = namespace_change_level(namespace, (log_level_t) new_level); 64 namespace_writer_detach(namespace); 65 66 return rc; 67 } 68 50 69 static void connection_handler_control(void) 51 70 { … … 67 86 case LOGGER_CTL_SET_DEFAULT_LEVEL: 68 87 rc = set_default_logging_level(IPC_GET_ARG1(call)); 88 async_answer_0(callid, rc); 89 break; 90 case LOGGER_CTL_SET_NAMESPACE_LEVEL: 91 rc = handle_namespace_level_change(IPC_GET_ARG1(call)); 69 92 async_answer_0(callid, rc); 70 93 break; -
uspace/srv/logger/namespace.c
reab3d04 r494f417 34 34 #include <str.h> 35 35 #include <stdio.h> 36 #include <errno.h> 36 37 #include "logger.h" 37 38 … … 198 199 } 199 200 201 int namespace_change_level(logging_namespace_t *namespace, log_level_t level) 202 { 203 if (level >= LVL_LIMIT) 204 return ERANGE; 205 206 fibril_mutex_lock(&namespace->guard); 207 namespace->level = level; 208 fibril_condvar_broadcast(&namespace->level_changed_cv); 209 fibril_mutex_unlock(&namespace->guard); 210 211 return EOK; 212 } 213 214 200 215 bool namespace_has_reader(logging_namespace_t *namespace, log_level_t level) 201 216 {
Note:
See TracChangeset
for help on using the changeset viewer.