This file is indexed.

/usr/share/perl5/Log/Agent/Rotate.pm is in liblog-agent-rotate-perl 0.104-2.

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

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
###########################################################################
# $Id: Rotate.pm,v 1.5 2002/05/14 05:15:30 wendigo Exp $
###########################################################################
#
# Log::Agent::Rotate
#
# RCS Revision: $Revision: 1.5 $
# Date: $Date: 2002/05/14 05:15:30 $
#
# Copyright (c) 2000 Raphael Manfredi.
# Copyright (c) 2002 Mark Rogaski, mrogaski@cpan.org; all rights reserved.
#
# See the README file included with the
# distribution for license information.
#
# $Log: Rotate.pm,v $
# Revision 1.5  2002/05/14 05:15:30  wendigo
# updated POD
#
# Revision 1.4  2002/05/14 04:58:28  wendigo
# corrected $VERSION
#
# Revision 1.3  2002/05/14 04:49:49  wendigo
# modified version control
#
# Revision 1.2  2002/05/14 04:47:21  wendigo
# added file_perm argument
#
# Revision 1.1  2002/05/12 17:33:43  wendigo
# Initial revision
#
# Revision 0.1.1.3  2001/04/11 16:00:29  ram
# patch3: switched to Getargs::Long for argument parsing
# patch3: updated version number
#
# Revision 0.1.1.2  2000/11/12 14:54:10  ram
# patch2: new -single_host parameter
#
# Revision 0.1.1.1  2000/11/06 20:03:35  ram
# patch1: moved to an array representation for the object
# patch1: added ability to specify -max_time in other units than seconds
# patch1: added is_same() to compare configurations
#
# Revision 0.1  2000/03/05 22:15:40  ram
# Baseline for first alpha release.
#
###########################################################################

use strict;

###########################################################################
package Log::Agent::Rotate;

use Getargs::Long qw(ignorecase);

#
# File rotating policy
#

use vars qw($VERSION);

$VERSION = sprintf "%d.%01d%02d%s", '$Name: rel0_1_4 $' =~ /(p?\d+)/g;

BEGIN {
    sub BACKLOG ()     {0}
    sub UNZIPPED ()    {1}
    sub MAX_SIZE ()    {2}
    sub MAX_WRITE ()   {3}
    sub MAX_TIME ()    {4}
    sub IS_ALONE ()    {5}
    sub SINGLE_HOST () {6}
    sub FILE_PERM ()   {7}
}

#
# ->make
#
# Creation routine.
#
# Attributes:
#   backlog       amount of old files to keep (0 for none)
#   unzipped      amount of old files to NOT compress (defaults to 1)
#   max_size      maximum amount of bytes in file
#   max_write     maximum amount of bytes to write in file
#   max_time      maximum amount of time to keep open
#   is_alone      hint: only one instance is busy manipulating the logfiles
#   single_host   hint: access to logfiles always made via one host
#
sub make {
    my $self = bless [], shift;

    (
        $self->[BACKLOG],
        $self->[UNZIPPED],
        $self->[MAX_SIZE],
        $self->[MAX_WRITE],
        $self->[MAX_TIME],
        $self->[IS_ALONE],
        $self->[SINGLE_HOST],
        $self->[FILE_PERM]
    ) = xgetargs(@_,
        -backlog        => ['i', 7],
        -unzipped       => ['i', 1],
        -max_size       => ['i', 1_048_576],
        -max_write      => ['i', 0],
        -max_time       => ['s', "0"],
        -is_alone       => ['i', 0],
        -single_host    => ['i', 0],
        -file_perm      => ['i', 0666]
    );

    $self->[MAX_TIME] = seconds_in_period($self->[MAX_TIME])
            if $self->[MAX_TIME];

    return $self;
}

#
# seconds_in_period
#
# Converts a period into a number of seconds.
#
sub seconds_in_period {
    my ($p) = @_;

    $p =~ s|^(\d+)||;
    my $base = int($1); # Number of elementary periods
    my $u = "s";        # Default Unit
    $u = substr($1, 0, 1) if $p =~ /^\s*(\w+)$/;
    my $sec;

    if ($u eq 'm') {
        $sec = 60;              # One minute = 60 seconds
    } elsif ($u eq 'h') {
        $sec = 3600;            # One hour = 3600 seconds
    } elsif ($u eq 'd') {
        $sec = 86400;           # One day = 24 hours
    } elsif ($u eq 'w') {
        $sec = 604800;          # One week = 7 days
    } elsif ($u eq 'M') {
        $sec = 2592000;         # One month = 30 days
    } elsif ($u eq 'y') {
        $sec = 31536000;        # One year = 365 days
    } else {
        $sec = 1;               # Unrecognized: defaults to seconds
    }

    return $base * $sec;
}

#
# Attribute access
#

sub backlog     { $_[0]->[BACKLOG] }
sub unzipped    { $_[0]->[UNZIPPED] }
sub max_size    { $_[0]->[MAX_SIZE] }
sub max_write   { $_[0]->[MAX_WRITE] }
sub max_time    { $_[0]->[MAX_TIME] }
sub is_alone    { $_[0]->[IS_ALONE] }
sub single_host { $_[0]->[SINGLE_HOST] }
sub file_perm   { $_[0]->[FILE_PERM] }

