This file is indexed.

/usr/bin/kumolog is in kumofs 0.4.13-6.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/env ruby
#
# kumofs
#
# Copyright (C) 2009 FURUHASHI Sadayuki
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

class StringSource
	def initialize(src)
		@src = src
	end

	def read(off, size)
		if @src.length < off + size
			throw :finish
		end
		@src[off, size]
	end

	def free_until(off)
	end
end

class StreamSource
	def initialize(io)
		@io = io
		@from = 0
		@buffer = ''
		@rbuf = ''
	end

	def read(off, size)
		while @from + @buffer.length < off + size
			@buffer << @io.sysread(1024, @rbuf)
		end
		@buffer[off - @from, size]
	rescue Exception
		throw :finish
	end

	def free_until(off)
		free = off - @from
		if free > 0
			@buffer.slice!(0, free)
			@from += free
		end
	end
end


def fixstr(code)
	r = ""
	8.times {|i|
		c = ((code >> (8*(7-i))) & 0xff)
		r << c.chr if c != 0
	}
	r
end

def type_check(obj)
	obj.is_a?(Array) && obj.length == 3 &&
		obj[0].is_a?(Numeric) && obj[1].is_a?(Numeric) &&
		obj[2].is_a?(Hash)
end


def do_recover(src, off)
	puts "recover at #{off}"
	pk = MessagePack::Unpacker.new

	while true
		br = src.read(off,4).unpack('N')[0]
		doff = off + 4

		begin
			pk.reset
			rl = pk.execute(src.read(doff,br), 0)

			if pk.finished && rl == br && type_check(pk.data)
				return off
			end
		rescue
			off += 1
		end
	end
end


def do_parse(src, skip, count, &block)
	count = (1<<31) if count < 0
	catch(:finish) {
		off = 0
		rl = 0
	
		pk = MessagePack::Unpacker.new
	
		while count > 0
			br = src.read(off,4).unpack('N')[0]
			off += 4
	
			begin
				pk.reset
				rl = pk.execute(src.read(off,br), 0)
	
				unless pk.finished? && rl == br && type_check(pk.data)
					raise "format error"
				end
	
				obj = pk.data
	
				hash = {}
				name = fixstr(obj[0])
				version = obj[1]
				obj[2].each_pair {|k,v|
					hash[fixstr(k)] = v
				}
	
			rescue
				off = do_recover(src, off-3)
				next
			end
	
			off += br
			src.free_until(off)
	
			if skip > 0
				skip -= 1
			else
				block.call(name, version, hash)
				count -= 1
			end
		end
	}
end


require 'optparse'

arg = {
	:follow => false,
	:tail   => false,
	:head   => false,
	:line   => 10,
}

op = OptionParser.new
op.on('-t', '--tail')   {|b| arg[:tail]  = b }
op.on('-h', '--head')   {|b| arg[:head]  = b }
op.on('-f', '--follow') {|b| arg[:follow] = b }
op.on('-n [-]N', '--lines', Integer) {|n| arg[:line] = n }
op.banner += " <logfile.mpac>"

op.parse!(ARGV)

if ARGV.length != 1
	puts op.to_s
	exit 1
end


fname = ARGV[0]
tail = nil
head = nil
skip  = 0
count = -1

if arg[:tail]
	if (n = arg[:line]) > 0
		tail = Array.new(n)
	else
		skip = -n
	end
elsif arg[:head]
	if (n = arg[:line]) > 0
		count = n
	else
		head = Array.new(-n)
	end
end


if arg[:follow]
	begin
		require 'shellwords'
		fname = Shellwords.escape(fname)
	rescue
		fname = "'#{fname}'"
	end
	stream = IO.popen("tail -f #{fname}")
elsif fname == "-"
	stream = $stdin
else
	stream = File.open(fname)
end

src = StreamSource.new(stream)
#src = StringSource.new(File.read(fname))



