From 6a5ff665807d282cb151a6286dafd3940706f2a6 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Mon, 19 Mar 2018 09:50:36 +0000 Subject: [PATCH] fixed a bug in the default log callback --- moo/Makefile.in | 9 ++++----- moo/configure | 14 +------------- moo/lib/Makefile.in | 1 - moo/lib/main.c | 34 ++++++++++++++++------------------ moo/mod/Makefile.in | 1 - 5 files changed, 21 insertions(+), 38 deletions(-) diff --git a/moo/Makefile.in b/moo/Makefile.in index f882b14..c9581d0 100644 --- a/moo/Makefile.in +++ b/moo/Makefile.in @@ -354,7 +354,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -585,7 +584,7 @@ distdir: $(DISTFILES) ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir @@ -611,7 +610,7 @@ dist-shar: distdir @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 - shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir @@ -629,7 +628,7 @@ dist dist-all: distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ @@ -639,7 +638,7 @@ distcheck: dist *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac diff --git a/moo/configure b/moo/configure index 6a94d9d..7c6f7b5 100755 --- a/moo/configure +++ b/moo/configure @@ -786,7 +786,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -882,7 +881,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1135,15 +1133,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1281,7 +1270,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1434,7 +1423,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] diff --git a/moo/lib/Makefile.in b/moo/lib/Makefile.in index dcf1a24..488079c 100644 --- a/moo/lib/Makefile.in +++ b/moo/lib/Makefile.in @@ -397,7 +397,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/moo/lib/main.c b/moo/lib/main.c index 9eaef40..5f1f985 100644 --- a/moo/lib/main.c +++ b/moo/lib/main.c @@ -558,8 +558,6 @@ static void free_heap (moo_t* moo, void* ptr) /* nothing to do */ #else - - static int write_all (int fd, const moo_bch_t* ptr, moo_oow_t len) { while (len > 0) @@ -595,7 +593,7 @@ static int write_all (int fd, const moo_bch_t* ptr, moo_oow_t len) } #endif -static int write_log (moo_t* moo, const moo_bch_t* ptr, moo_oow_t len) +static int write_log (moo_t* moo, int fd, const moo_bch_t* ptr, moo_oow_t len) { xtn_t* xtn; @@ -618,7 +616,7 @@ static int write_log (moo_t* moo, const moo_bch_t* ptr, moo_oow_t len) if (xtn->logbuf.len >= MOO_COUNTOF(xtn->logbuf.buf)) { int n; - n = write_all(xtn->logfd, xtn->logbuf.buf, xtn->logbuf.len); + n = write_all(fd, xtn->logbuf.buf, xtn->logbuf.len); xtn->logbuf.len = 0; if (n <= -1) return -1; } @@ -630,7 +628,7 @@ static int write_log (moo_t* moo, const moo_bch_t* ptr, moo_oow_t len) rcapa = MOO_COUNTOF(xtn->logbuf.buf); if (len >= rcapa) { - if (write_all(xtn->logfd, ptr, rcapa) <= -1) return -1; + if (write_all(fd, ptr, rcapa) <= -1) return -1; ptr += rcapa; len -= rcapa; } @@ -648,13 +646,13 @@ static int write_log (moo_t* moo, const moo_bch_t* ptr, moo_oow_t len) return 0; } -static void flush_log (moo_t* moo) +static void flush_log (moo_t* moo, int fd) { xtn_t* xtn; xtn = moo_getxtn(moo); if (xtn->logbuf.len > 0) { - write_all (xtn->logfd, xtn->logbuf.buf, xtn->logbuf.len); + write_all (fd, xtn->logbuf.buf, xtn->logbuf.len); xtn->logbuf.len = 0; } } @@ -718,14 +716,14 @@ static void log_write (moo_t* moo, unsigned int mask, const moo_ooch_t* msg, moo tslen = 25; } #endif - write_log (moo, ts, tslen); + write_log (moo, logfd, ts, tslen); } - if (xtn->logfd_istty) + if (logfd == xtn->logfd && xtn->logfd_istty) { - if (mask & MOO_LOG_FATAL) write_log (moo, "\x1B[1;31m", 7); - else if (mask & MOO_LOG_ERROR) write_log (moo, "\x1B[1;32m", 7); - else if (mask & MOO_LOG_WARN) write_log (moo, "\x1B[1;33m", 7); + if (mask & MOO_LOG_FATAL) write_log (moo, logfd, "\x1B[1;31m", 7); + else if (mask & MOO_LOG_ERROR) write_log (moo, logfd, "\x1B[1;32m", 7); + else if (mask & MOO_LOG_WARN) write_log (moo, logfd, "\x1B[1;33m", 7); } #if defined(MOO_OOCH_IS_UCH) @@ -735,7 +733,7 @@ static void log_write (moo_t* moo, unsigned int mask, const moo_ooch_t* msg, moo ucslen = len; bcslen = MOO_COUNTOF(buf); - n = moo_convootobchars (moo, &msg[msgidx], &ucslen, buf, &bcslen); + n = moo_convootobchars(moo, &msg[msgidx], &ucslen, buf, &bcslen); if (n == 0 || n == -2) { /* n = 0: @@ -747,7 +745,7 @@ static void log_write (moo_t* moo, unsigned int mask, const moo_ooch_t* msg, moo MOO_ASSERT (moo, ucslen > 0); /* if this fails, the buffer size must be increased */ /* attempt to write all converted characters */ - if (write_log (moo, buf, bcslen) <= -1) break; + if (write_log(moo, logfd, buf, bcslen) <= -1) break; if (n == 0) break; else @@ -763,15 +761,15 @@ static void log_write (moo_t* moo, unsigned int mask, const moo_ooch_t* msg, moo } } #else - write_log (moo, msg, len); + write_log (moo, logfd, msg, len); #endif - if (xtn->logfd_istty) + if (logfd == xtn->logfd && xtn->logfd_istty) { - if (mask & (MOO_LOG_FATAL | MOO_LOG_ERROR | MOO_LOG_WARN)) write_log (moo, "\x1B[0m", 4); + if (mask & (MOO_LOG_FATAL | MOO_LOG_ERROR | MOO_LOG_WARN)) write_log (moo, logfd, "\x1B[0m", 4); } - flush_log (moo); + flush_log (moo, logfd); } static void syserrstrb (moo_t* moo, int syserr, moo_bch_t* buf, moo_oow_t len) diff --git a/moo/mod/Makefile.in b/moo/mod/Makefile.in index f792e57..5f11861 100644 --- a/moo/mod/Makefile.in +++ b/moo/mod/Makefile.in @@ -423,7 +423,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@