glusterfs
615 строк · 9.3 Кб
1/*
2Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com>
3This file is part of GlusterFS.
4
5This file is licensed to you under your choice of the GNU Lesser
6General Public License, version 3 or any later version (LGPLv3 or
7later), or the GNU General Public License, version 2 (GPLv2), in all
8cases as published by the Free Software Foundation.
9*/
10
11/* LD PRELOAD'able library
12* A very simple library that intercepts booster supported system calls
13* and prints a log message to stdout.
14*
15* Combined with the ld-preload-test, we cam determine whether all system calls
16* are getting redirected into this library when LD_PRELOAD'ed. This helps us
17* conduct a basic test to ensure that the required syscalls actually will
18* be intercepted by the booster library.
19*/
20
21#include <dlfcn.h>22#include <sys/types.h>23#include <sys/uio.h>24#include <stdio.h>25#include <stdarg.h>26#include <stdlib.h>27#include <inttypes.h>28#include <string.h>29#include <assert.h>30#include <errno.h>31#include <utime.h>32#include <sys/statfs.h>33#include <sys/statvfs.h>34#include <fcntl.h>35#include <sys/stat.h>36#include <dirent.h>37#include <sys/xattr.h>38#include <sys/sendfile.h>39
40/* Err number that is assigned to errno so that test application can
41* verify that the function was intercepted correctly.
42*/
43#define PRELOAD_ERRNO_VERF 644944#define set_errno() (errno = PRELOAD_ERRNO_VERF)45
46void
47intercept(char *call, int tabs)48{
49while (tabs > 0) {50fprintf(stdout, "\t");51--tabs;52}53
54fprintf(stdout, "Intercepted by %s", call);55}
56
57int
58creat64(const char *pathname, mode_t mode)59{
60intercept("creat64", 2);61set_errno();62return -1;63}
64
65int
66creat(const char *pathname, mode_t mode)67{
68intercept("creat", 2);69set_errno();70return -1;71}
72
73int
74close(int fd)75{
76intercept("close", 2);77set_errno();78return -1;79}
80
81int
82open64(const char *pathname, int flags, ...)83{
84intercept("open64", 2);85set_errno();86return -1;87}
88
89int
90open(const char *pathname, int flags, ...)91{
92intercept("open", 2);93set_errno();94return -1;95}
96
97ssize_t
98read(int fd, void *buf, size_t count)99{
100intercept("read", 2);101set_errno();102return -1;103}
104
105ssize_t
106readv(int fd, const struct iovec *vector, int count)107{
108intercept("readv", 2);109set_errno();110return -1;111}
112
113ssize_t
114pread(int fd, void *buf, size_t count, unsigned long offset)115{
116intercept("pread", 2);117set_errno();118return -1;119}
120
121ssize_t
122pread64(int fd, void *buf, size_t count, uint64_t offset)123{
124intercept("pread64", 2);125set_errno();126return -1;127}
128
129ssize_t
130write(int fd, const void *buf, size_t count)131{
132intercept("write", 2);133set_errno();134return -1;135}
136
137ssize_t
138writev(int fd, const struct iovec *vector, int count)139{
140intercept("writev", 2);141set_errno();142return -1;143}
144
145ssize_t
146pwrite(int fd, const void *buf, size_t count, unsigned long offset)147{
148intercept("pwrite", 2);149set_errno();150return -1;151}
152
153ssize_t
154pwrite64(int fd, const void *buf, size_t count, uint64_t offset)155{
156intercept("pwrite64", 2);157set_errno();158return -1;159}
160
161off_t
162lseek(int fildes, unsigned long offset, int whence)163{
164intercept("lseek", 2);165set_errno();166return -1;167}
168
169off_t
170lseek64(int fildes, uint64_t offset, int whence)171{
172intercept("lseek64", 2);173set_errno();174return -1;175}
176
177int
178dup(int fd)179{
180intercept("dup", 2);181set_errno();182return -1;183}
184
185int
186dup2(int oldfd, int newfd)187{
188intercept("dup2", 2);189set_errno();190return -1;191}
192
193int
194mkdir(const char *pathname, mode_t mode)195{
196intercept("mkdir", 2);197set_errno();198return -1;199}
200
201int
202rmdir(const char *pathname)203{
204intercept("rmdir", 2);205set_errno();206return -1;207}
208
209int
210chmod(const char *pathname, mode_t mode)211{
212intercept("chmod", 2);213set_errno();214return -1;215}
216
217int
218chown(const char *pathname, uid_t owner, gid_t group)219{
220intercept("chown", 2);221set_errno();222return -1;223}
224
225int
226fchmod(int fd, mode_t mode)227{
228intercept("fchmod", 2);229set_errno();230return -1;231}
232
233int
234fchown(int fd, uid_t uid, gid_t gid)235{
236intercept("fchown", 2);237set_errno();238return -1;239}
240
241int
242fsync(int fd)243{
244intercept("fsync", 2);245set_errno();246return -1;247}
248
249int
250ftruncate(int fd, off_t length)251{
252intercept("ftruncate", 1);253set_errno();254return -1;255}
256
257int
258ftruncate64(int fd, off_t length)259{
260intercept("ftruncate64", 1);261set_errno();262return -1;263}
264
265int
266link(const char *oldpath, const char *newname)267{
268intercept("link", 2);269set_errno();270return -1;271}
272
273int
274rename(const char *oldpath, const char *newpath)275{
276intercept("rename", 2);277set_errno();278return -1;279}
280
281int
282utimes(const char *path, const struct timeval times[2])283{
284intercept("utimes", 2);285set_errno();286return -1;287}
288
289int
290futimes(int fd, const struct timeval times[2])291{
292intercept("futimes", 2);293set_errno();294return -1;295}
296
297int
298utime(const char *path, const struct utimbuf *buf)299{
300intercept("utime", 2);301set_errno();302return -1;303}
304
305int
306mknod(const char *path, mode_t mode, dev_t dev)307{
308intercept("mknod", 2);309set_errno();310return -1;311}
312
313int
314__xmknod(int ver, const char *path, mode_t mode, dev_t *dev)315{
316intercept("__xmknod", 2);317set_errno();318return -1;319}
320
321int
322mkfifo(const char *path, mode_t mode)323{
324intercept("mkfifo", 2);325set_errno();326return -1;327}
328
329int
330unlink(const char *path)331{
332intercept("unlink", 2);333set_errno();334return -1;335}
336
337int
338symlink(const char *oldpath, const char *newpath)339{
340intercept("symlink", 2);341set_errno();342return -1;343}
344
345int
346readlink(const char *path, char *buf, size_t bufsize)347{
348intercept("readlink", 1);349set_errno();350return -1;351}
352
353char *354realpath(const char *path, char *resolved)355{
356intercept("realpath", 1);357set_errno();358return NULL;359}
360
361DIR *362opendir(const char *path)363{
364intercept("opendir", 2);365set_errno();366return NULL;367}
368
369struct dirent *370readdir(DIR *dir)371{
372intercept("readdir\t", 2);373set_errno();374return NULL;375}
376
377struct dirent *378readdir64(DIR *dir)379{
380intercept("readdir64", 2);381set_errno();382return NULL;383}
384
385int
386readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)387{
388intercept("readdir_r", 1);389set_errno();390return -1;391}
392
393int
394readdir64_r(DIR *dir, struct dirent *entry, struct dirent **result)395{
396intercept("readdir64_r", 1);397set_errno();398return -1;399}
400
401int
402closedir(DIR *dh)403{
404intercept("closedir", 1);405set_errno();406return -1;407}
408
409int
410__xstat(int ver, const char *path, struct stat *buf)411{
412intercept("__xstat\t", 2);413set_errno();414return -1;415}
416
417int
418__xstat64(int ver, const char *path, struct stat *buf)419{
420intercept("__xstat64", 2);421set_errno();422return -1;423}
424
425int
426stat(const char *path, struct stat *buf)427{
428intercept("stat", 2);429set_errno();430return -1;431}
432
433int
434stat64(const char *path, struct stat *buf)435{
436intercept("stat64", 2);437set_errno();438return -1;439}
440
441int
442__fxstat(int ver, int fd, struct stat *buf)443{
444intercept("__fxstat\t", 2);445set_errno();446return -1;447}
448
449int
450__fxstat64(int ver, int fd, struct stat *buf)451{
452intercept("__fxstat64", 2);453set_errno();454return -1;455}
456
457int
458fstat(int fd, struct stat *buf)459{
460intercept("fstat", 2);461set_errno();462return -1;463}
464
465int
466fstat64(int fd, struct stat *buf)467{
468intercept("fstat64", 2);469set_errno();470return -1;471}
472
473int
474__lxstat(int ver, const char *path, struct stat *buf)475{
476intercept("__lxstat\t", 2);477set_errno();478return -1;479}
480
481int
482__lxstat64(int ver, const char *path, struct stat *buf)483{
484intercept("__lxstat64", 2);485set_errno();486return -1;487}
488
489int
490lstat(const char *path, struct stat *buf)491{
492intercept("lstat", 2);493set_errno();494return -1;495}
496
497int
498lstat64(const char *path, struct stat *buf)499{
500intercept("lstat64", 2);501set_errno();502return -1;503}
504
505int
506statfs(const char *path, struct statfs *buf)507{
508intercept("statfs", 2);509set_errno();510return -1;511}
512
513int
514statfs64(const char *path, struct statfs *buf)515{
516intercept("statfs64", 2);517set_errno();518return -1;519}
520
521int
522statvfs(const char *path, struct statvfs *buf)523{
524intercept("statvfs\t", 2);525set_errno();526return -1;527}
528
529int
530statvfs64(const char *path, struct statvfs *buf)531{
532intercept("statvfs64", 2);533set_errno();534return -1;535}
536
537ssize_t
538getxattr(const char *path, const char *name, void *value, size_t size)539{
540intercept("getxattr", 1);541set_errno();542return -1;543}
544
545ssize_t
546lgetxattr(const char *path, const char *name, void *value, size_t size)547{
548intercept("lgetxattr", 1);549set_errno();550return -1;551}
552
553int
554remove(const char *path)555{
556intercept("remove", 2);557set_errno();558return -1;559}
560
561int
562lchown(const char *path, uid_t owner, gid_t group)563{
564intercept("lchown", 2);565set_errno();566return -1;567}
568
569void
570rewinddir(DIR *dirp)571{
572intercept("rewinddir", 1);573set_errno();574return;575}
576
577void
578seekdir(DIR *dirp, off_t offset)579{
580intercept("seekdir", 2);581set_errno();582return;583}
584
585off_t
586telldir(DIR *dirp)587{
588intercept("telldir", 2);589set_errno();590return -1;591}
592
593ssize_t
594sendfile(int out_fd, int in_fd, off_t *offset, size_t count)595{
596intercept("sendfile\t", 1);597set_errno();598return -1;599}
600
601ssize_t
602sendfile64(int out_fd, int in_fd, off_t *offset, size_t count)603{
604intercept("sendfile64", 1);605set_errno();606return -1;607}
608
609int
610fcntl(int fd, int cmd, ...)611{
612intercept("fcntl", 2);613set_errno();614return -1;615}
616