This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Tarantool -- an efficient key/value data store".

The branch core-error-reporting has been created
        at  8cf4386e7998ac6cc00c97cfa15ae2e0c7649f50 (commit)


commit 8cf4386e7998ac6cc00c97cfa15ae2e0c7649f50
Author: Yuriy Vostrikov <[email protected]>
Date:   Tue Dec 14 16:52:41 2010 +0300

    [core] Cleanup error reporting.

diff --git a/cfg/warning.c b/cfg/warning.c
index fbfbf0f..7eb60c1 100644
--- a/cfg/warning.c
+++ b/cfg/warning.c
@@ -12,12 +12,12 @@ out_warning(ConfettyError v, char *format, ...)
        va_start(ap, format);
        switch (v) {
        case CNF_NOTSET:
-               vsay(S_FATAL, NULL, format, ap);
+               vsay(S_FATAL, __FILE__, __LINE__, NULL, format, ap);
                panic("can't read config");
 
                break;
 
        default:
-               vsay(S_WARN, NULL, format, ap);
+               vsay(S_WARN, __FILE__, __LINE__, NULL, format, ap);
        }
 }
diff --git a/core/say.c b/core/say.c
index 73d1266..f123e20 100644
--- a/core/say.c
+++ b/core/say.c
@@ -99,19 +99,40 @@ say_logger_init(int nonblock)
 }
 
 void
-vsay(int level, const char *error, const char *format, va_list ap)
+vsay(int level, const char *filename, int line, const char *error, const char 
*format, va_list ap)
 {
        char *peer_name = fiber_peer_name(fiber);
        size_t p = 0, len = PIPE_BUF;
+       const char *f;
        static char buf[PIPE_BUF];
 
+       if (booting) {
+               fprintf(stderr, "%s: ", binary_filename);
+               vfprintf(stderr, format, ap);
+               if (error)
+                       fprintf(stderr, ": %s", error);
+               fprintf(stderr, "\n");
+               fflush(stderr);
+               return;
+       }
+
        ev_now_update();
 
        if (peer_name == NULL)
                peer_name = "_";
 
-       p += snprintf(buf + p, len - p, "%.3f %i %i/%s %s %c> ",
-                     ev_now(), getpid(), fiber->fid, fiber->name, peer_name, 
level_to_char(level));
+       for (f = filename; *f; f++)
+               if (*f == '/' && *(f + 1) != '\0')
+                       filename = f + 1;
+
+       p += snprintf(buf + p, len - p, "%.3f %i %i/%s %s",
+                     ev_now(), getpid(), fiber->fid, fiber->name, peer_name);
+
+       if (level == S_WARN || level == S_ERROR)
+               p += snprintf(buf + p, len - p, " %s:%i", filename, line);
+
+       p += snprintf(buf + p, len - p, " %c> ", level_to_char(level));
+       /* until here it is guaranteed that p < len */
 
        p += vsnprintf(buf + p, len - p, format, ap);
        if (error && p < len - 1)
@@ -122,12 +143,18 @@ vsay(int level, const char *error, const char *format, 
va_list ap)
 
        int r = write(sayfd, buf, p + 1);
        (void)r;
+
+       if (S_FATAL && sayfd != STDERR_FILENO) {
+               r = write(STDERR_FILENO, buf, p + 1);
+               (void)r;
+       }
 }
 
 void
-_say(int level, const char *error, const char *format, ...)
+_say(int level, const char *filename, int line, const char *error, const char 
*format, ...)
 {
        va_list ap;
        va_start(ap, format);
-       vsay(level, error, format, ap);
+       vsay(level, filename, line, error, format, ap);
+       va_end(ap);
 }
diff --git a/core/tarantool.c b/core/tarantool.c
index c5e9250..f8ece3a 100644
--- a/core/tarantool.c
+++ b/core/tarantool.c
@@ -55,9 +55,10 @@
 
 static pid_t master_pid;
 const char *cfg_filename = "tarantool.cfg";
+char *binary_filename;
 struct tarantool_cfg cfg;
 
-bool init_storage;
+bool init_storage, booting = true;
 
 extern int daemonize(int nochdir, int noclose);
 
@@ -176,9 +177,6 @@ create_pid(void)
        char buf[16] = { 0 };
        pid_t pid;
 
-       if (cfg.pid_file == NULL)
-               panic("no pid file is specified in config");
-
        f = fopen(cfg.pid_file, "a+");
        if (f == NULL)
                panic_syserror("can't open pid file");
