4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2.1.2 */
35 #include "sys/types.h"
37 #include "sys/stropts.h"
38 #include "sys/strlog.h"
41 #define NSECDAY (60*60*24)
43 #define LOGDEFAULT "/var/adm/streams"
45 #define DIRECTORY 040000
48 static char prefix
[128];
52 static int clean(const char *name
, const struct stat
*stp
, int info
);
55 main(int ac
, char *av
[])
61 struct strbuf ctl
, dat
;
70 while ((c
= getopt(ac
, av
, "d:a:")) != EOF
) {
93 fprintf(stderr
, "Usage: strclean [-d <logdir>] [-a <age>]\n");
98 fprintf(stderr
, "strclean: <age> must be at least 1\n");
102 if ((stat(logname
, &stbuf
) < 0) || !(stbuf
.st_mode
& DIRECTORY
)) {
103 fprintf(stderr
, "strclean: %s not a directory\n", logname
);
107 if (access(logname
, ACCESS
) < 0) {
108 fprintf(stderr
, "strclean: cannot access directory %s\n",
113 cutoff
= time(NULL
) - age
* NSECDAY
;
115 ctl
.len
= sizeof (struct log_ctl
);
116 ctl
.maxlen
= sizeof (struct log_ctl
);
117 ctl
.buf
= (caddr_t
)&lctl
;
119 lctl
.flags
= SL_ERROR
|SL_NOTIFY
;
121 dat
.maxlen
= MSGSIZE
;
123 "strclean - removing log files more than %d days old", age
);
124 dat
.len
= strlen(dat
.buf
) + 1;
126 if ((fd
= open("/dev/log", O_RDWR
)) >= 0) {
127 putmsg(fd
, &ctl
, &dat
, 0);
132 strcpy(prefix
, logname
);
133 strcat(prefix
, "/error.");
135 ftw(logname
, clean
, 1);
141 * clean out all files in the log directory prefixed by 'prefix'
142 * and that are older than 'cutoff' (these are globals above).
145 clean(const char *name
, const struct stat
*stp
, int info
)
150 if (strncmp(name
, prefix
, strlen(prefix
)) != 0)
153 if (stp
->st_mtime
>= cutoff
)
156 if (unlink(name
) < 0)
157 fprintf(stderr
, "strclean: unable to unlink file %s\n", name
);