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 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
|
/*
* DCAP - dCache Access Protocol client interface
*
* Copyright (C) 2000,2004 DESY Hamburg DMG-Division.
*
* AUTHOR: Tigran Mkrtchayn (tigran.mkrtchyan@desy.de)
*
* This program can be distributed under the terms of the GNU LGPL.
* See the file COPYING.LIB
*
*/
/*
* $Id: dcap_preload.c,v 1.39 2006-09-26 07:47:27 tigran Exp $
*/
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <dirent.h>
#include "dcap.h"
#include "dcap_close.h"
#include "debug_level.h"
/*
* some applications do not close the file, which they have opned
*/
static int cleanupEnabled;
/* Replacing system calls with our if we are PRELOAD library */
int open(const char *path, int flags,...)
{
int rc;
mode_t mode = 0;
va_list args;
if (flags & O_CREAT) {
va_start(args, flags);
mode = va_arg(args, mode_t);
va_end(args);
}
rc = dc_open(path, flags, mode);
dc_debug(DC_TRACE, "Running preloaded open for %s, fd = %d", path, rc);
if( (rc >=0 ) && ! cleanupEnabled) {
dc_debug(DC_INFO, "Enabling cleanup atexit");
++cleanupEnabled;
atexit( dc_closeAll );
}
return rc;
}
int creat(const char *path, mode_t mode)
{
int rc;
rc = dc_creat(path, mode);
dc_debug(DC_TRACE, "Running preloaded creat for %s, fd = %d", path, rc);
return rc;
}
off_t lseek(int fd, off_t offset, int mode)
{
dc_debug(DC_TRACE, "Running preloaded lseek for [%d][%ld][%d]", fd, offset, mode);
return dc_lseek(fd, offset, mode);
}
#ifdef HAVE__XSTAT
int _xstat(int i, const char *p, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded _xstat for %s", p);
return dc_stat(p, s);
}
#else
int stat(const char *p, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded stat for %s", p);
return dc_stat(p, s);
}
#endif /* HAVE__XSTAT */
int __xstat(int i, const char *p, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded __xstat for %s", p);
return dc_stat(p, s);
}
#ifdef HAVE__LXSTAT
int _lxstat(int i, const char *p, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded _lxstat for %s", p);
return dc_lstat(p, s);
}
#else
int lstat(const char *p, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded lstat for %s", p);
return dc_lstat(p, s);
}
#endif /* HAVE__LXSTAT */
int __lxstat(int i, const char *p, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded __lxstat for %s", p);
return dc_lstat(p, s);
}
#ifdef HAVE__FXSTAT
int _fxstat(int i, int fd, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded _fxstat for [%d]", fd);
return dc_fstat(fd, s);
}
#else
int fstat(int fd, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded fstat for [%d]", fd);
return dc_fstat(fd, s);
}
#endif /* HAVE__FXSTAT */
int __fxstat(int i, int fd, struct stat *s)
{
dc_debug(DC_TRACE, "Running preloaded __fxstat for [%d]", fd);
return dc_fstat(fd, s);
}
#ifdef HAVE_ACL
int acl(const char *path, int cmd, int nentries, void *aclbufp)
{
dc_debug(DC_TRACE, "Running preloaded acl for path %s, %d.", path, cmd);
return dc_acl(path, cmd, nentries, aclbufp);
}
#endif /* HAVE_ACL */
#ifdef HAVE_FACL
int facl(int fd, int cmd, int nentries, void *aclbufp)
{
dc_debug(DC_TRACE, "Running preloaded facl for file ID %s, %d.", fd, cmd);
return dc_facl(fd, cmd, nentries, aclbufp);
}
#endif /* HAVE_FACL */
struct dirent *readdir( DIR *dir)
{
dc_debug(DC_TRACE, "Running preloaded readdir");
return dc_readdir(dir);
}
DIR * opendir(const char *fname)
{
DIR *dir;
dc_debug(DC_TRACE, "Running preloaded opendir for %s", fname);
dir= dc_opendir(fname);
dc_debug(DC_TRACE, "Running preloaded opendir for %s dir [0x%X]", dir );
return dir;
}
int closedir(DIR *dir)
{
dc_debug(DC_TRACE, "Running preloaded closedir for [0x%X]", dir);
return dc_closedir(dir);
}
long int telldir( DIR *dir)
{
dc_debug(DC_TRACE, "Running preloaded telldir");
return dc_telldir(dir);
}
void seekdir(DIR *dir, long int offset)
{
dc_debug(DC_TRACE, "Running preloaded seekdir");
dc_seekdir(dir, offset);
}
ssize_t read(int fd, void *buff, size_t n)
{
dc_debug(DC_TRACE, "Running preloaded read for [%d]", fd);
return dc_read(fd, buff, n);
}
ssize_t readv(int fd, const struct iovec *iov, int iovcnt)
{
dc_debug(DC_TRACE, "Running preloaded readv for [%d]", fd);
return dc_readv(fd, iov, iovcnt);
}
ssize_t pread(int fd, void *buff, size_t n , off_t off)
{
dc_debug(DC_TRACE, "Running preloaded pread for [%d]", fd);
return dc_pread(fd, buff, n, (off_t)off);
}
ssize_t write(int fd, const void *buff, size_t n)
{
dc_debug(DC_TRACE, "Running preloaded write for [%d]", fd);
return dc_write(fd, buff, n);
}
ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
{
dc_debug(DC_TRACE, "Running preloaded writev for [%d]", fd);
return dc_writev(fd, iov, iovcnt);
}
ssize_t pwrite(int fd, const void *buff, size_t n, off_t off)
{
dc_debug(DC_TRACE, "Running preloaded pwrite for [%d]", fd);
return dc_pwrite(fd, buff, n, (off_t) off);
}
int dup(int fd)
{
dc_debug(DC_TRACE, "Running preloaded dup for [%d]", fd);
return dc_dup(fd);
}
int access( const char *path, int mode)
{
dc_debug(DC_TRACE, "Running preloaded access for %s", path);
return dc_access(path, mode);
}
int fsync(int fd)
{
dc_debug(DC_TRACE, "Running preloaded fsync for [%d]", fd);
return dc_fsync(fd);
}
int close(int fd)
{
dc_debug(DC_TRACE, "Running preloaded close for [%d]", fd);
return dc_close(fd);
}
ssize_t listxattr(const char *path, char *list, size_t size)
{
dc_debug(DC_TRACE, "Running preloaded listxattr for %s", path);
errno = ENOTSUP;
return -1;
}
ssize_t flistxattr(int fd, char *list, size_t size)
{
dc_debug(DC_TRACE, "Running preloaded listxattr for [%d]", fd);
errno = ENOTSUP;
return -1;
}
ssize_t llistxattr(const char *path, char *list, size_t size)
{
dc_debug(DC_TRACE, "Running preloaded listxattr for %s", path);
errno = ENOTSUP;
return -1;
}
ssize_t getxattr (const char *path, const char *name, void *value, size_t size)
{
dc_debug(DC_TRACE, "Running preloaded getxattr for %s", path);
errno = ENOTSUP;
return -1;
}
ssize_t lgetxattr (const char *path, const char *name, void *value, size_t size)
{
dc_debug(DC_TRACE, "Running preloaded lgetxattr for %s", path);
errno = ENOTSUP;
return -1;
}
ssize_t fgetxattr (int fd, const char *name, void *value, size_t size)
{
dc_debug(DC_TRACE, "Running preloaded fgetxattr for [%d]", fd);
errno = ENOTSUP;
return -1;
}
FILE *fopen(const char *path, const char *mode)
{
dc_debug(DC_TRACE, "Running preloaded fopen for [%s, %s]", path, mode);
if(!cleanupEnabled) {
dc_debug(DC_INFO, "Enabling cleanup atexit");
++cleanupEnabled;
atexit( dc_closeAll );
}
return dc_fopen(path, mode);
}
FILE *fdopen(int fd, const char *mode)
{
dc_debug(DC_TRACE, "Running preloaded fdopen for [%d, %s]", fd, mode);
if(!cleanupEnabled) {
dc_debug(DC_INFO, "Enabling cleanup atexit");
++cleanupEnabled;
atexit( dc_closeAll );
}
return dc_fdopen(fd, mode);
}
int fclose(FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded fclose");
return dc_fclose(stream);
}
size_t fwrite(const void *buf, size_t i, size_t n , FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded fwrite");
return dc_fwrite( buf, i, n, stream );
}
size_t fread(void *buf, size_t i, size_t n, FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded fread");
return dc_fread( buf, i, n, stream );
}
int fseek(FILE *stream, long offset, int w)
{
dc_debug(DC_TRACE, "Running preloaded fseek");
return dc_fseek( stream, offset, w );
}
long ftell(FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded ftell");
return dc_ftell( stream );
}
int ferror(FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded ferror");
return dc_ferror( stream );
}
int fflush(FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded fflush");
return dc_fflush( stream );
}
int feof(FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded feof");
return dc_feof( stream );
}
char * fgets( char *s, int size, FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded fgets");
return dc_fgets(s, size, stream);
}
int fgetc(FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded fgetc");
return dc_fgetc(stream);
}
int getc(FILE *stream)
{
dc_debug(DC_TRACE, "Running preloaded getc");
return dc_fgetc(stream);
}
int fseeko( FILE *stream, off_t offset, int whence)
{
dc_debug(DC_TRACE, "Running preloaded fseeko");
return dc_fseeko( stream, offset, whence );
}
off_t ftello (FILE *stream )
{
dc_debug(DC_TRACE, "Running preloaded ftello");
return dc_ftello( stream );
}
int unlink( const char *path)
{
dc_debug(DC_TRACE, "Running preloaded unlink for path %s", path);
return dc_unlink(path);
}
int rmdir( const char *path)
{
dc_debug(DC_TRACE, "Running preloaded rmdir for path %s", path);
return dc_rmdir(path);
}
int mkdir( const char *path, mode_t mode)
{
dc_debug(DC_TRACE, "Running preloaded mkdir for path %s, mode 0%o", path, mode);
return dc_mkdir(path, mode);
}
int chmod( const char *path, mode_t mode)
{
dc_debug(DC_TRACE, "Running preloaded chmod for path %s, mode 0%o", path, mode);
return dc_chmod(path, mode);
}
int chown( const char *path, uid_t uid, gid_t gid)
{
dc_debug(DC_TRACE, "Running preloaded chown for path %s, %d:%d", path, uid, gid);
return dc_chown(path, uid, gid);
}
void clearerr(FILE *stream)
{
dc_errno = DEOK;
}
void rewind( FILE *stream )
{
dc_debug(DC_TRACE, "Running preloaded rewind");
(void)dc_fseek( stream, 0L, SEEK_SET );
}
int rename( const char *oldPath, const char *newPath)
{
dc_debug(DC_TRACE, "Running preloaded renam %s to %s.", oldPath, newPath);
return dc_rename(oldPath, newPath);
}
|