Changeset 80d8885 in mainline for uspace/srv/logger


Ignore:
Timestamp:
2012-08-16T15:08:19Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dc5aa568
Parents:
32b26cf7
Message:

Set levels for individual contexts

Location:
uspace/srv/logger
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/logger/logger.h

    r32b26cf7 r80d8885  
    6161
    6262int namespace_create_context(logging_namespace_t *, const char *);
     63int namespace_change_context_level(logging_namespace_t *, const char *, log_level_t);
    6364
    6465log_level_t get_default_logging_level(void);
  • uspace/srv/logger/main.c

    r32b26cf7 r80d8885  
    6767}
    6868
     69static int handle_context_level_change(sysarg_t new_level)
     70{
     71        void *namespace_name;
     72        int rc = async_data_write_accept(&namespace_name, true, 0, 0, 0, NULL);
     73        if (rc != EOK) {
     74                return rc;
     75        }
     76
     77        logging_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name);
     78        free(namespace_name);
     79        if (namespace == NULL)
     80                return ENOENT;
     81
     82        void *context_name;
     83        rc = async_data_write_accept(&context_name, true, 0, 0, 0, NULL);
     84        if (rc != EOK) {
     85                namespace_writer_detach(namespace);
     86                return rc;
     87        }
     88
     89        rc = namespace_change_context_level(namespace, context_name, new_level);
     90        free(context_name);
     91        namespace_writer_detach(namespace);
     92
     93        return rc;
     94}
     95
    6996static void connection_handler_control(void)
    7097{
     
    90117                case LOGGER_CTL_SET_NAMESPACE_LEVEL:
    91118                        rc = handle_namespace_level_change(IPC_GET_ARG1(call));
     119                        async_answer_0(callid, rc);
     120                        break;
     121                case LOGGER_CTL_SET_CONTEXT_LEVEL:
     122                        rc = handle_context_level_change(IPC_GET_ARG1(call));
    92123                        async_answer_0(callid, rc);
    93124                        break;
  • uspace/srv/logger/namespace.c

    r32b26cf7 r80d8885  
    7171        if (context >= namespace->context_count) {
    7272                fibril_mutex_unlock(&namespace->guard);
     73                fprintf(stderr, "Invalid context!\n");
    7374                return LVL_FATAL;
    7475        }
     
    265266}
    266267
     268int namespace_change_context_level(logging_namespace_t *namespace, const char *context, log_level_t new_level)
     269{
     270        if (new_level >= LVL_LIMIT)
     271                return ERANGE;
     272
     273        int rc;
     274        fibril_mutex_lock(&namespace->guard);
     275        for (size_t i = 0; i < namespace->context_count; i++) {
     276                if (str_cmp(namespace->context[i].name, context) == 0) {
     277                        namespace->context[i].level = new_level;
     278                        rc = EOK;
     279                        fibril_condvar_broadcast(&namespace->level_changed_cv);
     280                        goto leave;
     281                }
     282        }
     283        rc =  ENOENT;
     284
     285leave:
     286        fibril_mutex_unlock(&namespace->guard);
     287        return rc;
     288}
     289
    267290void namespace_wait_for_reader_change(logging_namespace_t *namespace, bool *has_reader_now)
    268291{
    269292        fibril_mutex_lock(&namespace->guard);
    270         log_level_t previous_level = namespace->level;
    271         while (previous_level == namespace->level) {
    272                 fibril_condvar_wait(&namespace->level_changed_cv, &namespace->guard);
    273         }
     293        // FIXME: properly watch for state change
     294        fibril_condvar_wait(&namespace->level_changed_cv, &namespace->guard);
    274295        *has_reader_now = true;
    275296        fibril_mutex_unlock(&namespace->guard);
Note: See TracChangeset for help on using the changeset viewer.