begin
	require 'rubygems'
rescue LoadError
end
require 'yaml'
require 'pp'
require 'msgpack'

class Hash
	def hmap(&block)
		m = {}
		each_pair {|k, v|
			m[k] = block.call(k, v)
		}
		m
	end
end

conf = YAML.load DATA.read.gsub(/(^\t+)/) {
	'  ' * $+.length
}

@msgdb = conf["message"]

@filterdb = conf["filter"].hmap {|name, hash|
	hash.hmap {|key, proc|
		[ proc[0], eval("lambda{|val|#{proc[1]}}") ]
	}
}


def print_log(name, version, hash)
	msg = @msgdb[name] || "#{name}.#{version}"

	if filter = @filterdb["#{name}.#{version}"]
		filter.each_pair {|key, proc|
			val = hash.delete(key)
			begin
				hash[proc[0]] = proc[1].call(val)
			rescue
			end
		}
	end

	vals = hash.map {|k, v|
		pv = v.pretty_inspect.rstrip
		pv = v if pv[1..-2] == v
		"#{k}=[#{pv}]"
	}.sort_by{|kv| kv[0] }.join('  ')

	puts "%s.%s  %-15s  %s" % [name, version, msg, vals]
end


if tail
	do_parse(src, skip, count) {|*params|
		tail.shift
		tail.push params
	}
	tail.each(&method(:print_log))

elsif head
	do_parse(src, skip, count) {|*params|
		head.shift
		head.push params
		if h = head[0]
			print_log(h)
		end
	}

else
	do_parse(src, skip, count, &method(:print_log))
end


__END__
proc:
	- &addr |
		require 'socket'
		if val.length == 6
			addr = Socket.pack_sockaddr_in(0, '0.0.0.0')
			addr[2,6] = val[0,6]
		else
			addr = Socket.pack_sockaddr_in(0, '::')
			addr[2,2]  = val[0,2]
			addr[8,20] = val[2,20]
		end
		Socket.unpack_sockaddr_in(addr).reverse.join(':')

	- &time |
		Time.at(val).strftime("%Y-%m-%d %H:%M:%S")

	- &clocktime |
		Time.at(val>>32).strftime("%Y-%m-%d %H:%M:%S") + " clock #{val & 0xffffffff}"

message:
	SM: Manager start
	SS: Server start
	SW: Gateway start
	eP: unknown partner
	nS: new server
	lS: lost server
	ers: replicate-set failed
	erd: replicate-delete failed
	eg: Get failed
	es: Set failed
	ed: Delete failed

filter:
	SM.2:
		time: [time, *time]
		addr: [address, *addr]
		Padd: [partner, *addr]
	SS.2:
		time: [time, *time]
		addr: [address, *addr]
		db:   [database, val]
		mgr1: [manager1, *addr]
		mgr2: [manager2, *addr]
		sadd: [stream_listen, *addr]
		tmpd: [tmp_dir, val]
		bkup: [backup_prefix, val]
	SW.2:
		time: [time, *time]
		mgr1: [manager1, *addr]
		mgr2: [manager2, *addr]
	eP.2:
		addr: [address, *addr]
	nS.2:
		addr: [address, *addr]
	lS.2:
		addr: [address, *addr]
	ers.3:
		to:   [to, *addr]
		cktm: [clocktime, *clocktime]
	erd.3:
		to:   [to, *addr]
	eP.3:
		addr: [address, *addr]
		time: [time, *time]
	nS.3:
		addr: [address, *addr]
		time: [time, *time]
	lS.3:
		addr: [address, *addr]
		time: [time, *time]
	eg.3:
		time: [time, *time]
	es.3:
		time: [time, *time]
	ed.3:
		time: [time, *time]
	ers.4:
		to:   [to, *addr]
		cktm: [clocktime, *clocktime]
		time: [time, *time]
	erd.4:
		to:   [to, *addr]
		time: [time, *time]