diff options
author | LAN-TW <lantw44@gmail.com> | 2013-11-16 21:47:42 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-11-16 21:47:42 +0800 |
commit | 65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38 (patch) | |
tree | 44d06b3a980938b5d6e2d61be4e2715f6fd7d9fe | |
parent | 2dddeef2f0e44283d704fb692782aadc1b61bb71 (diff) | |
download | sp2013-65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38.tar sp2013-65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38.tar.gz sp2013-65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38.tar.bz2 sp2013-65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38.tar.lz sp2013-65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38.tar.xz sp2013-65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38.tar.zst sp2013-65fe64b615bdf2ba1c8fb37a8ec150a3a4351d38.zip |
HW2: 加入 README.txt 並避免 log file deadlock
-rw-r--r-- | hw2/README.txt | 27 | ||||
-rw-r--r-- | hw2/logger.c | 6 |
2 files changed, 32 insertions, 1 deletions
diff --git a/hw2/README.txt b/hw2/README.txt new file mode 100644 index 0000000..26ed421 --- /dev/null +++ b/hw2/README.txt @@ -0,0 +1,27 @@ + +Compile (Makefile) +------------------ +檔案名稱為 Makefile.或 Makefile.simple,這兩個檔案的內容是相同的。 +輸入 make 會自動轉由 Autotools 編譯並取代為 Autotools 產生的 Makefile, +輸入 make all 編譯,make clean 可清除已編譯的檔案。若無法編譯成功,可 +嘗試輸入 make all CFLAGS= 。 +有些變數可以在執行 make 時更改以符合需求。這個程式必須使用支援 C99 或 C11 的 C +編譯器才能編譯成功,無法使用 C89 或 C++ 編譯器來編譯。 + 可修改的變數: + CC C 編譯器執行檔名,預設是 c99 + CFLAGS 使用者傳給 C 編譯器的參數(不會取代預設的必要參數) + LDFLAGS 使用者傳給 linker 的參數(不會取代預設的必要參數) + +Compile (Autotools) +------------------- +執行 ./configure 即可產生 Makefile,並執行 make 來編譯。如果需要顯示編譯 +時執行的指令,可用 make V=1。輸入 make dist 可將作業打包成 .tar.gz 檔案, +但由於預設的檔名不符合作業要求,需要額外執行 make submit 才能將檔名轉換成 +作業要求的格式。 + +Other Notes and Changes +----------------------- +1. 將環境變數 COMP135_DEBUG 設定成 1 或 yes 可以啟用紀錄檔功能。big_judge 和 + judge 中都有很多地方會寫入紀錄檔,這樣可以了解整個比賽進行的詳細過程。 +2. 設定環境變數 COMP135_LOGFILE 可以指定紀錄檔名稱。如果變數不存在或內容是空 + 的,則會使用 stderr 當作紀錄檔。 diff --git a/hw2/logger.c b/hw2/logger.c index 53e6a40..dd34ec1 100644 --- a/hw2/logger.c +++ b/hw2/logger.c @@ -64,8 +64,12 @@ void comp135_init (Comp135* comp, const char* static_name, bool no_init) { return; } + xfaddfd (fd, FD_CLOEXEC); + if (isatty (fd)) { comp->is_term = true; + } else { + comp->is_term = false; } FILE* fp = fdopen (fd, "wb"); @@ -104,7 +108,7 @@ void comp135_log (Comp135* comp, const char* format, ...) { struct flock lock_info = { .l_type = F_WRLCK, - .l_whence = SEEK_END, + .l_whence = SEEK_SET, .l_start = 0, .l_len = 0 }; |