@@ -186,12 +184,12 @@ create_pid(void)
        if (fgets(buf, sizeof(buf), f) != NULL && strlen(buf) > 0) {
                pid = strtol(buf, NULL, 10);
                if (pid > 0 && kill(pid, 0) == 0)
-                       panic("deamon is running");
+                       panic("i am already running");
                else
                        say_info("updating stale pid file");
                fseeko(f, 0, SEEK_SET);
                if (ftruncate(fileno(f), 0) == -1)
-                       panic_syserror("ftruncate");
+                       panic_syserror("ftruncate(`%s')", cfg.pid_file);
        }
 
        fprintf(f, "%i\n", getpid());
@@ -209,7 +207,7 @@ initialize(double slab_alloc_arena, int slab_alloc_minimal, 
double slab_alloc_fa
 {
 
        if (!salloc_init(slab_alloc_arena * (1 << 30), slab_alloc_minimal, 
slab_alloc_factor))
-               panic("can't initialize slab allocator");
+               panic_syserror("can't initialize slab allocator");
 
        fiber_init();
 }
@@ -226,6 +224,7 @@ main(int argc, char **argv)
 {
        const char *cat_filename = NULL;
        const char *cfg_paramname = NULL;
+       char *cfg_filename_fullpath;
        int n_accepted, n_skipped;
        FILE *f;
 
@@ -257,6 +256,7 @@ main(int argc, char **argv)
                                       "=<key>", "return value from config 
described by key"));
 
        void *opt = gopt_sort(&argc, (const char **)argv, opt_def);
+       binary_filename = argv[0];
 
        if (gopt(opt, 'V')){
                puts(tarantool_version());
@@ -279,26 +279,31 @@ main(int argc, char **argv)
        }
 
        if (cfg_filename[0] != '/') {
-               char *full_path = malloc(PATH_MAX);
-               if (getcwd(full_path, PATH_MAX - strlen(cfg_filename) - 1) == 
NULL) {
+               cfg_filename_fullpath = malloc(PATH_MAX);
+               if (getcwd(cfg_filename_fullpath, PATH_MAX - 
strlen(cfg_filename) - 1) == NULL) {
                        say_syserror("getcwd");
                        exit(EX_OSERR);
                }
 
-               strcat(full_path, "/");
-               strcat(full_path, cfg_filename);
-               cfg_filename = full_path;
-       }
+               strcat(cfg_filename_fullpath, "/");
+               strcat(cfg_filename_fullpath, cfg_filename);
+
+               f = fopen(cfg_filename_fullpath, "r");
+               free(cfg_filename_fullpath);
+       } else
+               f = fopen(cfg_filename, "r");
 
-       f = fopen(cfg_filename, "r");
        if (f == NULL)
-               panic("can't open config `%s'", cfg_filename);
+               panic_syserror("can't open config `%s'", cfg_filename);
 
        fill_default_tarantool_cfg(&cfg);
        parse_cfg_file_tarantool_cfg(&cfg, f, 0, &n_accepted, &n_skipped);
        check_cfg_tarantool_cfg(&cfg);
        fclose(f);
 
+       if (n_accepted == 0 || n_skipped > 0)
+               panic("where were errors in config file");
+
 #ifdef STORAGE
        if (gopt_arg(opt, 'C', &cat_filename)) {
                initialize_minimal();
@@ -308,6 +313,16 @@ main(int argc, char **argv)
                }
                return mod_cat(cat_filename);
        }
+
+       if (gopt(opt, 'I')) {
+               init_storage = true;
+               initialize_minimal();
+               mod_init();
+               next_lsn(recovery_state, 1);
+               confirm_lsn(recovery_state, 1);
+               snapshot_save(recovery_state, mod_snapshot);
+               exit(EXIT_SUCCESS);
+       }
 #endif
 
        if (gopt_arg(opt, 'g', &cfg_paramname)) {
@@ -332,8 +347,6 @@ main(int argc, char **argv)
        if (cfg.work_dir != NULL && chdir(cfg.work_dir) == -1)
                say_syserror("can't chdir to `%s'", cfg.work_dir);
 
-       say_logger_init(cfg.logger_nonblock);
-
        if (cfg.username != NULL) {
                if (getuid() == 0 || geteuid() == 0) {
                        struct passwd *pw;
@@ -368,17 +381,7 @@ main(int argc, char **argv)
                }
 #endif
        }
-#ifdef STORAGE
-       if (gopt(opt, 'I')) {
-               init_storage = true;
-               initialize_minimal();
-               mod_init();
-               next_lsn(recovery_state, 1);
-               confirm_lsn(recovery_state, 1);
-               snapshot_save(recovery_state, mod_snapshot);
-               exit(EXIT_SUCCESS);
-       }
-#endif
+
        if (gopt(opt, 'D'))
                daemonize(1, 1);
 
@@ -389,6 +392,9 @@ main(int argc, char **argv)
 
        argv = init_set_proc_title(argc, argv);
 
+       say_logger_init(cfg.logger_nonblock);
+       booting = false;
+
 #if defined(UTILITY)
        initialize_minimal();
        signal_init();
diff --git a/include/say.h b/include/say.h
index 41f9ac7..ff5da14 100644
--- a/include/say.h
+++ b/include/say.h
@@ -45,20 +45,22 @@ enum say_level {
 extern int sayfd;
 
 void say_logger_init(int nonblock);
-void vsay(int level, const char *error, const char *format, va_list ap)
-    __attribute__ ((format(FORMAT_PRINTF, 3, 0)));
-void _say(int level, const char *error, const char *format, ...)
-    __attribute__ ((format(FORMAT_PRINTF, 3, 4)));
+void vsay(int level, const char *filename, int line, const char *error,
+         const char *format, va_list ap)
+    __attribute__ ((format(FORMAT_PRINTF, 5, 0)));
+void _say(int level, const char *filename, int line, const char *error,
+         const char *format, ...)
+    __attribute__ ((format(FORMAT_PRINTF, 5, 6)));
 
-#define say(level, ...) ({ if(cfg.log_level >= level) _say(level, 
__VA_ARGS__); })
+#define say(level, ...) ({ if(cfg.log_level >= level) _say(level, __FILE__, 
__LINE__, __VA_ARGS__); })
 
