aboutsummaryrefslogtreecommitdiff
path: root/runit
diff options
context:
space:
mode:
Diffstat (limited to 'runit')
-rw-r--r--runit/svlogd.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/runit/svlogd.c b/runit/svlogd.c
index a588ffeb0..cf29e8e9f 100644
--- a/runit/svlogd.c
+++ b/runit/svlogd.c
@@ -55,7 +55,7 @@ static const char *replace = "";
55static char repl; 55static char repl;
56 56
57static struct logdir { 57static struct logdir {
58 ////char *btmp; 58//// char *btmp;
59 /* pattern list to match, in "aa\0bb\0\cc\0\0" form */ 59 /* pattern list to match, in "aa\0bb\0\cc\0\0" form */
60 char *inst; 60 char *inst;
61 char *processor; 61 char *processor;
@@ -732,6 +732,7 @@ int svlogd_main(int argc, char **argv)
732 int i; 732 int i;
733 unsigned opt; 733 unsigned opt;
734 unsigned timestamp = 0; 734 unsigned timestamp = 0;
735 void* (*memRchr)(const void *, int, size_t) = memchr;
735 736
736#define line bb_common_bufsiz1 737#define line bb_common_bufsiz1
737 738
@@ -748,10 +749,10 @@ int svlogd_main(int argc, char **argv)
748 if (linemax == 0) linemax = BUFSIZ-26; 749 if (linemax == 0) linemax = BUFSIZ-26;
749 if (linemax < 256) linemax = 256; 750 if (linemax < 256) linemax = 256;
750 } 751 }
751 if (opt & 8) { // -b 752//// if (opt & 8) { // -b
752 ////buflen = xatoi_u(b); 753//// buflen = xatoi_u(b);
753 ////if (buflen == 0) buflen = 1024; 754//// if (buflen == 0) buflen = 1024;
754 } 755//// }
755 //if (opt & 0x10) timestamp++; // -t 756 //if (opt & 0x10) timestamp++; // -t
756 //if (opt & 0x20) verbose++; // -v 757 //if (opt & 0x20) verbose++; // -v
757 //if (timestamp > 2) timestamp = 2; 758 //if (timestamp > 2) timestamp = 2;
@@ -789,7 +790,13 @@ int svlogd_main(int argc, char **argv)
789 790
790 logdirs_reopen(); 791 logdirs_reopen();
791 792
792 /* Each iteration processes one line */ 793 /* Without timestamps, we don't have to print each line
794 * separately, so we can look for _last_ newline, not first,
795 * thus batching writes */
796 if (!timestamp)
797 memRchr = memrchr;
798
799 /* Each iteration processes one line or more lines */
793 while (1) { 800 while (1) {
794 char stamp[FMT_PTIME]; 801 char stamp[FMT_PTIME];
795 char *lineptr; 802 char *lineptr;
@@ -817,15 +824,17 @@ int svlogd_main(int argc, char **argv)
817 /* (possibly has some unprocessed data from prev loop) */ 824 /* (possibly has some unprocessed data from prev loop) */
818 825
819 /* Refill the buffer if needed */ 826 /* Refill the buffer if needed */
820 np = memchr(lineptr, '\n', stdin_cnt); 827 np = memRchr(lineptr, '\n', stdin_cnt);
821 i = linemax - stdin_cnt; /* avail. bytes at tail */ 828 if (!np && !exitasap) {
822 if (i >= 128 && !exitasap && !np) { 829 i = linemax - stdin_cnt; /* avail. bytes at tail */
823 int sz = buffer_pread(0, lineptr + stdin_cnt, i); 830 if (i >= 128) {
824 if (sz <= 0) /* EOF or error on stdin */ 831 i = buffer_pread(0, lineptr + stdin_cnt, i);
825 exitasap = 1; 832 if (i <= 0) /* EOF or error on stdin */
826 else { 833 exitasap = 1;
827 np = memchr(lineptr + stdin_cnt, '\n', sz); 834 else {
828 stdin_cnt += sz; 835 np = memRchr(lineptr + stdin_cnt, '\n', i);
836 stdin_cnt += i;
837 }
829 } 838 }
830 } 839 }
831 if (stdin_cnt <= 0 && exitasap) 840 if (stdin_cnt <= 0 && exitasap)
@@ -874,8 +883,9 @@ int svlogd_main(int argc, char **argv)
874 stdin_cnt = 1; 883 stdin_cnt = 1;
875 } else { 884 } else {
876 linelen = stdin_cnt; 885 linelen = stdin_cnt;
877 np = memchr(lineptr, '\n', stdin_cnt); 886 np = memRchr(lineptr, '\n', stdin_cnt);
878 if (np) linelen = np - lineptr + 1; 887 if (np)
888 linelen = np - lineptr + 1;
879 ch = lineptr[linelen-1]; 889 ch = lineptr[linelen-1];
880 } 890 }
881 /* linelen == no of chars incl. '\n' (or == stdin_cnt) */ 891 /* linelen == no of chars incl. '\n' (or == stdin_cnt) */
@@ -893,7 +903,7 @@ int svlogd_main(int argc, char **argv)
893 lineptr += linelen; 903 lineptr += linelen;
894 /* If we see another '\n', we don't need to read 904 /* If we see another '\n', we don't need to read
895 * next piece of input: can print what we have */ 905 * next piece of input: can print what we have */
896 np = memchr(lineptr, '\n', stdin_cnt); 906 np = memRchr(lineptr, '\n', stdin_cnt);
897 if (np) 907 if (np)
898 goto print_to_nl; 908 goto print_to_nl;
899 /* Move unprocessed data to the front of line */ 909 /* Move unprocessed data to the front of line */
@@ -907,5 +917,5 @@ int svlogd_main(int argc, char **argv)
907 /* repeat */; 917 /* repeat */;
908 logdir_close(&dir[i]); 918 logdir_close(&dir[i]);
909 } 919 }
910 _exit(0); 920 return 0;
911} 921}