forked from erluko/socat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sycls.c
1639 lines (1491 loc) · 43.4 KB
/
sycls.c
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* source: sycls.c */
/* Copyright Gerhard Rieger */
/* Published under the GNU General Public License V.2, see file COPYING */
/* explicit system call and C library trace function, for those who miss strace
*/
#include "config.h"
#include "xioconfig.h" /* what features are enabled */
#if WITH_SYCLS
#include "sysincludes.h"
#include "mytypes.h"
#include "compat.h"
#include "errno.h"
#include "error.h"
#include "filan.h"
#include "utils.h"
#include "sysutils.h"
#include "sycls.h"
mode_t Umask(mode_t mask) {
mode_t result;
int _errno;
Debug1("umask("F_mode")", mask);
result = umask(mask);
_errno = errno;
Debug1("umask() -> "F_mode, result);
errno = _errno;
return result;
}
int Open(const char *pathname, int flags, mode_t mode) {
int result, _errno;
if (!diag_in_handler) diag_flush();
Debug3("open(\"%s\", 0%o, 0%03o)", pathname, flags, mode);
result = open(pathname, flags, mode);
_errno = errno;
if (!diag_in_handler) diag_flush();
Info4("open(\"%s\", 0%o, 0%03o) -> %d", pathname, flags, mode, result);
errno = _errno;
return result;
}
int Creat(const char *pathname, mode_t mode) {
int result, _errno;
Debug2("creat(\"%s\", 0%03o)", pathname, mode);
result = creat(pathname, mode);
_errno = errno;
Info3("creat(\"%s\", 0%03o) -> %d", pathname, mode, result);
errno = _errno;
return result;
}
off_t Lseek(int fildes, off_t offset, int whence) {
int _errno;
off_t result;
Debug3("lseek(%d, "F_off", %d)", fildes, offset, whence);
result = lseek(fildes, offset, whence);
_errno = errno;
Debug1("lseek() -> "F_off, result);
errno = _errno;
return result;
}
#if HAVE_LSEEK64
off64_t Lseek64(int fildes, off64_t offset, int whence) {
int _errno;
off64_t result;
Debug3("lseek64(%d, "F_off64", %d)", fildes, offset, whence);
result = lseek64(fildes, offset, whence);
_errno = errno;
Debug1("lseek64() -> "F_off64, result);
errno = _errno;
return result;
}
#endif /* HAVE_LSEEK64 */
pid_t Getpid(void) {
pid_t result;
int _errno;
Debug("getpid()");
result = getpid();
_errno = errno;
Debug1("getpid() -> "F_pid, result);
errno = _errno;
return result;
}
pid_t Getppid(void) {
pid_t result;
int _errno;
Debug("getppid()");
result = getppid();
_errno = errno;
Debug1("getppid() -> "F_pid, result);
errno = _errno;
return result;
}
pid_t Getpgrp(void) {
pid_t result;
int _errno;
Debug("getpgrp()");
result = getpgrp();
_errno = errno;
Debug1("getpgrp() -> "F_pid, result);
errno = _errno;
return result;
}
#if 0 /* does not compile for FreeBSD */
/* setpgrp() is not BSD compatible, needs setpgid(..., ...) instead */
int Setpgrp(void) {
int result, _errno;
Debug("setpgrp()");
result = setpgrp();
_errno = errno;
Debug1("setpgrp() -> %d", result);
errno = _errno;
return result;
}
#endif
#if HAVE_GETPGID
int Getpgid(pid_t pid) {
pid_t result;
int _errno;
Debug1("getpgid("F_pid")", pid);
result = getpgid(pid);
_errno = errno;
Debug1("getpgid() -> "F_pid, result);
errno = _errno;
return result;
}
#endif
int Setpgid(pid_t pid, pid_t pgid) {
int result, _errno;
Debug2("setpgid("F_pid", "F_pid")", pid, pgid);
result = setpgid(pid, pgid);
_errno = errno;
Debug1("setpgid() -> %d", result);
errno = _errno;
return result;
}
pid_t Tcgetpgrp(int fd) {
int result, _errno;
Debug1("tcgetpgrp(%d)", fd);
result = tcgetpgrp(fd);
_errno = errno;
Debug1("tcgetpgrp() -> %d", result);
errno = _errno;
return result;
}
int Tcsetpgrp(int fd, pid_t pgrpid) {
int result, _errno;
Debug2("tcsetpgrp(%d, "F_pid")", fd, pgrpid);
result = tcsetpgrp(fd, pgrpid);
_errno = errno;
Debug1("tcsetpgrp() -> %d", result);
errno = _errno;
return result;
}
#if HAVE_GETSID
pid_t Getsid(pid_t pid) {
int result, _errno;
Debug1("getsid("F_pid")", pid);
result = getsid(pid);
_errno = errno;
Debug1("getsid() -> "F_pid, result);
errno = _errno;
return result;
}
#endif
pid_t Setsid(void) {
int result, _errno;
Debug("setsid()");
result = setsid();
_errno = errno;
Debug1("setsid() -> "F_pid, result);
errno = _errno;
return result;
}
uid_t Getuid(void) {
uid_t result;
int _errno;
Debug("getuid()");
result = getuid();
_errno = errno;
Debug1("getuid() -> "F_uid, result);
errno = _errno;
return result;
}
uid_t Geteuid(void) {
uid_t result;
int _errno;
Debug("geteuid()");
result = geteuid();
_errno = errno;
Debug1("geteuid() -> "F_uid, result);
errno = _errno;
return result;
}
int Setuid(uid_t uid) {
int result, _errno;
Debug1("setuid("F_uid")", uid);
result = setuid(uid);
_errno = errno;
Debug1("setuid() -> %d", result);
errno = _errno;
return result;
}
gid_t Getgid(void) {
gid_t result;
int _errno;
Debug("getgid()");
result = getgid();
_errno = errno;
Debug1("getgid() -> "F_gid, result);
errno = _errno;
return result;
}
gid_t Getegid(void) {
gid_t result;
int _errno;
Debug("getegid()");
result = getegid();
_errno = errno;
Debug1("getegid() -> "F_gid, result);
errno = _errno;
return result;
}
int Setgid(gid_t gid) {
int result, _errno;
Debug1("setgid("F_gid")", gid);
result = setgid(gid);
_errno = errno;
Debug1("setgid() -> %d", result);
errno = _errno;
return result;
}
int Initgroups(const char *user, gid_t group) {
int result, _errno;
Debug2("initgroups(\"%s\", "F_gid")", user, group);
result = initgroups(user, group);
_errno = errno;
Debug1("initgroups() -> %d", result);
errno = _errno;
return result;
}
int Getgroups(int size, gid_t list[]) {
int result, _errno;
Debug2("getgroups(%d, "F_gid",...)", size, list[0]);
result = getgroups(size, list);
_errno = errno;
Debug1("getgroups() -> %d", result);
errno = _errno;
return result;
}
#if HAVE_SETGROUPS
int Setgroups(size_t size, const gid_t *list) {
int result, _errno;
switch (size) {
case 0: Debug1("setgroups("F_Zu", [])", size); break;;
case 1: Debug2("setgroups("F_Zu", ["F_gid"])", size, list[0]); break;;
case 2: Debug3("setgroups("F_Zu", ["F_gid","F_gid"])", size, list[0], list[1]); break;;
default: Debug3("setgroups("F_Zu", ["F_gid","F_gid",...])", size, list[0], list[1]); break;;
}
result = setgroups(size, list);
_errno = errno;
Debug1("setgroups() -> %d", result);
errno = _errno;
return result;
}
#endif
#if HAVE_GETGROUPLIST
int Getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups) {
int n = *ngroups, result;
Debug4("getgrouplist(\"%s\", "F_gid", %p, [%d])", user, group, groups, n);
result = getgrouplist(user, group, groups, ngroups);
switch (Min(n,*ngroups)) {
case 0: Debug2("getgrouplist(,, [], [%d]) -> %d", *ngroups, result); break;
case 1: Debug3("getgrouplist(,, ["F_gid"], [%d]) -> %d", groups[0], *ngroups, result); break;
case 2: Debug4("getgrouplist(,, ["F_gid","F_gid"], [%d]) -> %d", groups[0], groups[1], *ngroups, result); break;
default: Debug4("getgrouplist(,, ["F_gid","F_gid",...], [%d]) -> %d", groups[0], groups[1], *ngroups, result); break;
}
return result;
}
#endif
int Chdir(const char *path) {
int result, _errno;
Debug1("chdir(\"%s\")", path);
result = chdir(path);
_errno = errno;
Debug1("chdir() -> %d", result);
errno = _errno;
return result;
}
int Chroot(const char *path) {
int result, _errno;
Debug1("chroot(\"%s\")", path);
result = chroot(path);
_errno = errno;
Debug1("chroot() -> %d", result);
errno = _errno;
return result;
}
int Gettimeofday(struct timeval *tv, struct timezone *tz) {
int result, _errno;
#if WITH_MSGLEVEL <= E_DEBUG
if (tz) {
Debug3("gettimeofday(%p, {%d,%d})",
tv, tz->tz_minuteswest, tz->tz_dsttime);
} else {
Debug1("gettimeofday(%p, NULL)", tv);
}
#endif /* WITH_MSGLEVEL <= E_DEBUG */
result = gettimeofday(tv, tz);
_errno = errno;
#if WITH_MSGLEVEL <= E_DEBUG
if (tz) {
Debug5("gettimeofday({%ld,%ld}, {%d,%d}) -> %d",
tv->tv_sec, tv->tv_usec, tz->tz_minuteswest, tz->tz_dsttime,
result);
} else {
Debug3("gettimeofday({%ld,%ld},) -> %d",
tv->tv_sec, tv->tv_usec, result);
}
#endif /* WITH_MSGLEVEL <= E_DEBUG */
errno = _errno;
return result;
}
int Mknod(const char *pathname, mode_t mode, dev_t dev) {
int result, _errno;
Debug3("mknod(\"%s\", 0%o, "F_dev")", pathname, mode, dev);
result = mknod(pathname, mode, dev);
_errno = errno;
Debug1("mknod() -> %d", result);
errno = _errno;
return result;
}
int Mkfifo(const char *pathname, mode_t mode) {
int result, _errno;
Debug2("mkfifo(\"%s\", 0%o)", pathname, mode);
result = mkfifo(pathname, mode);
_errno = errno;
Debug1("mkfifo() -> %d", result);
errno = _errno;
return result;
}
static void prtstat(const char *func, struct stat *buf, int result) {
char txt[256], *t = txt;
t += sprintf(t, "%s(, {"F_dev","F_st_ino","F_mode","F_st_nlink","F_uid","F_gid,
func, buf->st_dev, buf->st_ino,
buf->st_mode, buf->st_nlink, buf->st_uid, buf->st_gid);
#if HAVE_ST_RDEV
t += sprintf(t, ","F_dev, buf->st_rdev);
#endif
t += sprintf(t, ","F_st_size, buf->st_size);
#if HAVE_ST_BLKSIZE
t += sprintf(t, ","F_st_blksize, buf->st_blksize);
#endif
#if HAVE_ST_BLOCKS
t += sprintf(t, ","F_st_blocks, buf->st_blocks);
#endif
sprintf(t, ",...}) -> %d", result);
Debug(txt);
}
#if defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64)
static void prtstat64(const char *func, struct stat64 *buf, int result) {
char txt[256], *t = txt;
if (result < 0) {
sprintf(t, "%s(, {}) -> %d", func, result);
} else {
t += sprintf(t, "%s(, {"F_dev","F_st64_ino","F_mode","F_st_nlink","F_uid","F_gid,
func, buf->st_dev, buf->st_ino,
buf->st_mode, buf->st_nlink, buf->st_uid, buf->st_gid);
#if HAVE_ST_RDEV
t += sprintf(t, ","F_dev, buf->st_rdev);
#endif
t += sprintf(t, ","F_st64_size, buf->st_size);
#if HAVE_ST_BLKSIZE
t += sprintf(t, ","F_st_blksize, buf->st_blksize);
#endif
#if HAVE_ST_BLOCKS
t += sprintf(t, ","F_st64_blocks, buf->st_blocks);
#endif
sprintf(t, ",...}) -> %d", result);
}
Debug(txt);
}
#endif /* defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64) */
int Stat(const char *file_name, struct stat *buf) {
int result, _errno;
Debug2("stat(%s, %p)", file_name, buf);
result = stat(file_name, buf);
_errno = errno;
prtstat("stat", buf, result);
errno = _errno;
return result;
}
#if HAVE_STAT64
int Stat64(const char *file_name, struct stat64 *buf) {
int result, _errno;
Debug2("stat64(%s, %p)", file_name, buf);
result = stat64(file_name, buf);
_errno = errno;
prtstat64("stat64", buf, result);
errno = _errno;
return result;
}
#endif /* HAVE_STAT64 */
int Fstat(int filedes, struct stat *buf) {
int result, _errno;
Debug2("fstat(%d, %p)", filedes, buf);
result = fstat(filedes, buf);
_errno = errno;
prtstat("fstat", buf, result);
errno = _errno;
return result;
}
#if HAVE_FSTAT64
int Fstat64(int filedes, struct stat64 *buf) {
int result, _errno;
Debug2("fstat64(%d, %p)", filedes, buf);
result = fstat64(filedes, buf);
_errno = errno;
prtstat64("fstat64", buf, result);
errno = _errno;
return result;
}
#endif /* HAVE_FSTAT64 */
int Lstat(const char *file_name, struct stat *buf) {
int result, _errno;
Debug2("lstat(%s, %p)", file_name, buf);
result = lstat(file_name, buf);
_errno = errno;
prtstat("lstat", buf, result);
errno = _errno;
return result;
}
#if HAVE_LSTAT64
int Lstat64(const char *file_name, struct stat64 *buf) {
int result, _errno;
Debug2("lstat64(%s, %p)", file_name, buf);
result = lstat64(file_name, buf);
_errno = errno;
prtstat64("lstat64", buf, result);
errno = _errno;
return result;
}
#endif /* HAVE_LSTAT64 */
int Dup(int oldfd) {
int newfd, _errno;
Debug1("dup(%d)", oldfd);
newfd = dup(oldfd);
_errno = errno;
Info2("dup(%d) -> %d", oldfd, newfd);
errno = _errno;
return newfd;
}
int Dup2(int oldfd, int newfd) {
int result, _errno;
Debug2("dup2(%d, %d)", oldfd, newfd);
result = dup2(oldfd, newfd);
_errno = errno;
Info3("dup2(%d, %d) -> %d", oldfd, newfd, result);
errno = _errno;
return result;
}
int Pipe(int filedes[2]) {
int result, _errno;
Debug1("pipe(%p)", filedes);
result = pipe(filedes);
_errno = errno;
Info3("pipe({%d,%d}) -> %d", filedes[0], filedes[1], result);
errno = _errno;
return result;
}
ssize_t Read(int fd, void *buf, size_t count) {
ssize_t result;
int _errno;
if (!diag_in_handler) diag_flush();
Debug3("read(%d, %p, "F_Zu")", fd, buf, count);
result = read(fd, buf, count);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug1("read -> "F_Zd, result);
errno = _errno;
return result;
}
ssize_t Write(int fd, const void *buf, size_t count) {
ssize_t result;
int _errno;
if (!diag_in_handler) diag_flush();
Debug3("write(%d, %p, "F_Zu")", fd, buf, count);
result = write(fd, buf, count);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug1("write -> "F_Zd, result);
errno = _errno;
return result;
}
int Fcntl(int fd, int cmd) {
int result, _errno;
if (!diag_in_handler) diag_flush();
Debug2("fcntl(%d, %d)", fd, cmd);
result = fcntl(fd, cmd);
if (!diag_in_handler) diag_flush();
_errno = errno;
Debug1("fcntl() -> %d", result);
errno = _errno;
return result;
}
int Fcntl_l(int fd, int cmd, long arg) {
int result, _errno;
if (!diag_in_handler) diag_flush();
Debug3("fcntl(%d, %d, %ld)", fd, cmd, arg);
result = fcntl(fd, cmd, arg);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug1("fcntl() -> %d", result);
errno = _errno;
return result;
}
int Fcntl_lock(int fd, int cmd, struct flock *l) {
int result, _errno;
if (!diag_in_handler) diag_flush();
Debug7("fcntl(%d, %d, {type=%hd,whence=%hd,start="F_off",len="F_off",pid="F_pid"})",
fd, cmd, l->l_type, l->l_whence, l->l_start, l->l_len, l->l_pid);
result = fcntl(fd, cmd, l);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug1("fcntl() -> %d", result);
errno = _errno;
return result;
}
int Ftruncate(int fd, off_t length) {
int retval, _errno;
Debug2("ftruncate(%d, "F_off")", fd, length);
retval = ftruncate(fd, length);
_errno = errno;
Debug1("ftruncate() -> %d", retval);
errno = _errno;
return retval;
}
#if HAVE_FTRUNCATE64
int Ftruncate64(int fd, off64_t length) {
int retval, _errno;
Debug2("ftruncate64(%d, "F_off64")", fd, length);
retval = ftruncate64(fd, length);
_errno = errno;
Debug1("ftruncate64() -> %d", retval);
errno = _errno;
return retval;
}
#endif /* HAVE_FTRUNCATE64 */
#if HAVE_FLOCK
int Flock(int fd, int operation) {
int retval, _errno;
if (!diag_in_handler) diag_flush();
Debug2("flock(%d, %d)", fd, operation);
retval = flock(fd, operation);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug1("flock() -> %d", retval);
errno = _errno;
return retval;
}
#endif /* HAVE_FLOCK */
int Ioctl(int d, int request, void *argp) {
int retval, _errno;
if (!diag_in_handler) diag_flush();
if (argp > (void *)0x10000) { /* fuzzy...*/
Debug4("ioctl(%d, 0x%x, %p{%lu})", d, request, argp, *(unsigned long *)argp);
} else {
Debug3("ioctl(%d, 0x%x, 0x%p)", d, request, argp);
}
retval = ioctl(d, request, argp);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug1("ioctl() -> %d", retval);
errno = _errno;
return retval;
}
int Ioctl_int(int d, int request, int arg) {
int retval, _errno;
Debug3("ioctl(%d, 0x%x, %d)", d, request, arg);
retval = ioctl(d, request, arg);
_errno = errno;
Debug1("ioctl() -> %d", retval);
errno = _errno;
return retval;
}
int Close(int fd) {
int retval, _errno;
Info1("close(%d)", fd);
retval = close(fd);
_errno = errno;
Debug1("close() -> %d", retval);
errno = _errno;
return retval;
}
int Fchown(int fd, uid_t owner, gid_t group) {
int retval, _errno;
Debug3("fchown(%d, "F_uid", "F_gid")", fd, owner, group);
retval = fchown(fd, owner, group);
_errno = errno;
Debug1("fchown() -> %d", retval);
errno = _errno;
return retval;
}
int Fchmod(int fd, mode_t mode) {
int retval, _errno;
Debug2("fchmod(%d, 0%o)", fd, mode);
retval = fchmod(fd, mode);
_errno = errno;
Debug1("fchmod() -> %d", retval);
errno = _errno;
return retval;
}
int Unlink(const char *pathname) {
int retval, _errno;
Debug1("unlink(\"%s\")", pathname);
retval = unlink(pathname);
_errno = errno;
Debug1("unlink() -> %d", retval);
errno = _errno;
return retval;
}
int Symlink(const char *oldpath, const char *newpath) {
int retval, _errno;
Debug2("symlink(\"%s\", \"%s\")", oldpath, newpath);
retval = symlink(oldpath, newpath);
_errno = errno;
Debug1("symlink() -> %d", retval);
errno = _errno;
return retval;
}
int Readlink(const char *path, char *buf, size_t bufsiz) {
int retval, _errno;
Debug3("readlink(\"%s\", %p, "F_Zu")", path, buf, bufsiz);
retval = readlink(path, buf, bufsiz);
_errno = errno;
Debug1("readlink() -> %d", retval);
errno = _errno;
return retval;
}
int Chown(const char *path, uid_t owner, gid_t group) {
int retval, _errno;
Debug3("chown(\"%s\", "F_uid", "F_gid")", path, owner, group);
retval = chown(path, owner, group);
_errno = errno;
Debug1("chown() -> %d", retval);
errno = _errno;
return retval;
}
int Chmod(const char *path, mode_t mode) {
int retval, _errno;
Debug2("chmod(\"%s\", 0%o)", path, mode);
retval = chmod(path, mode);
_errno = errno;
Debug1("chmod() -> %d", retval);
errno = _errno;
return retval;
}
#if HAVE_POLL
/* we only show the first struct pollfd; hope this is enough for most cases. */
int Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
int _errno, result;
if (!diag_in_handler) diag_flush();
if (nfds == 4) {
Debug10("poll({%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}, %u, %d)",
ufds[0].fd, ufds[0].events, ufds[1].fd, ufds[1].events,
ufds[2].fd, ufds[2].events, ufds[3].fd, ufds[3].events,
nfds, timeout);
} else {
Debug4("poll({%d,0x%02hx,}, , %u, %d)", ufds[0].fd, ufds[0].events, nfds, timeout);
}
result = poll(ufds, nfds, timeout);
_errno = errno;
if (!diag_in_handler) diag_flush();
if (nfds == 4) {
Debug5("poll(, {,,0x%02hx}{,,0x%02hx}{,,0x%02hx}{,,0x%02hx}) -> %d",
ufds[0].revents, ufds[1].revents, ufds[2].revents, ufds[3].revents, result);
} else {
Debug2("poll(, {,,0x%02hx}) -> %d", ufds[0].revents, result);
}
errno = _errno;
return result;
}
#endif /* HAVE_POLL */
/* we only show the first word of the fd_set's; hope this is enough for most
cases. */
int Select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout) {
int result, _errno;
if (!diag_in_handler) diag_flush();
#if HAVE_FDS_BITS
Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu."F_tv_usec")",
n, readfds?readfds->fds_bits[0]:0, writefds?writefds->fds_bits[0]:0,
exceptfds?exceptfds->fds_bits[0]:0,
timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
timeout?timeout->tv_usec:0);
#else
Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu.%06u)",
n, readfds?readfds->__fds_bits[0]:0, writefds?writefds->__fds_bits[0]:0,
exceptfds?exceptfds->__fds_bits[0]:0,
timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
timeout?timeout->tv_usec:0);
#endif
result = select(n, readfds, writefds, exceptfds, timeout);
_errno = errno;
if (!diag_in_handler) diag_flush();
#if HAVE_FDS_BITS
Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu."F_tv_usec"), %d",
readfds?readfds->fds_bits[0]:0, writefds?writefds->fds_bits[0]:0,
exceptfds?exceptfds->fds_bits[0]:0,
timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
timeout?timeout->tv_usec:0, result);
#else
Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu.%06u), %d",
readfds?readfds->__fds_bits[0]:0, writefds?writefds->__fds_bits[0]:0,
exceptfds?exceptfds->__fds_bits[0]:0,
timeout?"&":"NULL/", timeout?timeout->tv_sec:0,
timeout?timeout->tv_usec:0, result);
#endif
errno = _errno;
return result;
}
pid_t Fork(void) {
pid_t pid;
int _errno;
Debug("fork()");
pid = fork();
_errno = errno;
Debug1("fork() -> %d", pid); /* attention: called twice! */
errno = _errno;
return pid;
}
pid_t Waitpid(pid_t pid, int *status, int options) {
int _errno;
pid_t retval;
if (!diag_in_handler) diag_flush();
Debug3("waitpid("F_pid", %p, %d)", pid, status, options);
retval = waitpid(pid, status, options);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug2("waitpid(, {%d}, ) -> "F_pid, *status, retval);
errno = _errno;
return retval;
}
sighandler_t Signal(int signum, sighandler_t handler) {
int _errno;
sighandler_t retval;
Debug2("signal(%d, %p)", signum, handler);
retval = signal(signum, handler);
_errno = errno;
Debug1("signal() -> %p", retval);
errno = _errno;
return retval;
}
#if HAVE_SIGACTION
int Sigaction(int signum, const struct sigaction *act,
struct sigaction *oldact) {
int retval;
Debug3("sigaction(%d, %p, %p)", signum, act, oldact);
retval = sigaction(signum, act, oldact);
Debug1("sigaction() -> %d", retval);
return retval;
}
#endif /* HAVE_SIGACTION */
int Sigprocmask(int how, const sigset_t *set, sigset_t *oset) {
int retval;
Debug3("sigprocmask(%d, %p, %p)", how, set, oset);
retval = sigprocmask(how, set, oset);
Debug1("sigprocmask() -> %d", retval);
return retval;
}
unsigned int Alarm(unsigned int seconds) {
unsigned int retval;
Debug1("alarm(%u)", seconds);
retval = alarm(seconds);
Debug1("alarm() -> %u", retval);
return retval;
}
int Kill(pid_t pid, int sig) {
int retval, _errno;
Debug2("kill("F_pid", %d)", pid, sig);
retval = kill(pid, sig);
_errno = errno;
Debug1("kill() -> %d", retval);
errno = _errno;
return retval;
}
int Link(const char *oldpath, const char *newpath) {
int retval, _errno;
Debug2("link(\"%s\", \"%s\")", oldpath, newpath);
retval = link(oldpath, newpath);
_errno = errno;
Debug1("link() -> %d", retval);
errno = _errno;
return retval;
}
int Execvp(const char *file, char *const argv[]) {
int result, _errno;
if (argv[1] == NULL)
Debug2("execvp(\"%s\", \"%s\")", file, argv[0]);
else if (argv[2] == NULL)
Debug3("execvp(\"%s\", \"%s\" \"%s\")", file, argv[0], argv[1]);
else if (argv[3] == NULL)
Debug4("execvp(\"%s\", \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2]);
else if (argv[4] == NULL)
Debug5("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2], argv[3]);
else if (argv[5] == NULL)
Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\")", file, argv[0], argv[1], argv[2], argv[3], argv[4]);
else
Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" ...)", file, argv[0], argv[1], argv[2], argv[3], argv[4]);
result = execvp(file, argv);
_errno = errno;
Debug1("execvp() -> %d", result);
errno = _errno;
return result;
}
int System(const char *string) {
int result, _errno;
Debug1("system(\"%s\")", string);
diag_immediate_exit = 1;
result = system(string);
diag_immediate_exit = 0;
_errno = errno;
Debug1("system() -> %d", result);
errno = _errno;
return result;
}
int Socketpair(int d, int type, int protocol, int sv[2]) {
int result, _errno;
Debug4("socketpair(%d, %d, %d, %p)", d, type, protocol, sv);
result = socketpair(d, type, protocol, sv);
_errno = errno;
Info6("socketpair(%d, %d, %d, {%d,%d}) -> %d", d, type, protocol, sv[0], sv[1], result);
errno = _errno;
return result;
}
#if _WITH_SOCKET
int Socket(int domain, int type, int protocol) {
int result, _errno;
Debug3("socket(%d, %d, %d)", domain, type, protocol);
result = socket(domain, type, protocol);
_errno = errno;
Info4("socket(%d, %d, %d) -> %d", domain, type, protocol, result);
errno = _errno;
return result;
}
#endif /* _WITH_SOCKET */
#if _WITH_SOCKET
int Bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) {
int result, _errno;
char infobuff[256];
sockaddr_info(my_addr, addrlen, infobuff, sizeof(infobuff));
Debug3("bind(%d, %s, "F_socklen")", sockfd, infobuff, addrlen);
result = bind(sockfd, my_addr, addrlen);
_errno = errno;
Debug1("bind() -> %d", result);
errno = _errno;
return result;
}
#endif /* _WITH_SOCKET */
#if _WITH_SOCKET
int Connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) {
int result, _errno;
char infobuff[256];
if (!diag_in_handler) diag_flush();
/*sockaddr_info(serv_addr, infobuff, sizeof(infobuff));
Debug3("connect(%d, %s, "F_Zd")", sockfd, infobuff, addrlen);*/
#if 0
Debug18("connect(%d,{0x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x}, "F_Zd")",
sockfd,
((unsigned char *)serv_addr)[0], ((unsigned char *)serv_addr)[1],
((unsigned char *)serv_addr)[2], ((unsigned char *)serv_addr)[3],
((unsigned char *)serv_addr)[4], ((unsigned char *)serv_addr)[5],
((unsigned char *)serv_addr)[6], ((unsigned char *)serv_addr)[7],
((unsigned char *)serv_addr)[8], ((unsigned char *)serv_addr)[9],
((unsigned char *)serv_addr)[10], ((unsigned char *)serv_addr)[11],
((unsigned char *)serv_addr)[12], ((unsigned char *)serv_addr)[13],
((unsigned char *)serv_addr)[14], ((unsigned char *)serv_addr)[15],
addrlen);
#else
Debug4("connect(%d, {%d,%s}, "F_socklen")",
sockfd, serv_addr->sa_family,
sockaddr_info(serv_addr, addrlen, infobuff, sizeof(infobuff)),
addrlen);
#endif
result = connect(sockfd, serv_addr, addrlen);
_errno = errno;
if (!diag_in_handler) diag_flush();
Debug1("connect() -> %d", result);
errno = _errno;
return result;
}
#endif /* _WITH_SOCKET */
#if _WITH_SOCKET
int Listen(int s, int backlog) {
int result, _errno;
Debug2("listen(%d, %d)", s, backlog);
result = listen(s, backlog);
_errno = errno;
Debug1("listen() -> %d", result);
errno = _errno;
return result;
}
#endif /* _WITH_SOCKET */
#if _WITH_SOCKET
/* don't forget to handle EINTR when using Accept() ! */
int Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
int result, _errno;
fd_set accept_s;
if (!diag_in_handler) diag_flush();
FD_ZERO(&accept_s);
FD_SET(s, &accept_s);
if (diag_select(s+1, &accept_s, NULL, NULL, NULL) < 0) {
return -1;
}