-#define panic(...) ({ say(S_FATAL, NULL, "PANIC "__FILE__":" __VA_ARGS__); 
exit(EXIT_FAILURE); })
-#define panic_syserror(...) ({ say(S_FATAL, strerror(errno), "PANIC 
"__FILE__":" __VA_ARGS__); exit(EXIT_FAILURE); })
-#define say_syserror(...) say(S_ERROR, strerror(errno), __VA_ARGS__)
-#define say_error(...) say(S_ERROR, NULL, __VA_ARGS__)
-#define say_crit(...)  say(S_CRIT, NULL, __VA_ARGS__)
-#define say_warn(...)  say(S_WARN, NULL, __VA_ARGS__)
-#define say_info(...)  say(S_INFO, NULL, __VA_ARGS__)
-#define say_debug(...) say(S_DEBUG, NULL, __VA_ARGS__)
+#define panic(...)             ({ say(S_FATAL, NULL, __VA_ARGS__); 
exit(EXIT_FAILURE); })
+#define panic_syserror(...)    ({ say(S_FATAL, strerror(errno), __VA_ARGS__); 
exit(EXIT_FAILURE); })
+#define say_syserror(...)      say(S_ERROR, strerror(errno), __VA_ARGS__)
+#define say_error(...)         say(S_ERROR, NULL, __VA_ARGS__)
+#define say_crit(...)          say(S_CRIT, NULL, __VA_ARGS__)
+#define say_warn(...)          say(S_WARN, NULL, __VA_ARGS__)
+#define say_info(...)          say(S_INFO, NULL, __VA_ARGS__)
+#define say_debug(...)         say(S_DEBUG, NULL, __VA_ARGS__)
 
 #endif
diff --git a/include/tarantool.h b/include/tarantool.h
index cde791a..89f9669 100644
--- a/include/tarantool.h
+++ b/include/tarantool.h
@@ -42,7 +42,8 @@ void mod_exec(char *str, int len, struct tbuf *out);
 extern struct tarantool_module module;
 extern struct tarantool_cfg cfg;
 extern const char *cfg_filename;
-extern bool init_storage;
+extern bool init_storage, booting;
+extern char *binary_filename;
 void snapshot(void *ev __unused__, int events __unused__);
 const char *tarantool_version(void);
 void tarantool_info(struct tbuf *out);
diff --git a/mod/silverbox/box.c b/mod/silverbox/box.c
index 458ec4f..9077f86 100644
--- a/mod/silverbox/box.c
+++ b/mod/silverbox/box.c
@@ -99,7 +99,7 @@ box_hook_t *before_commit_update_hook;
 #define box_raise(n, err)                                              \
        ({                                                              \
                if (n != ERR_CODE_NODE_IS_RO)                           \
-                       say_warn("box.c:%i %s/%s", __LINE__, 
error_codes_strs[(n)], err); \
+                       say_warn("%s/%s", error_codes_strs[(n)], err);  \
                raise(n, err);                                          \
        })
 


-- 
Tarantool -- an efficient key/value data store

_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to