glusterfs

Форк
0
615 строк · 9.3 Кб
1
/*
2
   Copyright (c) 2007-2012 Red Hat, Inc. <http://www.redhat.com>
3
   This file is part of GlusterFS.
4

5
   This file is licensed to you under your choice of the GNU Lesser
6
   General Public License, version 3 or any later version (LGPLv3 or
7
   later), or the GNU General Public License, version 2 (GPLv2), in all
8
   cases 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 6449
44
#define set_errno() (errno = PRELOAD_ERRNO_VERF)
45

46
void
47
intercept(char *call, int tabs)
48
{
49
    while (tabs > 0) {
50
        fprintf(stdout, "\t");
51
        --tabs;
52
    }
53

54
    fprintf(stdout, "Intercepted by %s", call);
55
}
56

57
int
58
creat64(const char *pathname, mode_t mode)
59
{
60
    intercept("creat64", 2);
61
    set_errno();
62
    return -1;
63
}
64

65
int
66
creat(const char *pathname, mode_t mode)
67
{
68
    intercept("creat", 2);
69
    set_errno();
70
    return -1;
71
}
72

73
int
74
close(int fd)
75
{
76
    intercept("close", 2);
77
    set_errno();
78
    return -1;
79
}
80

81
int
82
open64(const char *pathname, int flags, ...)
83
{
84
    intercept("open64", 2);
85
    set_errno();
86
    return -1;
87
}
88

89
int
90
open(const char *pathname, int flags, ...)
91
{
92
    intercept("open", 2);
93
    set_errno();
94
    return -1;
95
}
96

97
ssize_t
98
read(int fd, void *buf, size_t count)
99
{
100
    intercept("read", 2);
101
    set_errno();
102
    return -1;
103
}
104

105
ssize_t
106
readv(int fd, const struct iovec *vector, int count)
107
{
108
    intercept("readv", 2);
109
    set_errno();
110
    return -1;
111
}
112

113
ssize_t
114
pread(int fd, void *buf, size_t count, unsigned long offset)
115
{
116
    intercept("pread", 2);
117
    set_errno();
118
    return -1;
119
}
120

121
ssize_t
122
pread64(int fd, void *buf, size_t count, uint64_t offset)
123
{
124
    intercept("pread64", 2);
125
    set_errno();
126
    return -1;
127
}
128

129
ssize_t
130
write(int fd, const void *buf, size_t count)
131
{
132
    intercept("write", 2);
133
    set_errno();
134
    return -1;
135
}
136

137
ssize_t
138
writev(int fd, const struct iovec *vector, int count)
139
{
140
    intercept("writev", 2);
141
    set_errno();
142
    return -1;
143
}
144

145
ssize_t
146
pwrite(int fd, const void *buf, size_t count, unsigned long offset)
147
{
148
    intercept("pwrite", 2);
149
    set_errno();
150
    return -1;
151
}
152

153
ssize_t
154
pwrite64(int fd, const void *buf, size_t count, uint64_t offset)
155
{
156
    intercept("pwrite64", 2);
157
    set_errno();
158
    return -1;
159
}
160

161
off_t
162
lseek(int fildes, unsigned long offset, int whence)
163
{
164
    intercept("lseek", 2);
165
    set_errno();
166
    return -1;
167
}
168

169
off_t
170
lseek64(int fildes, uint64_t offset, int whence)
171
{
172
    intercept("lseek64", 2);
173
    set_errno();
174
    return -1;
175
}
176

177
int
178
dup(int fd)
179
{
180
    intercept("dup", 2);
181
    set_errno();
182
    return -1;
183
}
184

185
int
186
dup2(int oldfd, int newfd)
187
{
188
    intercept("dup2", 2);
189
    set_errno();
190
    return -1;
191
}
192

193
int
194
mkdir(const char *pathname, mode_t mode)
195
{
196
    intercept("mkdir", 2);
197
    set_errno();
198
    return -1;
199
}
200

201
int
202
rmdir(const char *pathname)
203
{
204
    intercept("rmdir", 2);
205
    set_errno();
206
    return -1;
207
}
208

209
int
210
chmod(const char *pathname, mode_t mode)
211
{
212
    intercept("chmod", 2);
213
    set_errno();
214
    return -1;
215
}
216

217
int
218
chown(const char *pathname, uid_t owner, gid_t group)
219
{
220
    intercept("chown", 2);
221
    set_errno();
222
    return -1;
223
}
224

225
int
226
fchmod(int fd, mode_t mode)
227
{
228
    intercept("fchmod", 2);
229
    set_errno();
230
    return -1;
231
}
232

233
int
234
fchown(int fd, uid_t uid, gid_t gid)
235
{
236
    intercept("fchown", 2);
237
    set_errno();
238
    return -1;
239
}
240

241
int
242
fsync(int fd)
243
{
244
    intercept("fsync", 2);
245
    set_errno();
246
    return -1;
247
}
248

249
int
250
ftruncate(int fd, off_t length)
251
{
252
    intercept("ftruncate", 1);
253
    set_errno();
254
    return -1;
255
}
256

257
int
258
ftruncate64(int fd, off_t length)
259
{
260
    intercept("ftruncate64", 1);
261
    set_errno();
262
    return -1;
263
}
264

265
int
266
link(const char *oldpath, const char *newname)
267
{
268
    intercept("link", 2);
269
    set_errno();
270
    return -1;
271
}
272

273
int
274
rename(const char *oldpath, const char *newpath)
275
{
276
    intercept("rename", 2);
277
    set_errno();
278
    return -1;
279
}
280

281
int
282
utimes(const char *path, const struct timeval times[2])
283
{
284
    intercept("utimes", 2);
285
    set_errno();
286
    return -1;
287
}
288

289
int
290
futimes(int fd, const struct timeval times[2])
291
{
292
    intercept("futimes", 2);
293
    set_errno();
294
    return -1;
295
}
296

297
int
298
utime(const char *path, const struct utimbuf *buf)
299
{
300
    intercept("utime", 2);
301
    set_errno();
302
    return -1;
303
}
304

305
int
306
mknod(const char *path, mode_t mode, dev_t dev)
307
{
308
    intercept("mknod", 2);
309
    set_errno();
310
    return -1;
311
}
312

313
int
314
__xmknod(int ver, const char *path, mode_t mode, dev_t *dev)
315
{
316
    intercept("__xmknod", 2);
317
    set_errno();
318
    return -1;
319
}
320

321
int
322
mkfifo(const char *path, mode_t mode)
323
{
324
    intercept("mkfifo", 2);
325
    set_errno();
326
    return -1;
327
}
328

329
int
330
unlink(const char *path)
331
{
332
    intercept("unlink", 2);
333
    set_errno();
334
    return -1;
335
}
336

337
int
338
symlink(const char *oldpath, const char *newpath)
339
{
340
    intercept("symlink", 2);
341
    set_errno();
342
    return -1;
343
}
344

345
int
346
readlink(const char *path, char *buf, size_t bufsize)
347
{
348
    intercept("readlink", 1);
349
    set_errno();
350
    return -1;
351
}
352

353
char *
354
realpath(const char *path, char *resolved)
355
{
356
    intercept("realpath", 1);
357
    set_errno();
358
    return NULL;
359
}
360

361
DIR *
362
opendir(const char *path)
363
{
364
    intercept("opendir", 2);
365
    set_errno();
366
    return NULL;
367
}
368

369
struct dirent *
370
readdir(DIR *dir)
371
{
372
    intercept("readdir\t", 2);
373
    set_errno();
374
    return NULL;
375
}
376

377
struct dirent *
378
readdir64(DIR *dir)
379
{
380
    intercept("readdir64", 2);
381
    set_errno();
382
    return NULL;
383
}
384

385
int
386
readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
387
{
388
    intercept("readdir_r", 1);
389
    set_errno();
390
    return -1;
391
}
392

393
int
394
readdir64_r(DIR *dir, struct dirent *entry, struct dirent **result)
395
{
396
    intercept("readdir64_r", 1);
397
    set_errno();
398
    return -1;
399
}
400

401
int
402
closedir(DIR *dh)
403
{
404
    intercept("closedir", 1);
405
    set_errno();
406
    return -1;
407
}
408

409
int
410
__xstat(int ver, const char *path, struct stat *buf)
411
{
412
    intercept("__xstat\t", 2);
413
    set_errno();
414
    return -1;
415
}
416

417
int
418
__xstat64(int ver, const char *path, struct stat *buf)
419
{
420
    intercept("__xstat64", 2);
421
    set_errno();
422
    return -1;
423
}
424

425
int
426
stat(const char *path, struct stat *buf)
427
{
428
    intercept("stat", 2);
429
    set_errno();
430
    return -1;
431
}
432

433
int
434
stat64(const char *path, struct stat *buf)
435
{
436
    intercept("stat64", 2);
437
    set_errno();
438
    return -1;
439
}
440

441
int
442
__fxstat(int ver, int fd, struct stat *buf)
443
{
444
    intercept("__fxstat\t", 2);
445
    set_errno();
446
    return -1;
447
}
448

449
int
450
__fxstat64(int ver, int fd, struct stat *buf)
451
{
452
    intercept("__fxstat64", 2);
453
    set_errno();
454
    return -1;
455
}
456

457
int
458
fstat(int fd, struct stat *buf)
459
{
460
    intercept("fstat", 2);
461
    set_errno();
462
    return -1;
463
}
464

465
int
466
fstat64(int fd, struct stat *buf)
467
{
468
    intercept("fstat64", 2);
469
    set_errno();
470
    return -1;
471
}
472

473
int
474
__lxstat(int ver, const char *path, struct stat *buf)
475
{
476
    intercept("__lxstat\t", 2);
477
    set_errno();
478
    return -1;
479
}
480

481
int
482
__lxstat64(int ver, const char *path, struct stat *buf)
483
{
484
    intercept("__lxstat64", 2);
485
    set_errno();
486
    return -1;
487
}
488

489
int
490
lstat(const char *path, struct stat *buf)
491
{
492
    intercept("lstat", 2);
493
    set_errno();
494
    return -1;
495
}
496

497
int
498
lstat64(const char *path, struct stat *buf)
499
{
500
    intercept("lstat64", 2);
501
    set_errno();
502
    return -1;
503
}
504

505
int
506
statfs(const char *path, struct statfs *buf)
507
{
508
    intercept("statfs", 2);
509
    set_errno();
510
    return -1;
511
}
512

513
int
514
statfs64(const char *path, struct statfs *buf)
515
{
516
    intercept("statfs64", 2);
517
    set_errno();
518
    return -1;
519
}
520

521
int
522
statvfs(const char *path, struct statvfs *buf)
523
{
524
    intercept("statvfs\t", 2);
525
    set_errno();
526
    return -1;
527
}
528

529
int
530
statvfs64(const char *path, struct statvfs *buf)
531
{
532
    intercept("statvfs64", 2);
533
    set_errno();
534
    return -1;
535
}
536

537
ssize_t
538
getxattr(const char *path, const char *name, void *value, size_t size)
539
{
540
    intercept("getxattr", 1);
541
    set_errno();
542
    return -1;
543
}
544

545
ssize_t
546
lgetxattr(const char *path, const char *name, void *value, size_t size)
547
{
548
    intercept("lgetxattr", 1);
549
    set_errno();
550
    return -1;
551
}
552

553
int
554
remove(const char *path)
555
{
556
    intercept("remove", 2);
557
    set_errno();
558
    return -1;
559
}
560

561
int
562
lchown(const char *path, uid_t owner, gid_t group)
563
{
564
    intercept("lchown", 2);
565
    set_errno();
566
    return -1;
567
}
568

569
void
570
rewinddir(DIR *dirp)
571
{
572
    intercept("rewinddir", 1);
573
    set_errno();
574
    return;
575
}
576

577
void
578
seekdir(DIR *dirp, off_t offset)
579
{
580
    intercept("seekdir", 2);
581
    set_errno();
582
    return;
583
}
584

585
off_t
586
telldir(DIR *dirp)
587
{
588
    intercept("telldir", 2);
589
    set_errno();
590
    return -1;
591
}
592

593
ssize_t
594
sendfile(int out_fd, int in_fd, off_t *offset, size_t count)
595
{
596
    intercept("sendfile\t", 1);
597
    set_errno();
598
    return -1;
599
}
600

601
ssize_t
602
sendfile64(int out_fd, int in_fd, off_t *offset, size_t count)
603
{
604
    intercept("sendfile64", 1);
605
    set_errno();
606
    return -1;
607
}
608

609
int
610
fcntl(int fd, int cmd, ...)
611
{
612
    intercept("fcntl", 2);
613
    set_errno();
614
    return -1;
615
}
616

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.