OpenWrt 系統日誌之logread

2021-06-23 04:26:40 字數 2131 閱讀 5261

剛開始接觸openwrt的時候,根本不知道如何除錯各個程序,我之前從事ip camera開發可能也侷限了我的知識面,認為系統就改是那個樣子。

其實不然,就像linux發行版那樣,他們都有各自都管理系統,同乙個的訊息通知系統,dbus和ubus這些。系統除錯也是一樣dmesg, 現在還接觸到了logread。

logread是在除錯luci的時候用到的,極其方便,對於不太了解openwrt系統構成對人尤甚。

這個需要寫程序對人對syslogd提供支援,否則說來知識惘然,我們需要做系統,需要做好對系統,就需要油完善對日誌管理,精簡無冗餘對才是最有用的,這是我們使用其的目的。廢話不多說,直接看卡logread的組成吧。

在busybox中實現了syslogd 和 logread.

syslogd用來記錄log, logged則用來讀取log.

logread的**很簡潔,主要實現過程是:連線共享記憶體->訊號量加鎖->讀取共享記憶體中的資訊並輸出->訊號量解鎖。

log_shmid = shmget(key_id, 0, 0);

if (log_shmid == -1)

bb_perror_msg_and_die("can't %s syslogd buffer", "find");

/* attach shared memory to our char* */

shbuf = shmat(log_shmid, null, shm_rdonly);

if (shbuf == null)

bb_perror_msg_and_die("can't %s syslogd buffer", "access");

log_semid = semget(key_id, 0, 0);

if (log_semid == -1)

error_exit("can't get access to semaphores for syslogd buffer");

if (semop(log_semid, smrdn, 2) == -1)

error_exit("semop[smrdn]");

/* suppose atomic memory read */

/* max possible value for tail is shbuf->size - 1 */

cur = shbuf->tail;

/* loop for logread -f, one pass if there was no -f */

do /* advance to first byte of the message */

cur++;

if (cur >= shbuf_size) /* last byte in buffer? */

cur = 0;

} else

} /* read from cur to tail */

#if enable_feature_logread_reduced_locking

len_first_part = len_total = shbuf_tail - cur;

if (len_total < 0)

copy = xmalloc(len_total + 1);

if (len_first_part < 0)

memcpy(copy, shbuf_data + cur, len_first_part);

copy[len_total] = '\0';

cur = shbuf_tail;

#else

while (cur != shbuf_tail)

#endif

unlock:

/* release the lock on the log chain */

sem_up(log_semid);

#if enable_feature_logread_reduced_locking

for (i = 0; i < len_total; i += strlen(copy + i) + 1)

free(copy);

#endif

fflush_all();

log日誌系統《一》

using system using system.io using unityengine using system.reflection using system.diagnostics unity 的 debug 的封裝類 public class wilog public static vo...

OpenWrt系統定製之base files研究

base files屬於openwrt的rootfs框架,位於package base files files,裡面有些專案可以定製和修改 bin ipcalc.sh login.sh etc banner config network system device info diag.sh grou...

log4cxx日誌系統

本文主要從log4cxx級別 layout 格式化 命名規則 filter幾個方面介紹。一 log4cxx命名規則 logger由乙個string類的名字識別,logger的名字是大小寫敏感的,且名字之間具有繼承的關係,子名有父名作為字首,用點號.分隔。如 x.y是x.y.z的父親。根logger ...