#
# There's no set_xxx() routines: those objects are passed by reference and
# never "expanded", i.e. passed by copy.  Modifying any of the attributes
# would then lead to strange effects.
#

#
# ->is_same
#
# Compare settings of $self with that of $other
#
sub is_same {
    my $self = shift;
    my ($other) = @_;
    for (my $i = 0; $i < @$self; $i++) {
        return 0 if $self->[$i] != $other->[$i];
    }
    return 1;
}

1;        # for require
__END__

=head1 NAME

Log::Agent::Rotate - parameters for logfile rotation

=head1 SYNOPSIS

 require Log::Agent::Rotate;

 my $policy = Log::Agent::Rotate->make(
     -backlog     => 7,
     -unzipped    => 2,
     -is_alone    => 0,
     -max_size    => 100_000,
     -max_time    => "1w",
     -file_perm   => 0666
 );

=head1 DESCRIPTION

The C<Log::Agent::Rotate> class holds the parameters describing the logfile
rotation policy, and is meant to be supplied to instances of
C<Log::Agent::Driver::File> via arguments in the creation routine,
such as C<-rotate>, or by using array references as values in the
C<-channels> hashref: See complementary information in
L<Log::Agent::Driver::File>.

As rotation cycles are performed, the current logfile is renamed, and
possibly compressed, until the maximum backlog is reached, at which time
files are deleted.  Assuming a backlog of 5 and that the latest 2 files
are not compressed, the following files can be present on the filesystem:

    logfile           # the current logfile
    logfile.0         # most recently renamed logfile
    logfile.1
    logfile.2.gz
    logfile.3.gz
    logfile.4.gz      # oldest logfile, unlinked next cycle

The following I<switches> are available to the creation routine make(),
listed in alphabetical order, all taking a single integer value as argument:

=over 4

=item I<backlog>

The total amount of old logfiles to keep, besides the current logfile.

Defaults to 7.

=item I<file_perm>

The file permissions, given as an octal integer value, to supply to
sysopen() during file creation.  This value is modified during execution
by the umask of the process.  In most cases, it is good practice to leave
this set to the default and let the user process controll the file
permissions.

Defaults to 0666.

=item I<is_alone>

The argument is a boolean stating whether the program writing to the logfile
will be the only one or not.  This is a hint that drives some optimizations,
but it is up to the program to B<guarantee> that noone else will be able to
write to or unlink the current logfile when set to I<true>.

Defaults to I<false>.

=item I<max_size>

The maximum logfile size.  This is a threshold, which will cause
a logfile rotation cycle to be performed, when crossed after a write to
the file.  If set to C<0>, this threshold is not checked.

Defaults to 1 megabyte.

=item I<max_time>

The maximum time in seconds between the moment we opened the file and
the next rotation cycle occurs.  This threshold is only checked after
a write to the file.

The value can also be given as a string, postfixed by one of the
following letters to specify the period unit (e.g. "3w"):

    Letter   Unit
    ------   -------
       m     minutes
       h     hours
       d     days
       d     days
       w     weeks
       M     months (30 days of 24 hours)
       y     years

Defaults to C<0>, meaning it is not checked.

=item I<max_write>

The maximum amount of data we can write to the logfile.  Like C<max_size>,
this is a threshold, which is only checked after a write to the logfile.
This is not the total logfile size: if several programs write to the same
logfile and C<max_size> is not used, then the logfiles may never be rotated
at all if none of the programs write at least C<max_write> bytes to the
logfile before exiting.

Defaults to C<0>, meaning it is not checked.

=item I<single_host>

The argument is a boolean stating whether the access to the logfiles
will be made from one single host or not.  This is a hint that drives some
optimizations, but it is up to the program to B<guarantee> that it is
accurately set.

Defaults to I<false>, which is always a safe value.

=item I<unzipped>

The amount of old logfiles, amongst the most recent ones, that should
not be compressed but be kept as plain files.

Defaults to 1.

=back

To test whether two configurations are strictly identical, use is_same(),
as in:

    print "identical\n" if $x->is_same($y);

where both $x and $y are C<Log::Agent::Rotate> objects.

All the aforementioned switches also have a corresponding querying
routine that can be issued on instances of the class to get their value.
It is not possible to modify those attributes.

For instance:

    my $x = Log::Agent::Rotate->make(...);
    my $mwrite = $x->max_write();

would get the configured I<max_write> threshold.

=head1 AUTHORS

Originally written by Raphael Manfredi E<lt>Raphael_Manfredi@pobox.comE<gt>,
currently maintained by Mark Rogaski E<lt>mrogaski@cpan.orgE<gt>.

Thanks to Chris Meshkin for his suggestions on file permissions.

=head1 SEE ALSO

Log::Agent(3), Log::Agent::Driver::File(3),
Log::Agent::Rotate::File(3).

=cut