Changes in / [ad78054:52c4264] in mainline
- Files:
-
- 17 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
rad78054 r52c4264 74 74 $(USPACE_PATH)/srv/locsrv/locsrv \ 75 75 $(USPACE_PATH)/srv/bd/rd/rd \ 76 $(USPACE_PATH)/srv/vfs/vfs 76 $(USPACE_PATH)/srv/vfs/vfs \ 77 $(USPACE_PATH)/srv/logger/logger 77 78 78 79 ifeq ($(RDFMT),tmpfs) … … 169 170 $(USPACE_PATH)/app/killall/killall \ 170 171 $(USPACE_PATH)/app/loc/loc \ 172 $(USPACE_PATH)/app/logset/logset \ 171 173 $(USPACE_PATH)/app/mkfat/mkfat \ 172 174 $(USPACE_PATH)/app/mkexfat/mkexfat \ -
kernel/genarch/include/multiboot/multiboot.h
rad78054 r52c4264 99 99 100 100 extern void multiboot_extract_command(char *, size_t, const char *); 101 extern void multiboot_extract_argument(char *, size_t, const char *); 101 102 extern void multiboot_info_parse(uint32_t, const multiboot_info_t *); 102 103 -
kernel/genarch/src/multiboot/multiboot.c
rad78054 r52c4264 71 71 } 72 72 73 /** Extract arguments from the multiboot module command line. 74 * 75 * @param buf Destination buffer (will be always NULL-terminated). 76 * @param size Size of destination buffer (in bytes). 77 * @param cmd_line Input string (the command line). 78 * 79 */ 80 void multiboot_extract_argument(char *buf, size_t size, const char *cmd_line) 81 { 82 /* Start after first space. */ 83 const char *start = str_chr(cmd_line, ' '); 84 if (start == NULL) { 85 str_cpy(buf, size, ""); 86 return; 87 } 88 89 const char *end = cmd_line + str_size(cmd_line); 90 91 /* Skip the space(s). */ 92 while (start != end) { 93 if (start[0] == ' ') 94 start++; 95 else 96 break; 97 } 98 99 str_ncpy(buf, size, start, (size_t) (end - start)); 100 } 101 73 102 static void multiboot_modules(uint32_t count, multiboot_module_t *mods) 74 103 { … … 84 113 multiboot_extract_command(init.tasks[init.cnt].name, 85 114 CONFIG_TASK_NAME_BUFLEN, MULTIBOOT_PTR(mods[i].string)); 86 } else 115 multiboot_extract_argument(init.tasks[init.cnt].arguments, 116 CONFIG_TASK_ARGUMENTS_BUFLEN, MULTIBOOT_PTR(mods[i].string)); 117 } else { 87 118 init.tasks[init.cnt].name[0] = 0; 119 init.tasks[init.cnt].arguments[0] = 0; 120 } 88 121 89 122 init.cnt++; -
kernel/genarch/src/multiboot/multiboot2.c
rad78054 r52c4264 49 49 multiboot_extract_command(init.tasks[init.cnt].name, 50 50 CONFIG_TASK_NAME_BUFLEN, module->string); 51 multiboot_extract_argument(init.tasks[init.cnt].arguments, 52 CONFIG_TASK_ARGUMENTS_BUFLEN, module->string); 51 53 52 54 init.cnt++; -
kernel/generic/include/config.h
rad78054 r52c4264 47 47 #define CONFIG_INIT_TASKS 32 48 48 #define CONFIG_TASK_NAME_BUFLEN 32 49 #define CONFIG_TASK_ARGUMENTS_BUFLEN 64 49 50 50 51 #ifndef __ASM__ … … 56 57 size_t size; 57 58 char name[CONFIG_TASK_NAME_BUFLEN]; 59 char arguments[CONFIG_TASK_ARGUMENTS_BUFLEN]; 58 60 } init_task_t; 59 61 -
kernel/generic/src/main/kinit.c
rad78054 r52c4264 69 69 #include <str.h> 70 70 #include <sysinfo/stats.h> 71 #include <sysinfo/sysinfo.h> 71 72 #include <align.h> 72 73 … … 179 180 program_t programs[CONFIG_INIT_TASKS]; 180 181 182 // FIXME: do not propagate arguments through sysinfo 183 // but pass them directly to the tasks 184 for (i = 0; i < init.cnt; i++) { 185 const char *arguments = init.tasks[i].arguments; 186 if (str_length(arguments) == 0) 187 continue; 188 if (str_length(init.tasks[i].name) == 0) 189 continue; 190 size_t arguments_size = str_size(arguments); 191 192 void *arguments_copy = malloc(arguments_size, 0); 193 if (arguments_copy == NULL) 194 continue; 195 memcpy(arguments_copy, arguments, arguments_size); 196 197 char item_name[CONFIG_TASK_NAME_BUFLEN + 15]; 198 snprintf(item_name, CONFIG_TASK_NAME_BUFLEN + 15, 199 "init_args.%s", init.tasks[i].name); 200 201 sysinfo_set_item_data(item_name, NULL, arguments_copy, arguments_size); 202 } 203 181 204 for (i = 0; i < init.cnt; i++) { 182 205 if (init.tasks[i].paddr % FRAME_SIZE) { -
uspace/Makefile
rad78054 r52c4264 47 47 app/klog \ 48 48 app/loc \ 49 app/logset \ 49 50 app/mkfat \ 50 51 app/mkexfat \ … … 77 78 srv/clipboard \ 78 79 srv/locsrv \ 80 srv/logger \ 79 81 srv/devman \ 80 82 srv/loader \ -
uspace/app/tester/Makefile
rad78054 r52c4264 45 45 stdio/stdio1.c \ 46 46 stdio/stdio2.c \ 47 stdio/logger1.c \ 48 stdio/logger2.c \ 47 49 fault/fault1.c \ 48 50 fault/fault2.c \ -
uspace/app/tester/tester.c
rad78054 r52c4264 39 39 #include <stdio.h> 40 40 #include <str.h> 41 #include <io/log.h> 41 42 #include "tester.h" 42 43 … … 55 56 #include "stdio/stdio1.def" 56 57 #include "stdio/stdio2.def" 58 #include "stdio/logger1.def" 59 #include "stdio/logger2.def" 57 60 #include "fault/fault1.def" 58 61 #include "fault/fault2.def" … … 138 141 } 139 142 143 log_init("tester", LVL_NOTE); 144 140 145 test_quiet = false; 141 146 test_argc = argc - 2; -
uspace/app/tester/tester.h
rad78054 r52c4264 88 88 extern const char *test_stdio1(void); 89 89 extern const char *test_stdio2(void); 90 extern const char *test_logger1(void); 91 extern const char *test_logger2(void); 90 92 extern const char *test_fault1(void); 91 93 extern const char *test_fault2(void); -
uspace/lib/c/Makefile
rad78054 r52c4264 100 100 generic/io/printf.c \ 101 101 generic/io/log.c \ 102 generic/io/logctl.c \ 102 103 generic/io/klog.c \ 103 104 generic/io/snprintf.c \ -
uspace/lib/c/generic/io/log.c
rad78054 r52c4264 38 38 #include <stdlib.h> 39 39 #include <stdio.h> 40 40 #include <async.h> 41 41 #include <io/log.h> 42 43 /** Serialization mutex for logging functions. */ 44 static FIBRIL_MUTEX_INITIALIZE(log_serializer); 45 46 /** Current log level. */ 47 static log_level_t log_level; 48 49 static FILE *log_stream; 50 42 #include <ipc/logger.h> 43 #include <ns.h> 44 45 static sysarg_t default_log_id; 46 47 /** Log messages are printed under this name. */ 51 48 static const char *log_prog_name; 52 49 53 /** Prefixes for individual logging levels. */54 50 static const char *log_level_names[] = { 55 [LVL_FATAL] = "Fatal error", 56 [LVL_ERROR] = "Error", 57 [LVL_WARN] = "Warning", 58 [LVL_NOTE] = "Note", 59 [LVL_DEBUG] = "Debug", 60 [LVL_DEBUG2] = "Debug2" 51 "fatal", 52 "error", 53 "warn", 54 "note", 55 "debug", 56 "debug2", 57 NULL 61 58 }; 59 60 /** IPC session with the logger service. */ 61 static async_sess_t *logger_session; 62 63 /** Maximum length of a single log message (in bytes). */ 64 #define MESSAGE_BUFFER_SIZE 4096 65 66 static int logger_message(async_sess_t *session, log_t log, log_level_t level, const char *message) 67 { 68 async_exch_t *exchange = async_exchange_begin(session); 69 if (exchange == NULL) { 70 return ENOMEM; 71 } 72 if (log == LOG_DEFAULT) 73 log = default_log_id; 74 75 aid_t reg_msg = async_send_2(exchange, LOGGER_WRITER_MESSAGE, 76 log, level, NULL); 77 int rc = async_data_write_start(exchange, message, str_size(message)); 78 sysarg_t reg_msg_rc; 79 async_wait_for(reg_msg, ®_msg_rc); 80 81 async_exchange_end(exchange); 82 83 /* 84 * Getting ENAK means no-one wants our message. That is not an 85 * error at all. 86 */ 87 if (rc == ENAK) 88 rc = EOK; 89 90 if (rc != EOK) { 91 return rc; 92 } 93 94 return reg_msg_rc; 95 } 96 97 const char *log_level_str(log_level_t level) 98 { 99 if (level >= LVL_LIMIT) 100 return "unknown"; 101 else 102 return log_level_names[level]; 103 } 104 105 int log_level_from_str(const char *name, log_level_t *level_out) 106 { 107 log_level_t level = LVL_FATAL; 108 109 while (log_level_names[level] != NULL) { 110 if (str_cmp(name, log_level_names[level]) == 0) { 111 if (level_out != NULL) 112 *level_out = level; 113 return EOK; 114 } 115 level++; 116 } 117 118 /* Maybe user specified number directly. */ 119 char *end_ptr; 120 int level_int = strtol(name, &end_ptr, 0); 121 if ((end_ptr == name) || (str_length(end_ptr) != 0)) 122 return EINVAL; 123 if (level_int < 0) 124 return ERANGE; 125 if (level_int >= (int) LVL_LIMIT) 126 return ERANGE; 127 128 if (level_out != NULL) 129 *level_out = (log_level_t) level_int; 130 131 return EOK; 132 } 62 133 63 134 /** Initialize the logging system. … … 69 140 { 70 141 assert(level < LVL_LIMIT); 71 log_level = level; 72 73 log_stream = stdout; 142 74 143 log_prog_name = str_dup(prog_name); 75 144 if (log_prog_name == NULL) 76 145 return ENOMEM; 77 146 147 logger_session = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOGGER, LOGGER_INTERFACE_WRITER, 0); 148 if (logger_session == NULL) { 149 return ENOMEM; 150 } 151 152 default_log_id = log_create(prog_name, LOG_NO_PARENT); 153 78 154 return EOK; 155 } 156 157 /** Create a new (sub-) log. 158 * 159 * This function always returns a valid log_t. In case of errors, 160 * @c parent is returned and errors are silently ignored. 161 * 162 * @param name Log name under which message will be reported (appended to parents name). 163 * @param parent Parent log. 164 * @return Opaque identifier of the newly created log. 165 */ 166 log_t log_create(const char *name, log_t parent) 167 { 168 async_exch_t *exchange = async_exchange_begin(logger_session); 169 if (exchange == NULL) 170 return parent; 171 172 if (parent == LOG_DEFAULT) 173 parent = default_log_id; 174 175 ipc_call_t answer; 176 aid_t reg_msg = async_send_1(exchange, LOGGER_WRITER_CREATE_LOG, 177 parent, &answer); 178 int rc = async_data_write_start(exchange, name, str_size(name)); 179 sysarg_t reg_msg_rc; 180 async_wait_for(reg_msg, ®_msg_rc); 181 182 async_exchange_end(exchange); 183 184 if ((rc != EOK) || (reg_msg_rc != EOK)) 185 return parent; 186 187 return IPC_GET_ARG1(answer); 79 188 } 80 189 … … 86 195 * @param fmt Format string (no traling newline). 87 196 */ 88 void log_ msg(log_level_t level, const char *fmt, ...)197 void log_log_msg(log_t ctx, log_level_t level, const char *fmt, ...) 89 198 { 90 199 va_list args; 91 200 92 201 va_start(args, fmt); 93 log_ msgv(level, fmt, args);202 log_log_msgv(ctx, level, fmt, args); 94 203 va_end(args); 95 204 } … … 102 211 * @param fmt Format string (no trailing newline) 103 212 */ 104 void log_ msgv(log_level_t level, const char *fmt, va_list args)213 void log_log_msgv(log_t ctx, log_level_t level, const char *fmt, va_list args) 105 214 { 106 215 assert(level < LVL_LIMIT); 107 216 108 /* Higher number means higher verbosity. */ 109 if (level <= log_level) { 110 fibril_mutex_lock(&log_serializer); 111 112 fprintf(log_stream, "%s: %s: ", log_prog_name, 113 log_level_names[level]); 114 vfprintf(log_stream, fmt, args); 115 fputc('\n', log_stream); 116 fflush(log_stream); 117 118 fibril_mutex_unlock(&log_serializer); 119 } 217 char *message_buffer = malloc(MESSAGE_BUFFER_SIZE); 218 if (message_buffer == NULL) { 219 return; 220 } 221 222 vsnprintf(message_buffer, MESSAGE_BUFFER_SIZE, fmt, args); 223 logger_message(logger_session, ctx, level, message_buffer); 120 224 } 121 225 -
uspace/lib/c/include/io/log.h
rad78054 r52c4264 36 36 37 37 #include <stdarg.h> 38 #include <inttypes.h> 39 #include <bool.h> 38 40 39 41 typedef enum { … … 49 51 } log_level_t; 50 52 53 typedef sysarg_t log_t; 54 #define PRIlogctx PRIxn 55 #define LOG_DEFAULT ((log_t) -1) 56 #define LOG_NO_PARENT ((log_t) 0) 57 58 extern const char *log_level_str(log_level_t); 59 extern int log_level_from_str(const char *, log_level_t *); 60 51 61 extern int log_init(const char *, log_level_t); 52 extern void log_msg(log_level_t, const char *, ...); 53 extern void log_msgv(log_level_t, const char *, va_list); 62 extern log_t log_create(const char *, log_t); 63 64 #define log_msg(level, format, ...) \ 65 log_log_msg(LOG_DEFAULT, (level), (format), ##__VA_ARGS__) 66 #define log_msgv(level, format, args) \ 67 log_log_msgv(LOG_DEFAULT, (level), (format), (args)) 68 69 extern void log_log_msg(log_t, log_level_t, const char *, ...); 70 extern void log_log_msgv(log_t, log_level_t, const char *, va_list); 54 71 55 72 #endif -
uspace/lib/c/include/ipc/services.h
rad78054 r52c4264 45 45 SERVICE_VFS = FOURCC('v', 'f', 's', ' '), 46 46 SERVICE_LOC = FOURCC('l', 'o', 'c', ' '), 47 SERVICE_LOGGER = FOURCC('l', 'o', 'g', 'g'), 47 48 SERVICE_DEVMAN = FOURCC('d', 'e', 'v', 'n'), 48 49 SERVICE_IRC = FOURCC('i', 'r', 'c', ' '), -
uspace/lib/usb/src/debug.c
rad78054 r52c4264 74 74 } 75 75 } 76 log_init(message_prefix, LVL_DEBUG); 76 77 } 77 78 … … 148 149 } 149 150 151 va_start(args, format); 152 log_msgv(level, format, args); 153 va_end(args); 154 150 155 fibril_mutex_unlock(&log_serializer); 151 156 }
Note:
See TracChangeset
for help on using the changeset viewer.