"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "chironfs-1.1.1/src/chirondbg.c" of archive chironfs-1.1.1.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 /* Copyright 2005-2008 Luis Furquim
2 *
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19
20 #include "config.h"
21
22 #ifdef linux
23 #define __USE_BSD
24
25
26 /* For pread()/pwrite() */
27 #define _XOPEN_SOURCE 500
28 #endif
29
30 #define FUSE_USE_VERSION 25
31
32 //
33 // The lines below are from a patch contributed by Yen-Ming Lee,
34 // porting ChironFS to FreeBSD
35 //
36 #include <fuse.h>
37 #if defined(linux) || defined(__FreeBSD__)
38
39 #include <fuse/fuse.h>
40 #include <fuse/fuse_opt.h>
41
42 #else
43
44 typedef uint64_t cpuset_t;
45
46 //
47 // The lines below are from a patch contributed by Antti Kantee
48 // to make ChironFS run on NetBSD
49 //
50
51 #include <fuse_opt.h>
52
53 #endif
54 //
55 // End of BSD patches
56 //
57
58 #ifdef __linux__
59 #define __USE_BSD
60 #endif
61
62 #include <stdlib.h>
63 #include <stdio.h>
64 #include <string.h>
65 #include <stdarg.h>
66 #include <unistd.h>
67 #include <fcntl.h>
68 #include <dirent.h>
69 #include <errno.h>
70 #include <time.h>
71 #include <sys/time.h>
72 #include <libgen.h>
73
74 #ifdef HAVE_SETXATTR
75 #include <sys/xattr.h>
76 #endif
77
78 #ifdef __linux__
79
80 #include <linux/limits.h>
81 #include <mntent.h>
82 #include <bits/wordsize.h>
83
84 #else
85
86 #include <limits.h>
87 #include <sys/types.h>
88 #include <sys/statvfs.h>
89
90 #endif
91
92
93 //
94 // The lines below are from a patch contributed by Yen-Ming Lee,
95 // porting ChironFS to FreeBSD
96 //
97 #ifndef HAVE_GETMNTENT
98 #include <sys/param.h>
99 #include <sys/ucred.h>
100 #include <sys/mount.h>
101 #endif
102 //
103 // End of BSD patch
104 //
105
106
107 #include <stdint.h>
108 #include <pwd.h>
109 #include <grp.h>
110
111
112 #ifdef __linux__
113
114 #define _REENTRANT
115
116 #ifndef _POSIX_SOURCE
117 #define _POSIX_SOURCE
118 #endif
119
120 /* for LinuxThreads */
121 #define _P __P
122
123 #endif
124
125 #include <pthread.h>
126
127
128 #include "chiron-types.h"
129 #define _CHIRONDBG_H_
130 #include "chironfs.h"
131 #include "chirondbg.h"
132
133
134 ////////////////////////////////////////////////////////////////////////////
135 ////////////////////////////////////////////////////////////////////////////
136 //
137 //
138 // D E B U G S T U F F
139 //
140 //
141 ////////////////////////////////////////////////////////////////////////////
142 ////////////////////////////////////////////////////////////////////////////
143
144 #ifdef _DBG_
145 void debug(const char *s, ...);
146 int timeval_sub (struct timeval *result, struct timeval *x, struct timeval *y);
147
148 void debug(const char *s, ...)
149 {
150 FILE *fd;
151 int res;
152 int bkerrno = errno;
153 va_list ap;
154
155 va_start (ap, s);
156 fd = fopen("/tmp/chironfs-dbg.txt","a");
157 res = vfprintf(fd,s,ap);
158 fclose(fd);
159 va_end (ap);
160
161 errno = bkerrno;
162 }
163
164 /*
165 Subtract the `struct timeval' values X and Y,
166 storing the result in RESULT.
167 Return 1 if the difference is negative, otherwise 0.
168 */
169
170 int timeval_sub (struct timeval *result, struct timeval *x, struct timeval *y)
171 {
172 /* Perform the carry for the later subtraction by updating y. */
173 if (x->tv_usec < y->tv_usec) {
174 int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
175 y->tv_usec -= 1000000 * nsec;
176 y->tv_sec += nsec;
177 }
178 if (x->tv_usec - y->tv_usec > 1000000) {
179 int nsec = (x->tv_usec - y->tv_usec) / 1000000;
180 y->tv_usec += 1000000 * nsec;
181 y->tv_sec -= nsec;
182 }
183
184 /* Compute the time remaining to wait.
185 tv_usec is certainly positive. */
186 result->tv_sec = x->tv_sec - y->tv_sec;
187 result->tv_usec = x->tv_usec - y->tv_usec;
188
189 /* Return 1 if result is negative. */
190 return x->tv_sec < y->tv_sec;
191 }
192
193
194 #endif
195
196 ////////////////////////////////////////////////////////////////////////////
197 ////////////////////////////////////////////////////////////////////////////
198 //
199 //
200 // A U X I L I A R Y F U N C T I O N S
201 //
202 //
203 ////////////////////////////////////////////////////////////////////////////
204 ////////////////////////////////////////////////////////////////////////////
205
206 void print_err(int err, char *specifier)
207 {
208 if (!quiet_mode) {
209 if (specifier==NULL) {
210 if (err>0) {
211 fprintf(stderr,"%s\n",strerror(err));
212 } else {
213 fprintf(stderr,"%s\n",errtab[-(err+1)]);
214 }
215 } else {
216 if (err>0) {
217 fprintf(stderr,"%s: %s\n",specifier,strerror(err));
218 } else {
219 fprintf(stderr,"%s: %s\n",specifier,errtab[-(err+1)]);
220 }
221 }
222 }
223 }
224
225
226 void call_log(char *fnname, char *resource, int err)
227 {
228 time_t t;
229 struct tm *ptm;
230 char tmstr[20];
231
232 if (logfd!=NULL) {
233 attach_log();
234 flockfile(logfd);
235 t = time(NULL);
236 ptm = localtime(&t);
237 strftime(tmstr,19,"%Y/%m/%d %H:%M ",ptm);
238 fputs(tmstr,logfd);
239 fputs(fnname,logfd);
240 if (err!=CHIRONFS_ADM_FORCED) {
241 fputs(" failed accessing ",logfd);
242 } else {
243 fputs(" ",logfd);
244 }
245 fputs(resource,logfd);
246 if (err) {
247 fputs(" ",logfd);
248 if (err>0) {
249 fputs(strerror(err),logfd);
250 } else {
251 fputs(errtab[-(err+1)],logfd);
252 }
253 }
254 fputs("\n",logfd);
255 fflush(logfd);
256 funlockfile(logfd);
257 }
258 }
259
260 void attach_log(void)
261 {
262 mode_t tmpmask;
263
264 if (logfd) {
265 fclose(logfd);
266 }
267 tmpmask = umask(0133);
268 logfd = fopen(logname,"a");
269 umask(tmpmask);
270 if (logfd==NULL) {
271 print_err(CHIRONFS_ERR_BAD_LOG_FILE,logname);
272 exit(CHIRONFS_ERR_BAD_LOG_FILE);
273 }
274 setlinebuf(logfd);
275 }
276