diff --git a/include/lml.h b/include/lml.h index 9ec9f8af..860f7de7 100644 --- a/include/lml.h +++ b/include/lml.h @@ -14,6 +14,9 @@ extern clock_t lml_total_exec_duration; // For testing purpose +extern int lml_init(void); +extern void lml_cleanup(void); + extern int lml_render(const char *str_in, char *str_out, int buf_len, int width, int quote_mode); #endif //_LML_H_ diff --git a/src/Makefile.am b/src/Makefile.am index 2fc6d4ca..eea019fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,7 @@ bbsd_LDFLAGS=-export-dynamic test_trie_dict_SOURCES = log.c test_trie_dict.c trie_dict.c test_file_loader_SOURCES = file_loader.c log.c str_process.c test_file_loader.c test_section_list_SOURCES = bbs.c common.c database.c log.c section_list.c test_section_list.c trie_dict.c user_list.c user_priv.c user_stat.c -test_lml_SOURCES = lml.c log.c str_process.c test_lml.c +test_lml_SOURCES = lml.c log.c str_process.c test_lml.c trie_dict.c test_ssh_server_SOURCES = log.c test_ssh_server.c test_article_favor_SOURCES = article_favor.c bbs.c common.c database.c log.c section_list.c test_article_favor.c trie_dict.c \ user_list.c user_priv.c user_stat.c diff --git a/src/article_cache.c b/src/article_cache.c index db57d8a1..66ddf207 100644 --- a/src/article_cache.c +++ b/src/article_cache.c @@ -47,7 +47,7 @@ inline static int article_cache_path(char *file_path, size_t buf_len, const char { if (file_path == NULL || cache_dir == NULL || p_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -76,19 +76,19 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons if (cache_dir == NULL || p_article == NULL || content == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (content_f == NULL && (content_f = malloc(ARTICLE_CONTENT_MAX_LEN)) == NULL) { - log_error("malloc(content_f) error: OOM\n"); + log_error("malloc(content_f) error: OOM"); return -1; } if (article_cache_path(data_file, sizeof(data_file), cache_dir, p_article) < 0) { - log_error("article_cache_path(dir=%s, cid=%d) error\n", cache_dir, p_article->cid); + log_error("article_cache_path(dir=%s, cid=%d) error", cache_dir, p_article->cid); return -1; } @@ -103,7 +103,7 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons if ((fd = open(data_file, O_WRONLY | O_CREAT | O_TRUNC, 0640)) == -1) { - log_error("open(%s) error (%d)\n", data_file, errno); + log_error("open(%s) error (%d)", data_file, errno); return -2; } @@ -145,7 +145,7 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons if (body_len != (size_t)cache.line_offsets[cache.line_total]) { - log_debug("Body of article(aid=%d) is truncated from %ld to %ld, body_line=%ld, body_line_limit=%ld\n", + log_debug("Body of article(aid=%d) is truncated from %ld to %ld, body_line=%ld, body_line_limit=%ld", p_article->aid, body_len, cache.line_offsets[cache.line_total], body_line_cnt, MAX_SPLIT_FILE_LINES - header_line_cnt); cache.data_len = header_len + (size_t)(cache.line_offsets[cache.line_total]); @@ -161,7 +161,7 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons if (footer_len != cache.line_offsets[cache.line_total + footer_line_cnt]) { - log_debug("Footer of article(aid=%d) is truncated from %ld to %ld, footer_line=%ld, footer_line_limit=%ld\n", + log_debug("Footer of article(aid=%d) is truncated from %ld to %ld, footer_line=%ld, footer_line_limit=%ld", p_article->aid, footer_len, cache.line_offsets[cache.line_total + footer_line_cnt], footer_line_cnt, MAX_SPLIT_FILE_LINES - cache.line_total); footer_len = (size_t)(cache.line_offsets[cache.line_total + footer_line_cnt]); @@ -178,32 +178,32 @@ int article_cache_generate(const char *cache_dir, const ARTICLE *p_article, cons if (write(fd, &cache, cache.mmap_len - cache.data_len) == -1) { - log_error("write(%s, cache) error (%d)\n", data_file, errno); + log_error("write(%s, cache) error (%d)", data_file, errno); close(fd); return -3; } if (write(fd, header, header_len) == -1) { - log_error("write(%s, header) error (%d)\n", data_file, errno); + log_error("write(%s, header) error (%d)", data_file, errno); close(fd); return -3; } if (write(fd, content_f, cache.data_len - header_len - footer_len) == -1) { - log_error("write(%s, content) error (%d)\n", data_file, errno); + log_error("write(%s, content) error (%d)", data_file, errno); close(fd); return -3; } if (write(fd, footer, footer_len) == -1) { - log_error("write(%s, footer) error (%d)\n", data_file, errno); + log_error("write(%s, footer) error (%d)", data_file, errno); close(fd); return -3; } if (close(fd) == -1) { - log_error("close(%s) error (%d)\n", data_file, errno); + log_error("close(%s) error (%d)", data_file, errno); return -2; } @@ -229,25 +229,25 @@ int article_cache_load(ARTICLE_CACHE *p_cache, const char *cache_dir, const ARTI if (p_cache == NULL || cache_dir == NULL || p_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (article_cache_path(data_file, sizeof(data_file), cache_dir, p_article) < 0) { - log_error("article_cache_path(dir=%s, cid=%d) error\n", cache_dir, p_article->cid); + log_error("article_cache_path(dir=%s, cid=%d) error", cache_dir, p_article->cid); return -1; } if ((fd = open(data_file, O_RDONLY)) == -1) { - log_error("open(%s) error (%d)\n", data_file, errno); + log_error("open(%s) error (%d)", data_file, errno); return -2; } if (fstat(fd, &sb) < 0) { - log_error("fstat(fd) error (%d)\n", errno); + log_error("fstat(fd) error (%d)", errno); return -2; } @@ -256,19 +256,19 @@ int article_cache_load(ARTICLE_CACHE *p_cache, const char *cache_dir, const ARTI p_mmap = mmap(NULL, mmap_len, PROT_READ, MAP_SHARED, fd, 0L); if (p_mmap == MAP_FAILED) { - log_error("mmap(%s) error (%d)\n", data_file, errno); + log_error("mmap(%s) error (%d)", data_file, errno); return -2; } if (close(fd) == -1) { - log_error("close(%s) error (%d)\n", data_file, errno); + log_error("close(%s) error (%d)", data_file, errno); return -2; } if (((ARTICLE_CACHE *)p_mmap)->mmap_len != mmap_len) { - log_error("Inconsistent mmap len of article (cid=%d), %ld != %ld\n", p_article->cid, p_cache->mmap_len, mmap_len); + log_error("Inconsistent mmap len of article (cid=%d), %ld != %ld", p_article->cid, p_cache->mmap_len, mmap_len); return -3; } @@ -285,13 +285,13 @@ int article_cache_unload(ARTICLE_CACHE *p_cache) { if (p_cache == NULL || p_cache->p_mmap == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (munmap(p_cache->p_mmap, p_cache->mmap_len) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -2; } diff --git a/src/article_del.c b/src/article_del.c index bc120dcc..fb797adf 100644 --- a/src/article_del.c +++ b/src/article_del.c @@ -33,7 +33,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) if (p_section == NULL || p_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); } if (p_article->excerption) // Delete is not allowed @@ -79,7 +79,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -87,14 +87,14 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) // Begin transaction if (mysql_query(db, "SET autocommit=0") != 0) { - log_error("SET autocommit=0 error: %s\n", mysql_error(db)); + log_error("SET autocommit=0 error: %s", mysql_error(db)); ret = -1; goto cleanup; } if (mysql_query(db, "BEGIN") != 0) { - log_error("Begin transaction error: %s\n", mysql_error(db)); + log_error("Begin transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -105,13 +105,13 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) if (mysql_query(db, sql) != 0) { - log_error("Query article status error: %s\n", mysql_error(db)); + log_error("Query article status error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get article status data failed\n"); + log_error("Get article status data failed"); ret = -1; goto cleanup; } @@ -156,7 +156,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) if (mysql_query(db, sql) != 0) { - log_error("Update article status error: %s\n", mysql_error(db)); + log_error("Update article status error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -177,7 +177,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) if (mysql_query(db, sql) != 0) { - log_error("Update exp error: %s\n", mysql_error(db)); + log_error("Update exp error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -192,7 +192,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) if (mysql_query(db, sql) != 0) { - log_error("Add log error: %s\n", mysql_error(db)); + log_error("Add log error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -206,7 +206,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) if (mysql_query(db, sql) != 0) { - log_error("Update article error: %s\n", mysql_error(db)); + log_error("Update article error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -215,7 +215,7 @@ int article_del(const SECTION_LIST *p_section, const ARTICLE *p_article) // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } diff --git a/src/article_favor.c b/src/article_favor.c index 4b6f038b..0b790a73 100644 --- a/src/article_favor.c +++ b/src/article_favor.c @@ -29,7 +29,7 @@ int article_favor_load(int uid, ARTICLE_FAVOR *p_favor, int keep_inc) if (p_favor == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -49,7 +49,7 @@ int article_favor_load(int uid, ARTICLE_FAVOR *p_favor, int keep_inc) if ((db = db_open()) == NULL) { - log_error("article_favor_load() error: Unable to open DB\n"); + log_error("article_favor_load() error: Unable to open DB"); return -2; } @@ -59,12 +59,12 @@ int article_favor_load(int uid, ARTICLE_FAVOR *p_favor, int keep_inc) uid); if (mysql_query(db, sql) != 0) { - log_error("Query article_favorite error: %s\n", mysql_error(db)); + log_error("Query article_favorite error: %s", mysql_error(db)); return -3; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get article_favorite data failed\n"); + log_error("Get article_favorite data failed"); return -3; } @@ -76,7 +76,7 @@ int article_favor_load(int uid, ARTICLE_FAVOR *p_favor, int keep_inc) (p_favor->aid_base_cnt)++; if (p_favor->aid_base_cnt >= MAX_FAVOR_AID_BASE_CNT) { - log_error("Too many article_favorite records for uid=%d\n", + log_error("Too many article_favorite records for uid=%d", uid); break; } @@ -85,7 +85,7 @@ int article_favor_load(int uid, ARTICLE_FAVOR *p_favor, int keep_inc) mysql_close(db); - log_common("Loaded %d article_favorite records for uid=%d\n", p_favor->aid_base_cnt, uid); + log_common("Loaded %d article_favorite records for uid=%d", p_favor->aid_base_cnt, uid); if (!keep_inc) { @@ -99,7 +99,7 @@ int article_favor_unload(ARTICLE_FAVOR *p_favor) { if (p_favor == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -123,7 +123,7 @@ int article_favor_save_inc(const ARTICLE_FAVOR *p_favor) if (p_favor == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -134,7 +134,7 @@ int article_favor_save_inc(const ARTICLE_FAVOR *p_favor) if ((db = db_open()) == NULL) { - log_error("article_favor_load() error: Unable to open DB\n"); + log_error("article_favor_load() error: Unable to open DB"); return -2; } @@ -177,8 +177,8 @@ int article_favor_save_inc(const ARTICLE_FAVOR *p_favor) if (mysql_query(db, sql_add) != 0) { - log_error("Add article_favorite error: %s\n", mysql_error(db)); - log_error("%s\n", sql_add); + log_error("Add article_favorite error: %s", mysql_error(db)); + log_error("%s", sql_add); mysql_close(db); return -3; } @@ -197,8 +197,8 @@ int article_favor_save_inc(const ARTICLE_FAVOR *p_favor) if (mysql_query(db, sql_del) != 0) { - log_error("Delete article_favorite error: %s\n", mysql_error(db)); - log_error("%s\n", sql_del); + log_error("Delete article_favorite error: %s", mysql_error(db)); + log_error("%s", sql_del); mysql_close(db); return -3; } @@ -212,7 +212,7 @@ int article_favor_save_inc(const ARTICLE_FAVOR *p_favor) } } - log_common("Saved %d and deleted %d article_favorite records for uid=%d\n", + log_common("Saved %d and deleted %d article_favorite records for uid=%d", cnt_total_add, cnt_total_del, p_favor->uid); mysql_close(db); @@ -228,7 +228,7 @@ int article_favor_merge_inc(ARTICLE_FAVOR *p_favor) if (p_favor == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -264,7 +264,7 @@ int article_favor_merge_inc(ARTICLE_FAVOR *p_favor) } if (i < p_favor->aid_base_cnt) { - log_error("Too many base aids, %d will be discarded\n", p_favor->aid_base_cnt - i); + log_error("Too many base aids, %d will be discarded", p_favor->aid_base_cnt - i); } len = MIN(p_favor->aid_inc_cnt - j, MAX_FAVOR_AID_BASE_CNT - k); @@ -277,7 +277,7 @@ int article_favor_merge_inc(ARTICLE_FAVOR *p_favor) } if (j < p_favor->aid_inc_cnt) { - log_error("Too many inc aids, %d will be discarded\n", p_favor->aid_inc_cnt - j); + log_error("Too many inc aids, %d will be discarded", p_favor->aid_inc_cnt - j); } memcpy(p_favor->aid_base, aid_new, sizeof(int32_t) * (size_t)k); @@ -298,7 +298,7 @@ int article_favor_check(int32_t aid, const ARTICLE_FAVOR *p_favor) if (p_favor == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -349,7 +349,7 @@ int article_favor_set(int32_t aid, ARTICLE_FAVOR *p_favor, int state) if (p_favor == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -412,7 +412,7 @@ int article_favor_set(int32_t aid, ARTICLE_FAVOR *p_favor, int state) // Save incremental article favorite if (article_favor_save_inc(p_favor) < 0) { - log_error("article_favor_save_inc() error\n"); + log_error("article_favor_save_inc() error"); return -2; } @@ -454,18 +454,18 @@ int query_favor_articles(ARTICLE_FAVOR *p_favor, int page_id, const ARTICLE **p_ if (p_favor == NULL || p_articles == NULL || p_article_count == NULL || p_page_count == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (article_favor_save_inc(p_favor) < 0) { - log_error("article_favor_save_inc() error\n"); + log_error("article_favor_save_inc() error"); return -2; } if (article_favor_merge_inc(p_favor) < 0) { - log_error("article_favor_merge_inc() error\n"); + log_error("article_favor_merge_inc() error"); return -2; } @@ -480,7 +480,7 @@ int query_favor_articles(ARTICLE_FAVOR *p_favor, int page_id, const ARTICLE **p_ if (page_id < 0 || page_id >= *p_page_count) { - log_error("Invalid page_id = %d, not in range [0, %d)\n", page_id, *p_page_count); + log_error("Invalid page_id = %d, not in range [0, %d)", page_id, *p_page_count); return -1; } @@ -493,20 +493,20 @@ int query_favor_articles(ARTICLE_FAVOR *p_favor, int page_id, const ARTICLE **p_ p_articles[i] = article_block_find_by_aid(aid); if (p_articles[i] == NULL) { - log_error("article_block_find_by_aid(aid=%d) error: page_id=%d, i=%d\n", aid, page_id, i); + log_error("article_block_find_by_aid(aid=%d) error: page_id=%d, i=%d", aid, page_id, i); return -3; } p_section = section_list_find_by_sid(p_articles[i]->sid); if (p_section == NULL) { - log_error("section_list_find_by_sid(%d) error\n", p_articles[i]->sid); + log_error("section_list_find_by_sid(%d) error", p_articles[i]->sid); return -3; } if (get_section_info(p_section, p_snames[i], NULL, NULL) < 0) { - log_error("get_section_info(sid=%d) error\n", p_section->sid); + log_error("get_section_info(sid=%d) error", p_section->sid); return -4; } } diff --git a/src/article_favor_display.c b/src/article_favor_display.c index 85f92eca..91895fb7 100644 --- a/src/article_favor_display.c +++ b/src/article_favor_display.c @@ -85,7 +85,7 @@ static int article_favor_draw_items(int page_id, const ARTICLE *p_articles[], ch is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log); if (is_viewed < 0) { - log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid); + log_error("article_view_log_is_viewed(aid=%d) error", p_articles[i]->aid); is_viewed = 0; } } @@ -165,21 +165,21 @@ static enum select_cmd_t article_favor_select(int total_page, int item_count, in // Refresh current action if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } } switch (ch) { case KEY_NULL: // broken pipe - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); case KEY_ESC: case KEY_LEFT: return EXIT_LIST; // exit list case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); return EXIT_LIST; // exit list } continue; @@ -308,7 +308,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) if (p_favor == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -317,7 +317,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) ret = query_favor_articles(p_favor, page_id, p_articles, snames, &article_count, &page_count); if (ret < 0) { - log_error("query_favor_articles(page_id=%d) error\n", page_id); + log_error("query_favor_articles(page_id=%d) error", page_id); return -2; } @@ -331,7 +331,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) ret = article_favor_draw_items(page_id, p_articles, snames, article_count, display_sname); if (ret < 0) { - log_error("article_favor_draw_items(page_id=%d) error\n", page_id); + log_error("article_favor_draw_items(page_id=%d) error", page_id); return -3; } @@ -344,7 +344,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) if (user_online_update("ARTICLE_FAVOR") < 0) { - log_error("user_online_update(ARTICLE_FAVOR) error\n"); + log_error("user_online_update(ARTICLE_FAVOR) error"); } ret = article_favor_select(page_count, article_count, &page_id, &selected_index); @@ -355,7 +355,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) case UNSET_FAVOR: if (article_favor_set(p_articles[selected_index]->aid, &BBS_article_favor, 0) != 1) { - log_error("article_favor_set(aid=%d, 0) error\n", p_articles[selected_index]->aid); + log_error("article_favor_set(aid=%d, 0) error", p_articles[selected_index]->aid); break; } // continue to refresh list @@ -363,7 +363,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) ret = query_favor_articles(p_favor, page_id, p_articles, snames, &article_count, &page_count); if (ret < 0) { - log_error("query_favor_articles(page_id=%d) error\n", page_id); + log_error("query_favor_articles(page_id=%d) error", page_id); return -2; } @@ -379,7 +379,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) case LOCATE_ARTICLE: if (section_list_display(snames[selected_index], p_articles[selected_index]->aid) < 0) { - log_error("section_list_display(sname=%s, aid=%d) error\n", + log_error("section_list_display(sname=%s, aid=%d) error", snames[selected_index], p_articles[selected_index]->aid); } break; @@ -393,7 +393,7 @@ int article_favor_display(ARTICLE_FAVOR *p_favor) article_favor_draw_screen(display_sname); break; default: - log_error("Unknown command %d\n", ret); + log_error("Unknown command %d", ret); } } diff --git a/src/article_post.c b/src/article_post.c index 7325e129..1472b9b0 100644 --- a/src/article_post.c +++ b/src/article_post.c @@ -57,7 +57,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) if (p_section == NULL || p_article_new == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); } if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) @@ -77,7 +77,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) p_editor_data = editor_data_load(""); if (p_editor_data == NULL) { - log_error("editor_data_load() error\n"); + log_error("editor_data_load() error"); ret = -1; goto cleanup; } @@ -129,7 +129,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) { if ((ret = check_badwords(p, '*')) < 0) { - log_error("check_badwords(title) error\n"); + log_error("check_badwords(title) error"); } else if (ret > 0) { @@ -223,7 +223,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { - log_error("malloc(content) error: OOM\n"); + log_error("malloc(content) error: OOM"); ret = -1; goto cleanup; } @@ -231,14 +231,14 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) len_content = editor_data_save(p_editor_data, content, ARTICLE_CONTENT_MAX_LEN); if (len_content < 0) { - log_error("editor_data_save() error\n"); + log_error("editor_data_save() error"); ret = -1; goto cleanup; } if (check_badwords(content, '*') < 0) { - log_error("check_badwords(content) error\n"); + log_error("check_badwords(content) error"); ret = -1; goto cleanup; } @@ -246,7 +246,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -259,13 +259,13 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) if (mysql_query(db, sql) != 0) { - log_error("Query sign error: %s\n", mysql_error(db)); + log_error("Query sign error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get sign data failed\n"); + log_error("Get sign data failed"); ret = -1; goto cleanup; } @@ -286,14 +286,14 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) // Begin transaction if (mysql_query(db, "SET autocommit=0") != 0) { - log_error("SET autocommit=0 error: %s\n", mysql_error(db)); + log_error("SET autocommit=0 error: %s", mysql_error(db)); ret = -1; goto cleanup; } if (mysql_query(db, "BEGIN") != 0) { - log_error("Begin transaction error: %s\n", mysql_error(db)); + log_error("Begin transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -302,7 +302,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) content_f = malloc((size_t)len_content * 2 + 1); if (content_f == NULL) { - log_error("malloc(content_f) error: OOM\n"); + log_error("malloc(content_f) error: OOM"); ret = -1; goto cleanup; } @@ -318,7 +318,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); if (sql_content == NULL) { - log_error("malloc(sql_content) error: OOM\n"); + log_error("malloc(sql_content) error: OOM"); ret = -1; goto cleanup; } @@ -332,7 +332,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) if (mysql_query(db, sql_content) != 0) { - log_error("Add article content error: %s\n", mysql_error(db)); + log_error("Add article content error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -353,7 +353,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) if (mysql_query(db, sql) != 0) { - log_error("Add article error: %s\n", mysql_error(db)); + log_error("Add article error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -367,7 +367,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) if (mysql_query(db, sql) != 0) { - log_error("Update content error: %s\n", mysql_error(db)); + log_error("Update content error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -381,7 +381,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) if (mysql_query(db, sql) != 0) { - log_error("Update exp error: %s\n", mysql_error(db)); + log_error("Update exp error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -395,7 +395,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) if (mysql_query(db, sql) != 0) { - log_error("Add log error: %s\n", mysql_error(db)); + log_error("Add log error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -403,7 +403,7 @@ int article_post(const SECTION_LIST *p_section, ARTICLE *p_article_new) // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -452,7 +452,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI if (p_section == NULL || p_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); } if (p_article->excerption) // Modify is not allowed @@ -468,7 +468,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -481,13 +481,13 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI if (mysql_query(db, sql) != 0) { - log_error("Query article content error: %s\n", mysql_error(db)); + log_error("Query article content error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get article content data failed\n"); + log_error("Get article content data failed"); ret = -1; goto cleanup; } @@ -497,7 +497,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { - log_error("malloc(content) error: OOM\n"); + log_error("malloc(content) error: OOM"); ret = -1; goto cleanup; } @@ -511,7 +511,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI p_editor_data = editor_data_load(content); if (p_editor_data == NULL) { - log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); + log_error("editor_data_load(aid=%d, cid=%d) error", p_article->aid, atoi(row[0])); ret = -1; goto cleanup; } @@ -576,7 +576,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { - log_error("malloc(content) error: OOM\n"); + log_error("malloc(content) error: OOM"); ret = -1; goto cleanup; } @@ -584,14 +584,14 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI len_content = editor_data_save(p_editor_data, content, ARTICLE_CONTENT_MAX_LEN - LINE_BUFFER_LEN); if (len_content < 0) { - log_error("editor_data_save() error\n"); + log_error("editor_data_save() error"); ret = -1; goto cleanup; } if (check_badwords(content, '*') < 0) { - log_error("check_badwords(content) error\n"); + log_error("check_badwords(content) error"); ret = -1; goto cleanup; } @@ -610,7 +610,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -618,14 +618,14 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI // Begin transaction if (mysql_query(db, "SET autocommit=0") != 0) { - log_error("SET autocommit=0 error: %s\n", mysql_error(db)); + log_error("SET autocommit=0 error: %s", mysql_error(db)); ret = -1; goto cleanup; } if (mysql_query(db, "BEGIN") != 0) { - log_error("Begin transaction error: %s\n", mysql_error(db)); + log_error("Begin transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -634,7 +634,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI content_f = malloc((size_t)len_content * 2 + 1); if (content_f == NULL) { - log_error("malloc(content_f) error: OOM\n"); + log_error("malloc(content_f) error: OOM"); ret = -1; goto cleanup; } @@ -648,7 +648,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); if (sql_content == NULL) { - log_error("malloc(sql_content) error: OOM\n"); + log_error("malloc(sql_content) error: OOM"); ret = -1; goto cleanup; } @@ -662,7 +662,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI if (mysql_query(db, sql_content) != 0) { - log_error("Add article content error: %s\n", mysql_error(db)); + log_error("Add article content error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -679,14 +679,14 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI if (mysql_query(db, sql) != 0) { - log_error("Add article error: %s\n", mysql_error(db)); + log_error("Add article error: %s", mysql_error(db)); ret = -1; goto cleanup; } if (mysql_query(db, sql) != 0) { - log_error("Update content error: %s\n", mysql_error(db)); + log_error("Update content error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -699,7 +699,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI if (mysql_query(db, sql) != 0) { - log_error("Add log error: %s\n", mysql_error(db)); + log_error("Add log error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -707,7 +707,7 @@ int article_modify(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTI // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -769,7 +769,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (p_section == NULL || p_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); } if (!checkpriv(&BBS_priv, p_section->sid, S_POST)) @@ -790,7 +790,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -801,13 +801,13 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Query article status error: %s\n", mysql_error(db)); + log_error("Query article status error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get article status data failed\n"); + log_error("Get article status data failed"); ret = -1; goto cleanup; } @@ -843,13 +843,13 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Query article content error: %s\n", mysql_error(db)); + log_error("Query article content error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get article content data failed\n"); + log_error("Get article content data failed"); ret = -1; goto cleanup; } @@ -859,7 +859,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { - log_error("malloc(content) error: OOM\n"); + log_error("malloc(content) error: OOM"); ret = -1; goto cleanup; } @@ -867,7 +867,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC content_f = malloc(ARTICLE_CONTENT_MAX_LEN); if (content_f == NULL) { - log_error("malloc(content_f) error: OOM\n"); + log_error("malloc(content_f) error: OOM"); ret = -1; goto cleanup; } @@ -931,7 +931,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC { if ((ret = check_badwords(p, '*')) < 0) { - log_error("check_badwords(title) error\n"); + log_error("check_badwords(title) error"); } else if (ret > 0) { @@ -1007,7 +1007,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC p_editor_data = editor_data_load(content); if (p_editor_data == NULL) { - log_error("editor_data_load(aid=%d, cid=%d) error\n", p_article->aid, atoi(row[0])); + log_error("editor_data_load(aid=%d, cid=%d) error", p_article->aid, atoi(row[0])); ret = -1; goto cleanup; } @@ -1066,7 +1066,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC content = malloc(ARTICLE_CONTENT_MAX_LEN); if (content == NULL) { - log_error("malloc(content) error: OOM\n"); + log_error("malloc(content) error: OOM"); ret = -1; goto cleanup; } @@ -1074,14 +1074,14 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC len_content = editor_data_save(p_editor_data, content, ARTICLE_CONTENT_MAX_LEN); if (len_content < 0) { - log_error("editor_data_save() error\n"); + log_error("editor_data_save() error"); ret = -1; goto cleanup; } if (check_badwords(content, '*') < 0) { - log_error("check_badwords(content) error\n"); + log_error("check_badwords(content) error"); ret = -1; goto cleanup; } @@ -1089,7 +1089,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1102,13 +1102,13 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Query sign error: %s\n", mysql_error(db)); + log_error("Query sign error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get sign data failed\n"); + log_error("Get sign data failed"); ret = -1; goto cleanup; } @@ -1129,14 +1129,14 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC // Begin transaction if (mysql_query(db, "SET autocommit=0") != 0) { - log_error("SET autocommit=0 error: %s\n", mysql_error(db)); + log_error("SET autocommit=0 error: %s", mysql_error(db)); ret = -1; goto cleanup; } if (mysql_query(db, "BEGIN") != 0) { - log_error("Begin transaction error: %s\n", mysql_error(db)); + log_error("Begin transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1145,7 +1145,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC content_f = malloc((size_t)len_content * 2 + 1); if (content_f == NULL) { - log_error("malloc(content_f) error: OOM\n"); + log_error("malloc(content_f) error: OOM"); ret = -1; goto cleanup; } @@ -1161,7 +1161,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC sql_content = malloc(SQL_BUFFER_LEN + (size_t)len_content * 2 + 1); if (sql_content == NULL) { - log_error("malloc(sql_content) error: OOM\n"); + log_error("malloc(sql_content) error: OOM"); ret = -1; goto cleanup; } @@ -1175,7 +1175,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql_content) != 0) { - log_error("Add article content error: %s\n", mysql_error(db)); + log_error("Add article content error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1197,7 +1197,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Add article error: %s\n", mysql_error(db)); + log_error("Add article error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1214,7 +1214,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Update topic article error: %s\n", mysql_error(db)); + log_error("Update topic article error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1226,7 +1226,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Update content error: %s\n", mysql_error(db)); + log_error("Update content error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1239,13 +1239,13 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Read reply info error: %s\n", mysql_error(db)); + log_error("Read reply info error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get reply info failed\n"); + log_error("Get reply info failed"); ret = -1; goto cleanup; } @@ -1267,7 +1267,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Insert msg error: %s\n", mysql_error(db)); + log_error("Insert msg error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1284,7 +1284,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Update exp error: %s\n", mysql_error(db)); + log_error("Update exp error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1298,7 +1298,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC if (mysql_query(db, sql) != 0) { - log_error("Add log error: %s\n", mysql_error(db)); + log_error("Add log error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -1306,7 +1306,7 @@ int article_reply(const SECTION_LIST *p_section, const ARTICLE *p_article, ARTIC // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } diff --git a/src/article_view_log.c b/src/article_view_log.c index 1e5bfd5d..f2ea2c97 100644 --- a/src/article_view_log.c +++ b/src/article_view_log.c @@ -28,7 +28,7 @@ int article_view_log_load(int uid, ARTICLE_VIEW_LOG *p_view_log, int keep_inc) if (p_view_log == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -49,7 +49,7 @@ int article_view_log_load(int uid, ARTICLE_VIEW_LOG *p_view_log, int keep_inc) if ((db = db_open()) == NULL) { - log_error("article_view_log_load() error: Unable to open DB\n"); + log_error("article_view_log_load() error: Unable to open DB"); return -2; } @@ -59,12 +59,12 @@ int article_view_log_load(int uid, ARTICLE_VIEW_LOG *p_view_log, int keep_inc) uid); if (mysql_query(db, sql) != 0) { - log_error("Query view_article_log error: %s\n", mysql_error(db)); + log_error("Query view_article_log error: %s", mysql_error(db)); return -3; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get view_article_log data failed\n"); + log_error("Get view_article_log data failed"); return -3; } @@ -72,7 +72,7 @@ int article_view_log_load(int uid, ARTICLE_VIEW_LOG *p_view_log, int keep_inc) p_view_log->aid_base = malloc(sizeof(int32_t) * mysql_num_rows(rs)); if (p_view_log->aid_base == NULL) { - log_error("malloc(INT32 * %d) error: OOM\n", mysql_num_rows(rs)); + log_error("malloc(INT32 * %d) error: OOM", mysql_num_rows(rs)); mysql_free_result(rs); mysql_close(db); return -4; @@ -86,7 +86,7 @@ int article_view_log_load(int uid, ARTICLE_VIEW_LOG *p_view_log, int keep_inc) mysql_close(db); - log_common("Loaded %d view_article_log records for uid=%d\n", p_view_log->aid_base_cnt, uid); + log_common("Loaded %d view_article_log records for uid=%d", p_view_log->aid_base_cnt, uid); if (!keep_inc) { @@ -100,7 +100,7 @@ int article_view_log_unload(ARTICLE_VIEW_LOG *p_view_log) { if (p_view_log == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -124,7 +124,7 @@ int article_view_log_save_inc(const ARTICLE_VIEW_LOG *p_view_log) if (p_view_log == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -135,7 +135,7 @@ int article_view_log_save_inc(const ARTICLE_VIEW_LOG *p_view_log) if ((db = db_open()) == NULL) { - log_error("article_view_log_load() error: Unable to open DB\n"); + log_error("article_view_log_load() error: Unable to open DB"); return -2; } @@ -153,7 +153,7 @@ int article_view_log_save_inc(const ARTICLE_VIEW_LOG *p_view_log) { if (mysql_query(db, sql) != 0) { - log_error("Add view_article_log error: %s\n", mysql_error(db)); + log_error("Add view_article_log error: %s", mysql_error(db)); mysql_close(db); return -3; } @@ -169,7 +169,7 @@ int article_view_log_save_inc(const ARTICLE_VIEW_LOG *p_view_log) } } - log_common("Saved %d view_article_log records for uid=%d\n", affected_record, p_view_log->uid); + log_common("Saved %d view_article_log records for uid=%d", affected_record, p_view_log->uid); mysql_close(db); @@ -185,7 +185,7 @@ int article_view_log_merge_inc(ARTICLE_VIEW_LOG *p_view_log) if (p_view_log == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -199,7 +199,7 @@ int article_view_log_merge_inc(ARTICLE_VIEW_LOG *p_view_log) aid_new = malloc(sizeof(int32_t) * (size_t)aid_new_cnt); if (aid_new == NULL) { - log_error("malloc(INT32 * %d) error: OOM\n", aid_new_cnt); + log_error("malloc(INT32 * %d) error: OOM", aid_new_cnt); return -2; } @@ -209,7 +209,7 @@ int article_view_log_merge_inc(ARTICLE_VIEW_LOG *p_view_log) { if (p_view_log->aid_base[i] == p_view_log->aid_inc[j]) { - log_error("Duplicate aid = %d found in both Base (offset = %d) and Inc (offset = %d)\n", + log_error("Duplicate aid = %d found in both Base (offset = %d) and Inc (offset = %d)", p_view_log->aid_base[i], i, j); j++; // Skip duplicate one in Inc } @@ -255,7 +255,7 @@ int article_view_log_is_viewed(int32_t aid, const ARTICLE_VIEW_LOG *p_view_log) if (p_view_log == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -304,7 +304,7 @@ int article_view_log_set_viewed(int32_t aid, ARTICLE_VIEW_LOG *p_view_log) if (p_view_log == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -347,7 +347,7 @@ int article_view_log_set_viewed(int32_t aid, ARTICLE_VIEW_LOG *p_view_log) // Save incremental article view log if (article_view_log_save_inc(p_view_log) < 0) { - log_error("article_view_log_save_inc() error\n"); + log_error("article_view_log_save_inc() error"); return -2; } diff --git a/src/bbs_main.c b/src/bbs_main.c index e7c9c72e..31dad2d3 100644 --- a/src/bbs_main.c +++ b/src/bbs_main.c @@ -43,7 +43,7 @@ static void child_proc_sig_usr1_handler(int i) // Restart log if (log_restart() < 0) { - log_error("Restart logging failed\n"); + log_error("Restart logging failed"); } } @@ -64,7 +64,7 @@ int bbs_welcome(void) if (get_user_online_list_count(&u_online, &u_anonymous) < 0) { - log_error("get_user_online_list_count() error\n"); + log_error("get_user_online_list_count() error"); u_online = 0; } u_online += u_anonymous; @@ -76,13 +76,13 @@ int bbs_welcome(void) if (get_user_list_count(&u_total) < 0) { - log_error("get_user_list_count() error\n"); + log_error("get_user_list_count() error"); u_total = 0; } if (get_user_login_count(&u_login_count) < 0) { - log_error("get_user_login_count() error\n"); + log_error("get_user_login_count() error"); u_login_count = 0; } @@ -122,7 +122,7 @@ int bbs_logout(void) display_file(DATA_GOODBYE, 1); - log_common("User [%s] (uid=%d) logout, idle for %ld seconds since last input\n", + log_common("User [%s] (uid=%d) logout, idle for %ld seconds since last input", BBS_username, BBS_priv.uid, time(NULL) - BBS_last_access_tm); return 0; @@ -171,7 +171,7 @@ int bbs_center() if (ch != KEY_NULL && ch != KEY_TIMEOUT) { BBS_last_access_tm = time(NULL); - log_debug("Debug: BBS_last_access_tm is updated\n"); + log_debug("Debug: BBS_last_access_tm is updated"); } if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) @@ -186,19 +186,19 @@ int bbs_center() if (user_online_update("MENU") < 0) { - log_error("user_online_update(MENU) error\n"); + log_error("user_online_update(MENU) error"); } switch (ch) { case KEY_NULL: // broken pipe - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); loop = 0; break; case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); loop = 0; break; } @@ -253,7 +253,7 @@ int bbs_charset_select() case 'G': if (io_conv_init("GBK") < 0) { - log_error("io_conv_init(%s) error\n", "GBK"); + log_error("io_conv_init(%s) error", "GBK"); return -1; } break; @@ -301,19 +301,19 @@ int bbs_main() act.sa_handler = SIG_IGN; if (sigaction(SIGHUP, &act, NULL) == -1) { - log_error("set signal action of SIGHUP error: %d\n", errno); + log_error("set signal action of SIGHUP error: %d", errno); goto cleanup; } act.sa_handler = SIG_DFL; if (sigaction(SIGCHLD, &act, NULL) == -1) { - log_error("set signal action of SIGCHLD error: %d\n", errno); + log_error("set signal action of SIGCHLD error: %d", errno); goto cleanup; } act.sa_handler = child_proc_sig_usr1_handler; if (sigaction(SIGUSR1, &act, NULL) == -1) { - log_error("set signal action of SIGUSR1 error: %d\n", errno); + log_error("set signal action of SIGUSR1 error: %d", errno); goto cleanup; } @@ -346,7 +346,7 @@ int bbs_main() // Set default charset if (io_conv_init(BBS_default_charset) < 0) { - log_error("io_conv_init(%s) error\n", BBS_default_charset); + log_error("io_conv_init(%s) error", BBS_default_charset); goto cleanup; } @@ -380,7 +380,7 @@ int bbs_main() { goto cleanup; } - log_common("User [%s] (uid=%d) login from %s:%d\n", + log_common("User [%s] (uid=%d) login from %s:%d", BBS_username, BBS_priv.uid, hostaddr_client, port_client); // Check EULA update status @@ -393,28 +393,28 @@ int bbs_main() // Load section aid locations if (section_aid_locations_load(BBS_priv.uid) < 0) { - log_error("article_view_log_load() error\n"); + log_error("article_view_log_load() error"); goto cleanup; } // Load article view log if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0) { - log_error("article_view_log_load() error\n"); + log_error("article_view_log_load() error"); goto cleanup; } // Load article favorite if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0) { - log_error("article_favor_load() error\n"); + log_error("article_favor_load() error"); goto cleanup; } // Init editor memory pool if (editor_memory_pool_init() < 0) { - log_error("editor_memory_pool_init() error\n"); + log_error("editor_memory_pool_init() error"); goto cleanup; } @@ -432,19 +432,19 @@ int bbs_main() // Save section aid locations if (section_aid_locations_save(BBS_priv.uid) < 0) { - log_error("article_view_log_save() error\n"); + log_error("article_view_log_save() error"); } // Save incremental article view log if (article_view_log_save_inc(&BBS_article_view_log) < 0) { - log_error("article_view_log_save_inc() error\n"); + log_error("article_view_log_save_inc() error"); } // Save incremental article favorite if (article_favor_save_inc(&BBS_article_favor) < 0) { - log_error("article_favor_save_inc() error\n"); + log_error("article_favor_save_inc() error"); } cleanup: diff --git a/src/bbs_net.c b/src/bbs_net.c index e3586d1c..6604b9f4 100644 --- a/src/bbs_net.c +++ b/src/bbs_net.c @@ -87,7 +87,7 @@ static int load_bbsnet_conf(const char *file_config) bbsnet_menu.p_menu_pool = calloc(1, sizeof(MENU)); if (bbsnet_menu.p_menu_pool == NULL) { - log_error("calloc(p_menu_pool) error\n"); + log_error("calloc(p_menu_pool) error"); return -1; } bbsnet_menu.menu_count = 1; @@ -95,7 +95,7 @@ static int load_bbsnet_conf(const char *file_config) bbsnet_menu.p_menu_item_pool = calloc(MAXSTATION, sizeof(MENU_ITEM)); if (bbsnet_menu.p_menu_item_pool == NULL) { - log_error("calloc(p_menu_item_pool) error\n"); + log_error("calloc(p_menu_item_pool) error"); unload_bbsnet_conf(); return -1; } @@ -140,7 +140,7 @@ static int load_bbsnet_conf(const char *file_config) port = strtol(t4, &endptr, 10); if (*endptr != '\0' || port <= 0 || port > 65535) { - log_error("Invalid port value %ld of menu item %d\n", port, menu_item_id); + log_error("Invalid port value %ld of menu item %d", port, menu_item_id); fclose(fp); unload_bbsnet_conf(); return -3; @@ -154,7 +154,7 @@ static int load_bbsnet_conf(const char *file_config) p_menu_item = get_menu_item_by_id(&bbsnet_menu, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); fclose(fp); unload_bbsnet_conf(); return -3; @@ -310,7 +310,7 @@ static int bbsnet_connect(int n) if (user_online_update("BBS_NET") < 0) { - log_error("user_online_update(BBS_NET) error\n"); + log_error("user_online_update(BBS_NET) error"); } if (bbsnet_conf[n].use_ssh) @@ -366,14 +366,14 @@ static int bbsnet_connect(int n) if ((ret = getaddrinfo(BBS_address, NULL, &hints, &res)) != 0) { - log_error("getaddrinfo() error (%d): %s\n", ret, gai_strerror(ret)); + log_error("getaddrinfo() error (%d): %s", ret, gai_strerror(ret)); ret = -1; goto cleanup; } if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr), local_addr, sizeof(local_addr)) == NULL) { - log_error("inet_ntop() error (%d)\n", errno); + log_error("inet_ntop() error (%d)", errno); ret = -1; goto cleanup; } @@ -382,14 +382,14 @@ static int bbsnet_connect(int n) sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sock < 0) { - log_error("socket() error (%d)\n", errno); + log_error("socket() error (%d)", errno); ret = -1; goto cleanup; } if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) { - log_error("bind(%s:%u) error (%d)\n", local_addr, local_port, errno); + log_error("bind(%s:%u) error (%d)", local_addr, local_port, errno); ret = -1; goto cleanup; } @@ -405,7 +405,7 @@ static int bbsnet_connect(int n) if ((ret = getaddrinfo(bbsnet_conf[n].host_name, bbsnet_conf[n].port, &hints, &res)) != 0) { - log_error("getaddrinfo() error (%d): %s\n", ret, gai_strerror(ret)); + log_error("getaddrinfo() error (%d): %s", ret, gai_strerror(ret)); prints("\033[1;31m查找主机名失败!\033[m\r\n"); press_any_key(); ret = -1; @@ -414,7 +414,7 @@ static int bbsnet_connect(int n) if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr), remote_addr, sizeof(remote_addr)) == NULL) { - log_error("inet_ntop() error (%d)\n", errno); + log_error("inet_ntop() error (%d)", errno); ret = -1; goto cleanup; } @@ -423,13 +423,13 @@ static int bbsnet_connect(int n) // Set socket as non-blocking if ((flags_sock = fcntl(sock, F_GETFL, 0)) == -1) { - log_error("fcntl(F_GETFL) error (%d)\n", errno); + log_error("fcntl(F_GETFL) error (%d)", errno); ret = -1; goto cleanup; } if ((fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK)) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); ret = -1; goto cleanup; } @@ -437,25 +437,25 @@ static int bbsnet_connect(int n) // Set STDIN/STDOUT as non-blocking if ((flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1) { - log_error("fcntl(F_GETFL) error (%d)\n", errno); + log_error("fcntl(F_GETFL) error (%d)", errno); ret = -1; goto cleanup; } if ((flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1) { - log_error("fcntl(F_GETFL) error (%d)\n", errno); + log_error("fcntl(F_GETFL) error (%d)", errno); ret = -1; goto cleanup; } if ((fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK)) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); ret = -1; goto cleanup; } if ((fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK)) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); ret = -1; goto cleanup; } @@ -464,7 +464,7 @@ static int bbsnet_connect(int n) epollfd = epoll_create1(0); if (epollfd < 0) { - log_error("epoll_create1() error (%d)\n", errno); + log_error("epoll_create1() error (%d)", errno); ret = -1; goto cleanup; } @@ -473,7 +473,7 @@ static int bbsnet_connect(int n) ev.data.fd = sock; if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) { - log_error("epoll_ctl(socket) error (%d)\n", errno); + log_error("epoll_ctl(socket) error (%d)", errno); ret = -1; goto cleanup; } @@ -482,7 +482,7 @@ static int bbsnet_connect(int n) ev.data.fd = STDIN_FILENO; if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) { - log_error("epoll_ctl(STDIN_FILENO) error (%d)\n", errno); + log_error("epoll_ctl(STDIN_FILENO) error (%d)", errno); ret = -1; goto cleanup; } @@ -510,7 +510,7 @@ static int bbsnet_connect(int n) } else { - log_error("connect(socket) error (%d)\n", errno); + log_error("connect(socket) error (%d)", errno); prints("\033[1;31m连接失败!\033[m\r\n"); press_any_key(); ret = -1; @@ -525,7 +525,7 @@ static int bbsnet_connect(int n) if (clock_gettime(CLOCK_REALTIME, &ts_begin) == -1) { - log_error("clock_gettime() error (%d)\n", errno); + log_error("clock_gettime() error (%d)", errno); ret = -1; goto cleanup; } @@ -553,9 +553,9 @@ static int bbsnet_connect(int n) if (errno != EINTR) { #ifdef HAVE_SYS_EPOLL_H - log_error("epoll_wait() error (%d)\n", errno); + log_error("epoll_wait() error (%d)", errno); #else - log_error("poll() error (%d)\n", errno); + log_error("poll() error (%d)", errno); #endif break; } @@ -564,7 +564,7 @@ static int bbsnet_connect(int n) { if (clock_gettime(CLOCK_REALTIME, &ts_now) == -1) { - log_error("clock_gettime() error (%d)\n", errno); + log_error("clock_gettime() error (%d)", errno); ret = -1; goto cleanup; } @@ -601,7 +601,7 @@ static int bbsnet_connect(int n) socklen_t len = sizeof(error); if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { - log_error("getsockopt() error (%d) !\n", errno); + log_error("getsockopt() error (%d) !", errno); ret = -1; goto cleanup; } @@ -647,7 +647,7 @@ static int bbsnet_connect(int n) tos = IPTOS_LOWDELAY; if (setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) { - log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno); + log_error("setsockopt IP_TOS=%d error (%d)", tos, errno); } sock_len = sizeof(sin); @@ -660,7 +660,7 @@ static int bbsnet_connect(int n) if (inet_ntop(AF_INET, &(sin.sin_addr), local_addr, sizeof(local_addr)) == NULL) { - log_error("inet_ntop() error (%d)\n", errno); + log_error("inet_ntop() error (%d)", errno); ret = -1; goto cleanup; } @@ -671,7 +671,7 @@ static int bbsnet_connect(int n) outbound_session = ssh_new(); if (outbound_session == NULL) { - log_error("ssh_new() error\n"); + log_error("ssh_new() error"); ret = -1; goto cleanup; } @@ -684,7 +684,7 @@ static int bbsnet_connect(int n) ssh_options_set(outbound_session, SSH_OPTIONS_HOSTKEYS, "+ssh-ed25519,ecdsa-sha2-nistp256,ssh-rsa") < 0 || ssh_options_set(outbound_session, SSH_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) { - log_error("Error setting SSH options: %s\n", ssh_get_error(outbound_session)); + log_error("Error setting SSH options: %s", ssh_get_error(outbound_session)); ret = -1; goto cleanup; } @@ -702,11 +702,11 @@ static int bbsnet_connect(int n) } else if (ret == SSH_AGAIN) { - // log_debug("ssh_connect() error: SSH_AGAIN\n"); + // log_debug("ssh_connect() error: SSH_AGAIN"); } else // if (ret == SSH_ERROR) { - log_error("ssh_connect() error: SSH_ERROR\n"); + log_error("ssh_connect() error: SSH_ERROR"); ret = -1; goto cleanup; } @@ -726,18 +726,18 @@ static int bbsnet_connect(int n) case SSH_KNOWN_HOSTS_UNKNOWN: if (ssh_session_update_known_hosts(outbound_session) != SSH_OK) { - log_error("ssh_session_update_known_hosts(%s) error\n", bbsnet_conf[n].host_name); + log_error("ssh_session_update_known_hosts(%s) error", bbsnet_conf[n].host_name); prints("\033[1;31m无法添加服务器证书\033[m\r\n"); press_any_key(); ret = -1; goto cleanup; } - log_common("SSH key of (%s) is added into %s\n", bbsnet_conf[n].host_name, SSH_KNOWN_HOSTS_FILE); + log_common("SSH key of (%s) is added into %s", bbsnet_conf[n].host_name, SSH_KNOWN_HOSTS_FILE); case SSH_KNOWN_HOSTS_OK: break; case SSH_KNOWN_HOSTS_CHANGED: case SSH_KNOWN_HOSTS_OTHER: - log_error("ssh_session_is_known_server(%s) error: %d\n", bbsnet_conf[n].host_name, ret); + log_error("ssh_session_is_known_server(%s) error: %d", bbsnet_conf[n].host_name, ret); prints("\033[1;31m服务器证书已变更\033[m\r\n"); press_any_key(); ret = -1; @@ -754,17 +754,17 @@ static int bbsnet_connect(int n) } else if (ret == SSH_AUTH_AGAIN) { - // log_debug("ssh_userauth_password() error: SSH_AUTH_AGAIN\n"); + // log_debug("ssh_userauth_password() error: SSH_AUTH_AGAIN"); } else if (ret == SSH_AUTH_ERROR) { - log_error("ssh_userauth_password() error: SSH_AUTH_ERROR\n"); + log_error("ssh_userauth_password() error: SSH_AUTH_ERROR"); ret = -1; goto cleanup; } else // if (ret == SSH_AUTH_DENIED) { - log_error("ssh_userauth_password() error: SSH_AUTH_DENIED\n"); + log_error("ssh_userauth_password() error: SSH_AUTH_DENIED"); prints("\033[1;31m身份验证失败!\033[m\r\n"); press_any_key(); ret = -1; @@ -782,7 +782,7 @@ static int bbsnet_connect(int n) outbound_channel = ssh_channel_new(outbound_session); if (outbound_channel == NULL) { - log_error("ssh_channel_new() error\n"); + log_error("ssh_channel_new() error"); ret = -1; goto cleanup; } @@ -797,11 +797,11 @@ static int bbsnet_connect(int n) } else if (ret == SSH_AGAIN) { - // log_debug("ssh_channel_open_session() error: SSH_AGAIN\n"); + // log_debug("ssh_channel_open_session() error: SSH_AGAIN"); } else // if (ret == SSH_ERROR) { - log_error("ssh_channel_open_session() error: SSH_ERROR\n"); + log_error("ssh_channel_open_session() error: SSH_ERROR"); ret = -1; goto cleanup; } @@ -824,11 +824,11 @@ static int bbsnet_connect(int n) } else if (ret == SSH_AGAIN) { - // log_debug("ssh_channel_request_pty() error: SSH_AGAIN\n"); + // log_debug("ssh_channel_request_pty() error: SSH_AGAIN"); } else // if (ret == SSH_ERROR) { - log_error("ssh_channel_request_pty() error: SSH_ERROR\n"); + log_error("ssh_channel_request_pty() error: SSH_ERROR"); ret = -1; goto cleanup; } @@ -851,11 +851,11 @@ static int bbsnet_connect(int n) } else if (ret == SSH_AGAIN) { - // log_debug("ssh_channel_request_shell() error: SSH_AGAIN\n"); + // log_debug("ssh_channel_request_shell() error: SSH_AGAIN"); } else // if (ret == SSH_ERROR) { - log_error("ssh_channel_request_shell() error: SSH_ERROR\n"); + log_error("ssh_channel_request_shell() error: SSH_ERROR"); ret = -1; goto cleanup; } @@ -871,7 +871,7 @@ static int bbsnet_connect(int n) prints("\033[1;31m连接成功!\033[m\r\n"); iflush(); - log_common("BBSNET connect to %s:%d from %s:%d by [%s]\n", + log_common("BBSNET connect to %s:%d from %s:%d by [%s]", remote_addr, remote_port, local_addr, local_port, BBS_username); snprintf(tocode, sizeof(tocode), "%s%s", bbsnet_conf[n].charset, @@ -879,7 +879,7 @@ static int bbsnet_connect(int n) input_cd = iconv_open(tocode, stdio_charset); if (input_cd == (iconv_t)(-1)) { - log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno); + log_error("iconv_open(%s->%s) error: %d", stdio_charset, tocode, errno); ret = -1; goto cleanup; } @@ -889,7 +889,7 @@ static int bbsnet_connect(int n) output_cd = iconv_open(tocode, bbsnet_conf[n].charset); if (output_cd == (iconv_t)(-1)) { - log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno); + log_error("iconv_open(%s->%s) error: %d", bbsnet_conf[n].charset, tocode, errno); ret = -1; goto cleanup; } @@ -899,7 +899,7 @@ static int bbsnet_connect(int n) ev.data.fd = sock; if (epoll_ctl(epollfd, EPOLL_CTL_MOD, sock, &ev) == -1) { - log_error("epoll_ctl(socket) error (%d)\n", errno); + log_error("epoll_ctl(socket) error (%d)", errno); ret = -1; goto cleanup; } @@ -908,7 +908,7 @@ static int bbsnet_connect(int n) ev.data.fd = STDOUT_FILENO; if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) { - log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno); + log_error("epoll_ctl(STDOUT_FILENO) error (%d)", errno); ret = -1; goto cleanup; } @@ -921,14 +921,14 @@ static int bbsnet_connect(int n) { if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) { - log_debug("SSH channel is closed\n"); + log_debug("SSH channel is closed"); loop = 0; break; } if (bbsnet_conf[n].use_ssh && ssh_channel_is_closed(outbound_channel)) { - log_debug("Outbound channel is closed\n"); + log_debug("Outbound channel is closed"); loop = 0; break; } @@ -952,9 +952,9 @@ static int bbsnet_connect(int n) if (errno != EINTR) { #ifdef HAVE_SYS_EPOLL_H - log_error("epoll_wait() error (%d)\n", errno); + log_error("epoll_wait() error (%d)", errno); #else - log_error("poll() error (%d)\n", errno); + log_error("poll() error (%d)", errno); #endif break; } @@ -964,7 +964,7 @@ static int bbsnet_connect(int n) { if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); break; } } @@ -978,9 +978,9 @@ static int bbsnet_connect(int n) #endif { #ifdef HAVE_SYS_EPOLL_H - log_debug("FD (%d) error events (%d)\n", events[i].data.fd, events[i].events); + log_debug("FD (%d) error events (%d)", events[i].data.fd, events[i].events); #else - log_debug("FD (%d) error events (%d)\n", pfds[i].fd, pfds[i].revents); + log_debug("FD (%d) error events (%d)", pfds[i].fd, pfds[i].revents); #endif loop = 0; break; @@ -1039,7 +1039,7 @@ static int bbsnet_connect(int n) ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0); if (ret == SSH_ERROR) { - log_debug("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); + log_debug("ssh_channel_read_nonblocking() error: %s", ssh_get_error(SSH_session)); loop = 0; break; } @@ -1077,14 +1077,14 @@ static int bbsnet_connect(int n) } else { - log_error("read(STDIN) error (%d)\n", errno); + log_error("read(STDIN) error (%d)", errno); loop = 0; break; } } else if (ret == 0) // broken pipe { - log_debug("read(STDIN) EOF\n"); + log_debug("read(STDIN) EOF"); stdin_read_wait = 0; loop = 0; break; @@ -1097,7 +1097,7 @@ static int bbsnet_connect(int n) // Refresh current action while user input if (user_online_update("BBS_NET") < 0) { - log_error("user_online_update(BBS_NET) error\n"); + log_error("user_online_update(BBS_NET) error"); } continue; @@ -1113,14 +1113,14 @@ static int bbsnet_connect(int n) #ifdef _DEBUG for (int j = input_buf_offset; j < input_buf_len; j++) { - log_debug("input: <--[%u]\n", (input_buf[j] + 256) % 256); + log_debug("input: <--[%u]", (input_buf[j] + 256) % 256); } #endif ret = io_buf_conv(input_cd, input_buf, &input_buf_len, &input_buf_offset, input_conv, sizeof(input_conv), &input_conv_len); if (ret < 0) { - log_error("io_buf_conv(input, %d, %d, %d) error\n", input_buf_len, input_buf_offset, input_conv_len); + log_error("io_buf_conv(input, %d, %d, %d) error", input_buf_len, input_buf_offset, input_conv_len); input_buf_len = input_buf_offset; // Discard invalid sequence } @@ -1128,7 +1128,7 @@ static int bbsnet_connect(int n) #ifdef _DEBUG for (int j = input_conv_offset; j < input_conv_len; j++) { - log_debug("input_conv: <--[%u]\n", (input_conv[j] + 256) % 256); + log_debug("input_conv: <--[%u]", (input_conv[j] + 256) % 256); } #endif } @@ -1140,7 +1140,7 @@ static int bbsnet_connect(int n) ret = ssh_channel_write(outbound_channel, input_conv + input_conv_offset, (uint32_t)(input_conv_len - input_conv_offset)); if (ret == SSH_ERROR) { - log_debug("ssh_channel_write() error: %s\n", ssh_get_error(outbound_session)); + log_debug("ssh_channel_write() error: %s", ssh_get_error(outbound_session)); loop = 0; break; } @@ -1162,14 +1162,14 @@ static int bbsnet_connect(int n) } else { - log_debug("write(socket) error (%d)\n", errno); + log_debug("write(socket) error (%d)", errno); loop = 0; break; } } else if (ret == 0) // broken pipe { - log_debug("write(socket) EOF\n"); + log_debug("write(socket) EOF"); sock_write_wait = 0; loop = 0; break; @@ -1198,7 +1198,7 @@ static int bbsnet_connect(int n) (uint32_t)(sizeof(output_buf) - (size_t)output_buf_len), 0); if (ret == SSH_ERROR) { - log_debug("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(outbound_session)); + log_debug("ssh_channel_read_nonblocking() error: %s", ssh_get_error(outbound_session)); loop = 0; break; } @@ -1231,14 +1231,14 @@ static int bbsnet_connect(int n) } else { - log_debug("read(socket) error (%d)\n", errno); + log_debug("read(socket) error (%d)", errno); loop = 0; break; } } else if (ret == 0) // broken pipe { - log_debug("read(socket) EOF\n"); + log_debug("read(socket) EOF"); sock_read_wait = 0; loop = 0; break; @@ -1258,7 +1258,7 @@ static int bbsnet_connect(int n) ret = io_buf_conv(output_cd, output_buf, &output_buf_len, &output_buf_offset, output_conv, sizeof(output_conv), &output_conv_len); if (ret < 0) { - log_error("io_buf_conv(output, %d, %d, %d) error\n", output_buf_len, output_buf_offset, output_conv_len); + log_error("io_buf_conv(output, %d, %d, %d) error", output_buf_len, output_buf_offset, output_conv_len); output_buf_len = output_buf_offset; // Discard invalid sequence } } @@ -1270,7 +1270,7 @@ static int bbsnet_connect(int n) ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset)); if (ret == SSH_ERROR) { - log_debug("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); + log_debug("ssh_channel_write() error: %s", ssh_get_error(SSH_session)); loop = 0; break; } @@ -1292,14 +1292,14 @@ static int bbsnet_connect(int n) } else { - log_debug("write(STDOUT) error (%d)\n", errno); + log_debug("write(STDOUT) error (%d)", errno); loop = 0; break; } } else if (ret == 0) // broken pipe { - log_debug("write(STDOUT) EOF\n"); + log_debug("write(STDOUT) EOF"); stdout_write_wait = 0; loop = 0; break; @@ -1322,7 +1322,7 @@ static int bbsnet_connect(int n) ret = 1; // Normal disconnect BBS_last_access_tm = time(NULL); t_used = BBS_last_access_tm - t_begin; - log_common("BBSNET disconnect, %ld days %ld hours %ld minutes %ld seconds used\n", + log_common("BBSNET disconnect, %ld days %ld hours %ld minutes %ld seconds used", t_used / 86400, t_used % 86400 / 3600, t_used % 3600 / 60, t_used % 60); cleanup: @@ -1342,7 +1342,7 @@ static int bbsnet_connect(int n) #ifdef HAVE_SYS_EPOLL_H if (epollfd != -1 && close(epollfd) < 0) { - log_error("close(epoll) error (%d)\n"); + log_error("close(epoll) error (%d)"); } #endif @@ -1364,16 +1364,16 @@ static int bbsnet_connect(int n) // Restore STDIN/STDOUT flags if (flags_stdin != -1 && fcntl(STDIN_FILENO, F_SETFL, flags_stdin) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); } if (flags_stdout != -1 && fcntl(STDOUT_FILENO, F_SETFL, flags_stdout) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); } if (sock != -1 && close(sock) == -1) { - log_error("close(socket) error (%d)\n", errno); + log_error("close(socket) error (%d)", errno); } if (res) @@ -1461,12 +1461,12 @@ int bbs_net() switch (ch) { case KEY_NULL: // broken pipe - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); goto cleanup; case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); goto cleanup; } continue; @@ -1476,7 +1476,7 @@ int bbs_net() case CR: if (bbsnet_connect(bbsnet_menu.menu_item_pos[0]) < 0) { - log_debug("bbsnet_connect() error\n"); + log_debug("bbsnet_connect() error"); } // Force cleanup anything remaining in the output buffer clearscr(); diff --git a/src/bwf.c b/src/bwf.c index ddcada1e..d76d4285 100644 --- a/src/bwf.c +++ b/src/bwf.c @@ -38,13 +38,13 @@ int bwf_load(const char *filename) if (filename == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if ((fp = fopen(filename, "r")) == NULL) { - log_error("fopen(%s) error: %d\n", filename, errno); + log_error("fopen(%s) error: %d", filename, errno); return -2; } @@ -53,7 +53,7 @@ int bwf_load(const char *filename) len_line = strnlen(line, sizeof(line) - 1); if (!feof(fp) && line[len_line - 1] != '\n') { - log_error("Data line %d (len=%d) is truncated\n", line_id, len_line); + log_error("Data line %d (len=%d) is truncated", line_id, len_line); bwf_pattern_str[0] = '\0'; return -3; } @@ -76,7 +76,7 @@ int bwf_load(const char *filename) if (len_line + 2 > sizeof(bwf_pattern_str) - 1 - (size_t)(p - bwf_pattern_str)) { - log_error("Data in %s exceed length limit %d\n", filename, sizeof(bwf_pattern_str) - 1); + log_error("Data in %s exceed length limit %d", filename, sizeof(bwf_pattern_str) - 1); bwf_pattern_str[0] = '\0'; return -3; } @@ -91,7 +91,7 @@ int bwf_load(const char *filename) fclose(fp); - log_debug("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); + log_debug("Debug: bwf_pattern_str: %s", bwf_pattern_str); return 0; } @@ -134,7 +134,7 @@ int check_badwords(char *str, char c_mask) if (bwf_code == NULL) { - log_error("BWF not loaded\n"); + log_error("BWF not loaded"); return -1; } @@ -150,11 +150,11 @@ int check_badwords(char *str, char c_mask) } else if (ret < 0) { - log_error("pcre2_match() error: %d\n", ret); + log_error("pcre2_match() error: %d", ret); } else if (ret == 0) { - log_error("Vector of offsets is too small\n"); + log_error("Vector of offsets is too small"); } else // ret >= 1 { @@ -170,7 +170,7 @@ int check_badwords(char *str, char c_mask) } else { - log_debug("Debug: match pattern #%d of %d at offsets [%d, %d]\n", + log_debug("Debug: match pattern #%d of %d at offsets [%d, %d]", i, match_count, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); memset(str + ovector[i * 2], c_mask, ovector[i * 2 + 1] - ovector[i * 2]); total_match_count++; diff --git a/src/data_file_mgr.c b/src/data_file_mgr.c index d41ddbd3..e2affd8f 100644 --- a/src/data_file_mgr.c +++ b/src/data_file_mgr.c @@ -90,13 +90,13 @@ int data_file_mgr(void *param) if ((fd = open(path, O_RDONLY)) < 0 && (fd = open(data_file_list[i].path, O_RDONLY)) < 0) { - log_error("open(%s) error (%d)\n", data_file_list[i].path, errno); + log_error("open(%s) error (%d)", data_file_list[i].path, errno); return REDRAW; } if (fstat(fd, &sb) < 0) { - log_error("fstat(fd) error (%d)\n", errno); + log_error("fstat(fd) error (%d)", errno); goto cleanup; } @@ -104,13 +104,13 @@ int data_file_mgr(void *param) p_data = mmap(NULL, len_data, PROT_READ, MAP_SHARED, fd, 0L); if (p_data == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); goto cleanup; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); fd = -1; goto cleanup; } @@ -119,13 +119,13 @@ int data_file_mgr(void *param) p_editor_data = editor_data_load(p_data); if (p_editor_data == NULL) { - log_error("editor_data_load(data) error\n"); + log_error("editor_data_load(data) error"); goto cleanup; } if (munmap(p_data, len_data) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); p_data = NULL; goto cleanup; } @@ -134,7 +134,7 @@ int data_file_mgr(void *param) p_data_new = malloc(DATA_FILE_MAX_LEN); if (p_data_new == NULL) { - log_error("malloc(content) error: OOM\n"); + log_error("malloc(content) error: OOM"); goto cleanup; } @@ -169,7 +169,7 @@ int data_file_mgr(void *param) len_data_new = editor_data_save(p_editor_data, p_data_new, DATA_FILE_MAX_LEN); if (len_data_new < 0) { - log_error("editor_data_save() error\n"); + log_error("editor_data_save() error"); goto cleanup; } line_total = split_data_lines(p_data_new, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES, 1, NULL); @@ -205,19 +205,19 @@ int data_file_mgr(void *param) if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640)) < 0) { - log_error("open(%s) error (%d)\n", path, errno); + log_error("open(%s) error (%d)", path, errno); goto cleanup; } if (write(fd, p_data_new, (size_t)len_data_new) < 0) { - log_error("write(len=%ld) error (%d)\n", len_data_new, errno); + log_error("write(len=%ld) error (%d)", len_data_new, errno); goto cleanup; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); fd = -1; goto cleanup; } @@ -225,19 +225,19 @@ int data_file_mgr(void *param) // Make another copy of the data file so that the user editored copy will be kept after upgrade / reinstall if ((fd = open(data_file_list[i].path, O_WRONLY | O_CREAT | O_TRUNC, 0640)) < 0) { - log_error("open(%s) error (%d)\n", data_file_list[i].path, errno); + log_error("open(%s) error (%d)", data_file_list[i].path, errno); goto cleanup; } if (write(fd, p_data_new, (size_t)len_data_new) < 0) { - log_error("write(len=%ld) error (%d)\n", len_data_new, errno); + log_error("write(len=%ld) error (%d)", len_data_new, errno); goto cleanup; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); fd = -1; goto cleanup; } @@ -261,12 +261,12 @@ int data_file_mgr(void *param) if (p_data != NULL && munmap(p_data, len_data) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); } if (fd >= 0 && close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); } return REDRAW; diff --git a/src/database.c b/src/database.c index 9f25bc99..7f49d062 100644 --- a/src/database.c +++ b/src/database.c @@ -43,7 +43,7 @@ MYSQL *db_open() db = mysql_init(NULL); if (db == NULL) { - log_error("mysql_init() failed\n"); + log_error("mysql_init() failed"); return NULL; } @@ -52,7 +52,7 @@ MYSQL *db_open() { if (errno != ENOENT) { - log_error("open(%s) error: %d\n", DB_ca_cert, errno); + log_error("open(%s) error: %d", DB_ca_cert, errno); } } else @@ -66,20 +66,20 @@ MYSQL *db_open() if (mysql_ssl_set(db, NULL, NULL, (have_ca_cert ? DB_ca_cert : NULL), NULL, NULL) != 0) { - log_error("mysql_ssl_set() error\n"); + log_error("mysql_ssl_set() error"); return NULL; } #ifdef HAVE_MARIADB_CLIENT if (mysql_optionsv(db, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify_server_cert) != 0) { - log_error("mysql_optionsv() error\n"); + log_error("mysql_optionsv() error"); return NULL; } #else if (mysql_options(db, MYSQL_OPT_SSL_MODE, &ssl_mode) != 0) { - log_error("mysql_options() error\n"); + log_error("mysql_options() error"); return NULL; } #endif @@ -87,14 +87,14 @@ MYSQL *db_open() if (mysql_real_connect(db, DB_host, DB_username, DB_password, DB_database, 0, NULL, 0) == NULL) { - log_error("mysql_real_connect() error: %s\n", mysql_error(db)); + log_error("mysql_real_connect() error: %s", mysql_error(db)); mysql_close(db); return NULL; } if (mysql_set_character_set(db, "utf8") != 0) { - log_error("Set character set error: %s\n", mysql_error(db)); + log_error("Set character set error: %s", mysql_error(db)); mysql_close(db); return NULL; } @@ -105,7 +105,7 @@ MYSQL *db_open() if (mysql_query(db, sql) != 0) { - log_error("Set timezone error: %s\n", mysql_error(db)); + log_error("Set timezone error: %s", mysql_error(db)); mysql_close(db); return NULL; } diff --git a/src/editor.c b/src/editor.c index a04605fd..c9db1dbf 100644 --- a/src/editor.c +++ b/src/editor.c @@ -38,21 +38,21 @@ int editor_memory_pool_init(void) { if (p_mp_data_line != NULL || p_mp_editor_data != NULL) { - log_error("Editor mem pool already initialized\n"); + log_error("Editor mem pool already initialized"); return -1; } p_mp_data_line = memory_pool_init(MAX_EDITOR_DATA_LINE_LENGTH, EDITOR_MEM_POOL_LINE_PER_CHUNK, EDITOR_MEM_POOL_CHUNK_LIMIT); if (p_mp_data_line == NULL) { - log_error("Memory pool init error\n"); + log_error("Memory pool init error"); return -2; } p_mp_editor_data = memory_pool_init(sizeof(EDITOR_DATA), 1, 1); if (p_mp_editor_data == NULL) { - log_error("Memory pool init error\n"); + log_error("Memory pool init error"); return -3; } @@ -85,14 +85,14 @@ EDITOR_DATA *editor_data_load(const char *p_data) if (p_data == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return NULL; } p_editor_data = memory_pool_alloc(p_mp_editor_data); if (p_editor_data == NULL) { - log_error("memory_pool_alloc() error\n"); + log_error("memory_pool_alloc() error"); return NULL; } @@ -111,7 +111,7 @@ EDITOR_DATA *editor_data_load(const char *p_data) p_data_line = memory_pool_alloc(p_mp_data_line); if (p_data_line == NULL) { - log_error("memory_pool_alloc() error: i = %d\n", i); + log_error("memory_pool_alloc() error: i = %d", i); // Cleanup editor_data_cleanup(p_editor_data); return NULL; @@ -161,7 +161,7 @@ long editor_data_save(const EDITOR_DATA *p_editor_data, char *p_data, size_t buf if (p_editor_data == NULL || p_data == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -169,7 +169,7 @@ long editor_data_save(const EDITOR_DATA *p_editor_data, char *p_data, size_t buf { if (current_pos + p_editor_data->display_line_lengths[i] + 1 > buf_len) { - log_error("Data buffer not longer enough %d > %d\n", current_pos + p_editor_data->display_line_lengths[i] + 1, buf_len); + log_error("Data buffer not longer enough %d > %d", current_pos + p_editor_data->display_line_lengths[i] + 1, buf_len); p_data[current_pos] = '\0'; return -2; } @@ -235,7 +235,7 @@ int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p if (p_editor_data == NULL || p_last_updated_line == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -272,7 +272,7 @@ int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p { if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES) { - log_debug("Split line error, display_line_total(%ld) reach limit(%d)\n", + log_debug("Split line error, display_line_total(%ld) reach limit(%d)", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); return -2; @@ -282,7 +282,7 @@ int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p p_data_line = memory_pool_alloc(p_mp_data_line); if (p_data_line == NULL) { - log_error("memory_pool_alloc() error\n"); + log_error("memory_pool_alloc() error"); return -2; } @@ -367,7 +367,7 @@ int editor_data_insert(EDITOR_DATA *p_editor_data, long *p_display_line, long *p // Insert blank display line after last_display_line if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES) { - log_debug("display_line_total over limit %d >= %d\n", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); + log_debug("display_line_total over limit %d >= %d", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); // Terminate prior display line with \n, to avoid error on cleanup if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0) @@ -469,7 +469,7 @@ int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p if (p_editor_data == NULL || p_last_updated_line == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -527,7 +527,7 @@ int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p } else { - log_error("Some strange character at display_line %ld, offset %ld: %d %d\n", + log_error("Some strange character at display_line %ld, offset %ld: %d %d", display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1]); str_len = 1; } @@ -759,7 +759,7 @@ int editor_display(EDITOR_DATA *p_editor_data) ch = igetch(100); // 0.1 second if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input { - log_debug("Ignore %d bytes of incomplete UTF8 character\n", str_len); + log_debug("Ignore %d bytes of incomplete UTF8 character", str_len); str_len = 0; break; } @@ -773,7 +773,7 @@ int editor_display(EDITOR_DATA *p_editor_data) // Refresh current action while user input if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } if (str_len == 0) // ch >= 32 && ch < 127 @@ -794,14 +794,14 @@ int editor_display(EDITOR_DATA *p_editor_data) if (editor_data_delete(p_editor_data, &display_line_out, &offset_out, &last_updated_line, 0) < 0) { - log_error("editor_data_delete() error\n"); + log_error("editor_data_delete() error"); } } if (editor_data_insert(p_editor_data, &display_line_out, &offset_out, input_str, str_len, &last_updated_line) < 0) { - log_error("editor_data_insert(str_len=%d) error\n", str_len); + log_error("editor_data_insert(str_len=%d) error", str_len); } else { @@ -844,7 +844,7 @@ int editor_display(EDITOR_DATA *p_editor_data) { if (mbstowcs(wcs, input_str, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } col_pos += (str_len == 1 ? 1 : (UTF8_fixed_width ? 2 : wcwidth(wcs[0]))); } @@ -877,7 +877,7 @@ int editor_display(EDITOR_DATA *p_editor_data) // Refresh current action while user input if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } del_line = 0; @@ -916,7 +916,7 @@ int editor_display(EDITOR_DATA *p_editor_data) if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out, &last_updated_line, del_line)) < 0) { - log_error("editor_data_delete() error: %d\n", str_len); + log_error("editor_data_delete() error: %d", str_len); } else { @@ -968,10 +968,10 @@ int editor_display(EDITOR_DATA *p_editor_data) switch (ch) { case KEY_NULL: - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); goto cleanup; case KEY_TIMEOUT: - log_debug("User input timeout\n"); + log_debug("User input timeout"); goto cleanup; case Ctrl('W'): case Ctrl('X'): @@ -1065,13 +1065,13 @@ int editor_display(EDITOR_DATA *p_editor_data) if (str_len > 4) { - log_error("Invalid UTF-8 data detected: str_len > 4\n"); + log_error("Invalid UTF-8 data detected: str_len > 4"); } if (mbstowcs(wcs, p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); @@ -1124,13 +1124,13 @@ int editor_display(EDITOR_DATA *p_editor_data) if (str_len > 4) { - log_error("Invalid UTF-8 data detected: str_len > 4\n"); + log_error("Invalid UTF-8 data detected: str_len > 4"); } if (mbstowcs(wcs, p_editor_data->p_display_lines[line_current - output_current_row + row_pos] + offset_in, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); @@ -1229,7 +1229,7 @@ int editor_display(EDITOR_DATA *p_editor_data) // Refresh current action while user input if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } if (input_ok) @@ -1246,12 +1246,12 @@ int editor_display(EDITOR_DATA *p_editor_data) len = p_editor_data->display_line_lengths[line_current]; if (len >= sizeof(buffer)) { - log_error("Buffer overflow: len=%ld line=%ld \n", len, line_current); + log_error("Buffer overflow: len=%ld line=%ld ", len, line_current); len = sizeof(buffer) - 1; } else if (len < 0) { - log_error("Incorrect line offsets: len=%ld line=%ld \n", len, line_current); + log_error("Incorrect line offsets: len=%ld line=%ld ", len, line_current); len = 0; } diff --git a/src/file_loader.c b/src/file_loader.c index 29995078..9a4e9e5b 100644 --- a/src/file_loader.c +++ b/src/file_loader.c @@ -45,19 +45,19 @@ int load_file(const char *filename) if (filename == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if ((fd = open(filename, O_RDONLY)) < 0) { - log_error("open(%s) error (%d)\n", filename, errno); + log_error("open(%s) error (%d)", filename, errno); return -1; } if (fstat(fd, &sb) < 0) { - log_error("fstat(fd) error (%d)\n", errno); + log_error("fstat(fd) error (%d)", errno); close(fd); return -1; } @@ -66,14 +66,14 @@ int load_file(const char *filename) p_data = mmap(NULL, data_len, PROT_READ, MAP_SHARED, fd, 0L); if (p_data == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -88,18 +88,18 @@ int load_file(const char *filename) if (shm_unlink(shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", shm_name, errno); + log_error("shm_unlink(%s) error (%d)", shm_name, errno); return -2; } if ((fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", shm_name, errno); + log_error("shm_open(%s) error (%d)", shm_name, errno); return -2; } if (ftruncate(fd, (off_t)size) == -1) { - log_error("ftruncate(size=%d) error (%d)\n", size, errno); + log_error("ftruncate(size=%d) error (%d)", size, errno); close(fd); return -2; } @@ -107,14 +107,14 @@ int load_file(const char *filename) p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -125,7 +125,7 @@ int load_file(const char *filename) if (munmap(p_data, data_len) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); munmap(p_shm, size); return -2; } @@ -136,7 +136,7 @@ int load_file(const char *filename) if (munmap(p_shm, size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -2; } @@ -150,7 +150,7 @@ int unload_file(const char *filename) if (filename == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -160,7 +160,7 @@ int unload_file(const char *filename) if (shm_unlink(shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", shm_name, errno); + log_error("shm_unlink(%s) error (%d)", shm_name, errno); return -2; } @@ -178,7 +178,7 @@ void *get_file_shm_readonly(const char *filename, size_t *p_data_len, long *p_li if (filename == NULL || p_data_len == NULL || p_line_total == NULL || pp_data == NULL || pp_line_offsets == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return NULL; } @@ -188,13 +188,13 @@ void *get_file_shm_readonly(const char *filename, size_t *p_data_len, long *p_li if ((fd = shm_open(shm_name, O_RDONLY, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", shm_name, errno); + log_error("shm_open(%s) error (%d)", shm_name, errno); return NULL; } if (fstat(fd, &sb) < 0) { - log_error("fstat(fd) error (%d)\n", errno); + log_error("fstat(fd) error (%d)", errno); close(fd); return NULL; } @@ -204,20 +204,20 @@ void *get_file_shm_readonly(const char *filename, size_t *p_data_len, long *p_li p_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return NULL; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return NULL; } if (((struct shm_header_t *)p_shm)->shm_size != size) { - log_error("Shared memory size mismatch (%ld != %ld)\n", ((struct shm_header_t *)p_shm)->shm_size, size); + log_error("Shared memory size mismatch (%ld != %ld)", ((struct shm_header_t *)p_shm)->shm_size, size); munmap(p_shm, size); return NULL; } @@ -243,7 +243,7 @@ int detach_file_shm(void *p_shm) if (munmap(p_shm, size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -2; } diff --git a/src/hash_dict.c b/src/hash_dict.c index 3b8786e7..1b815692 100644 --- a/src/hash_dict.c +++ b/src/hash_dict.c @@ -42,14 +42,14 @@ HASH_DICT *hash_dict_create(int item_count_limit) if (item_count_limit <= 0) { - log_error("Invalid item_count_limit(%d)<=0\n", item_count_limit); + log_error("Invalid item_count_limit(%d)<=0", item_count_limit); return NULL; } p_dict = (HASH_DICT *)malloc(sizeof(HASH_DICT)); if (p_dict == NULL) { - log_error("malloc(HASH_DICT) error\n"); + log_error("malloc(HASH_DICT) error"); return NULL; } @@ -68,7 +68,7 @@ HASH_DICT *hash_dict_create(int item_count_limit) p_dict->p_item_pool = memory_pool_init(sizeof(HASH_ITEM), MP_NODE_COUNT_PER_CHUNK, item_count_limit / MP_NODE_COUNT_PER_CHUNK + 1); if (p_dict->p_item_pool == NULL) { - log_error("memory_pool_init(HASH_ITEM) error\n"); + log_error("memory_pool_init(HASH_ITEM) error"); free(p_dict); return NULL; } @@ -78,7 +78,7 @@ HASH_DICT *hash_dict_create(int item_count_limit) p_dict->buckets[i] = calloc(HASH_DICT_BUCKET_SIZE, sizeof(HASH_ITEM *)); if (p_dict->buckets[i] == NULL) { - log_error("calloc(HASH_DICT_BUCKET_SIZE, HASH_ITEM) error at bucket %d\n", i); + log_error("calloc(HASH_DICT_BUCKET_SIZE, HASH_ITEM) error at bucket %d", i); p_dict->bucket_count = i; hash_dict_destroy(p_dict); return NULL; @@ -127,7 +127,7 @@ int hash_dict_set(HASH_DICT *p_dict, uint64_t key, int64_t value) if (p_dict == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -148,7 +148,7 @@ int hash_dict_set(HASH_DICT *p_dict, uint64_t key, int64_t value) p_item = (HASH_ITEM *)memory_pool_alloc(p_dict->p_item_pool); if (p_item == NULL) { - log_error("memory_pool_alloc(HASH_ITEM) error\n"); + log_error("memory_pool_alloc(HASH_ITEM) error"); return -1; } @@ -170,7 +170,7 @@ int hash_dict_inc(HASH_DICT *p_dict, uint64_t key, int64_t value_inc) if (p_dict == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -199,7 +199,7 @@ int hash_dict_get(HASH_DICT *p_dict, uint64_t key, int64_t *p_value) if (p_dict == NULL || p_value == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -229,7 +229,7 @@ int hash_dict_del(HASH_DICT *p_dict, uint64_t key) if (p_dict == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } diff --git a/src/init.c b/src/init.c index e071e35d..c139f4a3 100644 --- a/src/init.c +++ b/src/init.c @@ -93,7 +93,7 @@ int load_conf(const char *conf_file) q = strtok_r(NULL, CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) // Empty value { - log_error("Skip empty value of config item: %s\n", p); + log_error("Skip empty value of config item: %s", p); continue; } @@ -101,7 +101,7 @@ int load_conf(const char *conf_file) r = strtok_r(NULL, CONF_DELIM_WITH_SPACE, &saveptr); if (r != NULL && r[0] != '#') { - log_error("Skip config line with extra value %s = %s %s\n", p, q, r); + log_error("Skip config line with extra value %s = %s %s", p, q, r); continue; } @@ -138,7 +138,7 @@ int load_conf(const char *conf_file) BBS_max_client = atoi(q); if (BBS_max_client <= 0 || BBS_max_client > MAX_CLIENT_LIMIT) { - log_error("Ignore config bbs_max_client with incorrect value %d\n", BBS_max_client); + log_error("Ignore config bbs_max_client with incorrect value %d", BBS_max_client); BBS_max_client = MAX_CLIENT_LIMIT; } } @@ -147,7 +147,7 @@ int load_conf(const char *conf_file) BBS_max_client_per_ip = atoi(q); if (BBS_max_client_per_ip <= 0 || BBS_max_client_per_ip > MAX_CLIENT_PER_IP_LIMIT) { - log_error("Ignore config bbs_max_client with incorrect value %d\n", BBS_max_client_per_ip); + log_error("Ignore config bbs_max_client with incorrect value %d", BBS_max_client_per_ip); BBS_max_client_per_ip = MAX_CLIENT_PER_IP_LIMIT; } } @@ -159,7 +159,7 @@ int load_conf(const char *conf_file) if (y == NULL || m == NULL || d == NULL) { - log_error("Ignore config bbs_start_dt with incorrect value\n"); + log_error("Ignore config bbs_start_dt with incorrect value"); continue; } snprintf(BBS_start_dt, sizeof(BBS_start_dt), "%4s年%2s月%2s日", y, m, d); @@ -169,7 +169,7 @@ int load_conf(const char *conf_file) v = atoi(q); if (v <= 0) { - log_error("Ignore config bbs_sys_id with incorrect value %d\n", v); + log_error("Ignore config bbs_sys_id with incorrect value %d", v); continue; } BBS_sys_id = v; @@ -201,7 +201,7 @@ int load_conf(const char *conf_file) } else { - log_error("Unknown config %s = %s\n", p, q); + log_error("Unknown config %s = %s", p, q); } } diff --git a/src/io.c b/src/io.c index 6d05c011..66276bcf 100644 --- a/src/io.c +++ b/src/io.c @@ -77,7 +77,7 @@ int io_init(void) stdin_epollfd = epoll_create1(0); if (stdin_epollfd == -1) { - log_error("epoll_create1() error (%d)\n", errno); + log_error("epoll_create1() error (%d)", errno); return -1; } @@ -85,10 +85,10 @@ int io_init(void) ev.data.fd = STDIN_FILENO; if (epoll_ctl(stdin_epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) { - log_error("epoll_ctl(STDIN_FILENO) error (%d)\n", errno); + log_error("epoll_ctl(STDIN_FILENO) error (%d)", errno); if (close(stdin_epollfd) < 0) { - log_error("close(stdin_epollfd) error (%d)\n", errno); + log_error("close(stdin_epollfd) error (%d)", errno); } stdin_epollfd = -1; return -1; @@ -96,20 +96,20 @@ int io_init(void) if ((stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1) { - log_error("fcntl(F_GETFL) error (%d)\n", errno); + log_error("fcntl(F_GETFL) error (%d)", errno); if (close(stdin_epollfd) < 0) { - log_error("close(stdin_epollfd) error (%d)\n", errno); + log_error("close(stdin_epollfd) error (%d)", errno); } stdin_epollfd = -1; return -1; } if ((fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK)) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); if (close(stdin_epollfd) < 0) { - log_error("close(stdin_epollfd) error (%d)\n", errno); + log_error("close(stdin_epollfd) error (%d)", errno); } stdin_epollfd = -1; return -1; @@ -121,7 +121,7 @@ int io_init(void) stdout_epollfd = epoll_create1(0); if (stdout_epollfd == -1) { - log_error("epoll_create1() error (%d)\n", errno); + log_error("epoll_create1() error (%d)", errno); return -1; } @@ -129,10 +129,10 @@ int io_init(void) ev.data.fd = STDOUT_FILENO; if (epoll_ctl(stdout_epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) { - log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno); + log_error("epoll_ctl(STDOUT_FILENO) error (%d)", errno); if (close(stdout_epollfd) < 0) { - log_error("close(stdout_epollfd) error (%d)\n", errno); + log_error("close(stdout_epollfd) error (%d)", errno); } stdout_epollfd = -1; return -1; @@ -140,20 +140,20 @@ int io_init(void) if ((stdout_flags = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1) { - log_error("fcntl(F_GETFL) error (%d)\n", errno); + log_error("fcntl(F_GETFL) error (%d)", errno); if (close(stdout_epollfd) < 0) { - log_error("close(stdout_epollfd) error (%d)\n", errno); + log_error("close(stdout_epollfd) error (%d)", errno); } stdout_epollfd = -1; return -1; } if ((fcntl(STDOUT_FILENO, F_SETFL, stdout_flags | O_NONBLOCK)) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); if (close(stdout_epollfd) < 0) { - log_error("close(stdout_epollfd) error (%d)\n", errno); + log_error("close(stdout_epollfd) error (%d)", errno); } stdout_epollfd = -1; return -1; @@ -164,12 +164,12 @@ int io_init(void) { if ((stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1) { - log_error("fcntl(F_GETFL) error (%d)\n", errno); + log_error("fcntl(F_GETFL) error (%d)", errno); return -1; } if ((fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK)) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); return -1; } } @@ -178,12 +178,12 @@ int io_init(void) { if ((stdout_flags = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1) { - log_error("fcntl(F_GETFL) error (%d)\n", errno); + log_error("fcntl(F_GETFL) error (%d)", errno); return -1; } if ((fcntl(STDOUT_FILENO, F_SETFL, stdout_flags | O_NONBLOCK)) == -1) { - log_error("fcntl(F_SETFL) error (%d)\n", errno); + log_error("fcntl(F_SETFL) error (%d)", errno); return -1; } } @@ -202,7 +202,7 @@ void io_cleanup(void) if (close(stdin_epollfd) < 0) { - log_error("close(stdin_epollfd) error (%d)\n", errno); + log_error("close(stdin_epollfd) error (%d)", errno); } stdin_epollfd = -1; } @@ -214,7 +214,7 @@ void io_cleanup(void) if (close(stdout_epollfd) < 0) { - log_error("close(stdout_epollfd) error (%d)\n", errno); + log_error("close(stdout_epollfd) error (%d)", errno); } stdout_epollfd = -1; } @@ -262,7 +262,7 @@ int prints(const char *format, ...) { errno = EAGAIN; int need = stdout_buf_len + written - OUTPUT_BUF_SIZE; - log_error("Output buffer is full, additional %d bytes are required\n", need); + log_error("Output buffer is full, additional %d bytes are required", need); ret = -need; } } @@ -322,9 +322,9 @@ int iflush(void) if (errno != EINTR) { #ifdef HAVE_SYS_EPOLL_H - log_error("epoll_wait() error (%d)\n", errno); + log_error("epoll_wait() error (%d)", errno); #else - log_error("poll() error (%d)\n", errno); + log_error("poll() error (%d)", errno); #endif break; } @@ -344,9 +344,9 @@ int iflush(void) #endif { #ifdef HAVE_SYS_EPOLL_H - log_debug("STDOUT error events (%d)\n", events[i].events); + log_debug("STDOUT error events (%d)", events[i].events); #else - log_debug("STDOUT error events (%d)\n", pfds[i].revents); + log_debug("STDOUT error events (%d)", pfds[i].revents); #endif retry = 0; break; @@ -363,7 +363,7 @@ int iflush(void) ret = io_buf_conv(stdout_cd, stdout_buf, &stdout_buf_len, &stdout_buf_offset, stdout_conv, sizeof(stdout_conv), &stdout_conv_len); if (ret < 0) { - log_error("io_buf_conv(stdout, %d, %d, %d) error\n", stdout_buf_len, stdout_buf_offset, stdout_conv_len); + log_error("io_buf_conv(stdout, %d, %d, %d) error", stdout_buf_len, stdout_buf_offset, stdout_conv_len); stdout_buf_len = stdout_buf_offset; // Discard invalid sequence } } @@ -375,7 +375,7 @@ int iflush(void) ret = ssh_channel_write(SSH_channel, stdout_conv + stdout_conv_offset, (uint32_t)(stdout_conv_len - stdout_conv_offset)); if (ret == SSH_ERROR) { - log_debug("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); + log_debug("ssh_channel_write() error: %s", ssh_get_error(SSH_session)); retry = 0; break; } @@ -396,7 +396,7 @@ int iflush(void) } else { - log_debug("write(STDOUT) error (%d)\n", errno); + log_debug("write(STDOUT) error (%d)", errno); retry = 0; break; } @@ -457,7 +457,7 @@ int igetch(int timeout) { if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) { - log_debug("SSH channel is closed\n"); + log_debug("SSH channel is closed"); loop = 0; break; } @@ -479,9 +479,9 @@ int igetch(int timeout) if (errno != EINTR) { #ifdef HAVE_SYS_EPOLL_H - log_error("epoll_wait() error (%d)\n", errno); + log_error("epoll_wait() error (%d)", errno); #else - log_error("poll() error (%d)\n", errno); + log_error("poll() error (%d)", errno); #endif break; } @@ -502,9 +502,9 @@ int igetch(int timeout) #endif { #ifdef HAVE_SYS_EPOLL_H - log_debug("STDIN error events (%d)\n", events[i].events); + log_debug("STDIN error events (%d)", events[i].events); #else - log_debug("STDIN error events (%d)\n", pfds[i].revents); + log_debug("STDIN error events (%d)", pfds[i].revents); #endif loop = 0; break; @@ -530,7 +530,7 @@ int igetch(int timeout) ret = ssh_channel_read_nonblocking(SSH_channel, stdin_buf + stdin_buf_len, sizeof(stdin_buf) - (uint32_t)stdin_buf_len, 0); if (ret == SSH_ERROR) { - log_debug("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); + log_debug("ssh_channel_read_nonblocking() error: %s", ssh_get_error(SSH_session)); loop = 0; break; } @@ -567,7 +567,7 @@ int igetch(int timeout) } else { - log_debug("read(STDIN) error (%d)\n", errno); + log_debug("read(STDIN) error (%d)", errno); loop = 0; break; } @@ -590,7 +590,7 @@ int igetch(int timeout) #ifdef _DEBUG for (int j = stdin_buf_offset; j < stdin_buf_len; j++) { - log_debug("input: <--[%u]\n", (stdin_buf[j] + 256) % 256); + log_debug("input: <--[%u]", (stdin_buf[j] + 256) % 256); } #endif } @@ -600,7 +600,7 @@ int igetch(int timeout) ret = io_buf_conv(stdin_cd, stdin_buf, &stdin_buf_len, &stdin_buf_offset, stdin_conv, sizeof(stdin_conv), &stdin_conv_len); if (ret < 0) { - log_error("io_buf_conv(stdin, %d, %d, %d) error\n", stdin_buf_len, stdin_buf_offset, stdin_conv_len); + log_error("io_buf_conv(stdin, %d, %d, %d) error", stdin_buf_len, stdin_buf_offset, stdin_conv_len); stdin_buf_len = stdin_buf_offset; // Discard invalid sequence } @@ -608,7 +608,7 @@ int igetch(int timeout) #ifdef _DEBUG for (int j = stdin_conv_offset; j < stdin_conv_len; j++) { - log_debug("input_conv: <--[%u]\n", (stdin_conv[j] + 256) % 256); + log_debug("input_conv: <--[%u]", (stdin_conv[j] + 256) % 256); } #endif } @@ -1074,7 +1074,7 @@ int igetch(int timeout) #ifdef _DEBUG if (out != KEY_TIMEOUT && out != KEY_NULL) { - log_debug("output: -->[0x %x]\n", out); + log_debug("output: -->[0x %x]", out); } #endif @@ -1116,7 +1116,7 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char if (cd == (iconv_t)(-1) || p_buf == NULL || p_buf_len == NULL || p_buf_offset == NULL || p_conv == NULL || p_conv_len == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1142,7 +1142,7 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char if (out_bytes <= 0) { - log_error("No enough free space in p_conv, conv_len=%d, conv_size=%d\n", *p_conv_len, conv_size); + log_error("No enough free space in p_conv, conv_len=%d, conv_size=%d", *p_conv_len, conv_size); return -2; } @@ -1168,7 +1168,7 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char { if (errno == EINVAL) // Incomplete { - log_debug("iconv(inbytes=%zu, outbytes=%zu) error: EINVAL, in_buf[0]=%d\n", + log_debug("iconv(inbytes=%zu, outbytes=%zu) error: EINVAL, in_buf[0]=%d", in_bytes, out_bytes, (unsigned char)in_buf[0]); if (p_buf != in_buf) { @@ -1182,14 +1182,14 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char } else if (errno == E2BIG) { - log_error("iconv(inbytes=%zu, outbytes=%zu) error: E2BIG\n", in_bytes, out_bytes); + log_error("iconv(inbytes=%zu, outbytes=%zu) error: E2BIG", in_bytes, out_bytes); return -1; } else if (errno == EILSEQ) { if (in_bytes > out_bytes || out_bytes <= 0) { - log_error("iconv(inbytes=%zu, outbytes=%zu) error: EILSEQ\n", in_bytes, out_bytes); + log_error("iconv(inbytes=%zu, outbytes=%zu) error: EILSEQ", in_bytes, out_bytes); return -2; } @@ -1197,16 +1197,16 @@ int io_buf_conv(iconv_t cd, char *p_buf, int *p_buf_len, int *p_buf_offset, char if (in_bytes == 0) { in_bytes = (size_t)(*p_buf_len - *p_buf_offset); - log_debug("Reset in_bytes from 0 to %zu\n", in_bytes); + log_debug("Reset in_bytes from 0 to %zu", in_bytes); } - log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: EILSEQ, in_buf[0]=%d\n", + log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: EILSEQ, in_buf[0]=%d", in_bytes, out_bytes, (unsigned char)in_buf[0]); skip_current = 1; } else // something strange { - log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: %d, in_buf[0]=%d\n", + log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: %d, in_buf[0]=%d", in_bytes, out_bytes, errno, (unsigned char)in_buf[0]); *p_buf_offset = (int)(in_buf - p_buf); *p_conv_len = (int)(conv_size - out_bytes); @@ -1235,7 +1235,7 @@ int io_conv_init(const char *charset) if (charset == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1249,7 +1249,7 @@ int io_conv_init(const char *charset) stdin_cd = iconv_open(tocode, stdio_charset); if (stdin_cd == (iconv_t)(-1)) { - log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno); + log_error("iconv_open(%s->%s) error: %d", stdio_charset, tocode, errno); return -2; } @@ -1258,7 +1258,7 @@ int io_conv_init(const char *charset) stdout_cd = iconv_open(tocode, BBS_default_charset); if (stdout_cd == (iconv_t)(-1)) { - log_error("iconv_open(%s->%s) error: %d\n", BBS_default_charset, tocode, errno); + log_error("iconv_open(%s->%s) error: %d", BBS_default_charset, tocode, errno); iconv_close(stdin_cd); stdin_cd = (iconv_t)(-1); return -2; diff --git a/src/lml.c b/src/lml.c index 5db6a1df..399d0529 100644 --- a/src/lml.c +++ b/src/lml.c @@ -14,6 +14,7 @@ #include "lml.h" #include "log.h" #include "str_process.h" +#include "trie_dict.h" #include #include #include @@ -21,6 +22,7 @@ enum _lml_constant_t { + LML_TAG_NAME_BUF_LEN = 21, LML_TAG_PARAM_BUF_LEN = 256, LML_TAG_OUTPUT_BUF_LEN = 1024, LML_TAG_QUOTE_MAX_LEVEL = 10, @@ -162,36 +164,73 @@ const LML_TAG_DEF lml_tag_def[] = { static const int lml_tag_count = sizeof(lml_tag_def) / sizeof(LML_TAG_DEF); static int lml_tag_name_len[sizeof(lml_tag_def) / sizeof(LML_TAG_DEF)]; +static TRIE_NODE *p_lml_tag_dict; static int lml_ready = 0; -inline static void lml_init(void) +int lml_init(void) { + char tag_name_buf[LML_TAG_NAME_BUF_LEN]; int i; + int j; - if (!lml_ready) + if (lml_ready) + { + lml_cleanup(); + } + + p_lml_tag_dict = trie_dict_create(); + if (p_lml_tag_dict == NULL) + { + log_error("trie_dict_create(lml_tag_dict) error"); + return -1; + } + + for (i = 0; i < lml_tag_count; i++) { - for (i = 0; i < lml_tag_count; i++) + for (j = 0; j < sizeof(tag_name_buf) - 1 && lml_tag_def[i].tag_name[j] != '\0'; j++) + { + tag_name_buf[j] = (char)tolower(lml_tag_def[i].tag_name[j]); + } + tag_name_buf[j] = '\0'; + lml_tag_name_len[i] = j; + + if (trie_dict_set(p_lml_tag_dict, tag_name_buf, (int64_t)i) != 1) { - lml_tag_name_len[i] = (int)strlen(lml_tag_def[i].tag_name); + log_error("trie_dict_set(lml_tag_dict, %s, %d) error", tag_name_buf, i); + lml_cleanup(); + return -1; } + } + + lml_ready = 1; - lml_ready = 1; + return 0; +} + +void lml_cleanup(void) +{ + if (p_lml_tag_dict != NULL) + { + trie_dict_destroy(p_lml_tag_dict); + p_lml_tag_dict = NULL; } + + lml_ready = 0; } -#define CHECK_AND_APPEND_OUTPUT(out_buf, out_buf_len, out_buf_offset, tag_out, tag_out_len, line_width) \ - if ((tag_out_len) > 0) \ - { \ - if ((out_buf_offset) + (tag_out_len) >= (out_buf_len)) \ - { \ - log_error("Buffer is not longer enough for output string %d >= %d\n", (out_buf_offset) + (tag_out_len), (out_buf_len)); \ - out_buf[out_buf_offset] = '\0'; \ - return (out_buf_offset); \ - } \ - memcpy((out_buf) + (out_buf_offset), (tag_out), (size_t)(tag_out_len)); \ - *((out_buf) + (out_buf_offset) + (size_t)(tag_out_len)) = '\0'; \ - (line_width) += str_length((out_buf) + (out_buf_offset), 1); \ - (out_buf_offset) += (tag_out_len); \ +#define CHECK_AND_APPEND_OUTPUT(out_buf, out_buf_len, out_buf_offset, tag_out, tag_out_len, line_width) \ + if ((tag_out_len) > 0) \ + { \ + if ((out_buf_offset) + (tag_out_len) >= (out_buf_len)) \ + { \ + log_error("Buffer is not longer enough for output string %d >= %d", (out_buf_offset) + (tag_out_len), (out_buf_len)); \ + out_buf[out_buf_offset] = '\0'; \ + return (out_buf_offset); \ + } \ + memcpy((out_buf) + (out_buf_offset), (tag_out), (size_t)(tag_out_len)); \ + *((out_buf) + (out_buf_offset) + (size_t)(tag_out_len)) = '\0'; \ + (line_width) += str_length((out_buf) + (out_buf_offset), 1); \ + (out_buf_offset) += (tag_out_len); \ } int lml_render(const char *str_in, char *str_out, int buf_len, int width, int quote_mode) @@ -200,11 +239,14 @@ int lml_render(const char *str_in, char *str_out, int buf_len, int width, int qu clock_t clock_end; char c; + char tag_name_buf[LML_TAG_NAME_BUF_LEN]; char tag_param_buf[LML_TAG_PARAM_BUF_LEN]; char tag_output_buf[LML_TAG_OUTPUT_BUF_LEN]; int i; int j = 0; int k; + int last_i = -1; + int64_t tag_index; int tag_start_pos = -1; int tag_name_pos = -1; int tag_end_pos = -1; @@ -212,7 +254,6 @@ int lml_render(const char *str_in, char *str_out, int buf_len, int width, int qu int tag_output_len; int new_line = 1; int fb_quote_level = 0; - int tag_name_found; int line_width = 0; char tab_spaces[TAB_SIZE + 1]; int tab_width = 0; @@ -223,7 +264,11 @@ int lml_render(const char *str_in, char *str_out, int buf_len, int width, int qu size_t str_in_len = strlen(str_in); #endif - lml_init(); + if (!lml_ready) + { + log_error("LML module is not initialized"); + return -1; + } lml_tag_disabled = 0; lml_tag_quote_level = 0; @@ -238,7 +283,7 @@ int lml_render(const char *str_in, char *str_out, int buf_len, int width, int qu #ifdef _DEBUG if (i >= str_in_len) { - log_error("Bug: i(%d) >= str_in_len(%d)\n", i, str_in_len); + log_error("Bug: i(%d) >= str_in_len(%d)", i, str_in_len); break; } #endif @@ -398,74 +443,99 @@ int lml_render(const char *str_in, char *str_out, int buf_len, int width, int qu tag_name_pos++; } - for (tag_name_found = 0, k = 0; k < lml_tag_count; k++) + for (k = 0; k < sizeof(tag_name_buf) - 1 && tag_name_pos + k < tag_end_pos; k++) + { + if (str_in[tag_name_pos + k] == ' ' || str_in[tag_name_pos + k] == ']') + { + break; + } + tag_name_buf[k] = (char)tolower(str_in[tag_name_pos + k]); + } + tag_name_buf[k] = '\0'; + + k = -1; + if (tag_name_buf[0] != '\0') + { + tag_index = -1; + if (trie_dict_get(p_lml_tag_dict, tag_name_buf, (int64_t *)&tag_index) < 0) + { + log_error("trie_dict_get(lml_tag_dict, %s) error", tag_name_buf); + } + else + { + k = (int)tag_index; + } + } + + if (k != -1) { - if (strncasecmp(lml_tag_def[k].tag_name, str_in + tag_name_pos, (size_t)lml_tag_name_len[k]) == 0) + tag_param_pos = -1; + switch (str_in[tag_name_pos + lml_tag_name_len[k]]) { - tag_param_pos = -1; - switch (str_in[tag_name_pos + lml_tag_name_len[k]]) + case ' ': + tag_param_pos = tag_name_pos + lml_tag_name_len[k] + 1; + while (str_in[tag_param_pos] == ' ') + { + tag_param_pos++; + } + strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)); + tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0'; + case ']': + if (tag_param_pos == -1 && lml_tag_def[k].tag_output != NULL && lml_tag_def[k].default_param != NULL) // Apply default param if not defined { - case ' ': - tag_name_found = 1; - tag_param_pos = tag_name_pos + lml_tag_name_len[k] + 1; - while (str_in[tag_param_pos] == ' ') + strncpy(tag_param_buf, lml_tag_def[k].default_param, LML_TAG_PARAM_BUF_LEN - 1); + tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; + } + tag_output_len = 0; + if (!quote_mode) + { + if (lml_tag_def[k].tag_output != NULL) { - tag_param_pos++; + tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].tag_output, tag_param_buf); } - strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)); - tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0'; - case ']': - tag_name_found = 1; - if (tag_param_pos == -1 && lml_tag_def[k].tag_output != NULL && lml_tag_def[k].default_param != NULL) // Apply default param if not defined + else if (lml_tag_def[k].tag_filter_cb != NULL) { - strncpy(tag_param_buf, lml_tag_def[k].default_param, LML_TAG_PARAM_BUF_LEN - 1); - tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; + tag_output_len = lml_tag_def[k].tag_filter_cb( + lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 0); } - tag_output_len = 0; - if (!quote_mode) + } + else // if (quote_mode) + { + if (lml_tag_def[k].quote_mode_output != NULL) { - if (lml_tag_def[k].tag_output != NULL) - { - tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].tag_output, tag_param_buf); - } - else if (lml_tag_def[k].tag_filter_cb != NULL) - { - tag_output_len = lml_tag_def[k].tag_filter_cb( - lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 0); - } + tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].quote_mode_output, tag_param_buf); } - else // if (quote_mode) + else if (lml_tag_def[k].tag_filter_cb != NULL) { - if (lml_tag_def[k].quote_mode_output != NULL) - { - tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].quote_mode_output, tag_param_buf); - } - else if (lml_tag_def[k].tag_filter_cb != NULL) - { - tag_output_len = lml_tag_def[k].tag_filter_cb( - lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 1); - } + tag_output_len = lml_tag_def[k].tag_filter_cb( + lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 1); } + } - if (line_width + tag_output_len > width) + if (line_width + tag_output_len > width) + { + if (i > last_i) { + last_i = i; CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, "\n", 1, line_width); new_line = 1; line_width = 0; i--; // redo at current i continue; } - - CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, tag_output_buf, tag_output_len, line_width); - break; - default: // tag_name not match - continue; + else + { + continue; // Output current tag in plain text if line width exceeded + } } + + CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, tag_output_buf, tag_output_len, line_width); break; + default: + log_error("Bug: tag name not match"); } } - - if (!tag_name_found) + else // tag_name not found { if (line_width + 1 > width) { diff --git a/src/log.c b/src/log.c index 006ff6cd..acc0f59c 100644 --- a/src/log.c +++ b/src/log.c @@ -123,7 +123,7 @@ int log_printf(enum log_level_t log_level, const char *app_file, int app_line, c // Encoding error return -1; } - else if (offset + ret >= sizeof(buf)) + else if (offset + ret + 1 >= sizeof(buf)) { buf[sizeof(buf) - 2] = '\n'; // Add newline for truncated messages buf[sizeof(buf) - 1] = '\0'; // Ensure null termination @@ -135,11 +135,13 @@ int log_printf(enum log_level_t log_level, const char *app_file, int app_line, c } else { + buf[offset + ret] = '\n'; // Add newline + buf[offset + ret + 1] = '\0'; // Ensure null termination if (fputs(buf, fp_log) == EOF) { return -3; // Write error } - ret = offset + ret; + ret = offset + ret + 1; // Return number of characters written (including newline) } if (fflush(fp_log) == EOF) @@ -172,7 +174,7 @@ int log_restart(void) fp_common = fopen(path_common_log, "a"); if (fp_common == NULL) { - log_error("fopen(%s) error: %s\n", path_common_log, strerror(errno)); + log_error("fopen(%s) error: %s", path_common_log, strerror(errno)); return -1; } } @@ -182,7 +184,7 @@ int log_restart(void) fp_error = fopen(path_error_log, "a"); if (fp_error == NULL) { - log_error("fopen(%s) error: %s\n", path_error_log, strerror(errno)); + log_error("fopen(%s) error: %s", path_error_log, strerror(errno)); if (fp_common) { fclose(fp_common); diff --git a/src/login.c b/src/login.c index 5d569dd1..3448006a 100644 --- a/src/login.c +++ b/src/login.c @@ -155,14 +155,14 @@ int check_user(const char *username, const char *password) // Begin transaction if (mysql_query(db, "SET autocommit=0") != 0) { - log_error("SET autocommit=0 error: %s\n", mysql_error(db)); + log_error("SET autocommit=0 error: %s", mysql_error(db)); ret = -1; goto cleanup; } if (mysql_query(db, "BEGIN") != 0) { - log_error("Begin transaction error: %s\n", mysql_error(db)); + log_error("Begin transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -179,13 +179,13 @@ int check_user(const char *username, const char *password) ip_mask(client_addr, 1, '%')); if (mysql_query(db, sql) != 0) { - log_error("Query user_list error: %s\n", mysql_error(db)); + log_error("Query user_list error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_list data failed\n"); + log_error("Get user_list data failed"); ret = -1; goto cleanup; } @@ -212,13 +212,13 @@ int check_user(const char *username, const char *password) username); if (mysql_query(db, sql) != 0) { - log_error("Query user_list error: %s\n", mysql_error(db)); + log_error("Query user_list error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_list data failed\n"); + log_error("Get user_list data failed"); ret = -1; goto cleanup; } @@ -240,13 +240,13 @@ int check_user(const char *username, const char *password) username, password); if (mysql_query(db, sql) != 0) { - log_error("Query user_list error: %s\n", mysql_error(db)); + log_error("Query user_list error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_list data failed\n"); + log_error("Get user_list data failed"); ret = -1; goto cleanup; } @@ -267,7 +267,7 @@ int check_user(const char *username, const char *password) BBS_uid, hostaddr_client); if (mysql_query(db, sql) != 0) { - log_error("Insert into user_login_log error: %s\n", mysql_error(db)); + log_error("Insert into user_login_log error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -275,7 +275,7 @@ int check_user(const char *username, const char *password) // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -298,7 +298,7 @@ int check_user(const char *username, const char *password) username, password, hostaddr_client); if (mysql_query(db, sql) != 0) { - log_error("Insert into user_err_login_log error: %s\n", mysql_error(db)); + log_error("Insert into user_err_login_log error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -306,7 +306,7 @@ int check_user(const char *username, const char *password) // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -319,7 +319,7 @@ int check_user(const char *username, const char *password) // Set AUTOCOMMIT = 1 if (mysql_query(db, "SET autocommit=1") != 0) { - log_error("SET autocommit=1 error: %s\n", mysql_error(db)); + log_error("SET autocommit=1 error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -359,7 +359,7 @@ int check_user(const char *username, const char *password) BBS_uid); if (mysql_query(db, sql) != 0) { - log_error("Update user_pubinfo error: %s\n", mysql_error(db)); + log_error("Update user_pubinfo error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -381,7 +381,7 @@ int check_user(const char *username, const char *password) if (setenv("TZ", user_tz_env, 1) == -1) { - log_error("setenv(TZ = %s) error %d\n", user_tz_env, errno); + log_error("setenv(TZ = %s) error %d", user_tz_env, errno); return -3; } @@ -410,13 +410,13 @@ int load_user_info(MYSQL *db, int BBS_uid) BBS_uid); if (mysql_query(db, sql) != 0) { - log_error("Query user_pubinfo error: %s\n", mysql_error(db)); + log_error("Query user_pubinfo error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_pubinfo data failed\n"); + log_error("Get user_pubinfo data failed"); ret = -1; goto cleanup; } @@ -515,7 +515,7 @@ int user_online_add(MYSQL *db) hostaddr_client); if (mysql_query(db, sql) != 0) { - log_error("Add visit log error: %s\n", mysql_error(db)); + log_error("Add visit log error: %s", mysql_error(db)); return -1; } @@ -530,7 +530,7 @@ int user_online_add(MYSQL *db) getpid(), BBS_priv.uid, hostaddr_client); if (mysql_query(db, sql) != 0) { - log_error("Add user_online error: %s\n", mysql_error(db)); + log_error("Add user_online error: %s", mysql_error(db)); return -3; } @@ -546,7 +546,7 @@ int user_online_del(MYSQL *db) getpid()); if (mysql_query(db, sql) != 0) { - log_error("Delete user_online error: %s\n", mysql_error(db)); + log_error("Delete user_online error: %s", mysql_error(db)); return -1; } @@ -567,7 +567,7 @@ int user_online_exp(MYSQL *db) BBS_priv.uid); if (mysql_query(db, sql) != 0) { - log_error("Update user_pubinfo error: %s\n", mysql_error(db)); + log_error("Update user_pubinfo error: %s", mysql_error(db)); return -1; } @@ -596,7 +596,7 @@ int user_online_update(const char *action) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); return -1; } @@ -606,7 +606,7 @@ int user_online_update(const char *action) BBS_current_action, getpid()); if (mysql_query(db, sql) != 0) { - log_error("Update user_online error: %s\n", mysql_error(db)); + log_error("Update user_online error: %s", mysql_error(db)); return -2; } @@ -667,7 +667,7 @@ int user_update_agreement(void) BBS_priv.uid); if (mysql_query(db, sql) != 0) { - log_error("Update user_pubinfo error: %s\n", mysql_error(db)); + log_error("Update user_pubinfo error: %s", mysql_error(db)); ret = -1; goto cleanup; } diff --git a/src/main.c b/src/main.c index f13a2c19..7ba0952b 100644 --- a/src/main.c +++ b/src/main.c @@ -16,6 +16,7 @@ #include "file_loader.h" #include "init.h" #include "io.h" +#include "lml.h" #include "log.h" #include "menu.h" #include "net_server.h" @@ -218,7 +219,7 @@ int main(int argc, char *argv[]) log_error_redir(STDERR_FILENO); } - log_common("Starting %s\n", APP_INFO); + log_common("Starting %s", APP_INFO); // Load configuration if (load_conf(CONF_BBSD) < 0) @@ -235,7 +236,7 @@ int main(int argc, char *argv[]) // Get EULA modification tm if (stat(DATA_EULA, &file_stat) == -1) { - log_error("stat(%s) error\n", DATA_EULA, errno); + log_error("stat(%s) error", DATA_EULA, errno); goto cleanup; } BBS_eula_tm = file_stat.st_mtim.tv_sec; @@ -244,7 +245,7 @@ int main(int argc, char *argv[]) ret = mkdir(VAR_ARTICLE_CACHE_DIR, 0750); if (ret == -1 && errno != EEXIST) { - log_error("mkdir(%s) error (%d)\n", VAR_ARTICLE_CACHE_DIR, errno); + log_error("mkdir(%s) error (%d)", VAR_ARTICLE_CACHE_DIR, errno); goto cleanup; } @@ -252,67 +253,75 @@ int main(int argc, char *argv[]) ret = mkdir(VAR_SECTION_AID_LOC_DIR, 0750); if (ret == -1 && errno != EEXIST) { - log_error("mkdir(%s) error (%d)\n", VAR_SECTION_AID_LOC_DIR, errno); + log_error("mkdir(%s) error (%d)", VAR_SECTION_AID_LOC_DIR, errno); goto cleanup; } // Initialize data pools if ((fp = fopen(VAR_ARTICLE_BLOCK_SHM, "w")) == NULL) { - log_error("fopen(%s) error\n", VAR_ARTICLE_BLOCK_SHM); + log_error("fopen(%s) error", VAR_ARTICLE_BLOCK_SHM); goto cleanup; } fclose(fp); if ((fp = fopen(VAR_SECTION_LIST_SHM, "w")) == NULL) { - log_error("fopen(%s) error\n", VAR_SECTION_LIST_SHM); + log_error("fopen(%s) error", VAR_SECTION_LIST_SHM); goto cleanup; } fclose(fp); if ((fp = fopen(VAR_TRIE_DICT_SHM, "w")) == NULL) { - log_error("fopen(%s) error\n", VAR_TRIE_DICT_SHM); + log_error("fopen(%s) error", VAR_TRIE_DICT_SHM); goto cleanup; } fclose(fp); if ((fp = fopen(VAR_USER_LIST_SHM, "w")) == NULL) { - log_error("fopen(%s) error\n", VAR_USER_LIST_SHM); + log_error("fopen(%s) error", VAR_USER_LIST_SHM); goto cleanup; } fclose(fp); if (trie_dict_init(VAR_TRIE_DICT_SHM, TRIE_NODE_PER_POOL) < 0) { - log_error("trie_dict_init(%s, %d) error\n", VAR_TRIE_DICT_SHM, TRIE_NODE_PER_POOL); + log_error("trie_dict_init(%s, %d) error", VAR_TRIE_DICT_SHM, TRIE_NODE_PER_POOL); goto cleanup; } if (article_block_init(VAR_ARTICLE_BLOCK_SHM, BBS_article_limit_per_section * BBS_max_section / BBS_article_count_per_block) < 0) { - log_error("article_block_init(%s, %d) error\n", VAR_ARTICLE_BLOCK_SHM, BBS_article_limit_per_section * BBS_max_section / BBS_article_count_per_block); + log_error("article_block_init(%s, %d) error", VAR_ARTICLE_BLOCK_SHM, BBS_article_limit_per_section * BBS_max_section / BBS_article_count_per_block); goto cleanup; } if (section_list_init(VAR_SECTION_LIST_SHM) < 0) { - log_error("section_list_pool_init(%s) error\n", VAR_SECTION_LIST_SHM); + log_error("section_list_pool_init(%s) error", VAR_SECTION_LIST_SHM); + goto cleanup; + } + + // Init LML module + if (lml_init() < 0) + { + log_error("lml_init() error"); goto cleanup; } // Load BBS cmd if (load_cmd() < 0) { + log_error("load_cmd() error"); goto cleanup; } // Load menus if (load_menu(&bbs_menu, CONF_MENU) < 0) { - log_error("load_menu(bbs_menu) error\n"); + log_error("load_menu(bbs_menu) error"); goto cleanup; } if (load_menu(&top10_menu, CONF_TOP10_MENU) < 0) { - log_error("load_menu(top10_menu) error\n"); + log_error("load_menu(top10_menu) error"); goto cleanup; } top10_menu.allow_exit = 1; @@ -322,31 +331,31 @@ int main(int argc, char *argv[]) { if (load_file(data_files_load_startup[i]) < 0) { - log_error("load_file(%s) error\n", data_files_load_startup[i]); + log_error("load_file(%s) error", data_files_load_startup[i]); } } // Load user_list and online_user_list if (user_list_pool_init(VAR_USER_LIST_SHM) < 0) { - log_error("user_list_pool_init(%s) error\n", VAR_USER_LIST_SHM); + log_error("user_list_pool_init(%s) error", VAR_USER_LIST_SHM); goto cleanup; } if (user_list_pool_reload(0) < 0) { - log_error("user_list_pool_reload(all_user) error\n"); + log_error("user_list_pool_reload(all_user) error"); goto cleanup; } if (user_list_pool_reload(1) < 0) { - log_error("user_list_pool_reload(online_user) error\n"); + log_error("user_list_pool_reload(online_user) error"); goto cleanup; } // Load section config and gen_ex if (load_section_config_from_db(1) < 0) { - log_error("load_section_config_from_db(0) error\n"); + log_error("load_section_config_from_db(0) error"); goto cleanup; } @@ -358,18 +367,18 @@ int main(int argc, char *argv[]) { if ((ret = append_articles_from_db(last_aid + 1, 1, LOAD_ARTICLE_COUNT_LIMIT)) < 0) { - log_error("append_articles_from_db(0, 1, %d) error\n", LOAD_ARTICLE_COUNT_LIMIT); + log_error("append_articles_from_db(0, 1, %d) error", LOAD_ARTICLE_COUNT_LIMIT); goto cleanup; } last_aid = article_block_last_aid(); } while (ret == LOAD_ARTICLE_COUNT_LIMIT); - log_common("Initially load %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid()); + log_common("Initially load %d articles, last_aid = %d", article_block_article_count(), article_block_last_aid()); if ((ret = user_stat_update()) < 0) { - log_error("user_stat_update() error\n"); + log_error("user_stat_update() error"); goto cleanup; } @@ -377,38 +386,38 @@ int main(int argc, char *argv[]) act.sa_handler = sig_hup_handler; if (sigaction(SIGHUP, &act, NULL) == -1) { - log_error("set signal action of SIGHUP error: %d\n", errno); + log_error("set signal action of SIGHUP error: %d", errno); goto cleanup; } act.sa_handler = sig_chld_handler; if (sigaction(SIGCHLD, &act, NULL) == -1) { - log_error("set signal action of SIGCHLD error: %d\n", errno); + log_error("set signal action of SIGCHLD error: %d", errno); goto cleanup; } act.sa_handler = sig_term_handler; if (sigaction(SIGTERM, &act, NULL) == -1) { - log_error("set signal action of SIGTERM error: %d\n", errno); + log_error("set signal action of SIGTERM error: %d", errno); goto cleanup; } act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, NULL) == -1) { - log_error("set signal action of SIGPIPE error: %d\n", errno); + log_error("set signal action of SIGPIPE error: %d", errno); goto cleanup; } act.sa_handler = SIG_IGN; if (sigaction(SIGUSR1, &act, NULL) == -1) { - log_error("set signal action of SIGUSR1 error: %d\n", errno); + log_error("set signal action of SIGUSR1 error: %d", errno); goto cleanup; } // Launch section_list_loader process if (section_list_loader_launch() < 0) { - log_error("section_list_loader_launch() error\n"); + log_error("section_list_loader_launch() error"); goto cleanup; } @@ -423,7 +432,7 @@ int main(int argc, char *argv[]) if (kill(section_list_loader_pid, SIGTERM) < 0) { - log_error("Send SIGTERM signal failed (%d)\n", errno); + log_error("Send SIGTERM signal failed (%d)", errno); } for (i = 0; SYS_child_exit == 0 && i < 5; i++) @@ -433,14 +442,14 @@ int main(int argc, char *argv[]) if ((ret = waitpid(section_list_loader_pid, NULL, WNOHANG)) < 0) { - log_error("waitpid(%d) error (%d)\n", section_list_loader_pid, errno); + log_error("waitpid(%d) error (%d)", section_list_loader_pid, errno); } else if (ret == 0) { - log_common("Force kill section_list_loader process (%d)\n", section_list_loader_pid); + log_common("Force kill section_list_loader process (%d)", section_list_loader_pid); if (kill(section_list_loader_pid, SIGKILL) < 0) { - log_error("Send SIGKILL signal failed (%d)\n", errno); + log_error("Send SIGKILL signal failed (%d)", errno); } } } @@ -450,7 +459,7 @@ int main(int argc, char *argv[]) { if (unload_file(data_files_load_startup[i]) < 0) { - log_error("unload_file(%s) error\n", data_files_load_startup[i]); + log_error("unload_file(%s) error", data_files_load_startup[i]); } } @@ -458,6 +467,9 @@ int main(int argc, char *argv[]) unload_menu(&bbs_menu); unload_menu(&top10_menu); + // Cleanup LML module + lml_cleanup(); + // Cleanup data pools section_list_cleanup(); article_block_cleanup(); @@ -466,22 +478,22 @@ int main(int argc, char *argv[]) if (unlink(VAR_ARTICLE_BLOCK_SHM) < 0) { - log_error("unlink(%s) error\n", VAR_ARTICLE_BLOCK_SHM); + log_error("unlink(%s) error", VAR_ARTICLE_BLOCK_SHM); } if (unlink(VAR_SECTION_LIST_SHM) < 0) { - log_error("unlink(%s) error\n", VAR_SECTION_LIST_SHM); + log_error("unlink(%s) error", VAR_SECTION_LIST_SHM); } if (unlink(VAR_TRIE_DICT_SHM) < 0) { - log_error("unlink(%s) error\n", VAR_TRIE_DICT_SHM); + log_error("unlink(%s) error", VAR_TRIE_DICT_SHM); } if (unlink(VAR_USER_LIST_SHM) < 0) { - log_error("unlink(%s) error\n", VAR_SECTION_LIST_SHM); + log_error("unlink(%s) error", VAR_SECTION_LIST_SHM); } - log_common("Main process exit normally\n"); + log_common("Main process exit normally"); log_end(); diff --git a/src/memory_pool.c b/src/memory_pool.c index 0a5d2e95..9bf4eac3 100644 --- a/src/memory_pool.c +++ b/src/memory_pool.c @@ -21,14 +21,14 @@ MEMORY_POOL *memory_pool_init(size_t node_size, size_t node_count_per_chunk, int if (node_size < sizeof(void *)) { - log_error("Error: node_size < sizeof(void *)\n"); + log_error("Error: node_size < sizeof(void *)"); return NULL; } p_pool = malloc(sizeof(MEMORY_POOL)); if (p_pool == NULL) { - log_error("malloc(MEMORY_POOL) error: OOM\n"); + log_error("malloc(MEMORY_POOL) error: OOM"); return NULL; } @@ -41,7 +41,7 @@ MEMORY_POOL *memory_pool_init(size_t node_size, size_t node_count_per_chunk, int p_pool->p_chunks = malloc(sizeof(void *) * (size_t)chunk_count_limit); if (p_pool->p_chunks == NULL) { - log_error("malloc(sizeof(void *) * %d) error: OOM\n", chunk_count_limit); + log_error("malloc(sizeof(void *) * %d) error: OOM", chunk_count_limit); free(p_pool); return NULL; } @@ -62,7 +62,7 @@ void memory_pool_cleanup(MEMORY_POOL *p_pool) if (p_pool->node_count_allocated > 0) { - log_error("Still have %d in-use nodes\n", p_pool->node_count_allocated); + log_error("Still have %d in-use nodes", p_pool->node_count_allocated); } while (p_pool->chunk_count > 0) @@ -83,13 +83,13 @@ inline static void *memory_pool_add_chunk(MEMORY_POOL *p_pool) if (p_pool->chunk_count >= p_pool->chunk_count_limit) { - log_error("Chunk count limit %d reached\n", p_pool->chunk_count); + log_error("Chunk count limit %d reached", p_pool->chunk_count); return NULL; } p_chunk = malloc(p_pool->node_size * p_pool->node_count_per_chunk); if (p_chunk == NULL) { - log_error("malloc(%d * %d) error: OOM\n", p_pool->node_size, p_pool->node_count_per_chunk); + log_error("malloc(%d * %d) error: OOM", p_pool->node_size, p_pool->node_count_per_chunk); return NULL; } @@ -117,13 +117,13 @@ void *memory_pool_alloc(MEMORY_POOL *p_pool) if (p_pool == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return NULL; } if (p_pool->p_free == NULL && memory_pool_add_chunk(p_pool) == NULL) { - log_error("Add chunk error\n"); + log_error("Add chunk error"); return NULL; } @@ -140,7 +140,7 @@ void memory_pool_free(MEMORY_POOL *p_pool, void *p_node) { if (p_pool == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return; } @@ -163,7 +163,7 @@ int memory_pool_check_node(MEMORY_POOL *p_pool, void *p_node) if (p_pool == NULL || p_node == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -179,13 +179,13 @@ int memory_pool_check_node(MEMORY_POOL *p_pool, void *p_node) } else { - log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)\n", + log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)", i, p_node >= p_pool->p_chunks[i], (char *)(p_pool->p_chunks[i]) + chunk_size); return -3; } } } - log_error("Address of node is not in range of chunks\n"); + log_error("Address of node is not in range of chunks"); return -2; } diff --git a/src/menu.c b/src/menu.c index 17df7865..d771550f 100644 --- a/src/menu.c +++ b/src/menu.c @@ -63,7 +63,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) if (p_menu_set == NULL || conf_file == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -74,7 +74,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) p_menu_set->p_menu_name_dict = trie_dict_create(); if (p_menu_set->p_menu_name_dict == NULL) { - log_error("trie_dict_create() error\n"); + log_error("trie_dict_create() error"); return -1; } @@ -82,13 +82,13 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) p_menu_set->p_menu_screen_dict = trie_dict_create(); if (p_menu_set->p_menu_screen_dict == NULL) { - log_error("trie_dict_create() error\n"); + log_error("trie_dict_create() error"); return -1; } if ((fin = fopen(conf_file, "r")) == NULL) { - log_error("Open %s failed\n", conf_file); + log_error("Open %s failed", conf_file); return -2; } @@ -105,18 +105,18 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", p_menu_set->shm_name, errno); + log_error("shm_unlink(%s) error (%d)", p_menu_set->shm_name, errno); return -2; } if ((fd = shm_open(p_menu_set->shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", p_menu_set->shm_name, errno); + log_error("shm_open(%s) error (%d)", p_menu_set->shm_name, errno); return -2; } if (ftruncate(fd, (off_t)size) == -1) { - log_error("ftruncate(size=%d) error (%d)\n", size, errno); + log_error("ftruncate(size=%d) error (%d)", size, errno); close(fd); return -2; } @@ -124,14 +124,14 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -175,13 +175,13 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) { if (p_menu != NULL) { - log_error("Incomplete menu definition in menu config line %d\n", fin_line); + log_error("Incomplete menu definition in menu config line %d", fin_line); return -1; } if (p_menu_set->menu_count >= MAX_MENUS) { - log_error("Menu count (%d) exceed limit (%d)\n", p_menu_set->menu_count, MAX_MENUS); + log_error("Menu count (%d) exceed limit (%d)", p_menu_set->menu_count, MAX_MENUS); return -3; } menu_id = (MENU_ID)p_menu_set->menu_count; @@ -199,7 +199,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu name in menu config line %d\n", fin_line); + log_error("Error menu name in menu config line %d", fin_line); return -1; } p = q; @@ -209,13 +209,13 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu name in menu config line %d\n", fin_line); + log_error("Error menu name in menu config line %d", fin_line); return -1; } if (q - p > sizeof(p_menu->name) - 1) { - log_error("Too longer menu name in menu config line %d\n", fin_line); + log_error("Too longer menu name in menu config line %d", fin_line); return -1; } strncpy(p_menu->name, p, sizeof(p_menu->name) - 1); @@ -223,14 +223,14 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) if (trie_dict_set(p_menu_set->p_menu_name_dict, p_menu->name, (int64_t)menu_id) != 1) { - log_error("Error set menu dict [%s]\n", p_menu->name); + log_error("Error set menu dict [%s]", p_menu->name); } // Check syntax q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q != NULL) { - log_error("Unknown extra content in menu config line %d\n", fin_line); + log_error("Unknown extra content in menu config line %d", fin_line); return -1; } @@ -259,12 +259,12 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) // BEGIN of menu item if (p_menu->item_count >= MAX_ITEMS_PER_MENU) { - log_error("Menuitem count per menu (%d) exceed limit (%d)\n", p_menu->item_count, MAX_ITEMS_PER_MENU); + log_error("Menuitem count per menu (%d) exceed limit (%d)", p_menu->item_count, MAX_ITEMS_PER_MENU); return -1; } if (p_menu_set->menu_item_count >= MAX_MENUITEMS) { - log_error("Menuitem count (%d) exceed limit (%d)\n", p_menu_set->menu_item_count, MAX_MENUITEMS); + log_error("Menuitem count (%d) exceed limit (%d)", p_menu_set->menu_item_count, MAX_MENUITEMS); return -3; } menu_item_id = (MENU_ITEM_ID)p_menu_set->menu_item_count; @@ -292,14 +292,14 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu item action in menu config line %d\n", fin_line); + log_error("Error menu item action in menu config line %d", fin_line); return -1; } } if (q - p > sizeof(p_menu_item->action) - 1) { - log_error("Too longer menu action in menu config line %d\n", fin_line); + log_error("Too longer menu action in menu config line %d", fin_line); return -1; } strncpy(p_menu_item->action, p, sizeof(p_menu_item->action) - 1); @@ -309,7 +309,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu item row in menu config line %d\n", fin_line); + log_error("Error menu item row in menu config line %d", fin_line); return -1; } p = q; @@ -319,7 +319,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu item row in menu config line %d\n", fin_line); + log_error("Error menu item row in menu config line %d", fin_line); return -1; } p_menu_item->row = (int16_t)atoi(p); @@ -328,7 +328,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu item col in menu config line %d\n", fin_line); + log_error("Error menu item col in menu config line %d", fin_line); return -1; } p = q; @@ -338,7 +338,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu item col in menu config line %d\n", fin_line); + log_error("Error menu item col in menu config line %d", fin_line); return -1; } p_menu_item->col = (int16_t)atoi(p); @@ -347,7 +347,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu item priv in menu config line %d\n", fin_line); + log_error("Error menu item priv in menu config line %d", fin_line); return -1; } p = q; @@ -357,7 +357,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu item priv in menu config line %d\n", fin_line); + log_error("Error menu item priv in menu config line %d", fin_line); return -1; } p_menu_item->priv = atoi(p); @@ -366,7 +366,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu item level in menu config line %d\n", fin_line); + log_error("Error menu item level in menu config line %d", fin_line); return -1; } p = q; @@ -376,7 +376,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu item level in menu config line %d\n", fin_line); + log_error("Error menu item level in menu config line %d", fin_line); return -1; } p_menu_item->level = atoi(p); @@ -385,7 +385,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL || *q != '\"') { - log_error("Error menu item name in menu config line %d\n", fin_line); + log_error("Error menu item name in menu config line %d", fin_line); return -1; } q++; @@ -405,14 +405,14 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\"' || *(q + 1) != '\0') { - log_error("Error menu item name in menu config line %d\n", fin_line); + log_error("Error menu item name in menu config line %d", fin_line); return -1; } *q = '\0'; if (q - p > sizeof(p_menu_item->name) - 1) { - log_error("Too longer menu name in menu config line %d\n", fin_line); + log_error("Too longer menu name in menu config line %d", fin_line); return -1; } strncpy(p_menu_item->name, p, sizeof(p_menu_item->name) - 1); @@ -422,7 +422,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr); if (q == NULL || (q = strchr(q, '\"')) == NULL) { - log_error("Error menu item text in menu config line %d\n", fin_line); + log_error("Error menu item text in menu config line %d", fin_line); return -1; } q++; @@ -442,14 +442,14 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\"') { - log_error("Error menu item text in menu config line %d\n", fin_line); + log_error("Error menu item text in menu config line %d", fin_line); return -1; } *q = '\0'; if (q - p > sizeof(p_menu_item->text) - 1) { - log_error("Too longer menu item text in menu config line %d\n", fin_line); + log_error("Too longer menu item text in menu config line %d", fin_line); return -1; } strncpy(p_menu_item->text, p, sizeof(p_menu_item->text) - 1); @@ -459,7 +459,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q != NULL) { - log_error("Unknown extra content in menu config line %d\n", fin_line); + log_error("Unknown extra content in menu config line %d", fin_line); return -1; } } @@ -471,7 +471,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu title row in menu config line %d\n", fin_line); + log_error("Error menu title row in menu config line %d", fin_line); return -1; } p = q; @@ -481,7 +481,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu title row in menu config line %d\n", fin_line); + log_error("Error menu title row in menu config line %d", fin_line); return -1; } p_menu->title.row = (int16_t)atoi(p); @@ -490,7 +490,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu title col in menu config line %d\n", fin_line); + log_error("Error menu title col in menu config line %d", fin_line); return -1; } p = q; @@ -500,7 +500,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu title col in menu config line %d\n", fin_line); + log_error("Error menu title col in menu config line %d", fin_line); return -1; } p_menu->title.col = (int16_t)atoi(p); @@ -509,7 +509,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr); if (q == NULL || (q = strchr(q, '\"')) == NULL) { - log_error("Error menu title text in menu config line %d\n", fin_line); + log_error("Error menu title text in menu config line %d", fin_line); return -1; } q++; @@ -529,14 +529,14 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\"') { - log_error("Error menu title text in menu config line %d\n", fin_line); + log_error("Error menu title text in menu config line %d", fin_line); return -1; } *q = '\0'; if (q - p > sizeof(p_menu->title.text) - 1) { - log_error("Too longer menu title text in menu config line %d\n", fin_line); + log_error("Too longer menu title text in menu config line %d", fin_line); return -1; } strncpy(p_menu->title.text, p, sizeof(p_menu->title.text) - 1); @@ -546,7 +546,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q != NULL) { - log_error("Unknown extra content in menu config line %d\n", fin_line); + log_error("Unknown extra content in menu config line %d", fin_line); return -1; } } @@ -558,7 +558,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu screen row in menu config line %d\n", fin_line); + log_error("Error menu screen row in menu config line %d", fin_line); return -1; } p = q; @@ -568,7 +568,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu screen row in menu config line %d\n", fin_line); + log_error("Error menu screen row in menu config line %d", fin_line); return -1; } p_menu->screen_row = (int16_t)atoi(p); @@ -577,7 +577,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu screen col in menu config line %d\n", fin_line); + log_error("Error menu screen col in menu config line %d", fin_line); return -1; } p = q; @@ -587,7 +587,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu screen col in menu config line %d\n", fin_line); + log_error("Error menu screen col in menu config line %d", fin_line); return -1; } p_menu->screen_col = (int16_t)atoi(p); @@ -596,7 +596,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu screen name in menu config line %d\n", fin_line); + log_error("Error menu screen name in menu config line %d", fin_line); return -1; } p = q; @@ -606,7 +606,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu screen name in menu config line %d\n", fin_line); + log_error("Error menu screen name in menu config line %d", fin_line); return -1; } strncpy(p_menu->screen_name, p, sizeof(p_menu->screen_name) - 1); @@ -616,7 +616,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q != NULL) { - log_error("Unknown extra content in menu config line %d\n", fin_line); + log_error("Unknown extra content in menu config line %d", fin_line); return -1; } } @@ -626,7 +626,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu page row in menu config line %d\n", fin_line); + log_error("Error menu page row in menu config line %d", fin_line); return -1; } p = q; @@ -636,7 +636,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu page row in menu config line %d\n", fin_line); + log_error("Error menu page row in menu config line %d", fin_line); return -1; } p_menu->page_row = (int16_t)atoi(p); @@ -645,7 +645,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu page col in menu config line %d\n", fin_line); + log_error("Error menu page col in menu config line %d", fin_line); return -1; } p = q; @@ -655,7 +655,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu page col in menu config line %d\n", fin_line); + log_error("Error menu page col in menu config line %d", fin_line); return -1; } p_menu->page_col = (int16_t)atoi(p); @@ -664,7 +664,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q == NULL) { - log_error("Error menu page item limit in menu config line %d\n", fin_line); + log_error("Error menu page item limit in menu config line %d", fin_line); return -1; } p = q; @@ -674,7 +674,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu page item limit in menu config line %d\n", fin_line); + log_error("Error menu page item limit in menu config line %d", fin_line); return -1; } p_menu->page_item_limit = (int16_t)atoi(p); @@ -683,7 +683,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q != NULL) { - log_error("Unknown extra content in menu config line %d\n", fin_line); + log_error("Unknown extra content in menu config line %d", fin_line); return -1; } } @@ -695,7 +695,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q != NULL) { - log_error("Unknown extra content in menu config line %d\n", fin_line); + log_error("Unknown extra content in menu config line %d", fin_line); return -1; } } @@ -705,7 +705,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) { if (p_menu_set->menu_item_count >= MAX_MENUS) { - log_error("Menu screen count (%d) exceed limit (%d)\n", p_menu_set->menu_screen_count, MAX_MENUS); + log_error("Menu screen count (%d) exceed limit (%d)", p_menu_set->menu_screen_count, MAX_MENUS); return -3; } screen_id = (MENU_SCREEN_ID)p_menu_set->menu_screen_count; @@ -720,7 +720,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) } if (*q != '\0') { - log_error("Error menu screen name in menu config line %d\n", fin_line); + log_error("Error menu screen name in menu config line %d", fin_line); return -1; } strncpy(p_screen->name, p, sizeof(p_screen->name) - 1); @@ -728,14 +728,14 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) if (trie_dict_set(p_menu_set->p_menu_screen_dict, p_screen->name, (int64_t)screen_id) != 1) { - log_error("Error set menu screen dict [%s]\n", p_screen->name); + log_error("Error set menu screen dict [%s]", p_screen->name); } // Check syntax q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); if (q != NULL) { - log_error("Unknown extra content in menu config line %d\n", fin_line); + log_error("Unknown extra content in menu config line %d", fin_line); return -1; } @@ -756,7 +756,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) { if (p_menu_set->p_menu_screen_buf_free + 1 > q) { - log_error("Menu screen buffer depleted (%p + 1 > %p)\n", p_menu_set->p_menu_screen_buf_free, q); + log_error("Menu screen buffer depleted (%p + 1 > %p)", p_menu_set->p_menu_screen_buf_free, q); return -3; } @@ -769,7 +769,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) // Clear line if (p_menu_set->p_menu_screen_buf_free + strlen(CTRL_SEQ_CLR_LINE) > q) { - log_error("Menu screen buffer depleted (%p + %d > %p)\n", p_menu_set->p_menu_screen_buf_free, q, strlen(CTRL_SEQ_CLR_LINE)); + log_error("Menu screen buffer depleted (%p + %d > %p)", p_menu_set->p_menu_screen_buf_free, q, strlen(CTRL_SEQ_CLR_LINE)); return -3; } p_menu_set->p_menu_screen_buf_free = stpcpy(p_menu_set->p_menu_screen_buf_free, CTRL_SEQ_CLR_LINE); @@ -779,7 +779,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) { if (p_menu_set->p_menu_screen_buf_free + 2 > q) { - log_error("Menu screen buffer depleted (%p + 2 > %p)\n", p_menu_set->p_menu_screen_buf_free, q); + log_error("Menu screen buffer depleted (%p + 2 > %p)", p_menu_set->p_menu_screen_buf_free, q); return -3; } @@ -797,13 +797,13 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) if (p_screen->buf_length == -1) { - log_error("End of menu screen [%s] not found\n", p_screen->name); + log_error("End of menu screen [%s] not found", p_screen->name); } } } else // Invalid prefix { - log_error("Error in menu config line %d\n", fin_line); + log_error("Error in menu config line %d", fin_line); return -1; } } @@ -815,7 +815,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) if (trie_dict_get(p_menu_set->p_menu_screen_dict, p_menu->screen_name, (int64_t *)(&(p_menu->screen_id))) != 1) { - log_error("Undefined menu screen [%s]\n", p); + log_error("Undefined menu screen [%s]", p); return -1; } @@ -824,7 +824,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) { if ((p_menu->filter_handler = get_cmd_handler(p_menu->name)) == NULL) { - log_error("Undefined menu filter handler [%s]\n", p_menu->name); + log_error("Undefined menu filter handler [%s]", p_menu->name); return -1; } } @@ -839,7 +839,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) { if ((p_menu_item->action_cmd_handler = get_cmd_handler(p_menu_item->action)) == NULL) { - log_error("Undefined menu action cmd handler [%s]\n", p_menu_item->action); + log_error("Undefined menu action cmd handler [%s]", p_menu_item->action); return -1; } } @@ -848,7 +848,7 @@ int load_menu(MENU_SET *p_menu_set, const char *conf_file) { if (trie_dict_get(p_menu_set->p_menu_name_dict, p_menu_item->action, (int64_t *)&menu_id) != 1) { - log_error("Undefined sub menu id [%s]\n", p_menu_item->action); + log_error("Undefined sub menu id [%s]", p_menu_item->action); return -1; } p_menu_item->action_menu_id = menu_id; @@ -875,7 +875,7 @@ int display_menu_cursor(MENU_SET *p_menu_set, int show) p_menu = get_menu_by_id(p_menu_set, menu_id); if (p_menu == NULL) { - log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id); + log_error("get_menu_by_id(%d) return NULL pointer", menu_id); return -1; } @@ -884,7 +884,7 @@ int display_menu_cursor(MENU_SET *p_menu_set, int show) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return -1; } @@ -910,7 +910,7 @@ static int display_menu_current_page(MENU_SET *p_menu_set) p_menu = get_menu_by_id(p_menu_set, menu_id); if (p_menu == NULL) { - log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id); + log_error("get_menu_by_id(%d) return NULL pointer", menu_id); return -1; } @@ -934,7 +934,7 @@ static int display_menu_current_page(MENU_SET *p_menu_set) p_menu_screen = get_menu_screen_by_id(p_menu_set, p_menu->screen_id); if (p_menu_screen == NULL) { - log_error("get_menu_screen_by_id(%d) return NULL pointer\n", p_menu->screen_id); + log_error("get_menu_screen_by_id(%d) return NULL pointer", p_menu->screen_id); return -1; } @@ -1006,7 +1006,7 @@ int display_menu(MENU_SET *p_menu_set) p_menu = get_menu_by_id(p_menu_set, menu_id); if (p_menu == NULL) { - log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id); + log_error("get_menu_by_id(%d) return NULL pointer", menu_id); if (p_menu_set->choose_step > 0) { p_menu_set->choose_step--; @@ -1029,7 +1029,7 @@ int display_menu(MENU_SET *p_menu_set) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return EXITMENU; } @@ -1122,7 +1122,7 @@ int menu_control(MENU_SET *p_menu_set, int key) if (p_menu_set->menu_count == 0) { - log_error("Empty menu set\n"); + log_error("Empty menu set"); return EXITBBS; } @@ -1130,7 +1130,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu = get_menu_by_id(p_menu_set, menu_id); if (p_menu == NULL) { - log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id); + log_error("get_menu_by_id(%d) return NULL pointer", menu_id); if (p_menu_set->choose_step > 0) { p_menu_set->choose_step--; @@ -1141,7 +1141,7 @@ int menu_control(MENU_SET *p_menu_set, int key) if (p_menu->item_count == 0) { - log_debug("Empty menu (%s)\n", p_menu->name); + log_debug("Empty menu (%s)", p_menu->name); if (p_menu_set->choose_step > 0) { p_menu_set->choose_step--; @@ -1157,7 +1157,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); p_menu_set->menu_item_pos[p_menu_set->choose_step] = 0; return REDRAW; } @@ -1208,7 +1208,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return -1; } @@ -1241,7 +1241,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return -1; } if (require_page_change && p_menu_set->menu_item_page_id[menu_item_pos] != page_id) @@ -1272,7 +1272,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return -1; } if (require_page_change && p_menu_set->menu_item_page_id[menu_item_pos] != page_id) @@ -1296,7 +1296,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return -1; } @@ -1323,7 +1323,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return -1; } @@ -1350,7 +1350,7 @@ int menu_control(MENU_SET *p_menu_set, int key) p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id); if (p_menu_item == NULL) { - log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); + log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id); return -1; } @@ -1377,7 +1377,7 @@ int unload_menu(MENU_SET *p_menu_set) { if (p_menu_set == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1397,7 +1397,7 @@ int unload_menu(MENU_SET *p_menu_set) if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", p_menu_set->shm_name, errno); + log_error("shm_unlink(%s) error (%d)", p_menu_set->shm_name, errno); return -2; } @@ -1413,19 +1413,19 @@ int get_menu_shm_readonly(MENU_SET *p_menu_set) if (p_menu_set == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if ((fd = shm_open(p_menu_set->shm_name, O_RDONLY, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", p_menu_set->shm_name, errno); + log_error("shm_open(%s) error (%d)", p_menu_set->shm_name, errno); return -2; } if (fstat(fd, &sb) < 0) { - log_error("fstat(fd) error (%d)\n", errno); + log_error("fstat(fd) error (%d)", errno); close(fd); return -2; } @@ -1435,14 +1435,14 @@ int get_menu_shm_readonly(MENU_SET *p_menu_set) p_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -1466,13 +1466,13 @@ int set_menu_shm_readonly(MENU_SET *p_menu_set) { if (p_menu_set == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_menu_set->p_reserved != NULL && mprotect(p_menu_set->p_reserved, p_menu_set->shm_size, PROT_READ) < 0) { - log_error("mprotect() error (%d)\n", errno); + log_error("mprotect() error (%d)", errno); return -2; } @@ -1483,7 +1483,7 @@ int detach_menu_shm(MENU_SET *p_menu_set) { if (p_menu_set == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1503,7 +1503,7 @@ int detach_menu_shm(MENU_SET *p_menu_set) if (p_menu_set->p_reserved != NULL && munmap(p_menu_set->p_reserved, p_menu_set->shm_size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -2; } diff --git a/src/menu_proc.c b/src/menu_proc.c index 14f2da4a..9142f290 100644 --- a/src/menu_proc.c +++ b/src/menu_proc.c @@ -159,7 +159,7 @@ int reload_bbs_conf(void *param) if (kill(getppid(), SIGHUP) < 0) { - log_error("Send SIGHUP signal failed (%d)\n", errno); + log_error("Send SIGHUP signal failed (%d)", errno); prints("发送指令失败\r\n"); } @@ -182,11 +182,11 @@ int shutdown_bbs(void *param) if (toupper(buf[0]) == 'Y') { - log_common("Notify main process to exit by [%s]\n", BBS_username); + log_common("Notify main process to exit by [%s]", BBS_username); if (kill(getppid(), SIGTERM) < 0) { - log_error("Send SIGTERM signal failed (%d)\n", errno); + log_error("Send SIGTERM signal failed (%d)", errno); } } @@ -227,19 +227,19 @@ int view_ex_article(void *param) p_article = article_block_find_by_aid(aid); if (p_article == NULL) { - log_error("article_block_find_by_aid(%d) error\n", aid); + log_error("article_block_find_by_aid(%d) error", aid); return NOREDRAW; } if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0) { - log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + log_error("article_cache_load(aid=%d, cid=%d) error", p_article->aid, p_article->cid); return NOREDRAW; } if (user_online_update("VIEW_ARTICLE") < 0) { - log_error("user_online_update(VIEW_ARTICLE) error\n"); + log_error("user_online_update(VIEW_ARTICLE) error"); } ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, @@ -247,13 +247,13 @@ int view_ex_article(void *param) if (article_cache_unload(&cache) < 0) { - log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + log_error("article_cache_unload(aid=%d, cid=%d) error", p_article->aid, p_article->cid); } // Update article_view_log if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0) { - log_error("article_view_log_set_viewed(aid=%d) error\n", p_article->aid); + log_error("article_view_log_set_viewed(aid=%d) error", p_article->aid); } return REDRAW; @@ -266,13 +266,13 @@ int list_ex_section(void *param) p_section = section_list_find_by_name(param); if (p_section == NULL) { - log_error("Section %s not found\n", (const char *)param); + log_error("Section %s not found", (const char *)param); return -1; } if (section_list_ex_dir_display(p_section) < 0) { - log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid); + log_error("section_list_ex_dir_display(sid=%d) error", p_section->sid); } return REDRAW; @@ -308,19 +308,19 @@ int show_top10_menu(void *param) if (user_online_update("TOP10_MENU") < 0) { - log_error("user_online_update(TOP10_MENU) error\n"); + log_error("user_online_update(TOP10_MENU) error"); } switch (ch) { case KEY_NULL: // broken pipe - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); loop = 0; break; case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); loop = 0; break; } @@ -363,7 +363,7 @@ int locate_article(void *param) if (sname == NULL || aid == NULL) { - log_error("top10_locate(%s) error: invalid parameter\n", param); + log_error("top10_locate(%s) error: invalid parameter", param); return NOREDRAW; } @@ -376,7 +376,7 @@ int favor_topic(void *param) { if (article_favor_display(&BBS_article_favor) < 0) { - log_error("article_favor_display() error\n"); + log_error("article_favor_display() error"); } return REDRAW; @@ -386,7 +386,7 @@ int list_user(void *param) { if (user_list_display(0) < 0) { - log_error("user_list_display(all_user) error\n"); + log_error("user_list_display(all_user) error"); } return REDRAW; @@ -396,7 +396,7 @@ int list_online_user(void *param) { if (user_list_display(1) < 0) { - log_error("user_list_display(online_user) error\n"); + log_error("user_list_display(online_user) error"); } return REDRAW; @@ -406,7 +406,7 @@ int edit_intro(void *param) { if (user_intro_edit(BBS_priv.uid) < 0) { - log_error("user_intro_edit(%d) error\n", BBS_priv.uid); + log_error("user_intro_edit(%d) error", BBS_priv.uid); } return REDRAW; @@ -416,7 +416,7 @@ int edit_sign(void *param) { if (user_sign_edit(BBS_priv.uid) < 0) { - log_error("user_sign_edit(%d) error\n", BBS_priv.uid); + log_error("user_sign_edit(%d) error", BBS_priv.uid); } return REDRAW; diff --git a/src/net_server.c b/src/net_server.c index b66bdfa0..7ba4b888 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -153,7 +153,7 @@ static int pty_request(ssh_session session, ssh_channel channel, const char *ter rc = openpty(&cdata->pty_master, &cdata->pty_slave, NULL, NULL, cdata->winsize); if (rc != 0) { - log_error("Failed to open pty\n"); + log_error("Failed to open pty"); return SSH_ERROR; } @@ -187,7 +187,7 @@ static int exec_pty(const char *mode, const char *command, struct channel_data_s if (command != NULL) { - log_error("Forbid exec /bin/sh %s %s)\n", mode, command); + log_error("Forbid exec /bin/sh %s %s)", mode, command); } return SSH_OK; @@ -199,7 +199,7 @@ static int exec_nopty(const char *command, struct channel_data_struct *cdata) if (command != NULL) { - log_error("Forbid exec /bin/sh -c %s)\n", command); + log_error("Forbid exec /bin/sh -c %s)", command); } return SSH_OK; @@ -249,7 +249,7 @@ static int subsystem_request(ssh_session session, ssh_channel channel, const cha (void)session; (void)channel; - log_error("subsystem_request(subsystem=%s)\n", subsystem); + log_error("subsystem_request(subsystem=%s)", subsystem); /* subsystem requests behave similarly to exec requests. */ if (strcmp(subsystem, "sftp") == 0) @@ -323,12 +323,12 @@ static int fork_server(void) if (pid > 0) // Parent process { SYS_child_process_count++; - log_common("Child process (%d) start\n", pid); + log_common("Child process (%d) start", pid); return pid; } else if (pid < 0) // Error { - log_error("fork() error (%d)\n", errno); + log_error("fork() error (%d)", errno); return -1; } @@ -336,7 +336,7 @@ static int fork_server(void) #ifdef HAVE_SYS_EPOLL_H if (close(epollfd_server) < 0) { - log_error("close(epollfd_server) error (%d)\n"); + log_error("close(epollfd_server) error (%d)"); } #endif @@ -344,7 +344,7 @@ static int fork_server(void) { if (close(socket_server[i]) == -1) { - log_error("Close server socket failed\n"); + log_error("Close server socket failed"); } } @@ -357,7 +357,7 @@ static int fork_server(void) { if (ssh_bind_accept_fd(sshbind, SSH_session, socket_client) != SSH_OK) { - log_error("ssh_bind_accept_fd() error: %s\n", ssh_get_error(SSH_session)); + log_error("ssh_bind_accept_fd() error: %s", ssh_get_error(SSH_session)); goto cleanup; } @@ -366,7 +366,7 @@ static int fork_server(void) ssh_timeout = 60; // second if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) { - log_error("Error setting SSH options: %s\n", ssh_get_error(SSH_session)); + log_error("Error setting SSH options: %s", ssh_get_error(SSH_session)); goto cleanup; } @@ -379,7 +379,7 @@ static int fork_server(void) if (ssh_handle_key_exchange(SSH_session)) { - log_error("ssh_handle_key_exchange() error: %s\n", ssh_get_error(SSH_session)); + log_error("ssh_handle_key_exchange() error: %s", ssh_get_error(SSH_session)); goto cleanup; } @@ -391,14 +391,14 @@ static int fork_server(void) ret = ssh_event_dopoll(event, 100); // 0.1 second if (ret == SSH_ERROR) { - log_debug("ssh_event_dopoll() error: %s\n", ssh_get_error(SSH_session)); + log_debug("ssh_event_dopoll() error: %s", ssh_get_error(SSH_session)); goto cleanup; } } if (cb_data.error) { - log_error("SSH auth error, tried %d times\n", cb_data.tries); + log_error("SSH auth error, tried %d times", cb_data.tries); goto cleanup; } @@ -423,7 +423,7 @@ static int fork_server(void) ssh_timeout = 0; if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) { - log_error("Error setting SSH options: %s\n", ssh_get_error(SSH_session)); + log_error("Error setting SSH options: %s", ssh_get_error(SSH_session)); goto cleanup; } @@ -433,20 +433,20 @@ static int fork_server(void) // Redirect Input if (dup2(socket_client, STDIN_FILENO) == -1) { - log_error("Redirect stdin to client socket failed\n"); + log_error("Redirect stdin to client socket failed"); goto cleanup; } // Redirect Output if (dup2(socket_client, STDOUT_FILENO) == -1) { - log_error("Redirect stdout to client socket failed\n"); + log_error("Redirect stdout to client socket failed"); goto cleanup; } if (io_init() < 0) { - log_error("io_init() error\n"); + log_error("io_init() error"); goto cleanup; } @@ -455,7 +455,7 @@ static int fork_server(void) // BWF compile if (bwf_compile() < 0) { - log_error("bwf_compile() error\n"); + log_error("bwf_compile() error"); goto cleanup; } @@ -489,7 +489,7 @@ static int fork_server(void) } else if (close(socket_client) == -1) { - log_error("Close client socket failed\n"); + log_error("Close client socket failed"); } ssh_free(SSH_session); @@ -503,7 +503,7 @@ static int fork_server(void) close(STDIN_FILENO); close(STDOUT_FILENO); - log_common("Process exit normally\n"); + log_common("Process exit normally"); log_end(); _exit(0); @@ -542,7 +542,7 @@ int net_server(const char *hostaddr, in_port_t port[]) if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_RSA_KEY_FILE) < 0) { - log_error("Error loading SSH RSA key: %s\n", SSH_HOST_RSA_KEY_FILE); + log_error("Error loading SSH RSA key: %s", SSH_HOST_RSA_KEY_FILE); } else { @@ -550,7 +550,7 @@ int net_server(const char *hostaddr, in_port_t port[]) } if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ED25519_KEY_FILE) < 0) { - log_error("Error loading SSH ED25519 key: %s\n", SSH_HOST_ED25519_KEY_FILE); + log_error("Error loading SSH ED25519 key: %s", SSH_HOST_ED25519_KEY_FILE); } else { @@ -558,7 +558,7 @@ int net_server(const char *hostaddr, in_port_t port[]) } if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ECDSA_KEY_FILE) < 0) { - log_error("Error loading SSH ECDSA key: %s\n", SSH_HOST_ECDSA_KEY_FILE); + log_error("Error loading SSH ECDSA key: %s", SSH_HOST_ECDSA_KEY_FILE); } else { @@ -567,7 +567,7 @@ int net_server(const char *hostaddr, in_port_t port[]) if (!ssh_key_valid) { - log_error("Error: no valid SSH host key\n"); + log_error("Error: no valid SSH host key"); ssh_bind_free(sshbind); return -1; } @@ -577,7 +577,7 @@ int net_server(const char *hostaddr, in_port_t port[]) ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "+ssh-ed25519,ecdsa-sha2-nistp256,ssh-rsa") < 0 || ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) { - log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind)); + log_error("Error setting SSH bind options: %s", ssh_get_error(sshbind)); ssh_bind_free(sshbind); return -1; } @@ -586,7 +586,7 @@ int net_server(const char *hostaddr, in_port_t port[]) epollfd_server = epoll_create1(0); if (epollfd_server == -1) { - log_error("epoll_create1() error (%d)\n", errno); + log_error("epoll_create1() error (%d)", errno); return -1; } #endif @@ -598,7 +598,7 @@ int net_server(const char *hostaddr, in_port_t port[]) if (socket_server[i] < 0) { - log_error("Create socket_server error (%d)\n", errno); + log_error("Create socket_server error (%d)", errno); return -1; } @@ -610,39 +610,39 @@ int net_server(const char *hostaddr, in_port_t port[]) flags_server[i] = 1; if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEADDR, &flags_server[i], sizeof(flags_server[i])) < 0) { - log_error("setsockopt SO_REUSEADDR error (%d)\n", errno); + log_error("setsockopt SO_REUSEADDR error (%d)", errno); } #if defined(SO_REUSEPORT) if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEPORT, &flags_server[i], sizeof(flags_server[i])) < 0) { - log_error("setsockopt SO_REUSEPORT error (%d)\n", errno); + log_error("setsockopt SO_REUSEPORT error (%d)", errno); } #endif if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0) { - log_error("Bind address %s:%u error (%d)\n", + log_error("Bind address %s:%u error (%d)", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno); return -1; } if (listen(socket_server[i], 10) < 0) { - log_error("Telnet socket listen error (%d)\n", errno); + log_error("Telnet socket listen error (%d)", errno); return -1; } - log_common("Listening at %s:%u\n", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); + log_common("Listening at %s:%u", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); #ifdef HAVE_SYS_EPOLL_H ev.events = EPOLLIN; ev.data.fd = socket_server[i]; if (epoll_ctl(epollfd_server, EPOLL_CTL_ADD, socket_server[i], &ev) == -1) { - log_error("epoll_ctl(socket_server[%d]) error (%d)\n", i, errno); + log_error("epoll_ctl(socket_server[%d]) error (%d)", i, errno); if (close(epollfd_server) < 0) { - log_error("close(epoll) error (%d)\n"); + log_error("close(epoll) error (%d)"); } return -1; } @@ -657,13 +657,13 @@ int net_server(const char *hostaddr, in_port_t port[]) hash_dict_pid_sockaddr = hash_dict_create(MAX_CLIENT_LIMIT); if (hash_dict_pid_sockaddr == NULL) { - log_error("hash_dict_create(hash_dict_pid_sockaddr) error\n"); + log_error("hash_dict_create(hash_dict_pid_sockaddr) error"); return -1; } hash_dict_sockaddr_count = hash_dict_create(MAX_CLIENT_LIMIT); if (hash_dict_sockaddr_count == NULL) { - log_error("hash_dict_create(hash_dict_sockaddr_count) error\n"); + log_error("hash_dict_create(hash_dict_sockaddr_count) error"); return -1; } @@ -697,15 +697,15 @@ int net_server(const char *hostaddr, in_port_t port[]) if (WIFEXITED(ret)) { - log_common("Child process (%d) exited, status=%d\n", pid, WEXITSTATUS(ret)); + log_common("Child process (%d) exited, status=%d", pid, WEXITSTATUS(ret)); } else if (WIFSIGNALED(ret)) { - log_common("Child process (%d) is killed, status=%d\n", pid, WTERMSIG(ret)); + log_common("Child process (%d) is killed, status=%d", pid, WTERMSIG(ret)); } else { - log_common("Child process (%d) exited abnormally, status=%d\n", pid, ret); + log_common("Child process (%d) exited abnormally, status=%d", pid, ret); } if (pid != section_list_loader_pid) @@ -714,20 +714,20 @@ int net_server(const char *hostaddr, in_port_t port[]) ret = hash_dict_get(hash_dict_pid_sockaddr, (uint64_t)pid, &j); if (ret < 0) { - log_error("hash_dict_get(hash_dict_pid_sockaddr, %d) error\n", pid); + log_error("hash_dict_get(hash_dict_pid_sockaddr, %d) error", pid); } else { ret = hash_dict_inc(hash_dict_sockaddr_count, (in_addr_t)j, -1); if (ret <= 0) { - log_error("hash_dict_inc(hash_dict_sockaddr_count, %lu, -1) error: %d\n", (in_addr_t)j, ret); + log_error("hash_dict_inc(hash_dict_sockaddr_count, %lu, -1) error: %d", (in_addr_t)j, ret); } ret = hash_dict_del(hash_dict_pid_sockaddr, (uint64_t)pid); if (ret < 0) { - log_error("hash_dict_del(hash_dict_pid_sockaddr, %lu) error\n", (uint64_t)pid); + log_error("hash_dict_del(hash_dict_pid_sockaddr, %lu) error", (uint64_t)pid); } } } @@ -738,7 +738,7 @@ int net_server(const char *hostaddr, in_port_t port[]) } else if (pid < 0) { - log_error("Error in waitpid(): %d\n", errno); + log_error("Error in waitpid(): %d", errno); break; } } @@ -749,12 +749,12 @@ int net_server(const char *hostaddr, in_port_t port[]) { #ifdef HAVE_SYSTEMD_SD_DAEMON_H sd_notifyf(0, "STATUS=Notify %d child process to exit", SYS_child_process_count); - log_common("Notify %d child process to exit\n", SYS_child_process_count); + log_common("Notify %d child process to exit", SYS_child_process_count); #endif if (kill(0, SIGTERM) < 0) { - log_error("Send SIGTERM signal failed (%d)\n", errno); + log_error("Send SIGTERM signal failed (%d)", errno); } notify_child_exit = 1; @@ -768,7 +768,7 @@ int net_server(const char *hostaddr, in_port_t port[]) if (kill(0, SIGKILL) < 0) { - log_error("Send SIGKILL signal failed (%d)\n", errno); + log_error("Send SIGKILL signal failed (%d)", errno); } notify_child_exit = 2; @@ -776,7 +776,7 @@ int net_server(const char *hostaddr, in_port_t port[]) } else if (notify_child_exit == 2 && time(NULL) - tm_notify_child_exit >= WAIT_CHILD_PROCESS_KILL_TIMEOUT) { - log_error("Main process prepare to exit without waiting for %d child process any longer\n", SYS_child_process_count); + log_error("Main process prepare to exit without waiting for %d child process any longer", SYS_child_process_count); SYS_child_process_count = 0; } } @@ -789,30 +789,30 @@ int net_server(const char *hostaddr, in_port_t port[]) sd_notify(0, "RELOADING=1"); #endif - log_common("Reload configuration\n"); + log_common("Reload configuration"); // Restart log if (log_restart() < 0) { - log_error("Restart logging failed\n"); + log_error("Restart logging failed"); } // Reload configuration if (load_conf(CONF_BBSD) < 0) { - log_error("Reload conf failed\n"); + log_error("Reload conf failed"); } // Reload BWF config if (bwf_load(CONF_BWF) < 0) { - log_error("Reload BWF conf failed\n"); + log_error("Reload BWF conf failed"); } // Get EULA modification tm if (stat(DATA_EULA, &file_stat) == -1) { - log_error("stat(%s) error\n", DATA_EULA, errno); + log_error("stat(%s) error", DATA_EULA, errno); } else { @@ -821,21 +821,21 @@ int net_server(const char *hostaddr, in_port_t port[]) if (detach_menu_shm(&bbs_menu) < 0) { - log_error("detach_menu_shm(bbs_menu) error\n"); + log_error("detach_menu_shm(bbs_menu) error"); } if (load_menu(&bbs_menu, CONF_MENU) < 0) { - log_error("load_menu(bbs_menu) error\n"); + log_error("load_menu(bbs_menu) error"); unload_menu(&bbs_menu); } if (detach_menu_shm(&top10_menu) < 0) { - log_error("detach_menu_shm(top10_menu) error\n"); + log_error("detach_menu_shm(top10_menu) error"); } if (load_menu(&top10_menu, CONF_TOP10_MENU) < 0) { - log_error("load_menu(top10_menu) error\n"); + log_error("load_menu(top10_menu) error"); unload_menu(&top10_menu); } top10_menu.allow_exit = 1; @@ -844,20 +844,20 @@ int net_server(const char *hostaddr, in_port_t port[]) { if (load_file(data_files_load_startup[i]) < 0) { - log_error("load_file(%s) error\n", data_files_load_startup[i]); + log_error("load_file(%s) error", data_files_load_startup[i]); } } // Load section config and gen_ex if (load_section_config_from_db(1) < 0) { - log_error("load_section_config_from_db(1) error\n"); + log_error("load_section_config_from_db(1) error"); } // Notify child processes to reload configuration if (kill(0, SIGUSR1) < 0) { - log_error("Send SIGUSR1 signal failed (%d)\n", errno); + log_error("Send SIGUSR1 signal failed (%d)", errno); } #ifdef HAVE_SYSTEMD_SD_DAEMON_H @@ -881,9 +881,9 @@ int net_server(const char *hostaddr, in_port_t port[]) if (errno != EINTR) { #ifdef HAVE_SYS_EPOLL_H - log_error("epoll_wait() error (%d)\n", errno); + log_error("epoll_wait() error (%d)", errno); #else - log_error("poll() error (%d)\n", errno); + log_error("poll() error (%d)", errno); #endif break; } @@ -926,7 +926,7 @@ int net_server(const char *hostaddr, in_port_t port[]) } else { - log_error("accept(socket_server) error (%d)\n", errno); + log_error("accept(socket_server) error (%d)", errno); break; } } @@ -942,64 +942,64 @@ int net_server(const char *hostaddr, in_port_t port[]) ret = hash_dict_get(hash_dict_sockaddr_count, sin.sin_addr.s_addr, &j); if (ret < 0) { - log_error("hash_dict_get(hash_dict_sockaddr_count, %s) error\n", hostaddr_client); + log_error("hash_dict_get(hash_dict_sockaddr_count, %s) error", hostaddr_client); } if (j < BBS_max_client_per_ip) { if ((pid = fork_server()) < 0) { - log_error("fork_server() error\n"); + log_error("fork_server() error"); } else if (pid > 0) { ret = hash_dict_set(hash_dict_pid_sockaddr, (uint64_t)pid, sin.sin_addr.s_addr); if (ret < 0) { - log_error("hash_dict_set(hash_dict_pid_sockaddr, %lu, %s) error\n", (uint64_t)pid, hostaddr_client); + log_error("hash_dict_set(hash_dict_pid_sockaddr, %lu, %s) error", (uint64_t)pid, hostaddr_client); } if (j == 0) { // First connection from this IP - log_common("Accept %s connection from %s:%d\n", + log_common("Accept %s connection from %s:%d", (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client); ret = hash_dict_set(hash_dict_sockaddr_count, (uint64_t)sin.sin_addr.s_addr, 1); if (ret < 0) { - log_error("hash_dict_set(hash_dict_sockaddr_count, %s, 1) error\n", hostaddr_client); + log_error("hash_dict_set(hash_dict_sockaddr_count, %s, 1) error", hostaddr_client); } } else { // Increase connection count from this IP - log_common("Accept %s connection from %s:%d, already have %d connections\n", + log_common("Accept %s connection from %s:%d, already have %d connections", (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client, j); ret = hash_dict_inc(hash_dict_sockaddr_count, (uint64_t)sin.sin_addr.s_addr, 1); if (ret <= 0) { - log_error("hash_dict_inc(hash_dict_sockaddr_count, %s, 1) error: %d\n", hostaddr_client, ret); + log_error("hash_dict_inc(hash_dict_sockaddr_count, %s, 1) error: %d", hostaddr_client, ret); } } } } else { - log_error("Rejected %s connection from %s:%d over limit per IP (%d >= %d)\n", + log_error("Rejected %s connection from %s:%d over limit per IP (%d >= %d)", (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client, j, BBS_max_client_per_ip); } } else { - log_error("Rejected %s connection from %s:%d over limit (%d >= %d)\n", + log_error("Rejected %s connection from %s:%d over limit (%d >= %d)", (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client, SYS_child_process_count - 1, BBS_max_client); } if (close(socket_client) == -1) { - log_error("close(socket_lient) error (%d)\n", errno); + log_error("close(socket_lient) error (%d)", errno); } } } @@ -1009,7 +1009,7 @@ int net_server(const char *hostaddr, in_port_t port[]) #ifdef HAVE_SYS_EPOLL_H if (close(epollfd_server) < 0) { - log_error("close(epollfd_server) error (%d)\n"); + log_error("close(epollfd_server) error (%d)"); } #endif @@ -1017,7 +1017,7 @@ int net_server(const char *hostaddr, in_port_t port[]) { if (close(socket_server[i]) == -1) { - log_error("Close server socket failed\n"); + log_error("Close server socket failed"); } } diff --git a/src/screen.c b/src/screen.c index 1fedf65a..dcc9568a 100644 --- a/src/screen.c +++ b/src/screen.c @@ -209,7 +209,7 @@ static int _str_input(char *buffer, int buf_size, int max_display_len, enum io_e ch = igetch(100); // 0.1 second if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input { - log_debug("Ignore %d bytes of incomplete UTF8 character\n", str_len); + log_debug("Ignore %d bytes of incomplete UTF8 character", str_len); str_len = 0; break; } @@ -223,7 +223,7 @@ static int _str_input(char *buffer, int buf_size, int max_display_len, enum io_e if (mbstowcs(wcs, input_str, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } if (offset + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character { @@ -356,7 +356,7 @@ int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); @@ -430,7 +430,7 @@ int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); @@ -462,7 +462,7 @@ int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); @@ -531,7 +531,7 @@ int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max ch = igetch(100); // 0.1 second if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input { - log_debug("Ignore %d bytes of incomplete UTF8 character\n", str_len); + log_debug("Ignore %d bytes of incomplete UTF8 character", str_len); str_len = 0; break; } @@ -545,7 +545,7 @@ int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max if (mbstowcs(wcs, input_str, 1) == (size_t)-1) { - log_error("mbstowcs() error\n"); + log_error("mbstowcs() error"); } wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); @@ -703,7 +703,7 @@ int display_data(const void *p_data, long display_line_total, const long *p_line // Refresh current action if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } } @@ -716,10 +716,10 @@ int display_data(const void *p_data, long display_line_total, const long *p_line switch (ch) { case KEY_NULL: - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); goto cleanup; case KEY_TIMEOUT: - log_debug("User input timeout\n"); + log_debug("User input timeout"); goto cleanup; case KEY_HOME: if (line_current - output_current_row < 0) // Reach begin @@ -829,13 +829,13 @@ int display_data(const void *p_data, long display_line_total, const long *p_line len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; if (len >= sizeof(buffer)) { - log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld \n", + log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld ", len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); len = sizeof(buffer) - 1; } else if (len < 0) { - log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld \n", + log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld ", len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); len = 0; } @@ -880,20 +880,20 @@ int display_file(const char *filename, int eof_exit) if ((p_shm = get_file_shm_readonly(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL) { - log_error("get_file_shm(%s) error\n", filename); + log_error("get_file_shm(%s) error", filename); return KEY_NULL; } if (user_online_update("VIEW_FILE") < 0) { - log_error("user_online_update(VIEW_FILE) error\n"); + log_error("user_online_update(VIEW_FILE) error"); } ret = display_data(p_data, line_total, p_line_offsets, eof_exit, display_file_key_handler, DATA_READ_HELP); if (detach_file_shm(p_shm) < 0) { - log_error("detach_file_shm(%s) error\n", filename); + log_error("detach_file_shm(%s) error", filename); } return ret; @@ -1006,7 +1006,7 @@ int show_active_board() { if ((p_shm = get_file_shm_readonly(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL) { - log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD); + log_error("get_file_shm(%s) error", DATA_ACTIVE_BOARD); return KEY_NULL; } } @@ -1028,7 +1028,7 @@ int show_active_board() len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; if (len >= LINE_BUFFER_LEN) { - log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n", + log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld ", len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); len = LINE_BUFFER_LEN - 1; } diff --git a/src/section_list.c b/src/section_list.c index 69eb5b6d..747026cc 100644 --- a/src/section_list.c +++ b/src/section_list.c @@ -98,13 +98,13 @@ int article_block_init(const char *filename, int block_count) if (p_article_block_pool != NULL) { - log_error("article_block_pool already initialized\n"); + log_error("article_block_pool already initialized"); return -1; } if (block_count <= 0 || block_count > ARTICLE_BLOCK_PER_POOL) { - log_error("article_block_count exceed limit %d\n", ARTICLE_BLOCK_PER_POOL); + log_error("article_block_count exceed limit %d", ARTICLE_BLOCK_PER_POOL); return -2; } @@ -118,18 +118,18 @@ int article_block_init(const char *filename, int block_count) if (shm_unlink(filepath) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", filepath, errno); + log_error("shm_unlink(%s) error (%d)", filepath, errno); return -2; } if ((fd = shm_open(filepath, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", filepath, errno); + log_error("shm_open(%s) error (%d)", filepath, errno); return -2; } if (ftruncate(fd, (off_t)size) == -1) { - log_error("ftruncate(size=%d) error (%d)\n", size, errno); + log_error("ftruncate(size=%d) error (%d)", size, errno); close(fd); return -2; } @@ -137,14 +137,14 @@ int article_block_init(const char *filename, int block_count) p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -164,18 +164,18 @@ int article_block_init(const char *filename, int block_count) if (shm_unlink(filepath) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", filepath, errno); + log_error("shm_unlink(%s) error (%d)", filepath, errno); return -2; } if ((fd = shm_open(filepath, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", filepath, errno); + log_error("shm_open(%s) error (%d)", filepath, errno); return -2; } if (ftruncate(fd, (off_t)size) == -1) { - log_error("ftruncate(size=%d) error (%d)\n", size, errno); + log_error("ftruncate(size=%d) error (%d)", size, errno); close(fd); return -2; } @@ -183,14 +183,14 @@ int article_block_init(const char *filename, int block_count) p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -235,7 +235,7 @@ void article_block_cleanup(void) if (shm_unlink(filepath) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", filepath, errno); + log_error("shm_unlink(%s) error (%d)", filepath, errno); } } @@ -243,7 +243,7 @@ void article_block_cleanup(void) if (shm_unlink(filepath) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", filepath, errno); + log_error("shm_unlink(%s) error (%d)", filepath, errno); } detach_article_block_shm(); @@ -255,7 +255,7 @@ int set_article_block_shm_readonly(void) if (p_article_block_pool == NULL) { - log_error("article_block_pool not initialized\n"); + log_error("article_block_pool not initialized"); return -1; } @@ -264,7 +264,7 @@ int set_article_block_shm_readonly(void) // if ((p_article_block_pool->shm_pool + i)->p_shm != NULL && // mprotect((p_article_block_pool->shm_pool + i)->p_shm, (p_article_block_pool->shm_pool + i)->shm_size, PROT_READ) < 0) // { - // log_error("mprotect() error (%d)\n", errno); + // log_error("mprotect() error (%d)", errno); // return -2; // } // } @@ -272,7 +272,7 @@ int set_article_block_shm_readonly(void) if (p_article_block_pool != NULL && mprotect(p_article_block_pool, p_article_block_pool->shm_size, PROT_READ) < 0) { - log_error("mprotect() error (%d)\n", errno); + log_error("mprotect() error (%d)", errno); return -3; } @@ -291,14 +291,14 @@ int detach_article_block_shm(void) if ((p_article_block_pool->shm_pool + i)->p_shm != NULL && munmap((p_article_block_pool->shm_pool + i)->p_shm, (p_article_block_pool->shm_pool + i)->shm_size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -2; } } if (p_article_block_pool != NULL && munmap(p_article_block_pool, p_article_block_pool->shm_size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -3; } @@ -334,7 +334,7 @@ int article_block_reset(void) if (p_article_block_pool == NULL) { - log_error("article_block_pool not initialized\n"); + log_error("article_block_pool not initialized"); return -1; } @@ -357,7 +357,7 @@ ARTICLE *article_block_find_by_aid(int32_t aid) if (p_article_block_pool == NULL) { - log_error("article_block_pool not initialized\n"); + log_error("article_block_pool not initialized"); return NULL; } @@ -419,13 +419,13 @@ ARTICLE *article_block_find_by_index(int index) if (p_article_block_pool == NULL) { - log_error("article_block_pool not initialized\n"); + log_error("article_block_pool not initialized"); return NULL; } if (index < 0 || index / BBS_article_count_per_block >= p_article_block_pool->block_count) { - log_error("article_block_find_by_index(%d) is out of boundary of block [0, %d)\n", index, p_article_block_pool->block_count); + log_error("article_block_find_by_index(%d) is out of boundary of block [0, %d)", index, p_article_block_pool->block_count); return NULL; } @@ -433,7 +433,7 @@ ARTICLE *article_block_find_by_index(int index) if (index % BBS_article_count_per_block >= p_block->article_count) { - log_error("article_block_find_by_index(%d) is out of boundary of article [0, %d)\n", index, p_block->article_count); + log_error("article_block_find_by_index(%d) is out of boundary of article [0, %d)", index, p_block->article_count); return NULL; } @@ -468,18 +468,18 @@ extern int section_list_init(const char *filename) if (shm_unlink(section_list_shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", section_list_shm_name, errno); + log_error("shm_unlink(%s) error (%d)", section_list_shm_name, errno); return -2; } if ((fd = shm_open(section_list_shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", section_list_shm_name, errno); + log_error("shm_open(%s) error (%d)", section_list_shm_name, errno); return -2; } if (ftruncate(fd, (off_t)size) == -1) { - log_error("ftruncate(size=%d) error (%d)\n", size, errno); + log_error("ftruncate(size=%d) error (%d)", size, errno); close(fd); return -2; } @@ -487,14 +487,14 @@ extern int section_list_init(const char *filename) p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -508,7 +508,7 @@ extern int section_list_init(const char *filename) { if (sem_init(&(p_section_list_pool->sem[i]), 1, 1) == -1) { - log_error("sem_init(sem[%d]) error (%d)\n", i, errno); + log_error("sem_init(sem[%d]) error (%d)", i, errno); return -3; } @@ -520,7 +520,7 @@ extern int section_list_init(const char *filename) key = ftok(filename, proj_id); if (key == -1) { - log_error("ftok(%s, %d) error (%d)\n", filename, proj_id, errno); + log_error("ftok(%s, %d) error (%d)", filename, proj_id, errno); return -3; } @@ -528,7 +528,7 @@ extern int section_list_init(const char *filename) semid = semget(key, (int)size, IPC_CREAT | IPC_EXCL | 0600); if (semid == -1) { - log_error("semget(section_list_pool_sem, size = %d) error (%d)\n", size, errno); + log_error("semget(section_list_pool_sem, size = %d) error (%d)", size, errno); return -3; } @@ -538,7 +538,7 @@ extern int section_list_init(const char *filename) { if (semctl(semid, i, SETVAL, arg) == -1) { - log_error("semctl(section_list_pool_sem, SETVAL) error (%d)\n", errno); + log_error("semctl(section_list_pool_sem, SETVAL) error (%d)", errno); return -3; } } @@ -549,14 +549,14 @@ extern int section_list_init(const char *filename) p_section_list_pool->p_trie_dict_section_by_name = trie_dict_create(); if (p_section_list_pool->p_trie_dict_section_by_name == NULL) { - log_error("trie_dict_create() OOM\n", BBS_max_section); + log_error("trie_dict_create() OOM", BBS_max_section); return -2; } p_section_list_pool->p_trie_dict_section_by_sid = trie_dict_create(); if (p_section_list_pool->p_trie_dict_section_by_sid == NULL) { - log_error("trie_dict_create() OOM\n", BBS_max_section); + log_error("trie_dict_create() OOM", BBS_max_section); return -2; } @@ -585,14 +585,14 @@ void section_list_cleanup(void) #ifdef HAVE_SYSTEM_V if (semctl(p_section_list_pool->semid, 0, IPC_RMID) == -1) { - log_error("semctl(semid = %d, IPC_RMID) error (%d)\n", p_section_list_pool->semid, errno); + log_error("semctl(semid = %d, IPC_RMID) error (%d)", p_section_list_pool->semid, errno); } #else for (int i = 0; i <= BBS_max_section; i++) { if (sem_destroy(&(p_section_list_pool->sem[i])) == -1) { - log_error("sem_destroy(sem[%d]) error (%d)\n", i, errno); + log_error("sem_destroy(sem[%d]) error (%d)", i, errno); } } #endif @@ -601,7 +601,7 @@ void section_list_cleanup(void) if (shm_unlink(section_list_shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", section_list_shm_name, errno); + log_error("shm_unlink(%s) error (%d)", section_list_shm_name, errno); } } @@ -609,14 +609,14 @@ int set_section_list_shm_readonly(void) { if (p_section_list_pool == NULL) { - log_error("p_section_list_pool not initialized\n"); + log_error("p_section_list_pool not initialized"); return -1; } if (p_section_list_pool != NULL && mprotect(p_section_list_pool, p_section_list_pool->shm_size, PROT_READ) < 0) { - log_error("mprotect() error (%d)\n", errno); + log_error("mprotect() error (%d)", errno); return -2; } @@ -627,7 +627,7 @@ int detach_section_list_shm(void) { if (p_section_list_pool != NULL && munmap(p_section_list_pool, p_section_list_pool->shm_size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -1; } @@ -657,13 +657,13 @@ SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *st if (p_section_list_pool == NULL) { - log_error("session_list_pool not initialized\n"); + log_error("session_list_pool not initialized"); return NULL; } if (p_section_list_pool->section_count >= BBS_max_section) { - log_error("section_count reach limit %d >= %d\n", p_section_list_pool->section_count, BBS_max_section); + log_error("section_count reach limit %d >= %d", p_section_list_pool->section_count, BBS_max_section); return NULL; } @@ -685,13 +685,13 @@ SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *st if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, p_section_list_pool->section_count) != 1) { - log_error("trie_dict_set(section, %s, %d) error\n", sname, p_section_list_pool->section_count); + log_error("trie_dict_set(section, %s, %d) error", sname, p_section_list_pool->section_count); return NULL; } if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_sid, sid_str, p_section_list_pool->section_count) != 1) { - log_error("trie_dict_set(section, %d, %d) error\n", sid, p_section_list_pool->section_count); + log_error("trie_dict_set(section, %d, %d) error", sid, p_section_list_pool->section_count); return NULL; } @@ -708,7 +708,7 @@ int section_list_update(SECTION_LIST *p_section, const char *sname, const char * if (p_section == NULL || sname == NULL || stitle == NULL || master_list == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -725,7 +725,7 @@ int section_list_update(SECTION_LIST *p_section, const char *sname, const char * if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, index) < 0) { - log_error("trie_dict_set(section, %s, %d) error\n", sname, index); + log_error("trie_dict_set(section, %s, %d) error", sname, index); return -2; } @@ -754,14 +754,14 @@ SECTION_LIST *section_list_find_by_name(const char *sname) if (p_section_list_pool == NULL) { - log_error("section_list not initialized\n"); + log_error("section_list not initialized"); return NULL; } ret = trie_dict_get(p_section_list_pool->p_trie_dict_section_by_name, sname, &index); if (ret < 0) { - log_error("trie_dict_get(section, %s) error\n", sname); + log_error("trie_dict_get(section, %s) error", sname); return NULL; } else if (ret == 0) @@ -780,7 +780,7 @@ SECTION_LIST *section_list_find_by_sid(int32_t sid) if (p_section_list_pool == NULL) { - log_error("section_list not initialized\n"); + log_error("section_list not initialized"); return NULL; } @@ -789,7 +789,7 @@ SECTION_LIST *section_list_find_by_sid(int32_t sid) ret = trie_dict_get(p_section_list_pool->p_trie_dict_section_by_sid, sid_str, &index); if (ret < 0) { - log_error("trie_dict_get(section, %d) error\n", sid); + log_error("trie_dict_get(section, %d) error", sid); return NULL; } else if (ret == 0) @@ -810,25 +810,25 @@ int section_list_append_article(SECTION_LIST *p_section, const ARTICLE *p_articl if (p_section == NULL || p_article_src == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_article_block_pool == NULL) { - log_error("article_block_pool not initialized\n"); + log_error("article_block_pool not initialized"); return -1; } if (p_section->sid != p_article_src->sid) { - log_error("section_list_append_article() error: section sid %d != article sid %d\n", p_section->sid, p_article_src->sid); + log_error("section_list_append_article() error: section sid %d != article sid %d", p_section->sid, p_article_src->sid); return -2; } if (p_section->article_count >= BBS_article_limit_per_section) { - log_error("section_list_append_article() error: article_count reach limit in section %d\n", p_section->sid); + log_error("section_list_append_article() error: article_count reach limit in section %d", p_section->sid); return -2; } @@ -837,7 +837,7 @@ int section_list_append_article(SECTION_LIST *p_section, const ARTICLE *p_articl { if ((p_block = pop_free_article_block()) == NULL) { - log_error("pop_free_article_block() error\n"); + log_error("pop_free_article_block() error"); return -2; } @@ -858,7 +858,7 @@ int section_list_append_article(SECTION_LIST *p_section, const ARTICLE *p_articl // AID of articles should be strictly ascending if (p_article_src->aid <= last_aid) { - log_error("section_list_append_article(aid=%d) error: last_aid=%d\n", p_article_src->aid, last_aid); + log_error("section_list_append_article(aid=%d) error: last_aid=%d", p_article_src->aid, last_aid); return -3; } @@ -880,14 +880,14 @@ int section_list_append_article(SECTION_LIST *p_section, const ARTICLE *p_articl p_topic_head = article_block_find_by_aid(p_article->tid); if (p_topic_head == NULL) { - log_error("search head of topic (aid=%d) error\n", p_article->tid); + log_error("search head of topic (aid=%d) error", p_article->tid); return -4; } p_topic_tail = p_topic_head->p_topic_prior; if (p_topic_tail == NULL) { - log_error("tail of topic (aid=%d) is NULL\n", p_article->tid); + log_error("tail of topic (aid=%d) is NULL", p_article->tid); return -4; } } @@ -937,7 +937,7 @@ int section_list_append_article(SECTION_LIST *p_section, const ARTICLE *p_articl if (p_article->ontop && section_list_update_article_ontop(p_section, p_article) < 0) { - log_error("section_list_update_article_ontop(sid=%d, aid=%d) error\n", + log_error("section_list_update_article_ontop(sid=%d, aid=%d) error", p_section->sid, p_article->aid); return -5; } @@ -953,7 +953,7 @@ int section_list_set_article_visible(SECTION_LIST *p_section, int32_t aid, int8_ if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -965,7 +965,7 @@ int section_list_set_article_visible(SECTION_LIST *p_section, int32_t aid, int8_ if (p_section->sid != p_article->sid) { - log_error("Inconsistent section sid %d != article sid %d\n", p_section->sid, p_article->sid); + log_error("Inconsistent section sid %d != article sid %d", p_section->sid, p_article->sid); return -2; } @@ -980,7 +980,7 @@ int section_list_set_article_visible(SECTION_LIST *p_section, int32_t aid, int8_ if (user_article_cnt_inc(p_article->uid, -1) < 0) { - log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_article->uid); + log_error("user_article_cnt_inc(uid=%d, -1) error", p_article->uid); } if (p_article->tid == 0) @@ -992,7 +992,7 @@ int section_list_set_article_visible(SECTION_LIST *p_section, int32_t aid, int8_ { if (p_reply->tid != aid) { - log_error("Inconsistent tid = %d found in reply %d of topic %d\n", p_reply->tid, p_reply->aid, aid); + log_error("Inconsistent tid = %d found in reply %d of topic %d", p_reply->tid, p_reply->aid, aid); continue; } @@ -1004,7 +1004,7 @@ int section_list_set_article_visible(SECTION_LIST *p_section, int32_t aid, int8_ if (user_article_cnt_inc(p_reply->uid, -1) < 0) { - log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_reply->uid); + log_error("user_article_cnt_inc(uid=%d, -1) error", p_reply->uid); } } } @@ -1021,7 +1021,7 @@ int section_list_set_article_visible(SECTION_LIST *p_section, int32_t aid, int8_ if (user_article_cnt_inc(p_article->uid, 1) < 0) { - log_error("user_article_cnt_inc(uid=%d, 1) error\n", p_article->uid); + log_error("user_article_cnt_inc(uid=%d, 1) error", p_article->uid); } } @@ -1037,7 +1037,7 @@ int section_list_set_article_excerption(SECTION_LIST *p_section, int32_t aid, in if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1049,7 +1049,7 @@ int section_list_set_article_excerption(SECTION_LIST *p_section, int32_t aid, in if (p_section->sid != p_article->sid) { - log_error("Inconsistent section sid %d != article sid %d\n", p_section->sid, p_article->sid); + log_error("Inconsistent section sid %d != article sid %d", p_section->sid, p_article->sid); return -2; } @@ -1069,13 +1069,13 @@ int section_list_update_article_ontop(SECTION_LIST *p_section, ARTICLE *p_articl if (p_section == NULL || p_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_section->sid != p_article->sid) { - log_error("Inconsistent section sid %d != article sid %d\n", p_section->sid, p_article->sid); + log_error("Inconsistent section sid %d != article sid %d", p_section->sid, p_article->sid); return -2; } @@ -1085,7 +1085,7 @@ int section_list_update_article_ontop(SECTION_LIST *p_section, ARTICLE *p_articl { if (p_section->p_ontop_articles[i]->aid == p_article->aid) { - log_error("Inconsistent state found: article %d already ontop in section %d\n", p_article->aid, p_section->sid); + log_error("Inconsistent state found: article %d already ontop in section %d", p_article->aid, p_section->sid); return 0; } else if (p_section->p_ontop_articles[i]->aid > p_article->aid) @@ -1130,7 +1130,7 @@ int section_list_update_article_ontop(SECTION_LIST *p_section, ARTICLE *p_articl } if (i == p_section->ontop_article_count) // not found { - log_error("Inconsistent state found: article %d not ontop in section %d\n", p_article->aid, p_section->sid); + log_error("Inconsistent state found: article %d not ontop in section %d", p_article->aid, p_section->sid); return 0; } @@ -1149,7 +1149,7 @@ int section_list_page_count_with_ontop(SECTION_LIST *p_section) if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1169,7 +1169,7 @@ int section_list_page_article_count_with_ontop(SECTION_LIST *p_section, int32_t { if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1199,7 +1199,7 @@ ARTICLE *section_list_find_article_with_offset(SECTION_LIST *p_section, int32_t if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return NULL; } @@ -1285,7 +1285,7 @@ int section_list_calculate_page(SECTION_LIST *p_section, int32_t start_aid) if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1307,7 +1307,7 @@ int section_list_calculate_page(SECTION_LIST *p_section, int32_t start_aid) if (p_section->sid != p_article->sid) { - log_error("section_list_calculate_page() error: section sid %d != start article sid %d\n", p_section->sid, p_article->sid); + log_error("section_list_calculate_page() error: section sid %d != start article sid %d", p_section->sid, p_article->sid); return -2; } @@ -1318,7 +1318,7 @@ int section_list_calculate_page(SECTION_LIST *p_section, int32_t start_aid) { return -1; } - log_error("section_list_calculate_page() aid = %d not found in section sid = %d\n", + log_error("section_list_calculate_page() aid = %d not found in section sid = %d", start_aid, p_section->sid); return -2; } @@ -1367,7 +1367,7 @@ int section_list_calculate_page(SECTION_LIST *p_section, int32_t start_aid) if (page >= BBS_article_limit_per_section / BBS_article_limit_per_page && p_article != p_section->p_article_head) { - log_error("Count of page exceed limit in section %d\n", p_section->sid); + log_error("Count of page exceed limit in section %d", p_section->sid); break; } } @@ -1421,7 +1421,7 @@ int article_count_of_topic(int32_t aid) { if (p_article->tid != 0 && p_article->tid != aid) { - log_error("article_count_of_topic(%d) error: article %d not linked to the topic\n", aid, p_article->aid); + log_error("article_count_of_topic(%d) error: article %d not linked to the topic", aid, p_article->aid); break; } @@ -1446,32 +1446,32 @@ int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section if (p_section_src == NULL || p_section_dest == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_section_src->sid == p_section_dest->sid) { - log_error("section_list_move_topic() src and dest section are the same\n"); + log_error("section_list_move_topic() src and dest section are the same"); return -1; } if ((p_article = article_block_find_by_aid(aid)) == NULL) { - log_error("article_block_find_by_aid(aid = %d) error: article not found\n", aid); + log_error("article_block_find_by_aid(aid = %d) error: article not found", aid); return -2; } if (p_section_src->sid != p_article->sid) { - log_error("section_list_move_topic() error: src section sid %d != article %d sid %d\n", + log_error("section_list_move_topic() error: src section sid %d != article %d sid %d", p_section_src->sid, p_article->aid, p_article->sid); return -2; } if (p_article->tid != 0) { - log_error("section_list_move_topic(aid = %d) error: article is not head of topic, tid = %d\n", aid, p_article->tid); + log_error("section_list_move_topic(aid = %d) error: article is not head of topic, tid = %d", aid, p_article->tid); return -2; } @@ -1480,13 +1480,13 @@ int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section move_article_count = article_count_of_topic(aid); if (move_article_count <= 0) { - log_error("article_count_of_topic(aid = %d) <= 0\n", aid); + log_error("article_count_of_topic(aid = %d) <= 0", aid); return -2; } if (p_section_dest->article_count + move_article_count > BBS_article_limit_per_section) { - log_error("section_list_move_topic() error: article_count %d reach limit in section %d\n", + log_error("section_list_move_topic() error: article_count %d reach limit in section %d", p_section_dest->article_count + move_article_count, p_section_dest->sid); return -3; } @@ -1499,7 +1499,7 @@ int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section { if (p_section_src->sid != p_article->sid) { - log_error("section_list_move_topic() warning: src section sid %d != article %d sid %d\n", + log_error("section_list_move_topic() warning: src section sid %d != article %d sid %d", p_section_src->sid, p_article->aid, p_article->sid); p_article = p_article->p_topic_next; continue; @@ -1528,7 +1528,7 @@ int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section if (section_list_find_article_with_offset(p_section_dest, p_article->aid, &page, &offset, &p_next) != NULL) { - log_error("section_list_move_topic() warning: article %d already in section %d\n", p_article->aid, p_section_dest->sid); + log_error("section_list_move_topic() warning: article %d already in section %d", p_article->aid, p_section_dest->sid); p_article = p_article->p_topic_next; continue; } @@ -1598,7 +1598,7 @@ int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section // Re-calculate pages of desc section if (section_list_calculate_page(p_section_dest, first_inserted_aid_dest) < 0) { - log_error("section_list_calculate_page(dest section = %d, aid = %d) error\n", + log_error("section_list_calculate_page(dest section = %d, aid = %d) error", p_section_dest->sid, first_inserted_aid_dest); } @@ -1608,14 +1608,14 @@ int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section if (p_section_dest->article_count - dest_article_count_old != move_article_count) { - log_error("section_list_move_topic() warning: count of moved articles %d != %d\n", + log_error("section_list_move_topic() warning: count of moved articles %d != %d", p_section_dest->article_count - dest_article_count_old, move_article_count); } // Re-calculate pages of src section if (section_list_calculate_page(p_section_src, last_unaffected_aid_src) < 0) { - log_error("section_list_calculate_page(src section = %d, aid = %d) error at aid = %d\n", + log_error("section_list_calculate_page(src section = %d, aid = %d) error at aid = %d", p_section_src->sid, last_unaffected_aid_src, aid); } @@ -1624,7 +1624,7 @@ int section_list_move_topic(SECTION_LIST *p_section_src, SECTION_LIST *p_section // Re-calculate pages of desc section if (section_list_calculate_page(p_section_dest, first_inserted_aid_dest) < 0) { - log_error("section_list_calculate_page(dest section = %d, aid = %d) error\n", + log_error("section_list_calculate_page(dest section = %d, aid = %d) error", p_section_dest->sid, first_inserted_aid_dest); } } @@ -1638,7 +1638,7 @@ int get_section_index(SECTION_LIST *p_section) if (p_section_list_pool == NULL) { - log_error("get_section_index() error: uninitialized\n"); + log_error("get_section_index() error: uninitialized"); return -1; } @@ -1651,7 +1651,7 @@ int get_section_index(SECTION_LIST *p_section) index = (int)(p_section - p_section_list_pool->sections); if (index < 0 || index >= BBS_max_section) { - log_error("get_section_index(%d) error: index out of range\n", index); + log_error("get_section_index(%d) error: index out of range", index); return -2; } } @@ -1663,13 +1663,13 @@ int get_section_info(SECTION_LIST *p_section, char *sname, char *stitle, char *m { if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (section_list_rd_lock(p_section) < 0) { - log_error("section_list_rd_lock(sid=%d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid=%d) error", p_section->sid); return -2; } @@ -1689,7 +1689,7 @@ int get_section_info(SECTION_LIST *p_section, char *sname, char *stitle, char *m // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid=%d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid=%d) error", p_section->sid); return -2; } @@ -1740,14 +1740,14 @@ int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec) ret = semtimedop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4), &timeout); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(index = %d, lock read) error %d\n", index, errno); + log_error("semop(index = %d, lock read) error %d", index, errno); } #else if (sem_timedwait(&(p_section_list_pool->sem[index]), &timeout) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_timedwait(sem[%d]) error %d\n", index, errno); + log_error("sem_timedwait(sem[%d]) error %d", index, errno); } return -1; } @@ -1758,12 +1758,12 @@ int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_timedwait(sem[%d]) error %d\n", BBS_max_section, errno); + log_error("sem_timedwait(sem[%d]) error %d", BBS_max_section, errno); } // release previously acquired lock if (sem_post(&(p_section_list_pool->sem[index])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", index, errno); + log_error("sem_post(sem[%d]) error %d", index, errno); } return -1; } @@ -1789,14 +1789,14 @@ int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec) // release lock on "all section" if (sem_post(&(p_section_list_pool->sem[BBS_max_section])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", BBS_max_section, errno); + log_error("sem_post(sem[%d]) error %d", BBS_max_section, errno); ret = -1; } } if (sem_post(&(p_section_list_pool->sem[index])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", index, errno); + log_error("sem_post(sem[%d]) error %d", index, errno); return -1; } #endif @@ -1838,14 +1838,14 @@ int section_list_try_rw_lock(SECTION_LIST *p_section, int wait_sec) ret = semtimedop(p_section_list_pool->semid, sops, 3, &timeout); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(index = %d, lock write) error %d\n", index, errno); + log_error("semop(index = %d, lock write) error %d", index, errno); } #else if (sem_timedwait(&(p_section_list_pool->sem[index]), &timeout) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_timedwait(sem[%d]) error %d\n", index, errno); + log_error("sem_timedwait(sem[%d]) error %d", index, errno); } return -1; } @@ -1862,7 +1862,7 @@ int section_list_try_rw_lock(SECTION_LIST *p_section, int wait_sec) if (sem_post(&(p_section_list_pool->sem[index])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", index, errno); + log_error("sem_post(sem[%d]) error %d", index, errno); return -1; } #endif @@ -1899,14 +1899,14 @@ int section_list_rd_unlock(SECTION_LIST *p_section) ret = semop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 1 : 2)); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(index = %d, unlock read) error %d\n", index, errno); + log_error("semop(index = %d, unlock read) error %d", index, errno); } #else if (sem_wait(&(p_section_list_pool->sem[index])) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_wait(sem[%d]) error %d\n", index, errno); + log_error("sem_wait(sem[%d]) error %d", index, errno); } return -1; } @@ -1917,12 +1917,12 @@ int section_list_rd_unlock(SECTION_LIST *p_section) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_wait(sem[%d]) error %d\n", BBS_max_section, errno); + log_error("sem_wait(sem[%d]) error %d", BBS_max_section, errno); } // release previously acquired lock if (sem_post(&(p_section_list_pool->sem[index])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", index, errno); + log_error("sem_post(sem[%d]) error %d", index, errno); } return -1; } @@ -1934,7 +1934,7 @@ int section_list_rd_unlock(SECTION_LIST *p_section) } else { - log_error("read_lock_count[%d] already 0\n", index); + log_error("read_lock_count[%d] already 0", index); } if (index != BBS_max_section && p_section_list_pool->read_lock_count[BBS_max_section] > 0) @@ -1943,7 +1943,7 @@ int section_list_rd_unlock(SECTION_LIST *p_section) } else { - log_error("read_lock_count[%d] already 0\n", BBS_max_section); + log_error("read_lock_count[%d] already 0", BBS_max_section); } if (index != BBS_max_section) @@ -1951,14 +1951,14 @@ int section_list_rd_unlock(SECTION_LIST *p_section) // release lock on "all section" if (sem_post(&(p_section_list_pool->sem[BBS_max_section])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", BBS_max_section, errno); + log_error("sem_post(sem[%d]) error %d", BBS_max_section, errno); ret = -1; } } if (sem_post(&(p_section_list_pool->sem[index])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", index, errno); + log_error("sem_post(sem[%d]) error %d", index, errno); return -1; } #endif @@ -1988,14 +1988,14 @@ int section_list_rw_unlock(SECTION_LIST *p_section) ret = semop(p_section_list_pool->semid, sops, 1); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(index = %d, unlock write) error %d\n", index, errno); + log_error("semop(index = %d, unlock write) error %d", index, errno); } #else if (sem_wait(&(p_section_list_pool->sem[index])) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_wait(sem[%d]) error %d\n", index, errno); + log_error("sem_wait(sem[%d]) error %d", index, errno); } return -1; } @@ -2006,12 +2006,12 @@ int section_list_rw_unlock(SECTION_LIST *p_section) } else { - log_error("write_lock_count[%d] already 0\n", index); + log_error("write_lock_count[%d] already 0", index); } if (sem_post(&(p_section_list_pool->sem[index])) == -1) { - log_error("sem_post(sem[%d]) error %d\n", index, errno); + log_error("sem_post(sem[%d]) error %d", index, errno); return -1; } #endif @@ -2044,13 +2044,13 @@ int section_list_rd_lock(SECTION_LIST *p_section) timer++; if (timer % SECTION_TRY_LOCK_TIMES == 0) { - log_error("section_list_try_rd_lock() tried %d times on section %d\n", timer, sid); + log_error("section_list_try_rd_lock() tried %d times on section %d", timer, sid); if (time(NULL) - tm_first_failure >= SECTION_DEAD_LOCK_TIMEOUT) { - log_error("Unable to acquire rd_lock for %d seconds\n", time(NULL) - tm_first_failure); + log_error("Unable to acquire rd_lock for %d seconds", time(NULL) - tm_first_failure); #ifndef HAVE_SYSTEM_V section_list_reset_lock(p_section); - log_error("Reset POSIX semaphore to resolve dead lock\n"); + log_error("Reset POSIX semaphore to resolve dead lock"); #endif break; } @@ -2059,7 +2059,7 @@ int section_list_rd_lock(SECTION_LIST *p_section) } else // failed { - log_error("section_list_try_rd_lock() failed on section %d\n", sid); + log_error("section_list_try_rd_lock() failed on section %d", sid); break; } } @@ -2092,13 +2092,13 @@ int section_list_rw_lock(SECTION_LIST *p_section) timer++; if (timer % SECTION_TRY_LOCK_TIMES == 0) { - log_error("section_list_try_rw_lock() tried %d times on section %d\n", timer, sid); + log_error("section_list_try_rw_lock() tried %d times on section %d", timer, sid); if (time(NULL) - tm_first_failure >= SECTION_DEAD_LOCK_TIMEOUT) { - log_error("Unable to acquire rw_lock for %d seconds\n", time(NULL) - tm_first_failure); + log_error("Unable to acquire rw_lock for %d seconds", time(NULL) - tm_first_failure); #ifndef HAVE_SYSTEM_V section_list_reset_lock(p_section); - log_error("Reset POSIX semaphore to resolve dead lock\n"); + log_error("Reset POSIX semaphore to resolve dead lock"); #endif break; } @@ -2107,7 +2107,7 @@ int section_list_rw_lock(SECTION_LIST *p_section) } else // failed { - log_error("section_list_try_rw_lock() failed on section %d\n", sid); + log_error("section_list_try_rw_lock() failed on section %d", sid); break; } } @@ -2122,7 +2122,7 @@ int section_list_reset_lock(SECTION_LIST *p_section) if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -2134,7 +2134,7 @@ int section_list_reset_lock(SECTION_LIST *p_section) if (sem_destroy(&(p_section_list_pool->sem[index])) == -1) { - log_error("sem_destroy(sem[%d]) error (%d)\n", index, errno); + log_error("sem_destroy(sem[%d]) error (%d)", index, errno); } p_section_list_pool->read_lock_count[index] = 0; @@ -2142,14 +2142,14 @@ int section_list_reset_lock(SECTION_LIST *p_section) if (sem_init(&(p_section_list_pool->sem[index]), 1, 1) == -1) { - log_error("sem_init(sem[%d]) error (%d)\n", index, errno); + log_error("sem_init(sem[%d]) error (%d)", index, errno); } if (index != BBS_max_section) { if (sem_destroy(&(p_section_list_pool->sem[BBS_max_section])) == -1) { - log_error("sem_destroy(sem[%d]) error (%d)\n", BBS_max_section, errno); + log_error("sem_destroy(sem[%d]) error (%d)", BBS_max_section, errno); } p_section_list_pool->read_lock_count[BBS_max_section] = 0; @@ -2157,7 +2157,7 @@ int section_list_reset_lock(SECTION_LIST *p_section) if (sem_init(&(p_section_list_pool->sem[BBS_max_section]), 1, 1) == -1) { - log_error("sem_init(sem[%d]) error (%d)\n", BBS_max_section, errno); + log_error("sem_init(sem[%d]) error (%d)", BBS_max_section, errno); } } diff --git a/src/section_list_display.c b/src/section_list_display.c index 2c5205df..e66c8639 100644 --- a/src/section_list_display.c +++ b/src/section_list_display.c @@ -101,7 +101,7 @@ static int section_list_draw_items(int page_id, const ARTICLE *p_articles[], int is_viewed = article_view_log_is_viewed(p_articles[i]->aid, &BBS_article_view_log); if (is_viewed < 0) { - log_error("article_view_log_is_viewed(aid=%d) error\n", p_articles[i]->aid); + log_error("article_view_log_is_viewed(aid=%d) error", p_articles[i]->aid); is_viewed = 0; } } @@ -111,7 +111,7 @@ static int section_list_draw_items(int page_id, const ARTICLE *p_articles[], int is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor); if (is_favor < 0) { - log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid); + log_error("article_favor_check(aid=%d) error", p_articles[i]->aid); is_favor = 0; } } @@ -274,19 +274,19 @@ static enum select_cmd_t section_list_select(int total_page, int item_count, int // Refresh current action if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } } switch (ch) { case KEY_NULL: // broken pipe - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); return EXIT_SECTION; case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); return EXIT_SECTION; } continue; @@ -615,13 +615,13 @@ int section_list_display(const char *sname, int32_t aid) p_section = section_list_find_by_name(sname); if (p_section == NULL) { - log_error("Section %s not found\n", sname); + log_error("Section %s not found", sname); return -1; } if (!checkpriv(&BBS_priv, p_section->sid, S_LIST)) { - log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n", + log_error("Forbid access to unauthorized section, sid=%d, uid=%d", p_section->sid, BBS_priv.uid); return -1; } @@ -630,7 +630,7 @@ int section_list_display(const char *sname, int32_t aid) if (get_section_info(p_section, NULL, stitle, master_list) < 0) { - log_error("get_section_info(sid=%d) error\n", p_section->sid); + log_error("get_section_info(sid=%d) error", p_section->sid); return -4; } @@ -649,7 +649,7 @@ int section_list_display(const char *sname, int32_t aid) p_article_locate = article_block_find_by_aid(aid_location); if (p_article_locate == NULL) { - log_error("article_block_find_by_aid(%d) error\n", aid_location); + log_error("article_block_find_by_aid(%d) error", aid_location); return -3; } @@ -657,7 +657,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", p_section->sid, p_article_locate->aid); return -3; } @@ -665,14 +665,14 @@ int section_list_display(const char *sname, int32_t aid) if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } @@ -696,7 +696,7 @@ int section_list_display(const char *sname, int32_t aid) ret = section_list_draw_items(page_id, p_articles, article_count, display_nickname, ontop_start_offset); if (ret < 0) { - log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("section_list_draw_items(sid=%d, page_id=%d) error", p_section->sid, page_id); return -4; } @@ -709,7 +709,7 @@ int section_list_display(const char *sname, int32_t aid) if (user_online_update(sname) < 0) { - log_error("user_online_update(%s) error\n", sname); + log_error("user_online_update(%s) error", sname); } ret = section_list_select(page_count, article_count, &page_id, &selected_index); @@ -725,7 +725,7 @@ int section_list_display(const char *sname, int32_t aid) ret = last_article_in_section(p_section, &p_article_locate); if (ret < 0) { - log_error("last_article_in_section(sid=%d) error\n", p_section->sid); + log_error("last_article_in_section(sid=%d) error", p_section->sid); return -3; } else if (ret == 0) @@ -747,7 +747,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } if (article_count == 0) // empty section @@ -766,13 +766,13 @@ int section_list_display(const char *sname, int32_t aid) if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0) { - log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); + log_error("article_cache_load(aid=%d, cid=%d) error", p_articles[selected_index]->aid, p_articles[selected_index]->cid); break; } if (user_online_update("VIEW_ARTICLE") < 0) { - log_error("user_online_update(VIEW_ARTICLE) error\n"); + log_error("user_online_update(VIEW_ARTICLE) error"); } ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0, @@ -780,14 +780,14 @@ int section_list_display(const char *sname, int32_t aid) if (article_cache_unload(&cache) < 0) { - log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); + log_error("article_cache_unload(aid=%d, cid=%d) error", p_articles[selected_index]->aid, p_articles[selected_index]->cid); break; } // Update article_view_log if (article_view_log_set_viewed(p_articles[selected_index]->aid, &BBS_article_view_log) < 0) { - log_error("article_view_log_set_viewed(aid=%d) error\n", p_articles[selected_index]->aid); + log_error("article_view_log_set_viewed(aid=%d) error", p_articles[selected_index]->aid); } switch (ret) @@ -803,7 +803,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } @@ -834,7 +834,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } @@ -861,7 +861,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=1) error", p_section->sid, p_articles[selected_index]->aid, direction); return -3; } @@ -870,7 +870,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } loop = 1; @@ -879,19 +879,19 @@ int section_list_display(const char *sname, int32_t aid) case 'r': // Reply article if (user_online_update("REPLY_ARTICLE") < 0) { - log_error("user_online_update(REPLY_ARTICLE) error\n"); + log_error("user_online_update(REPLY_ARTICLE) error"); } if (article_reply(p_section, p_articles[selected_index], &article_new) < 0) { - log_error("article_reply(aid=%d) error\n", p_articles[selected_index]->aid); + log_error("article_reply(aid=%d) error", p_articles[selected_index]->aid); } else if (ret > 0) // Article replied { ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } @@ -905,7 +905,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error", p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); return -3; } @@ -916,7 +916,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } @@ -931,7 +931,7 @@ int section_list_display(const char *sname, int32_t aid) if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; @@ -939,32 +939,32 @@ int section_list_display(const char *sname, int32_t aid) display_nickname = !display_nickname; if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; case POST_ARTICLE: if (user_online_update("POST_ARTICLE") < 0) { - log_error("user_online_update(POST_ARTICLE) error\n"); + log_error("user_online_update(POST_ARTICLE) error"); } if ((ret = article_post(p_section, &article_new)) < 0) { - log_error("article_post(sid=%d) error\n", p_section->sid); + log_error("article_post(sid=%d) error", p_section->sid); } else if (ret > 0) // New article posted { ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error: %d\n", p_section->sid, page_id, ret); + log_error("query_section_articles(sid=%d, page_id=%d) error: %d", p_section->sid, page_id, ret); return -3; } } if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; @@ -977,25 +977,25 @@ int section_list_display(const char *sname, int32_t aid) if (user_online_update("EDIT_ARTICLE") < 0) { - log_error("user_online_update() error\n"); + log_error("user_online_update() error"); } if (article_modify(p_section, p_articles[selected_index], &article_new) < 0) { - log_error("article_modify(aid=%d) error\n", p_articles[selected_index]->aid); + log_error("article_modify(aid=%d) error", p_articles[selected_index]->aid); } else if (ret > 0) // Article modified { ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; @@ -1007,7 +1007,7 @@ int section_list_display(const char *sname, int32_t aid) } if ((ret = article_del(p_section, p_articles[selected_index])) < 0) { - log_error("article_del(aid=%d) error\n", p_articles[selected_index]->aid); + log_error("article_del(aid=%d) error", p_articles[selected_index]->aid); } else if (ret > 0) // Article deleted { @@ -1033,25 +1033,25 @@ int section_list_display(const char *sname, int32_t aid) } if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; case QUERY_ARTICLE: if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0) { - log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid); + log_error("display_article_meta(aid=%d) error", p_articles[selected_index]->aid); } if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; case QUERY_USER: if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info, user_intro, sizeof(user_intro))) < 0) { - log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid); + log_error("query_user_info_by_uid(uid=%d) error", p_articles[selected_index]->uid); return -2; } else if (ret == 0) @@ -1062,12 +1062,12 @@ int section_list_display(const char *sname, int32_t aid) } else if (user_info_display(&user_info) < 0) // && ret > 0 { - log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid); + log_error("user_info_display(uid=%d) error", p_articles[selected_index]->uid); } if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; @@ -1078,7 +1078,7 @@ int section_list_display(const char *sname, int32_t aid) &BBS_article_favor, 1); if (ret < 0) { - log_error("article_favor_set(aid=%d, 1) error\n", + log_error("article_favor_set(aid=%d, 1) error", p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); } break; @@ -1089,7 +1089,7 @@ int section_list_display(const char *sname, int32_t aid) &BBS_article_favor, 0); if (ret < 0) { - log_error("article_favor_set(aid=%d, 0) error\n", + log_error("article_favor_set(aid=%d, 0) error", p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid); } break; @@ -1101,7 +1101,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d, step=%d) error", p_section->sid, p_articles[selected_index]->aid, direction, BBS_article_limit_per_section); return -3; } @@ -1110,7 +1110,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } @@ -1120,7 +1120,7 @@ int section_list_display(const char *sname, int32_t aid) ret = last_article_in_section(p_section, &p_article_locate); if (ret < 0) { - log_error("last_article_in_section(sid=%d) error\n", p_section->sid); + log_error("last_article_in_section(sid=%d) error", p_section->sid); return -3; } else if (ret == 0) @@ -1131,7 +1131,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", p_section->sid, p_article_locate->aid); return -3; } @@ -1140,7 +1140,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } @@ -1149,7 +1149,7 @@ int section_list_display(const char *sname, int32_t aid) ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate); if (ret < 0) { - log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n", + log_error("scan_unread_article_in_section(sid=%d, aid=%d) error", p_section->sid, p_articles[selected_index]->aid); return -3; } @@ -1162,7 +1162,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", p_section->sid, p_article_locate->aid); return -3; } @@ -1171,7 +1171,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } @@ -1214,7 +1214,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_user_info_by_username(username, 1, &uid, username_list); if (ret < 0) { - log_error("query_user_info_by_username(%s) error\n", username); + log_error("query_user_info_by_username(%s) error", username); break; } @@ -1224,7 +1224,7 @@ int section_list_display(const char *sname, int32_t aid) direction, uid, &p_article_locate); if (ret < 0) { - log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error\n", + log_error("scan_article_in_section_by_uid(sid=%d, aid=%d, direction=%d, uid=%d) error", p_section->sid, p_articles[selected_index]->aid, direction, uid); return -3; } @@ -1239,7 +1239,7 @@ int section_list_display(const char *sname, int32_t aid) direction, username, &p_article_locate); if (ret < 0) { - log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error\n", + log_error("scan_article_in_section_by_username(sid=%d, aid=%d, direction=%d, username=%s) error", p_section->sid, p_articles[selected_index]->aid, direction, username); return -3; } @@ -1254,7 +1254,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", p_section->sid, p_article_locate->aid); return -3; } @@ -1263,7 +1263,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } @@ -1287,7 +1287,7 @@ int section_list_display(const char *sname, int32_t aid) direction, title, &p_article_locate); if (ret < 0) { - log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error\n", + log_error("scan_article_in_section_by_title(sid=%d, aid=%d, direction=%d, title=%s) error", p_section->sid, p_articles[selected_index]->aid, direction, title); return -3; } @@ -1301,7 +1301,7 @@ int section_list_display(const char *sname, int32_t aid) &page_id, &selected_index, &article_count); if (ret < 0) { - log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n", + log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error", p_section->sid, p_article_locate->aid); return -3; } @@ -1310,7 +1310,7 @@ int section_list_display(const char *sname, int32_t aid) ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset); if (ret < 0) { - log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); + log_error("query_section_articles(sid=%d, page_id=%d) error", p_section->sid, page_id); return -3; } } @@ -1319,7 +1319,7 @@ int section_list_display(const char *sname, int32_t aid) user_list_search(); if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; @@ -1328,18 +1328,18 @@ int section_list_display(const char *sname, int32_t aid) display_file(DATA_READ_HELP, 1); if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; case VIEW_EX_DIR: if (section_list_ex_dir_display(p_section) < 0) { - log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid); + log_error("section_list_ex_dir_display(sid=%d) error", p_section->sid); } if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; @@ -1347,12 +1347,12 @@ int section_list_display(const char *sname, int32_t aid) show_top10_menu(NULL); if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) { - log_error("section_list_draw_screen() error\n"); + log_error("section_list_draw_screen() error"); return -2; } break; default: - log_error("Unknown command %d\n", ret); + log_error("Unknown command %d", ret); } } @@ -1367,7 +1367,7 @@ int section_list_ex_dir_display(SECTION_LIST *p_section) if (p_section == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1382,12 +1382,12 @@ int section_list_ex_dir_display(SECTION_LIST *p_section) if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0) { - log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid); + log_error("get_section_ex_menu_set(sid=%d) error", p_section->sid); return -3; } if (get_menu_shm_readonly(&ex_menu_set) < 0) { - log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid); + log_error("get_menu_shm_readonly(sid=%d) error", p_section->sid); return -3; } @@ -1408,20 +1408,20 @@ int section_list_ex_dir_display(SECTION_LIST *p_section) // Refresh current action if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } } switch (ch) { case KEY_NULL: // broken pipe - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); loop = 0; break; case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); loop = 0; break; } @@ -1463,7 +1463,7 @@ int section_aid_locations_save(int uid) if ((fp = fopen(filename, "wb")) == NULL) { - log_error("fopen(%s, wb) error: %d\n", filename, errno); + log_error("fopen(%s, wb) error: %d", filename, errno); return -1; } @@ -1471,14 +1471,14 @@ int section_aid_locations_save(int uid) { if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1) { - log_error("fwrite(%s, sid) error\n", filename); + log_error("fwrite(%s, sid) error", filename); ret = -2; break; } if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1) { - log_error("fwrite(%s, aid) error\n", filename); + log_error("fwrite(%s, aid) error", filename); ret = -2; break; } @@ -1486,7 +1486,7 @@ int section_aid_locations_save(int uid) if (fclose(fp) < 0) { - log_error("fclose(%s) error: %d\n", filename, errno); + log_error("fclose(%s) error: %d", filename, errno); ret = -1; } @@ -1511,7 +1511,7 @@ int section_aid_locations_load(int uid) { return 0; } - log_error("fopen(%s, rb) error: %d\n", filename, errno); + log_error("fopen(%s, rb) error: %d", filename, errno); return -1; } @@ -1523,7 +1523,7 @@ int section_aid_locations_load(int uid) { break; } - log_error("fread(%s, sid) error: %d\n", filename, ferror(fp)); + log_error("fread(%s, sid) error: %d", filename, ferror(fp)); ret = -2; break; } @@ -1534,7 +1534,7 @@ int section_aid_locations_load(int uid) { break; } - log_error("fread(%s, aid) error: %d\n", filename, ferror(fp)); + log_error("fread(%s, aid) error: %d", filename, ferror(fp)); ret = -2; break; } @@ -1548,7 +1548,7 @@ int section_aid_locations_load(int uid) i = get_section_index(p_section); if (i < 0) { - log_error("get_section_index(sid=%d) error\n", sid); + log_error("get_section_index(sid=%d) error", sid); ret = -3; break; } @@ -1557,7 +1557,7 @@ int section_aid_locations_load(int uid) if (fclose(fp) < 0) { - log_error("fclose(%s) error: %d\n", filename, errno); + log_error("fclose(%s) error: %d", filename, errno); ret = -1; } diff --git a/src/section_list_loader.c b/src/section_list_loader.c index 924aa22c..deda3bc0 100644 --- a/src/section_list_loader.c +++ b/src/section_list_loader.c @@ -35,7 +35,7 @@ static void loader_proc_sig_usr1_handler(int i) // Restart log if (log_restart() < 0) { - log_error("Restart logging failed\n"); + log_error("Restart logging failed"); } } @@ -54,7 +54,7 @@ int load_section_config_from_db(int update_gen_ex) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -68,13 +68,13 @@ int load_section_config_from_db(int update_gen_ex) if (mysql_query(db, sql) != 0) { - log_error("Query section_list error: %s\n", mysql_error(db)); + log_error("Query section_list error: %s", mysql_error(db)); ret = -2; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get section_list data failed\n"); + log_error("Get section_list data failed"); ret = -2; goto cleanup; } @@ -94,13 +94,13 @@ int load_section_config_from_db(int update_gen_ex) if (mysql_query(db, sql) != 0) { - log_error("Query section_master error: %s\n", mysql_error(db)); + log_error("Query section_master error: %s", mysql_error(db)); ret = -3; break; } if ((rs2 = mysql_store_result(db)) == NULL) { - log_error("Get section_master data failed\n"); + log_error("Get section_master data failed"); ret = -3; break; } @@ -121,7 +121,7 @@ int load_section_config_from_db(int update_gen_ex) p_section = section_list_create(sid, row[1], row[2], master_list); if (p_section == NULL) { - log_error("section_list_create() error: load new section sid = %d sname = %s\n", sid, row[1]); + log_error("section_list_create() error: load new section sid = %d sname = %s", sid, row[1]); ret = -4; break; } @@ -144,7 +144,7 @@ int load_section_config_from_db(int update_gen_ex) if (section_list_update(p_section, row[1], row[2], master_list) < 0) { - log_error("section_list_update(sid=%d) error\n", p_section->sid); + log_error("section_list_update(sid=%d) error", p_section->sid); ret = -4; break; } @@ -162,18 +162,18 @@ int load_section_config_from_db(int update_gen_ex) if (detach_menu_shm(&(p_section->ex_menu_set)) < 0) { - log_error("detach_menu_shm(%s) error\n", ex_menu_conf); + log_error("detach_menu_shm(%s) error", ex_menu_conf); } if (load_menu(&(p_section->ex_menu_set), ex_menu_conf) < 0) { - log_error("load_menu(%s) error\n", ex_menu_conf); + log_error("load_menu(%s) error", ex_menu_conf); unload_menu(&(p_section->ex_menu_set)); } else { p_section->ex_menu_set.allow_exit = 1; // Allow exit menu p_section->ex_menu_tm = atol(row[7]); - log_debug("Loaded gen_ex_menu of section %d [%s]\n", p_section->sid, p_section->sname); + log_debug("Loaded gen_ex_menu of section %d [%s]", p_section->sid, p_section->sname); } } @@ -211,7 +211,7 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -226,13 +226,13 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun if (mysql_query(db, sql) != 0) { - log_error("Query article list error: %s\n", mysql_error(db)); + log_error("Query article list error: %s", mysql_error(db)); ret = -2; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get article list data failed\n"); + log_error("Get article list data failed"); ret = -2; goto cleanup; } @@ -240,7 +240,7 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun // acquire global lock if (global_lock && (ret = section_list_rw_lock(NULL)) < 0) { - log_error("section_list_rw_lock(sid = 0) error\n"); + log_error("section_list_rw_lock(sid = 0) error"); goto cleanup; } @@ -280,14 +280,14 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun { if ((ret = section_list_rw_unlock(p_section)) < 0) { - log_error("section_list_rw_unlock(sid=%d) error\n", p_section->sid); + log_error("section_list_rw_unlock(sid=%d) error", p_section->sid); break; } } if ((p_section = section_list_find_by_sid(article.sid)) == NULL) { - log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", article.sid); + log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config", article.sid); ret = ERR_UNKNOWN_SECTION; // Unknown section found break; } @@ -298,7 +298,7 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun p_topic = article_block_find_by_aid(article.tid); if (p_topic == NULL || p_topic->visible == 0) { - // log_error("Set article (aid = %d) as invisible due to invisible or non-existing topic head\n", article.aid); + // log_error("Set article (aid = %d) as invisible due to invisible or non-existing topic head", article.aid); article.tid = 0; article.visible = 0; } @@ -309,7 +309,7 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun { if ((ret = section_list_rw_lock(p_section)) < 0) { - log_error("section_list_rw_lock(sid=0) error\n"); + log_error("section_list_rw_lock(sid=0) error"); break; } } @@ -319,7 +319,7 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun if (section_list_append_article(p_section, &article) < 0) { - log_error("section_list_append_article(sid=%d, aid=%d) error\n", + log_error("section_list_append_article(sid=%d, aid=%d) error", p_section->sid, article.aid); ret = -3; break; @@ -329,7 +329,7 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, &article, p_section, row[i++], sub_ip, 0) < 0) { - log_error("article_cache_generate(aid=%d, cid=%d) error\n", article.aid, article.cid); + log_error("article_cache_generate(aid=%d, cid=%d) error", article.aid, article.cid); ret = -4; break; } @@ -340,14 +340,14 @@ int append_articles_from_db(int32_t start_aid, int global_lock, int article_coun { if ((ret = section_list_rw_unlock(p_section)) < 0) { - log_error("section_list_rw_unlock(sid=%d) error\n", p_section->sid); + log_error("section_list_rw_unlock(sid=%d) error", p_section->sid); } } // release global lock if (global_lock && (ret = section_list_rw_unlock(NULL)) < 0) { - log_error("section_list_rw_unlock(sid=0) error\n"); + log_error("section_list_rw_unlock(sid=0) error"); } cleanup: @@ -370,7 +370,7 @@ int set_last_article_op_log_from_db(void) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -380,13 +380,13 @@ int set_last_article_op_log_from_db(void) if (mysql_query(db, sql) != 0) { - log_error("Query article op error: %s\n", mysql_error(db)); + log_error("Query article op error: %s", mysql_error(db)); ret = -2; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get article op data failed\n"); + log_error("Get article op data failed"); ret = -2; goto cleanup; } @@ -421,7 +421,7 @@ int apply_article_op_log_from_db(int op_count_limit) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -434,13 +434,13 @@ int apply_article_op_log_from_db(int op_count_limit) if (mysql_query(db, sql) != 0) { - log_error("Query article log error: %s\n", mysql_error(db)); + log_error("Query article log error: %s", mysql_error(db)); ret = -2; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get article log data failed\n"); + log_error("Get article log data failed"); ret = -2; goto cleanup; } @@ -459,14 +459,14 @@ int apply_article_op_log_from_db(int op_count_limit) { if ((ret = section_list_rw_unlock(p_section)) < 0) { - log_error("section_list_rw_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rw_unlock(sid = %d) error", p_section->sid); break; } } if ((p_section = section_list_find_by_sid(p_article->sid)) == NULL) { - log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", p_article->sid); + log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config", p_article->sid); ret = ERR_UNKNOWN_SECTION; // Unknown section found break; } @@ -476,7 +476,7 @@ int apply_article_op_log_from_db(int op_count_limit) { if ((ret = section_list_rw_lock(p_section)) < 0) { - log_error("section_list_rw_lock(sid = 0) error\n"); + log_error("section_list_rw_lock(sid = 0) error"); break; } } @@ -486,27 +486,27 @@ int apply_article_op_log_from_db(int op_count_limit) switch (row[2][0]) { case 'A': // Add article - log_error("Operation type=A should not be found\n"); + log_error("Operation type=A should not be found"); break; case 'D': // Delete article case 'X': // Delete article by Admin if (section_list_set_article_visible(p_section, atoi(row[1]), 0) < 0) { - log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=0) error\n", p_section->sid, atoi(row[1])); + log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=0) error", p_section->sid, atoi(row[1])); } if (section_list_calculate_page(p_section, atoi(row[1])) < 0) { - log_error("section_list_calculate_page(aid=%d) error\n", atoi(row[1])); + log_error("section_list_calculate_page(aid=%d) error", atoi(row[1])); } break; case 'S': // Restore article if (section_list_set_article_visible(p_section, atoi(row[1]), 1) < 0) { - log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=1) error\n", p_section->sid, atoi(row[1])); + log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=1) error", p_section->sid, atoi(row[1])); } if (section_list_calculate_page(p_section, atoi(row[1])) < 0) { - log_error("section_list_calculate_page(aid=%d) error\n", atoi(row[1])); + log_error("section_list_calculate_page(aid=%d) error", atoi(row[1])); } break; case 'L': // Lock article @@ -524,13 +524,13 @@ int apply_article_op_log_from_db(int op_count_limit) if (mysql_query(db, sql) != 0) { - log_error("Query article error: %s\n", mysql_error(db)); + log_error("Query article error: %s", mysql_error(db)); ret = -3; break; } if ((rs2 = mysql_use_result(db)) == NULL) { - log_error("Get article data failed\n"); + log_error("Get article data failed"); ret = -3; break; } @@ -544,7 +544,7 @@ int apply_article_op_log_from_db(int op_count_limit) if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, p_section, row2[2], sub_ip, 0) < 0) { - log_error("article_cache_generate(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid); + log_error("article_cache_generate(aid=%d, cid=%d) error", p_article->aid, p_article->cid); ret = -4; } } @@ -565,13 +565,13 @@ int apply_article_op_log_from_db(int op_count_limit) if (mysql_query(db, sql) != 0) { - log_error("Query article error: %s\n", mysql_error(db)); + log_error("Query article error: %s", mysql_error(db)); ret = -3; break; } if ((rs2 = mysql_store_result(db)) == NULL) { - log_error("Get article data failed\n"); + log_error("Get article data failed"); ret = -3; break; } @@ -598,19 +598,19 @@ int apply_article_op_log_from_db(int op_count_limit) // acquire lock of dest section if ((ret = section_list_rw_lock(p_section_dest)) < 0) { - log_error("section_list_rw_lock(sid = %d) error\n", p_section_dest); + log_error("section_list_rw_lock(sid = %d) error", p_section_dest); break; } // Move topic if ((ret = section_list_move_topic(p_section, p_section_dest, p_article->aid)) < 0) { - log_error("section_list_move_topic(src_sid=%d, dest_sid=%d, aid=%d) error (%d), retry in the next loop\n", + log_error("section_list_move_topic(src_sid=%d, dest_sid=%d, aid=%d) error (%d), retry in the next loop", p_section->sid, p_section_dest->sid, p_article->aid, ret); } // release lock of dest section if (section_list_rw_unlock(p_section_dest) < 0) { - log_error("section_list_rw_unlock(sid = %d) error\n", p_section_dest); + log_error("section_list_rw_unlock(sid = %d) error", p_section_dest); ret = -1; } } @@ -626,7 +626,7 @@ int apply_article_op_log_from_db(int op_count_limit) p_article->ontop = (row[2][0] == 'F' ? 1 : 0); if (section_list_update_article_ontop(p_section, p_article) < 0) { - log_error("section_list_update_article_ontop(sid=%d, aid=%d) error\n", + log_error("section_list_update_article_ontop(sid=%d, aid=%d) error", p_section->sid, p_article->aid); } break; @@ -634,7 +634,7 @@ int apply_article_op_log_from_db(int op_count_limit) p_article->transship = 1; break; default: - // log_error("Operation type=%s unknown, mid=%s\n", row[2], row[0]); + // log_error("Operation type=%s unknown, mid=%s", row[2], row[0]); break; } @@ -654,7 +654,7 @@ int apply_article_op_log_from_db(int op_count_limit) { if ((ret = section_list_rw_unlock(p_section)) < 0) { - log_error("section_list_rw_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rw_unlock(sid = %d) error", p_section->sid); } } @@ -694,7 +694,7 @@ int section_list_loader_launch(void) if (section_list_loader_pid != 0) { - log_error("section_list_loader already running, pid = %d\n", section_list_loader_pid); + log_error("section_list_loader already running, pid = %d", section_list_loader_pid); return -2; } @@ -704,12 +704,12 @@ int section_list_loader_launch(void) { SYS_child_process_count++; section_list_loader_pid = pid; - log_common("Section list loader process (pid = %d) start\n", pid); + log_common("Section list loader process (pid = %d) start", pid); return 0; } else if (pid < 0) // Error { - log_error("fork() error (%d)\n", errno); + log_error("fork() error (%d)", errno); return -1; } @@ -724,17 +724,17 @@ int section_list_loader_launch(void) act.sa_handler = SIG_IGN; if (sigaction(SIGHUP, &act, NULL) == -1) { - log_error("set signal action of SIGHUP error: %d\n", errno); + log_error("set signal action of SIGHUP error: %d", errno); } act.sa_handler = SIG_DFL; if (sigaction(SIGCHLD, &act, NULL) == -1) { - log_error("set signal action of SIGCHLD error: %d\n", errno); + log_error("set signal action of SIGCHLD error: %d", errno); } act.sa_handler = loader_proc_sig_usr1_handler; if (sigaction(SIGUSR1, &act, NULL) == -1) { - log_error("set signal action of SIGUSR1 error: %d\n", errno); + log_error("set signal action of SIGUSR1 error: %d", errno); } // Do section data loader periodically @@ -749,11 +749,11 @@ int section_list_loader_launch(void) // Load section config if (load_section_config_from_db(0) < 0) { - log_error("load_section_config_from_db(0) error\n"); + log_error("load_section_config_from_db(0) error"); } else { - log_common("Reload section config successfully\n"); + log_common("Reload section config successfully"); } } @@ -766,7 +766,7 @@ int section_list_loader_launch(void) if ((ret = append_articles_from_db(last_aid + 1, 0, LOAD_ARTICLE_COUNT_LIMIT)) < 0) { - log_error("append_articles_from_db(%d, 0, %d) error\n", last_aid + 1, LOAD_ARTICLE_COUNT_LIMIT); + log_error("append_articles_from_db(%d, 0, %d) error", last_aid + 1, LOAD_ARTICLE_COUNT_LIMIT); if (ret == ERR_UNKNOWN_SECTION) { @@ -778,7 +778,7 @@ int section_list_loader_launch(void) load_count = article_block_article_count() - article_count; if (load_count > 0) { - log_common("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); + log_common("Incrementally load %d articles, last_aid = %d", load_count, article_block_last_aid()); } if (SYS_conf_reload) @@ -793,7 +793,7 @@ int section_list_loader_launch(void) { if ((ret = apply_article_op_log_from_db(LOAD_ARTICLE_COUNT_LIMIT)) < 0) { - log_error("apply_article_op_log_from_db() error\n"); + log_error("apply_article_op_log_from_db() error"); if (ret == ERR_UNKNOWN_SECTION) { @@ -804,7 +804,7 @@ int section_list_loader_launch(void) if (last_article_op_log_mid > last_mid) { - log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid); + log_common("Proceeded %d article logs, last_mid = %d", last_article_op_log_mid - last_mid, last_article_op_log_mid); } // Reload user list @@ -812,12 +812,12 @@ int section_list_loader_launch(void) { if (user_list_pool_reload(0) < 0) { - log_error("user_list_pool_reload(all_user) error\n"); + log_error("user_list_pool_reload(all_user) error"); } if (user_stat_update() < 0) { - log_error("user_stat_update() error\n"); + log_error("user_stat_update() error"); } tm_user_list_reload = time(NULL); @@ -828,7 +828,7 @@ int section_list_loader_launch(void) { if (user_list_pool_reload(1) < 0) { - log_error("user_list_pool_reload(online_user) error\n"); + log_error("user_list_pool_reload(online_user) error"); } tm_user_online_list_reload = time(NULL); @@ -854,7 +854,7 @@ int section_list_loader_launch(void) detach_trie_dict_shm(); detach_user_list_pool_shm(); - log_common("Section list loader process exit normally\n"); + log_common("Section list loader process exit normally"); log_end(); section_list_loader_pid = 0; @@ -874,14 +874,14 @@ int query_section_articles(SECTION_LIST *p_section, int page_id, const ARTICLE * if (p_section == NULL || p_articles == NULL || p_article_count == NULL || p_page_count == NULL || p_ontop_start_offset == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -895,7 +895,7 @@ int query_section_articles(SECTION_LIST *p_section, int page_id, const ARTICLE * } else if (page_id < 0 || page_id >= *p_page_count) { - log_debug("Invalid page_id=%d, not in range [0, %d)\n", page_id, *p_page_count); + log_debug("Invalid page_id=%d, not in range [0, %d)", page_id, *p_page_count); ret = -3; } else @@ -920,7 +920,7 @@ int query_section_articles(SECTION_LIST *p_section, int page_id, const ARTICLE * if (*p_article_count != (page_id < p_section->page_count - 1 ? BBS_article_limit_per_page : p_section->last_page_visible_article_count)) { - log_error("Inconsistent visible article count %d detected in section %d page %d\n", *p_article_count, p_section->sid, page_id); + log_error("Inconsistent visible article count %d detected in section %d page %d", *p_article_count, p_section->sid, page_id); } } @@ -943,7 +943,7 @@ int query_section_articles(SECTION_LIST *p_section, int page_id, const ARTICLE * // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); ret = -2; } @@ -964,14 +964,14 @@ int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_ if (p_section == NULL || p_article_cur == NULL || p_page_id == NULL || p_visible_offset == NULL || p_article_count == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -1035,7 +1035,7 @@ int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_ i++; if (i >= *p_article_count) { - log_error("Visible article (aid=%d) not found in page %d\n", aid, page_id); + log_error("Visible article (aid=%d) not found in page %d", aid, page_id); p_article = NULL; break; } @@ -1044,7 +1044,7 @@ int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_ p_article = p_article->p_next; if (p_article == p_section->p_page_first_article[page_id]) { - log_error("Dead loop detected at page=%d, article_count=%d\n", page_id, *p_article_count); + log_error("Dead loop detected at page=%d, article_count=%d", page_id, *p_article_count); break; } } @@ -1057,7 +1057,7 @@ int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_ // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); ret = -2; } @@ -1072,7 +1072,7 @@ int last_article_in_section(SECTION_LIST *p_section, const ARTICLE **pp_article) if (p_section == NULL || pp_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1081,7 +1081,7 @@ int last_article_in_section(SECTION_LIST *p_section, const ARTICLE **pp_article) // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -1099,7 +1099,7 @@ int last_article_in_section(SECTION_LIST *p_section, const ARTICLE **pp_article) // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); ret = -2; } @@ -1113,20 +1113,20 @@ int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_art if (p_section == NULL || p_article_cur == NULL || pp_article_unread == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_article_cur->sid != p_section->sid) { - log_error("Inconsistent SID\n"); + log_error("Inconsistent SID"); return -1; } // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -1144,7 +1144,7 @@ int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_art // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); return -2; } @@ -1159,20 +1159,20 @@ int scan_article_in_section_by_uid(SECTION_LIST *p_section, const ARTICLE *p_art if (p_section == NULL || p_article_cur == NULL || pp_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_article_cur->sid != p_section->sid) { - log_error("Inconsistent SID\n"); + log_error("Inconsistent SID"); return -1; } // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -1204,7 +1204,7 @@ int scan_article_in_section_by_uid(SECTION_LIST *p_section, const ARTICLE *p_art // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); return -2; } @@ -1219,20 +1219,20 @@ int scan_article_in_section_by_username(SECTION_LIST *p_section, const ARTICLE * if (p_section == NULL || p_article_cur == NULL || username == NULL || pp_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_article_cur->sid != p_section->sid) { - log_error("Inconsistent SID\n"); + log_error("Inconsistent SID"); return -1; } // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -1264,7 +1264,7 @@ int scan_article_in_section_by_username(SECTION_LIST *p_section, const ARTICLE * // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); return -2; } @@ -1279,20 +1279,20 @@ int scan_article_in_section_by_title(SECTION_LIST *p_section, const ARTICLE *p_a if (p_section == NULL || p_article_cur == NULL || title == NULL || pp_article == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_article_cur->sid != p_section->sid) { - log_error("Inconsistent SID\n"); + log_error("Inconsistent SID"); return -1; } // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -1324,7 +1324,7 @@ int scan_article_in_section_by_title(SECTION_LIST *p_section, const ARTICLE *p_a // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); return -2; } @@ -1337,14 +1337,14 @@ int get_section_ex_menu_set(SECTION_LIST *p_section, MENU_SET *p_ex_menu_set) if (p_section == NULL || p_ex_menu_set == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of section if ((ret = section_list_rd_lock(p_section)) < 0) { - log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_lock(sid = %d) error", p_section->sid); return -2; } @@ -1353,7 +1353,7 @@ int get_section_ex_menu_set(SECTION_LIST *p_section, MENU_SET *p_ex_menu_set) // release lock of section if (section_list_rd_unlock(p_section) < 0) { - log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); + log_error("section_list_rd_unlock(sid = %d) error", p_section->sid); ret = -2; } diff --git a/src/str_process.c b/src/str_process.c index d0b88db2..1385f6ba 100644 --- a/src/str_process.c +++ b/src/str_process.c @@ -76,7 +76,7 @@ int str_length(const char *str, int skip_ctrl_seq) if (mbstowcs(wcs, input_str, 1) == (size_t)-1) { - log_debug("mbstowcs(%s) error\n", input_str); + log_debug("mbstowcs(%s) error", input_str); wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback } else @@ -140,7 +140,7 @@ int split_line(const char *buffer, int max_display_len, int *p_eol, int *p_displ if (mbstowcs(wcs, input_str, 1) == (size_t)-1) { - log_debug("mbstowcs(%s) error\n", input_str); + log_debug("mbstowcs(%s) error", input_str); wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback } else @@ -199,7 +199,7 @@ long split_data_lines(const char *p_buf, int max_display_len, long *p_line_offse // Exceed max_line_cnt if (line_cnt + 1 >= line_offsets_count) { - log_debug("Line count %d reaches limit %d\n", line_cnt + 1, line_offsets_count); + log_debug("Line count %d reaches limit %d", line_cnt + 1, line_offsets_count); return line_cnt; } diff --git a/src/test_file_loader.c b/src/test_file_loader.c index b096cbba..c054ba7d 100644 --- a/src/test_file_loader.c +++ b/src/test_file_loader.c @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) if (detach_file_shm(p_shm) < 0) { - log_error("detach_file_shm(%s) error\n", files[i]); + log_error("detach_file_shm(%s) error", files[i]); } } } @@ -123,7 +123,7 @@ int main(int argc, char *argv[]) if (detach_file_shm(p_shm) < 0) { - log_error("detach_file_shm(%s) error\n", files[i]); + log_error("detach_file_shm(%s) error", files[i]); } } } diff --git a/src/test_lml.c b/src/test_lml.c index 47222cbd..b834bd4e 100644 --- a/src/test_lml.c +++ b/src/test_lml.c @@ -12,6 +12,7 @@ #include "lml.h" #include "log.h" +#include "trie_dict.h" #include #include #include @@ -24,6 +25,8 @@ enum _test_lml_constant_t STR_OUT_BUF_SIZE = 4096, }; +static const char TRIE_DICT_SHM_FILE[] = "~trie_dict_shm.dat"; + const char *str_in[] = { "[left]ABCD[right]EFG", "A[u]B[italic]CD[/i]E[/u]F[b]G[/bold]", @@ -65,6 +68,7 @@ const char *str_in[] = { ": : 我已经割掉了\n" ": : 555555555555\n" ": : ", + "[image http://us.ent4.yimg.com/movies.yahoo.com/images/hv/photo/movie_pix/images/hv/photo/movie_pix/]\n", }; const int str_cnt = sizeof(str_in) / sizeof(const char *); @@ -77,6 +81,7 @@ int main(int argc, char *argv[]) double lml_time_spent; char str_out_buf[STR_OUT_BUF_SIZE]; + FILE *fp; int i; int j; @@ -96,8 +101,28 @@ int main(int argc, char *argv[]) log_common_redir(STDOUT_FILENO); log_error_redir(STDERR_FILENO); + if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL) + { + log_error("fopen(%s) error", TRIE_DICT_SHM_FILE); + return -1; + } + fclose(fp); + + if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0) + { + printf("trie_dict_init failed\n"); + return -1; + } + clock_begin = clock(); + if (lml_init() < 0) + { + printf("lml_init() error\n"); + log_end(); + return -1; + } + printf("Test #1: quote_mode = 0\n"); for (i = 0; i < str_cnt; i++) { @@ -134,6 +159,15 @@ int main(int argc, char *argv[]) printf("\npage_exec_duration=%.2f, lml_exec_duration=%.2f\n", prog_time_spent, lml_time_spent); + lml_cleanup(); + trie_dict_cleanup(); + + if (unlink(TRIE_DICT_SHM_FILE) < 0) + { + log_error("unlink(%s) error", TRIE_DICT_SHM_FILE); + return -1; + } + log_end(); return 0; diff --git a/src/test_section_list.c b/src/test_section_list.c index 8a04394d..4ae29659 100644 --- a/src/test_section_list.c +++ b/src/test_section_list.c @@ -76,28 +76,28 @@ int main(int argc, char *argv[]) if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL) { - log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE); + log_error("fopen(%s) error", ARTICLE_BLOCK_SHM_FILE); return -1; } fclose(fp); if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL) { - log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE); + log_error("fopen(%s) error", SECTION_LIST_SHM_FILE); return -1; } fclose(fp); if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL) { - log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE); + log_error("fopen(%s) error", TRIE_DICT_SHM_FILE); return -1; } fclose(fp); if ((fp = fopen(USER_LIST_SHM_FILE, "w")) == NULL) { - log_error("fopen(%s) error\n", USER_LIST_SHM_FILE); + log_error("fopen(%s) error", USER_LIST_SHM_FILE); return -1; } fclose(fp); @@ -110,20 +110,20 @@ int main(int argc, char *argv[]) if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0) { - log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count); + log_error("article_block_init(%s, %d) error", ARTICLE_BLOCK_SHM_FILE, block_count); return -2; } if (section_list_init(SECTION_LIST_SHM_FILE) < 0) { - log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE); + log_error("section_list_pool_init(%s) error", SECTION_LIST_SHM_FILE); return -2; } // Load user_list and online_user_list if (user_list_pool_init(USER_LIST_SHM_FILE) < 0) { - log_error("user_list_pool_init() error\n"); + log_error("user_list_pool_init() error"); return -2; } @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) if (article_block_reset() != 0) { - log_error("article_block_reset() error\n"); + log_error("article_block_reset() error"); return -4; } @@ -736,7 +736,7 @@ int main(int argc, char *argv[]) if (article_block_reset() != 0) { - log_error("article_block_reset() error\n"); + log_error("article_block_reset() error"); return -4; } @@ -991,25 +991,25 @@ int main(int argc, char *argv[]) if (unlink(USER_LIST_SHM_FILE) < 0) { - log_error("unlink(%s) error\n", USER_LIST_SHM_FILE); + log_error("unlink(%s) error", USER_LIST_SHM_FILE); return -1; } if (unlink(TRIE_DICT_SHM_FILE) < 0) { - log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); + log_error("unlink(%s) error", TRIE_DICT_SHM_FILE); return -1; } if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0) { - log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE); + log_error("unlink(%s) error", ARTICLE_BLOCK_SHM_FILE); return -1; } if (unlink(SECTION_LIST_SHM_FILE) < 0) { - log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE); + log_error("unlink(%s) error", SECTION_LIST_SHM_FILE); return -1; } diff --git a/src/test_ssh_server.c b/src/test_ssh_server.c index c4e75347..13cb244b 100644 --- a/src/test_ssh_server.c +++ b/src/test_ssh_server.c @@ -40,16 +40,16 @@ static int auth_password(ssh_session session, const char *user, { (void)userdata; - log_common("Authenticating user %s pwd %s\n", user, password); + log_common("Authenticating user %s pwd %s", user, password); if (strcmp(user, USER) == 0 && strcmp(password, PASSWORD) == 0) { authenticated = 1; - log_common("Authenticated\n"); + log_common("Authenticated"); return SSH_AUTH_SUCCESS; } if (tries >= 3) { - log_error("Too many authentication tries\n"); + log_error("Too many authentication tries"); ssh_disconnect(session); error = 1; return SSH_AUTH_DENIED; @@ -69,7 +69,7 @@ static int pty_request(ssh_session session, ssh_channel channel, const char *ter (void)px; (void)py; (void)userdata; - log_common("Allocated terminal\n"); + log_common("Allocated terminal"); return 0; } @@ -78,7 +78,7 @@ static int shell_request(ssh_session session, ssh_channel channel, void *userdat (void)session; (void)channel; (void)userdata; - log_common("Allocated shell\n"); + log_common("Allocated shell"); return 0; } @@ -94,7 +94,7 @@ static ssh_channel channel_open(ssh_session session, void *userdata) if (SSH_channel != NULL) return NULL; - log_common("Allocated session channel\n"); + log_common("Allocated session channel"); SSH_channel = ssh_channel_new(session); ssh_callbacks_init(&channel_cb); ssh_set_channel_callbacks(SSH_channel, &channel_cb); @@ -128,7 +128,7 @@ int ssh_server(const char *hostaddr, unsigned int port) if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_RSA_KEY_FILE) < 0) { - log_error("Error loading SSH RSA key: %s\n", SSH_HOST_RSA_KEY_FILE); + log_error("Error loading SSH RSA key: %s", SSH_HOST_RSA_KEY_FILE); } else { @@ -136,7 +136,7 @@ int ssh_server(const char *hostaddr, unsigned int port) } if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ED25519_KEY_FILE) < 0) { - log_error("Error loading SSH ED25519 key: %s\n", SSH_HOST_ED25519_KEY_FILE); + log_error("Error loading SSH ED25519 key: %s", SSH_HOST_ED25519_KEY_FILE); } else { @@ -144,7 +144,7 @@ int ssh_server(const char *hostaddr, unsigned int port) } if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ECDSA_KEY_FILE) < 0) { - log_error("Error loading SSH ECDSA key: %s\n", SSH_HOST_ECDSA_KEY_FILE); + log_error("Error loading SSH ECDSA key: %s", SSH_HOST_ECDSA_KEY_FILE); } else { @@ -153,7 +153,7 @@ int ssh_server(const char *hostaddr, unsigned int port) if (!ssh_key_valid) { - log_error("Error: no valid SSH host key\n"); + log_error("Error: no valid SSH host key"); ssh_bind_free(sshbind); return -1; } @@ -163,14 +163,14 @@ int ssh_server(const char *hostaddr, unsigned int port) ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "+ssh-ed25519,ecdsa-sha2-nistp256,ssh-rsa") < 0 || ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) { - log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind)); + log_error("Error setting SSH bind options: %s", ssh_get_error(sshbind)); ssh_bind_free(sshbind); return -1; } if (ssh_bind_listen(sshbind) < 0) { - log_error("Error listening at SSH server port: %s\n", ssh_get_error(sshbind)); + log_error("Error listening at SSH server port: %s", ssh_get_error(sshbind)); ssh_bind_free(sshbind); return -1; } @@ -193,14 +193,14 @@ int ssh_server(const char *hostaddr, unsigned int port) ssh_timeout = 60; // second if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) { - log_error("Error setting SSH options: %s\n", ssh_get_error(session)); + log_error("Error setting SSH options: %s", ssh_get_error(session)); ssh_disconnect(session); _exit(1); } if (ssh_handle_key_exchange(session)) { - log_error("ssh_handle_key_exchange: %s\n", ssh_get_error(session)); + log_error("ssh_handle_key_exchange: %s", ssh_get_error(session)); ssh_disconnect(session); _exit(1); } @@ -216,7 +216,7 @@ int ssh_server(const char *hostaddr, unsigned int port) r = ssh_event_dopoll(event, -1); if (r == SSH_ERROR) { - log_error("Error : %s\n", ssh_get_error(session)); + log_error("Error : %s", ssh_get_error(session)); ssh_disconnect(session); _exit(1); } @@ -224,23 +224,23 @@ int ssh_server(const char *hostaddr, unsigned int port) if (error) { - log_error("Error, exiting loop\n"); + log_error("Error, exiting loop"); _exit(1); } else { - log_common("Authenticated and got a channel\n"); + log_common("Authenticated and got a channel"); } ssh_timeout = 0; if (ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0) { - log_error("Error setting SSH options: %s\n", ssh_get_error(session)); + log_error("Error setting SSH options: %s", ssh_get_error(session)); ssh_disconnect(session); _exit(1); } - snprintf(buf, sizeof(buf), "Hello, welcome to the Sample SSH proxy.\r\nPlease select your destination: "); + snprintf(buf, sizeof(buf), "Hello, welcome to the Sample SSH proxy.\nPlease select your destination: "); ssh_channel_write(SSH_channel, buf, (uint32_t)strlen(buf)); do { @@ -261,11 +261,11 @@ int ssh_server(const char *hostaddr, unsigned int port) } else { - log_error("Error: %s\n", ssh_get_error(session)); + log_error("Error: %s", ssh_get_error(session)); _exit(1); } } while (i > 0); - snprintf(buf, sizeof(buf), "Trying to connect to \"%s\"\r\n", host); + snprintf(buf, sizeof(buf), "Trying to connect to \"%s\"\n", host); ssh_channel_write(SSH_channel, buf, (uint32_t)strlen(buf)); log_common("%s", buf); @@ -274,13 +274,13 @@ int ssh_server(const char *hostaddr, unsigned int port) _exit(0); case -1: - log_error("Failed to fork\n"); + log_error("Failed to fork"); break; } } else { - log_error("%s\n", ssh_get_error(sshbind)); + log_error("%s", ssh_get_error(sshbind)); } /* Since the session has been passed to a child fork, do some cleaning diff --git a/src/test_trie_dict.c b/src/test_trie_dict.c index 2b26a569..df50ade2 100644 --- a/src/test_trie_dict.c +++ b/src/test_trie_dict.c @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL) { - log_error("fopen(%s) error\n", TRIE_DICT_SHM_FILE); + log_error("fopen(%s) error", TRIE_DICT_SHM_FILE); return -1; } fclose(fp); @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) if (unlink(TRIE_DICT_SHM_FILE) < 0) { - log_error("unlink(%s) error\n", TRIE_DICT_SHM_FILE); + log_error("unlink(%s) error", TRIE_DICT_SHM_FILE); return -1; } diff --git a/src/trie_dict.c b/src/trie_dict.c index ae15cf8f..ab18310b 100644 --- a/src/trie_dict.c +++ b/src/trie_dict.c @@ -46,19 +46,19 @@ int trie_dict_init(const char *filename, int node_count_limit) if (filename == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } if (p_trie_node_pool != NULL) { - log_error("trie_dict_pool already initialized\n"); + log_error("trie_dict_pool already initialized"); return -1; } if (node_count_limit <= 0 || node_count_limit > TRIE_NODE_PER_POOL) { - log_error("trie_dict_init(%d) error: invalid node_count_limit\n", node_count_limit); + log_error("trie_dict_init(%d) error: invalid node_count_limit", node_count_limit); return -1; } @@ -71,18 +71,18 @@ int trie_dict_init(const char *filename, int node_count_limit) if (shm_unlink(trie_node_shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", trie_node_shm_name, errno); + log_error("shm_unlink(%s) error (%d)", trie_node_shm_name, errno); return -2; } if ((fd = shm_open(trie_node_shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", trie_node_shm_name, errno); + log_error("shm_open(%s) error (%d)", trie_node_shm_name, errno); return -2; } if (ftruncate(fd, (off_t)size) == -1) { - log_error("ftruncate(size=%d) error (%d)\n", size, errno); + log_error("ftruncate(size=%d) error (%d)", size, errno); close(fd); return -2; } @@ -90,14 +90,14 @@ int trie_dict_init(const char *filename, int node_count_limit) p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -128,7 +128,7 @@ void trie_dict_cleanup(void) if (shm_unlink(trie_node_shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", trie_node_shm_name, errno); + log_error("shm_unlink(%s) error (%d)", trie_node_shm_name, errno); } trie_node_shm_name[0] = '\0'; @@ -138,7 +138,7 @@ int set_trie_dict_shm_readonly(void) { if (p_trie_node_pool != NULL && mprotect(p_trie_node_pool, p_trie_node_pool->shm_size, PROT_READ) < 0) { - log_error("mprotect() error (%d)\n", errno); + log_error("mprotect() error (%d)", errno); return -1; } @@ -149,7 +149,7 @@ int detach_trie_dict_shm(void) { if (p_trie_node_pool != NULL && munmap(p_trie_node_pool, p_trie_node_pool->shm_size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -1; } @@ -173,7 +173,7 @@ TRIE_NODE *trie_dict_create(void) } else if (p_trie_node_pool != NULL) { - log_error("trie_dict_create() error: node depleted %d >= %d\n", p_trie_node_pool->node_count, p_trie_node_pool->node_count_limit); + log_error("trie_dict_create() error: node depleted %d >= %d", p_trie_node_pool->node_count, p_trie_node_pool->node_count_limit); } return p_dict; diff --git a/src/user_info_display.c b/src/user_info_display.c index 7b6eebc1..31b3e6c8 100644 --- a/src/user_info_display.c +++ b/src/user_info_display.c @@ -67,7 +67,7 @@ int user_info_display(USER_INFO *p_user_info) if (p_user_info == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -111,7 +111,7 @@ int user_info_display(USER_INFO *p_user_info) ret = query_user_online_info_by_uid(p_user_info->uid, sessions, &session_cnt, 0); if (ret < 0) { - log_error("query_user_online_info_by_uid(uid=%d, cnt=%d) error: %d\n", + log_error("query_user_online_info_by_uid(uid=%d, cnt=%d) error: %d", p_user_info->uid, session_cnt, ret); session_cnt = 0; } @@ -125,7 +125,7 @@ int user_info_display(USER_INFO *p_user_info) if (p + strlen(p_action_title) + 4 >= action_str + sizeof(action_str)) // buffer overflow { - log_error("action_str of user(uid=%d) truncated at i=%d\n", p_user_info->uid, i); + log_error("action_str of user(uid=%d) truncated at i=%d", p_user_info->uid, i); break; } *p++ = '['; diff --git a/src/user_info_update.c b/src/user_info_update.c index c2f29efb..628681fe 100644 --- a/src/user_info_update.c +++ b/src/user_info_update.c @@ -53,7 +53,7 @@ int user_intro_edit(int uid) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -61,13 +61,13 @@ int user_intro_edit(int uid) snprintf(sql_intro, sizeof(sql_intro), "SELECT introduction FROM user_pubinfo WHERE UID=%d", uid); if (mysql_query(db, sql_intro) != 0) { - log_error("Query user_pubinfo error: %s\n", mysql_error(db)); + log_error("Query user_pubinfo error: %s", mysql_error(db)); ret = -2; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_intro data failed\n"); + log_error("Get user_intro data failed"); ret = -2; goto cleanup; } @@ -77,7 +77,7 @@ int user_intro_edit(int uid) } else { - log_error("mysql_fetch_row() failed\n"); + log_error("mysql_fetch_row() failed"); ret = -2; goto cleanup; } @@ -109,14 +109,14 @@ int user_intro_edit(int uid) len_intro = editor_data_save(p_editor_data, intro, BBS_user_intro_max_len); if (len_intro < 0) { - log_error("editor_data_save() error\n"); + log_error("editor_data_save() error"); ret = -3; goto cleanup; } if (check_badwords(intro, '*') < 0) { - log_error("check_badwords(introduction) error\n"); + log_error("check_badwords(introduction) error"); ret = -3; goto cleanup; } @@ -154,7 +154,7 @@ int user_intro_edit(int uid) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -169,7 +169,7 @@ int user_intro_edit(int uid) if (mysql_query(db, sql_intro) != 0) { - log_error("Update user_pubinfo error: %s\n", mysql_error(db)); + log_error("Update user_pubinfo error: %s", mysql_error(db)); ret = -2; goto cleanup; } @@ -222,7 +222,7 @@ int user_sign_edit(int uid) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -230,13 +230,13 @@ int user_sign_edit(int uid) snprintf(sql_sign, sizeof(sql_sign), "SELECT sign_%d FROM user_pubinfo WHERE UID=%d", sign_id, uid); if (mysql_query(db, sql_sign) != 0) { - log_error("Query user_pubinfo error: %s\n", mysql_error(db)); + log_error("Query user_pubinfo error: %s", mysql_error(db)); ret = -2; goto cleanup; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_sign data failed\n"); + log_error("Get user_sign data failed"); ret = -2; goto cleanup; } @@ -246,7 +246,7 @@ int user_sign_edit(int uid) } else { - log_error("mysql_fetch_row() failed\n"); + log_error("mysql_fetch_row() failed"); ret = -2; goto cleanup; } @@ -279,14 +279,14 @@ int user_sign_edit(int uid) len_sign = editor_data_save(p_editor_data, sign, BBS_user_sign_max_len); if (len_sign < 0) { - log_error("editor_data_save() error\n"); + log_error("editor_data_save() error"); ret = -3; goto cleanup; } if (check_badwords(sign, '*') < 0) { - log_error("check_badwords(sign) error\n"); + log_error("check_badwords(sign) error"); ret = -3; goto cleanup; } @@ -324,7 +324,7 @@ int user_sign_edit(int uid) db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); ret = -1; goto cleanup; } @@ -339,7 +339,7 @@ int user_sign_edit(int uid) if (mysql_query(db, sql_sign) != 0) { - log_error("Update user_pubinfo error: %s\n", mysql_error(db)); + log_error("Update user_pubinfo error: %s", mysql_error(db)); ret = -2; goto cleanup; } diff --git a/src/user_list.c b/src/user_list.c index 34a6d8ca..28fe90d9 100644 --- a/src/user_list.c +++ b/src/user_list.c @@ -152,7 +152,7 @@ int user_list_load(MYSQL *db, USER_LIST *p_list) if (db == NULL || p_list == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -175,14 +175,14 @@ int user_list_load(MYSQL *db, USER_LIST *p_list) if (mysql_query(db, sql) != 0) { - log_error("Query user info error: %s\n", mysql_error(db)); + log_error("Query user info error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get user info data failed\n"); + log_error("Get user info data failed"); ret = -1; goto cleanup; } @@ -210,7 +210,7 @@ int user_list_load(MYSQL *db, USER_LIST *p_list) intro_len = strlen((row[12] == NULL ? "" : row[12])); if (intro_len >= sizeof(p_list->user_intro_buf) - 1 - intro_buf_offset) { - log_error("OOM for user introduction: len=%d, i=%d\n", intro_len, i); + log_error("OOM for user introduction: len=%d, i=%d", intro_len, i); break; } memcpy(p_list->user_intro_buf + intro_buf_offset, @@ -222,7 +222,7 @@ int user_list_load(MYSQL *db, USER_LIST *p_list) i++; if (i >= BBS_max_user_count) { - log_error("Too many users, exceed limit %d\n", BBS_max_user_count); + log_error("Too many users, exceed limit %d", BBS_max_user_count); break; } } @@ -240,12 +240,12 @@ int user_list_load(MYSQL *db, USER_LIST *p_list) qsort(p_list->index_uid, (size_t)i, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); - log_debug("Rebuild index of %d users, last_uid=%d\n", i, p_list->users[i - 1].uid); + log_debug("Rebuild index of %d users, last_uid=%d", i, p_list->users[i - 1].uid); } p_list->user_count = i; - log_debug("Loaded %d users\n", p_list->user_count); + log_debug("Loaded %d users", p_list->user_count); cleanup: mysql_free_result(rs); @@ -266,7 +266,7 @@ int user_online_list_load(MYSQL *db, USER_ONLINE_LIST *p_online_list) if (db == NULL || p_online_list == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -279,14 +279,14 @@ int user_online_list_load(MYSQL *db, USER_ONLINE_LIST *p_online_list) if (mysql_query(db, sql) != 0) { - log_error("Query user online error: %s\n", mysql_error(db)); + log_error("Query user online error: %s", mysql_error(db)); ret = -1; goto cleanup; } if ((rs = mysql_use_result(db)) == NULL) { - log_error("Get user online data failed\n"); + log_error("Get user online data failed"); ret = -1; goto cleanup; } @@ -312,7 +312,7 @@ int user_online_list_load(MYSQL *db, USER_ONLINE_LIST *p_online_list) if ((ret = query_user_info_by_uid(atoi(row[1]), &(p_online_list->users[i].user_info), NULL, 0)) <= 0) { - log_error("query_user_info_by_uid(%d) error\n", atoi(row[1])); + log_error("query_user_info_by_uid(%d) error", atoi(row[1])); continue; } @@ -328,7 +328,7 @@ int user_online_list_load(MYSQL *db, USER_ONLINE_LIST *p_online_list) } else if (trie_dict_get(p_trie_action_dict, p_online_list->users[i].current_action, (int64_t *)(&(p_online_list->users[i].current_action_title))) < 0) { - log_error("trie_dict_get(p_trie_action_dict, %s) error on session_id=%s\n", + log_error("trie_dict_get(p_trie_action_dict, %s) error on session_id=%s", p_online_list->users[i].current_action, p_online_list->users[i].session_id); continue; } @@ -339,7 +339,7 @@ int user_online_list_load(MYSQL *db, USER_ONLINE_LIST *p_online_list) i++; if (i >= BBS_max_user_online_count) { - log_error("Too many online users, exceed limit %d\n", BBS_max_user_online_count); + log_error("Too many online users, exceed limit %d", BBS_max_user_online_count); break; } } @@ -375,7 +375,7 @@ int user_login_count_load(MYSQL *db) if (db == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -383,12 +383,12 @@ int user_login_count_load(MYSQL *db) "SELECT ID FROM user_login_log ORDER BY ID DESC LIMIT 1"); if (mysql_query(db, sql) != 0) { - log_error("Query user_login_log error: %s\n", mysql_error(db)); + log_error("Query user_login_log error: %s", mysql_error(db)); return -2; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_login_log data failed\n"); + log_error("Get user_login_log data failed"); return -2; } if ((row = mysql_fetch_row(rs))) @@ -416,14 +416,14 @@ int user_list_pool_init(const char *filename) if (p_user_list_pool != NULL || p_trie_action_dict != NULL) { - log_error("p_user_list_pool already initialized\n"); + log_error("p_user_list_pool already initialized"); return -1; } p_trie_action_dict = trie_dict_create(); if (p_trie_action_dict == NULL) { - log_error("trie_dict_create() error\n"); + log_error("trie_dict_create() error"); return -1; } @@ -431,7 +431,7 @@ int user_list_pool_init(const char *filename) { if (trie_dict_set(p_trie_action_dict, user_action_map[i].name, (int64_t)(user_action_map[i].title)) < 0) { - log_error("trie_dict_set(p_trie_action_dict, %s) error\n", user_action_map[i].name); + log_error("trie_dict_set(p_trie_action_dict, %s) error", user_action_map[i].name); } } @@ -444,18 +444,18 @@ int user_list_pool_init(const char *filename) if (shm_unlink(user_list_shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", user_list_shm_name, errno); + log_error("shm_unlink(%s) error (%d)", user_list_shm_name, errno); return -2; } if ((fd = shm_open(user_list_shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) { - log_error("shm_open(%s) error (%d)\n", user_list_shm_name, errno); + log_error("shm_open(%s) error (%d)", user_list_shm_name, errno); return -2; } if (ftruncate(fd, (off_t)size) == -1) { - log_error("ftruncate(size=%d) error (%d)\n", size, errno); + log_error("ftruncate(size=%d) error (%d)", size, errno); close(fd); return -2; } @@ -463,14 +463,14 @@ int user_list_pool_init(const char *filename) p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L); if (p_shm == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); close(fd); return -2; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); return -1; } @@ -481,7 +481,7 @@ int user_list_pool_init(const char *filename) #ifndef HAVE_SYSTEM_V if (sem_init(&(p_user_list_pool->sem), 1, 1) == -1) { - log_error("sem_init() error (%d)\n", errno); + log_error("sem_init() error (%d)", errno); return -3; } @@ -492,7 +492,7 @@ int user_list_pool_init(const char *filename) key = ftok(filename, proj_id); if (key == -1) { - log_error("ftok(%s %d) error (%d)\n", filename, proj_id, errno); + log_error("ftok(%s %d) error (%d)", filename, proj_id, errno); return -2; } @@ -500,7 +500,7 @@ int user_list_pool_init(const char *filename) semid = semget(key, (int)size, IPC_CREAT | IPC_EXCL | 0600); if (semid == -1) { - log_error("semget(user_list_pool_sem, size = %d) error (%d)\n", size, errno); + log_error("semget(user_list_pool_sem, size = %d) error (%d)", size, errno); return -3; } @@ -510,7 +510,7 @@ int user_list_pool_init(const char *filename) { if (semctl(semid, i, SETVAL, arg) == -1) { - log_error("semctl(user_list_pool_sem, SETVAL) error (%d)\n", errno); + log_error("semctl(user_list_pool_sem, SETVAL) error (%d)", errno); return -3; } } @@ -543,12 +543,12 @@ void user_list_pool_cleanup(void) #ifdef HAVE_SYSTEM_V if (semctl(p_user_list_pool->semid, 0, IPC_RMID) == -1) { - log_error("semctl(semid = %d, IPC_RMID) error (%d)\n", p_user_list_pool->semid, errno); + log_error("semctl(semid = %d, IPC_RMID) error (%d)", p_user_list_pool->semid, errno); } #else if (sem_destroy(&(p_user_list_pool->sem)) == -1) { - log_error("sem_destroy() error (%d)\n", errno); + log_error("sem_destroy() error (%d)", errno); } #endif @@ -556,7 +556,7 @@ void user_list_pool_cleanup(void) if (shm_unlink(user_list_shm_name) == -1 && errno != ENOENT) { - log_error("shm_unlink(%s) error (%d)\n", user_list_shm_name, errno); + log_error("shm_unlink(%s) error (%d)", user_list_shm_name, errno); } user_list_shm_name[0] = '\0'; @@ -573,7 +573,7 @@ int set_user_list_pool_shm_readonly(void) { if (p_user_list_pool != NULL && mprotect(p_user_list_pool, p_user_list_pool->shm_size, PROT_READ) < 0) { - log_error("mprotect() error (%d)\n", errno); + log_error("mprotect() error (%d)", errno); return -1; } @@ -584,7 +584,7 @@ int detach_user_list_pool_shm(void) { if (p_user_list_pool != NULL && munmap(p_user_list_pool, p_user_list_pool->shm_size) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); return -1; } @@ -601,14 +601,14 @@ int user_list_pool_reload(int online_user) if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } db = db_open(); if (db == NULL) { - log_error("db_open() error: %s\n", mysql_error(db)); + log_error("db_open() error: %s", mysql_error(db)); return -1; } @@ -616,14 +616,14 @@ int user_list_pool_reload(int online_user) { if (user_online_list_load(db, &(p_user_list_pool->user_online_list[p_user_list_pool->user_online_list_index_new])) < 0) { - log_error("user_online_list_load() error\n"); + log_error("user_online_list_load() error"); ret = -2; goto cleanup; } if (user_login_count_load(db) < 0) { - log_error("user_login_count_load() error\n"); + log_error("user_login_count_load() error"); ret = -2; goto cleanup; } @@ -632,7 +632,7 @@ int user_list_pool_reload(int online_user) { if (user_list_load(db, &(p_user_list_pool->user_list[p_user_list_pool->user_list_index_new])) < 0) { - log_error("user_list_load() error\n"); + log_error("user_list_load() error"); ret = -2; goto cleanup; } @@ -643,7 +643,7 @@ int user_list_pool_reload(int online_user) if (user_list_rw_lock() < 0) { - log_error("user_list_rw_lock() error\n"); + log_error("user_list_rw_lock() error"); ret = -3; goto cleanup; } @@ -665,7 +665,7 @@ int user_list_pool_reload(int online_user) if (user_list_rw_unlock() < 0) { - log_error("user_list_rw_unlock() error\n"); + log_error("user_list_rw_unlock() error"); ret = -3; goto cleanup; } @@ -686,7 +686,7 @@ int user_list_try_rd_lock(int wait_sec) if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } @@ -705,14 +705,14 @@ int user_list_try_rd_lock(int wait_sec) ret = semtimedop(p_user_list_pool->semid, sops, 2, &timeout); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(lock read) error %d\n", errno); + log_error("semop(lock read) error %d", errno); } #else if (sem_timedwait(&(p_user_list_pool->sem), &timeout) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_timedwait() error %d\n", errno); + log_error("sem_timedwait() error %d", errno); } return -1; } @@ -729,7 +729,7 @@ int user_list_try_rd_lock(int wait_sec) if (sem_post(&(p_user_list_pool->sem)) == -1) { - log_error("sem_post() error %d\n", errno); + log_error("sem_post() error %d", errno); return -1; } #endif @@ -747,7 +747,7 @@ int user_list_try_rw_lock(int wait_sec) if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } @@ -770,14 +770,14 @@ int user_list_try_rw_lock(int wait_sec) ret = semtimedop(p_user_list_pool->semid, sops, 3, &timeout); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(lock write) error %d\n", errno); + log_error("semop(lock write) error %d", errno); } #else if (sem_timedwait(&(p_user_list_pool->sem), &timeout) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_timedwait() error %d\n", errno); + log_error("sem_timedwait() error %d", errno); } return -1; } @@ -794,7 +794,7 @@ int user_list_try_rw_lock(int wait_sec) if (sem_post(&(p_user_list_pool->sem)) == -1) { - log_error("sem_post() error %d\n", errno); + log_error("sem_post() error %d", errno); return -1; } #endif @@ -811,7 +811,7 @@ int user_list_rd_unlock(void) if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } @@ -823,14 +823,14 @@ int user_list_rd_unlock(void) ret = semop(p_user_list_pool->semid, sops, 1); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(unlock read) error %d\n", errno); + log_error("semop(unlock read) error %d", errno); } #else if (sem_wait(&(p_user_list_pool->sem)) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_wait() error %d\n", errno); + log_error("sem_wait() error %d", errno); } return -1; } @@ -841,12 +841,12 @@ int user_list_rd_unlock(void) } else { - log_error("read_lock_count already 0\n"); + log_error("read_lock_count already 0"); } if (sem_post(&(p_user_list_pool->sem)) == -1) { - log_error("sem_post() error %d\n", errno); + log_error("sem_post() error %d", errno); return -1; } #endif @@ -863,7 +863,7 @@ int user_list_rw_unlock(void) if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } @@ -875,14 +875,14 @@ int user_list_rw_unlock(void) ret = semop(p_user_list_pool->semid, sops, 1); if (ret == -1 && errno != EAGAIN && errno != EINTR) { - log_error("semop(unlock write) error %d\n", errno); + log_error("semop(unlock write) error %d", errno); } #else if (sem_wait(&(p_user_list_pool->sem)) == -1) { if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) { - log_error("sem_wait() error %d\n", errno); + log_error("sem_wait() error %d", errno); } return -1; } @@ -893,12 +893,12 @@ int user_list_rw_unlock(void) } else { - log_error("write_lock_count already 0\n"); + log_error("write_lock_count already 0"); } if (sem_post(&(p_user_list_pool->sem)) == -1) { - log_error("sem_post() error %d\n", errno); + log_error("sem_post() error %d", errno); return -1; } #endif @@ -914,7 +914,7 @@ int user_list_rd_lock(void) if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } @@ -930,14 +930,14 @@ int user_list_rd_lock(void) timer++; if (timer % USER_LIST_TRY_LOCK_TIMES == 0) { - log_error("user_list_try_rd_lock() tried %d times\n", timer); + log_error("user_list_try_rd_lock() tried %d times", timer); if (time(NULL) - tm_first_failure >= USER_LIST_DEAD_LOCK_TIMEOUT) { - log_error("Unable to acquire rw_lock for %d seconds\n", time(NULL) - tm_first_failure); + log_error("Unable to acquire rw_lock for %d seconds", time(NULL) - tm_first_failure); #ifndef HAVE_SYSTEM_V user_list_reset_lock(); - log_error("Reset POSIX semaphore to resolve dead lock\n"); + log_error("Reset POSIX semaphore to resolve dead lock"); #endif break; } @@ -946,7 +946,7 @@ int user_list_rd_lock(void) } else // failed { - log_error("user_list_try_rd_lock() failed\n"); + log_error("user_list_try_rd_lock() failed"); break; } } @@ -962,7 +962,7 @@ int user_list_rw_lock(void) if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } @@ -978,14 +978,14 @@ int user_list_rw_lock(void) timer++; if (timer % USER_LIST_TRY_LOCK_TIMES == 0) { - log_error("user_list_try_rw_lock() tried %d times\n", timer); + log_error("user_list_try_rw_lock() tried %d times", timer); if (time(NULL) - tm_first_failure >= USER_LIST_DEAD_LOCK_TIMEOUT) { - log_error("Unable to acquire rw_lock for %d seconds\n", time(NULL) - tm_first_failure); + log_error("Unable to acquire rw_lock for %d seconds", time(NULL) - tm_first_failure); #ifndef HAVE_SYSTEM_V user_list_reset_lock(); - log_error("Reset POSIX semaphore to resolve dead lock\n"); + log_error("Reset POSIX semaphore to resolve dead lock"); #endif break; } @@ -994,7 +994,7 @@ int user_list_rw_lock(void) } else // failed { - log_error("user_list_try_rw_lock() failed\n"); + log_error("user_list_try_rw_lock() failed"); break; } } @@ -1007,13 +1007,13 @@ int user_list_reset_lock(void) { if (p_user_list_pool == NULL) { - log_error("p_user_list_pool not initialized\n"); + log_error("p_user_list_pool not initialized"); return -1; } if (sem_destroy(&(p_user_list_pool->sem)) == -1) { - log_error("sem_destroy() error (%d)\n", errno); + log_error("sem_destroy() error (%d)", errno); } p_user_list_pool->read_lock_count = 0; @@ -1021,7 +1021,7 @@ int user_list_reset_lock(void) if (sem_init(&(p_user_list_pool->sem), 1, 1) == -1) { - log_error("sem_init() error (%d)\n", errno); + log_error("sem_init() error (%d)", errno); } return 0; @@ -1034,7 +1034,7 @@ int query_user_list(int page_id, USER_INFO *p_users, int *p_user_count, int *p_p if (p_users == NULL || p_user_count == NULL || p_page_count == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1044,7 +1044,7 @@ int query_user_list(int page_id, USER_INFO *p_users, int *p_user_count, int *p_p // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1060,7 +1060,7 @@ int query_user_list(int page_id, USER_INFO *p_users, int *p_user_count, int *p_p if (page_id < 0 || page_id >= *p_page_count) { - log_error("Invalid page_id = %d, not in range [0, %d)\n", page_id, *p_page_count); + log_error("Invalid page_id = %d, not in range [0, %d)", page_id, *p_page_count); ret = -3; goto cleanup; } @@ -1077,7 +1077,7 @@ int query_user_list(int page_id, USER_INFO *p_users, int *p_user_count, int *p_p // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1090,7 +1090,7 @@ int query_user_online_list(int page_id, USER_ONLINE_INFO *p_online_users, int *p if (p_online_users == NULL || p_user_count == NULL || p_page_count == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1100,7 +1100,7 @@ int query_user_online_list(int page_id, USER_ONLINE_INFO *p_online_users, int *p // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1115,7 +1115,7 @@ int query_user_online_list(int page_id, USER_ONLINE_INFO *p_online_users, int *p if (page_id < 0 || page_id >= *p_page_count) { - log_error("Invalid page_id = %d, not in range [0, %d)\n", page_id, *p_page_count); + log_error("Invalid page_id = %d, not in range [0, %d)", page_id, *p_page_count); ret = -3; goto cleanup; } @@ -1132,7 +1132,7 @@ int query_user_online_list(int page_id, USER_ONLINE_INFO *p_online_users, int *p // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1143,14 +1143,14 @@ int get_user_list_count(int *p_user_cnt) { if (p_user_cnt == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1159,7 +1159,7 @@ int get_user_list_count(int *p_user_cnt) // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); return -2; } @@ -1170,14 +1170,14 @@ int get_user_online_list_count(int *p_user_cnt, int *p_guest_cnt) { if (p_user_cnt == NULL || p_guest_cnt == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1187,7 +1187,7 @@ int get_user_online_list_count(int *p_user_cnt, int *p_guest_cnt) // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); return -2; } @@ -1198,7 +1198,7 @@ int get_user_login_count(int *p_login_cnt) { if (p_login_cnt == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1213,14 +1213,14 @@ int query_user_info(int32_t id, USER_INFO *p_user) if (p_user == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1233,7 +1233,7 @@ int query_user_info(int32_t id, USER_INFO *p_user) // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1250,14 +1250,14 @@ int query_user_info_by_uid(int32_t uid, USER_INFO *p_user, char *p_intro_buf, si if (p_user == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1299,7 +1299,7 @@ int query_user_info_by_uid(int32_t uid, USER_INFO *p_user, char *p_intro_buf, si // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1320,7 +1320,7 @@ int query_user_info_by_username(const char *username_prefix, int max_user_cnt, if (username_prefix == NULL || uid_list == NULL || username_list == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1329,7 +1329,7 @@ int query_user_info_by_username(const char *username_prefix, int max_user_cnt, // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1357,7 +1357,7 @@ int query_user_info_by_username(const char *username_prefix, int max_user_cnt, if (strncasecmp(username_prefix, p_user_list_pool->user_list[p_user_list_pool->user_list_index_current].users[left].username, prefix_len) == 0) // Found { - log_debug("Debug: match found, pos=%d\n", left); + log_debug("Debug: match found, pos=%d", left); left_save = left; right = left; @@ -1383,7 +1383,7 @@ int query_user_info_by_username(const char *username_prefix, int max_user_cnt, } } - log_debug("Debug: first match found, pos=%d\n", right); + log_debug("Debug: first match found, pos=%d", right); left = left_save; left_save = right; @@ -1409,7 +1409,7 @@ int query_user_info_by_username(const char *username_prefix, int max_user_cnt, } } - log_debug("Debug: last match found, pos=%d\n", left); + log_debug("Debug: last match found, pos=%d", left); right = left; left = left_save; @@ -1427,7 +1427,7 @@ int query_user_info_by_username(const char *username_prefix, int max_user_cnt, // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1440,14 +1440,14 @@ int query_user_online_info(int32_t id, USER_ONLINE_INFO *p_user) if (p_user == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1460,7 +1460,7 @@ int query_user_online_info(int32_t id, USER_ONLINE_INFO *p_user) // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1479,7 +1479,7 @@ int query_user_online_info_by_uid(int32_t uid, USER_ONLINE_INFO *p_users, int *p if (p_users == NULL || p_user_cnt == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -1489,7 +1489,7 @@ int query_user_online_info_by_uid(int32_t uid, USER_ONLINE_INFO *p_users, int *p // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1551,7 +1551,7 @@ int query_user_online_info_by_uid(int32_t uid, USER_ONLINE_INFO *p_users, int *p // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1568,14 +1568,14 @@ int get_user_id_list(int32_t *p_uid_list, int *p_user_cnt, int start_uid) if (p_uid_list == NULL || p_user_cnt == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // acquire lock of user list if (user_list_rd_lock() < 0) { - log_error("user_list_rd_lock() error\n"); + log_error("user_list_rd_lock() error"); return -2; } @@ -1609,7 +1609,7 @@ int get_user_id_list(int32_t *p_uid_list, int *p_user_cnt, int start_uid) // release lock of user list if (user_list_rd_unlock() < 0) { - log_error("user_list_rd_unlock() error\n"); + log_error("user_list_rd_unlock() error"); ret = -1; } @@ -1634,7 +1634,7 @@ int get_user_article_cnt(int32_t uid) ret = user_stat_get(&(p_user_list_pool->user_stat_map), uid, &p_stat); if (ret < 0) { - log_error("user_stat_get(uid=%d) error: %d\n", uid, ret); + log_error("user_stat_get(uid=%d) error: %d", uid, ret); return -1; } else if (ret == 0) // user not found diff --git a/src/user_list_display.c b/src/user_list_display.c index 655ba732..4a5e89f4 100644 --- a/src/user_list_display.c +++ b/src/user_list_display.c @@ -75,7 +75,7 @@ static int user_list_draw_items(int page_id, USER_INFO *p_users, int user_count) p_tm = gmtime(&tm_duration); if (p_tm == NULL) { - log_error("Invalid time duration\n"); + log_error("Invalid time duration"); str_time_login[0] = '\0'; } else if (p_tm->tm_year > 70) @@ -135,7 +135,7 @@ static int user_online_list_draw_items(int page_id, USER_ONLINE_INFO *p_users, i p_tm = gmtime(&tm_duration); if (p_tm == NULL) { - log_error("Invalid time duration\n"); + log_error("Invalid time duration"); str_time_login[0] = '\0'; } else if (p_tm->tm_yday > 0) @@ -158,7 +158,7 @@ static int user_online_list_draw_items(int page_id, USER_ONLINE_INFO *p_users, i p_tm = gmtime(&tm_duration); if (p_tm == NULL) { - log_error("Invalid time duration\n"); + log_error("Invalid time duration"); str_time_idle[0] = '\0'; } else if (p_tm->tm_min > 0) @@ -222,21 +222,21 @@ static enum select_cmd_t user_list_select(int total_page, int item_count, int *p // Refresh current action if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } } switch (ch) { case KEY_NULL: // broken pipe - log_debug("KEY_NULL\n"); + log_debug("KEY_NULL"); case KEY_ESC: case KEY_LEFT: return EXIT_LIST; // exit list case KEY_TIMEOUT: if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { - log_debug("User input timeout\n"); + log_debug("User input timeout"); return EXIT_LIST; // exit list } continue; @@ -364,7 +364,7 @@ int user_list_display(int online_user) ret = query_user_online_list(page_id, online_users, &user_count, &page_count); if (ret < 0) { - log_error("query_user_online_list(page_id=%d) error\n", page_id); + log_error("query_user_online_list(page_id=%d) error", page_id); return -2; } } @@ -373,7 +373,7 @@ int user_list_display(int online_user) ret = query_user_list(page_id, users, &user_count, &page_count); if (ret < 0) { - log_error("query_user_list(page_id=%d) error\n", page_id); + log_error("query_user_list(page_id=%d) error", page_id); return -2; } } @@ -390,7 +390,7 @@ int user_list_display(int online_user) ret = user_online_list_draw_items(page_id, online_users, user_count); if (ret < 0) { - log_error("user_online_list_draw_items(page_id=%d) error\n", page_id); + log_error("user_online_list_draw_items(page_id=%d) error", page_id); return -3; } } @@ -399,7 +399,7 @@ int user_list_display(int online_user) ret = user_list_draw_items(page_id, users, user_count); if (ret < 0) { - log_error("user_list_draw_items(page_id=%d) error\n", page_id); + log_error("user_list_draw_items(page_id=%d) error", page_id); return -3; } } @@ -413,7 +413,7 @@ int user_list_display(int online_user) if (user_online_update(online_user ? "USER_ONLINE" : "USER_LIST") < 0) { - log_error("user_online_update(%s) error\n", + log_error("user_online_update(%s) error", (online_user ? "USER_ONLINE" : "USER_LIST")); } @@ -429,7 +429,7 @@ int user_list_display(int online_user) ret = query_user_online_list(page_id, online_users, &user_count, &page_count); if (ret < 0) { - log_error("query_user_online_list(page_id=%d) error\n", page_id); + log_error("query_user_online_list(page_id=%d) error", page_id); return -2; } } @@ -438,7 +438,7 @@ int user_list_display(int online_user) ret = query_user_list(page_id, users, &user_count, &page_count); if (ret < 0) { - log_error("query_user_list(page_id=%d) error\n", page_id); + log_error("query_user_list(page_id=%d) error", page_id); return -2; } } @@ -466,7 +466,7 @@ int user_list_display(int online_user) user_list_draw_screen(online_user); break; default: - log_error("Unknown command %d\n", ret); + log_error("Unknown command %d", ret); } } @@ -529,7 +529,7 @@ int user_list_search(void) if (ret < 0) { - log_error("query_user_info_by_username(%s) error\n", username); + log_error("query_user_info_by_username(%s) error", username); return -1; } else if (ret > 1) @@ -583,12 +583,12 @@ int user_list_search(void) { if (query_user_info_by_uid(uid_list[0], &user_info, user_intro, sizeof(user_intro)) <= 0) { - log_error("query_user_info_by_uid(uid=%d) error\n", uid_list[0]); + log_error("query_user_info_by_uid(uid=%d) error", uid_list[0]); return -2; } else if (user_info_display(&user_info) < 0) { - log_error("user_info_display(uid=%d) error\n", uid_list[0]); + log_error("user_info_display(uid=%d) error", uid_list[0]); return -3; } return 1; diff --git a/src/user_priv.c b/src/user_priv.c index 8fa340bf..515e5f23 100644 --- a/src/user_priv.c +++ b/src/user_priv.c @@ -126,12 +126,12 @@ int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid) uid); if (mysql_query(db, sql) != 0) { - log_error("Query user_list error: %s\n", mysql_error(db)); + log_error("Query user_list error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_list data failed\n"); + log_error("Get user_list data failed"); return -1; } if ((row = mysql_fetch_row(rs))) @@ -148,12 +148,12 @@ int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid) uid); if (mysql_query(db, sql) != 0) { - log_error("Query admin_config error: %s\n", mysql_error(db)); + log_error("Query admin_config error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get admin_config data failed\n"); + log_error("Get admin_config data failed"); return -1; } if ((row = mysql_fetch_row(rs))) @@ -172,12 +172,12 @@ int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid) uid); if (mysql_query(db, sql) != 0) { - log_error("Query section_master error: %s\n", mysql_error(db)); + log_error("Query section_master error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get section_master data failed\n"); + log_error("Get section_master data failed"); return -1; } while ((row = mysql_fetch_row(rs))) @@ -196,12 +196,12 @@ int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid) "ORDER BY SID"); if (mysql_query(db, sql) != 0) { - log_error("Query section_config error: %s\n", mysql_error(db)); + log_error("Query section_config error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get section_config data failed\n"); + log_error("Get section_config data failed"); return -1; } while ((row = mysql_fetch_row(rs))) @@ -230,12 +230,12 @@ int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid) uid); if (mysql_query(db, sql) != 0) { - log_error("Query ban_user_list error: %s\n", mysql_error(db)); + log_error("Query ban_user_list error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get ban_user_list data failed\n"); + log_error("Get ban_user_list data failed"); return -1; } while ((row = mysql_fetch_row(rs))) @@ -251,12 +251,12 @@ int load_priv(MYSQL *db, BBS_user_priv *p_priv, int uid) uid); if (mysql_query(db, sql) != 0) { - log_error("Query section_favorite error: %s\n", mysql_error(db)); + log_error("Query section_favorite error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get section_favorite data failed\n"); + log_error("Get section_favorite data failed"); return -1; } while ((row = mysql_fetch_row(rs))) diff --git a/src/user_stat.c b/src/user_stat.c index 230f742d..2f05e8f9 100644 --- a/src/user_stat.c +++ b/src/user_stat.c @@ -19,7 +19,7 @@ int user_stat_map_init(USER_STAT_MAP *p_map) { if (p_map == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -40,14 +40,14 @@ int user_stat_map_update(USER_STAT_MAP *p_map) if (p_map == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } // Load uid_list if (get_user_id_list(uid_list, &user_cnt, p_map->last_uid + 1) < 0) { - log_error("get_user_id_list(%d, 0) error\n", user_cnt); + log_error("get_user_id_list(%d, 0) error", user_cnt); return -2; } @@ -67,7 +67,7 @@ int user_stat_map_update(USER_STAT_MAP *p_map) p_article = article_block_find_by_index(i); if (p_article == NULL) { - log_error("article_block_find_by_index(index=%d) error\n", i); + log_error("article_block_find_by_index(index=%d) error", i); break; } @@ -78,14 +78,14 @@ int user_stat_map_update(USER_STAT_MAP *p_map) if (p_article->uid > p_map->last_uid) { - log_debug("uid=%d of article(aid=%d) is greater than last_uid=%d\n", + log_debug("uid=%d of article(aid=%d) is greater than last_uid=%d", p_article->uid, p_article->aid, p_map->last_uid); continue; } if (user_stat_article_cnt_inc(p_map, p_article->uid, 1) < 0) { - log_error("user_stat_article_cnt_inc(uid=%d, 1) error\n", p_article->uid); + log_error("user_stat_article_cnt_inc(uid=%d, 1) error", p_article->uid); break; } } @@ -103,7 +103,7 @@ int user_stat_article_cnt_inc(USER_STAT_MAP *p_map, int32_t uid, int n) if (p_map == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -145,7 +145,7 @@ int user_stat_get(USER_STAT_MAP *p_map, int32_t uid, const USER_STAT **pp_stat) if (p_map == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } diff --git a/utils/bin/gen_top.php b/utils/bin/gen_top.php index 82d3c2a3..6db66f37 100644 --- a/utils/bin/gen_top.php +++ b/utils/bin/gen_top.php @@ -14,7 +14,7 @@ $menu_file_path = "../../var/bbs_top_menu.conf"; $buffer_text = - " \033[1;34m-----\033[37m=====\033[41;37m 本站十大热门话题 \033[40m=====\033[34m-----\033[m\r\n\r\n"; + " \033[1;34m-----\033[37m=====\033[41;37m 本站十大热门话题 \033[40m=====\033[34m-----\033[m\n\n"; $buffer_screen = << 0) { @@ -174,7 +174,7 @@ static int create_a_egg() if ((fp = fopen(fname, "w")) == NULL) { - log_error("Error!!cannot open file '%s'!\n", fname); + log_error("Error!!cannot open file '%s'!", fname); return -2; } fprintf(fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %s ", @@ -183,7 +183,7 @@ static int create_a_egg() if ((fp = fopen(LOG_FILE, "a")) == NULL) { - log_error("Error!!cannot open file '%s'!\n", LOG_FILE); + log_error("Error!!cannot open file '%s'!", LOG_FILE); return -2; } fprintf(fp, "%s 在 [%d/%d %d:%02d] 养了一只叫 %s 的小鸡\r\n", @@ -418,7 +418,7 @@ static int select_menu() // Refresh current action if (user_online_update(NULL) < 0) { - log_error("user_online_update(NULL) error\n"); + log_error("user_online_update(NULL) error"); } if (tiredstrong > 20) @@ -622,7 +622,7 @@ static int select_menu() { if ((ret = check_badwords(name_tmp, '*')) < 0) { - log_error("check_badwords(name) error\n"); + log_error("check_badwords(name) error"); } else if (ret == 0) { @@ -656,7 +656,7 @@ int death() clrtobot(5); if ((fp = fopen(LOG_FILE, "a")) == NULL) { - log_error("Error!!cannot open file '%s'!\n", LOG_FILE); + log_error("Error!!cannot open file '%s'!", LOG_FILE); return -1; } fprintf(fp, "%s 在 [%d/%d %d:%02d] 的小鸡 %s 挂了~~ \r\n", @@ -838,7 +838,7 @@ int sell() if (money_deposit(sel) <= 0) { - log_error("Cannot deposit money %d\n", sel); + log_error("Cannot deposit money %d", sel); moveto(21, 0); prints("无法存钱,放弃交易!"); return -2; @@ -846,7 +846,7 @@ int sell() if ((fp = fopen(LOG_FILE, "a")) == NULL) { - log_error("Error!!cannot open file '%s'!\n", LOG_FILE); + log_error("Error!!cannot open file '%s'!", LOG_FILE); return -2; } fprintf(fp, "%s 在 [%d/%d %d:%02d] 把小鸡 %s 以 %d 糖果卖了\r\n", diff --git a/utils/game/money.c b/utils/game/money.c index c0eeaaf9..04ce3cb5 100644 --- a/utils/game/money.c +++ b/utils/game/money.c @@ -47,13 +47,13 @@ int money_deposit(int money) // Begin transaction if (mysql_query(db, "SET autocommit=0") != 0) { - log_error("SET autocommit=0 error: %s\n", mysql_error(db)); + log_error("SET autocommit=0 error: %s", mysql_error(db)); return -1; } if (mysql_query(db, "BEGIN") != 0) { - log_error("Begin transaction error: %s\n", mysql_error(db)); + log_error("Begin transaction error: %s", mysql_error(db)); return -1; } @@ -63,12 +63,12 @@ int money_deposit(int money) if (mysql_query(db, sql) != 0) { - log_error("Query user_pubinfo error: %s\n", mysql_error(db)); + log_error("Query user_pubinfo error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user money failed\n"); + log_error("Get user money failed"); return -1; } if ((row = mysql_fetch_row(rs))) @@ -99,14 +99,14 @@ int money_deposit(int money) if (mysql_query(db, sql) != 0) { - log_error("Update user_pubinfo error: %s\n", mysql_error(db)); + log_error("Update user_pubinfo error: %s", mysql_error(db)); return -1; } // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); return -1; } @@ -137,13 +137,13 @@ int money_withdraw(int money) // Begin transaction if (mysql_query(db, "SET autocommit=0") != 0) { - log_error("SET autocommit=0 error: %s\n", mysql_error(db)); + log_error("SET autocommit=0 error: %s", mysql_error(db)); return -1; } if (mysql_query(db, "BEGIN") != 0) { - log_error("Begin transaction error: %s\n", mysql_error(db)); + log_error("Begin transaction error: %s", mysql_error(db)); return -1; } @@ -153,12 +153,12 @@ int money_withdraw(int money) if (mysql_query(db, sql) != 0) { - log_error("Query user_pubinfo error: %s\n", mysql_error(db)); + log_error("Query user_pubinfo error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user money failed\n"); + log_error("Get user money failed"); return -1; } if ((row = mysql_fetch_row(rs))) @@ -184,14 +184,14 @@ int money_withdraw(int money) if (mysql_query(db, sql) != 0) { - log_error("Update user_pubinfo error: %s\n", mysql_error(db)); + log_error("Update user_pubinfo error: %s", mysql_error(db)); return -1; } // Commit transaction if (mysql_query(db, "COMMIT") != 0) { - log_error("Commit transaction error: %s\n", mysql_error(db)); + log_error("Commit transaction error: %s", mysql_error(db)); return -1; } @@ -219,12 +219,12 @@ int money_refresh(void) if (mysql_query(db, sql) != 0) { - log_error("Query user_pubinfo error: %s\n", mysql_error(db)); + log_error("Query user_pubinfo error: %s", mysql_error(db)); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user money failed\n"); + log_error("Get user money failed"); return -1; } if ((row = mysql_fetch_row(rs)))