]> git.wh0rd.org Git - patches.git/blob - metalog-0.7beta-ext2attr.patch
initial import
[patches.git] / metalog-0.7beta-ext2attr.patch
1 diff -uwr metalog-0.7beta/configure.in metalog-0.7beta-ext2attr/configure.in
2 --- metalog-0.7beta/configure.in        2002-04-29 23:30:00.000000000 +0200
3 +++ metalog-0.7beta-ext2attr/configure.in       2002-10-30 00:35:28.000000000 +0100
4 @@ -30,6 +30,7 @@
5  AC_CHECK_HEADERS(unistd.h)
6  AC_CHECK_HEADERS(sys/time.h sys/wait.h fcntl.h sys/fcntl.h)
7  AC_CHECK_HEADERS(getopt.h stddef.h sys/klog.h)
8 +AC_CHECK_HEADERS(linux/ext2_fs.h)
9  
10  dnl Checks for types
11  
12 diff -uwr metalog-0.7beta/src/metalog.h metalog-0.7beta-ext2attr/src/metalog.h
13 --- metalog-0.7beta/src/metalog.h       2002-04-29 23:35:16.000000000 +0200
14 +++ metalog-0.7beta-ext2attr/src/metalog.h      2002-10-30 00:44:53.000000000 +0100
15 @@ -79,6 +79,16 @@
16  #endif
17  #include <pcre.h>
18  
19 +
20 +/* PinG's ext2 patch */
21 +/* Include headers if needed */
22 +#if defined(__linux__) && defined(HAVE_LINUX_EXT2_FS_H)
23 +# define USE_EXT2
24 +# include <linux/ext2_fs.h>
25 +# include <sys/ioctl.h>
26 +#endif
27 +
28 +
29  #ifdef HAVE_ALLOCA
30  # ifdef HAVE_ALLOCA_H
31  #  include <alloca.h>
32  
33 diff -uwr metalog-0.7beta/src/metalog.c metalog-0.7beta-ext2attr/src/metalogch
34 --- metalog-0.7beta/src/metalog.c       2002-04-29 23:35:16.000000000 +0200
35 +++ metalog-0.7beta-ext2attr/src/metalog.c      2002-10-30 01:13:57.000000000 +0100
36 @@ -700,6 +700,13 @@
37  
38  static int rotateLogFiles(const char * const directory, const int maxfiles)
39  {
40 +
41 +/* PinG's ext2 patch. I need a file descriptor 'n a long :op */
42 +#ifdef USE_EXT2
43 +   int fd;
44 +   long flags;
45 +#endif
46 +
47      char path[PATH_MAX];
48      char old_name[PATH_MAX];
49      const char *name;
50 @@ -710,6 +717,7 @@
51      int older_year, older_mon = INT_MAX, older_mday = INT_MAX,
52          older_hour = INT_MAX, older_min = INT_MAX, older_sec = INT_MAX;
53      
54 +   
55      rescan:
56      foundlogs = 0;
57      *old_name = 0;
58 @@ -754,6 +762,15 @@
59                      directory, old_name);
60              return -4;
61          }
62 +       
63 +       /* PinG's ext2 patch. Un-immutate file before unlink it ;) */
64 +#ifdef USE_EXT2
65 +       if ((fd = open(path,O_RDONLY))>0){
66 +         flags = 0;
67 +         ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
68 +         close(fd);
69 +       }
70 +#endif
71          if (unlink(path) < 0) {
72              return -2;
73          }
74 @@ -769,6 +786,14 @@
75  static int writeLogLine(Output * const output, const char * const date,
76                          const char * const prg, const char * const info)
77  {
78 +/* PinG's ext2 patch. */
79 +#ifdef USE_EXT2
80 +   int fd;
81 +   long flags;
82 +#endif
83 +
84 +   
85 +   
86      time_t now = time(NULL);
87      
88      if (output == NULL || output->directory == NULL) {
89 @@ -787,7 +812,25 @@
90                  fprintf(stderr, "Can't create [%s]\n", output->directory);
91                  return -1;
92              }                
93 +          /* PinG's ext2 patch. Set noatime flag */
94 +#ifdef USE_EXT2
95 +          if ((fd = open(output->directory,O_RDONLY))>0){
96 +             flags = EXT2_NOATIME_FL;
97 +             ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
98 +             close(fd);
99 +          }
100 +#endif
101 +          
102          } else if (!S_ISDIR(st.st_mode)) {
103 +          /* PinG's ext2 patch. Blank flags */
104 +#ifdef USE_EXT2
105 +          if ((fd = open(output->directory,O_RDONLY))>0){
106 +             flags = 0;
107 +             ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
108 +             close(fd);
109 +          }
110 +#endif
111 +
112              if (unlink(output->directory) < 0) {
113                  fprintf(stderr, "Can't unlink [%s]\n", output->directory);
114                  return -1;
115 @@ -800,6 +843,17 @@
116                      output->directory);
117              return -2;
118          }
119 +
120 +/* PinG's ext2 patch. Set append-only & noatime flags */
121 +#ifdef USE_EXT2
122 +       if ((fd = open(path,O_RDONLY|O_CREAT))>0){
123 +         flags = EXT2_APPEND_FL | EXT2_NOATIME_FL;
124 +         ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
125 +         close(fd);
126 +       }
127 +#endif
128
129 +       
130          if ((fp = fopen(path, "at")) == NULL) {
131              fprintf(stderr, "Unable to access [%s]\n", path);
132              return -3;
133 @@ -811,6 +865,15 @@
134              fclose(fp);
135              return -2;
136          }
137 +       /* PinG's ext2 patch. */
138 +#ifdef USE_EXT2
139 +       if ((fd = open(path,O_RDONLY|O_CREAT))>0){
140 +         flags = 0;
141 +         ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
142 +         close(fd);
143 +       }
144 +#endif
145 +       
146          if ((fp_ts = fopen(path, "rt")) == NULL) {
147              recreate_ts:
148              creatime = time(NULL);
149 @@ -833,6 +896,15 @@
150              fprintf(stderr, "Unable to close [%s]\n", path);
151              return -3;
152          }
153 +       /* PinG's ext2 patch. */
154 +#ifdef USE_EXT2
155 +       if ((fd = open(path,O_RDONLY|O_CREAT))>0){
156 +         flags =  EXT2_IMMUTABLE_FL | EXT2_NOATIME_FL;
157 +         ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
158 +         close(fd);
159 +       }
160 +#endif
161 +       
162          output->creatime = creatime;
163          output->size = (off_t) ftell(fp);
164          output->fp = fp;
165 @@ -871,11 +943,33 @@
166          rotateLogFiles(output->directory, output->maxfiles);
167          fclose(output->fp);
168          output->fp = NULL;
169 +
170 +       
171 +/* PinG's ext2 patch. */
172 +#ifdef USE_EXT2
173 +       if ((fd = open(path,O_RDONLY))>0){
174 +         flags = 0;
175 +         ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
176 +         close(fd);
177 +       }
178 +#endif
179 +        
180 +       
181          if (rename(path, newpath) < 0 && unlink(path) < 0) {
182              fprintf(stderr, "Unable to rename [%s] to [%s]\n",
183                      path, newpath);
184              return -5;
185          }
186 +
187 +/* PinG's ext2 patch. Set immutable & noatime flags */
188 +#ifdef USE_EXT2
189 +       if ((fd = open(newpath,O_RDONLY))>0){
190 +         flags = EXT2_IMMUTABLE_FL | EXT2_NOATIME_FL;
191 +         ioctl(fd,EXT2_IOC_SETFLAGS,&flags);
192 +         close(fd);
193 +       }
194 +#endif
195 +       
196          if (snprintf(path, sizeof path, "%s/" OUTPUT_DIR_TIMESTAMP,
197                       output->directory) < 0) {
198              fprintf(stderr, "Path name too long for timestamp in [%s]\n",
199
200