2 /* Copyright Gerhard Rieger 2001-2008 */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* explicit system call and C library trace function, for those who miss strace
9 #include "xioconfig.h" /* what features are enabled */
13 #include "sysincludes.h"
25 mode_t
Umask(mode_t mask
) {
28 Debug1("umask("F_mode
")", mask
);
31 Debug1("umask() -> "F_mode
, result
);
36 int Open(const char *pathname
, int flags
, mode_t mode
) {
38 Debug3("open(\"%s\", 0%o, 0%03o)", pathname
, flags
, mode
);
39 result
= open(pathname
, flags
, mode
);
41 Info4("open(\"%s\", 0%o, 0%03o) -> %d", pathname
, flags
, mode
, result
);
46 int Creat(const char *pathname
, mode_t mode
) {
48 Debug2("creat(\"%s\", 0%03o)", pathname
, mode
);
49 result
= creat(pathname
, mode
);
51 Info3("creat(\"%s\", 0%03o) -> %d", pathname
, mode
, result
);
56 off_t
Lseek(int fildes
, off_t offset
, int whence
) {
59 Debug3("lseek(%d, "F_off
", %d)", fildes
, offset
, whence
);
60 result
= lseek(fildes
, offset
, whence
);
62 Debug1("lseek() -> "F_off
, result
);
68 off64_t
Lseek64(int fildes
, off64_t offset
, int whence
) {
71 Debug3("lseek64(%d, "F_off64
", %d)", fildes
, offset
, whence
);
72 result
= lseek64(fildes
, offset
, whence
);
74 Debug1("lseek64() -> "F_off64
, result
);
78 #endif /* HAVE_LSEEK64 */
86 Debug1("getpid() -> "F_pid
, result
);
97 Debug1("getppid() -> "F_pid
, result
);
102 pid_t
Getpgrp(void) {
108 Debug1("getpgrp() -> "F_pid
, result
);
113 #if 0 /* does not compile for FreeBSD */
114 /* setpgrp() is not BSD compatible, needs setpgid(..., ...) instead */
120 Debug1("setpgrp() -> %d", result
);
127 int Getpgid(pid_t pid
) {
130 Debug1("getpgid("F_pid
")", pid
);
131 result
= getpgid(pid
);
133 Debug1("getpgid() -> "F_pid
, result
);
139 int Setpgid(pid_t pid
, pid_t pgid
) {
141 Debug2("setpgid("F_pid
", "F_pid
")", pid
, pgid
);
142 result
= setpgid(pid
, pgid
);
144 Debug1("setpgid() -> %d", result
);
149 pid_t
Tcgetpgrp(int fd
) {
151 Debug1("tcgetpgrp(%d)", fd
);
152 result
= tcgetpgrp(fd
);
154 Debug1("tcgetpgrp() -> %d", result
);
159 int Tcsetpgrp(int fd
, pid_t pgrpid
) {
161 Debug2("tcsetpgrp(%d, "F_pid
")", fd
, pgrpid
);
162 result
= tcsetpgrp(fd
, pgrpid
);
164 Debug1("tcsetpgrp() -> %d", result
);
170 pid_t
Getsid(pid_t pid
) {
172 Debug1("getsid("F_pid
")", pid
);
173 result
= getsid(pid
);
175 Debug1("getsid() -> "F_pid
, result
);
186 Debug1("setsid() -> "F_pid
, result
);
197 Debug1("getuid() -> "F_uid
, result
);
202 uid_t
Geteuid(void) {
208 Debug1("geteuid() -> "F_uid
, result
);
213 int Setuid(uid_t uid
) {
215 Debug1("setuid("F_uid
")", uid
);
216 result
= setuid(uid
);
218 Debug1("setuid() -> %d", result
);
229 Debug1("getgid() -> "F_gid
, result
);
234 gid_t
Getegid(void) {
240 Debug1("getegid() -> "F_gid
, result
);
245 int Setgid(gid_t gid
) {
247 Debug1("setgid("F_gid
")", gid
);
248 result
= setgid(gid
);
250 Debug1("setgid() -> %d", result
);
255 int Initgroups(const char *user
, gid_t group
) {
257 Debug2("initgroups(\"%s\", "F_gid
")", user
, group
);
258 result
= initgroups(user
, group
);
260 Debug1("initgroups() -> %d", result
);
265 int Getgroups(int size
, gid_t list
[]) {
267 Debug2("getgroups(%d, "F_gid
",...)", size
, list
[0]);
268 result
= getgroups(size
, list
);
270 Debug1("getgroups() -> %d", result
);
276 int Setgroups(size_t size
, const gid_t
*list
) {
278 Debug2("setgroups("F_Zu
", "F_gid
",...)", size
, list
[0]);
279 result
= setgroups(size
, list
);
281 Debug1("setgroups() -> %d", result
);
287 int Chdir(const char *path
) {
289 Debug1("chdir(\"%s\")", path
);
290 result
= chdir(path
);
292 Debug1("chdir() -> %d", result
);
297 int Chroot(const char *path
) {
299 Debug1("chroot(\"%s\")", path
);
300 result
= chroot(path
);
302 Debug1("chroot() -> %d", result
);
307 int Gettimeofday(struct timeval
*tv
, struct timezone
*tz
) {
309 #if WITH_MSGLEVEL <= E_DEBUG
311 Debug3("gettimeofday(%p, {%d,%d})",
312 tv
, tz
->tz_minuteswest
, tz
->tz_dsttime
);
314 Debug1("gettimeofday(%p, NULL)", tv
);
316 #endif /* WITH_MSGLEVEL <= E_DEBUG */
317 result
= gettimeofday(tv
, tz
);
319 #if WITH_MSGLEVEL <= E_DEBUG
321 Debug5("gettimeofday({%ld,%ld}, {%d,%d}) -> %d",
322 tv
->tv_sec
, tv
->tv_usec
, tz
->tz_minuteswest
, tz
->tz_dsttime
,
325 Debug3("gettimeofday({%ld,%ld},) -> %d",
326 tv
->tv_sec
, tv
->tv_usec
, result
);
328 #endif /* WITH_MSGLEVEL <= E_DEBUG */
333 int Mknod(const char *pathname
, mode_t mode
, dev_t dev
) {
335 Debug3("mknod(\"%s\", 0%o, %d)", pathname
, mode
, dev
);
336 result
= mknod(pathname
, mode
, dev
);
338 Debug1("mknod() -> %d", result
);
343 int Mkfifo(const char *pathname
, mode_t mode
) {
345 Debug2("mkfifo(\"%s\", 0%o)", pathname
, mode
);
346 result
= mkfifo(pathname
, mode
);
348 Debug1("mkfifo() -> %d", result
);
353 static void prtstat(const char *func
, struct stat
*buf
, int result
) {
354 char txt
[256], *t
= txt
;
356 t
+= sprintf(t
, "%s(, {"F_st_dev
","F_st_ino
","F_mode
","F_st_nlink
","F_uid
","F_gid
,
357 func
, buf
->st_dev
, buf
->st_ino
,
358 buf
->st_mode
, buf
->st_nlink
, buf
->st_uid
, buf
->st_gid
);
360 t
+= sprintf(t
, ","F_st_dev
, buf
->st_rdev
);
362 t
+= sprintf(t
, ","F_st_size
, buf
->st_size
);
364 t
+= sprintf(t
, ","F_st_blksize
, buf
->st_blksize
);
367 t
+= sprintf(t
, ","F_st_blocks
, buf
->st_blocks
);
369 sprintf(t
, ",...}) -> %d", result
);
373 #if defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64)
374 static void prtstat64(const char *func
, struct stat64
*buf
, int result
) {
375 char txt
[256], *t
= txt
;
378 sprintf(t
, "%s(, {}) -> %d", func
, result
);
380 t
+= sprintf(t
, "%s(, {"F_st_dev
","F_st64_ino
","F_mode
","F_st_nlink
","F_uid
","F_gid
,
381 func
, buf
->st_dev
, buf
->st_ino
,
382 buf
->st_mode
, buf
->st_nlink
, buf
->st_uid
, buf
->st_gid
);
384 t
+= sprintf(t
, ","F_st_dev
, buf
->st_rdev
);
386 t
+= sprintf(t
, ","F_st64_size
, buf
->st_size
);
388 t
+= sprintf(t
, ","F_st_blksize
, buf
->st_blksize
);
391 t
+= sprintf(t
, ","F_st64_blocks
, buf
->st_blocks
);
393 sprintf(t
, ",...}) -> %d", result
);
397 #endif /* defined(HAVE_STAT64) || defined(HAVE_FSTAT64) || defined(HAVE_LSTAT64) */
399 int Stat(const char *file_name
, struct stat
*buf
) {
401 Debug2("stat(%s, %p)", file_name
, buf
);
402 result
= stat(file_name
, buf
);
404 prtstat("stat", buf
, result
);
410 int Stat64(const char *file_name
, struct stat64
*buf
) {
412 Debug2("stat64(%s, %p)", file_name
, buf
);
413 result
= stat64(file_name
, buf
);
415 prtstat64("stat64", buf
, result
);
419 #endif /* HAVE_STAT64 */
421 int Fstat(int filedes
, struct stat
*buf
) {
423 Debug2("fstat(%d, %p)", filedes
, buf
);
424 result
= fstat(filedes
, buf
);
426 prtstat("fstat", buf
, result
);
432 int Fstat64(int filedes
, struct stat64
*buf
) {
434 Debug2("fstat64(%d, %p)", filedes
, buf
);
435 result
= fstat64(filedes
, buf
);
437 prtstat64("fstat64", buf
, result
);
441 #endif /* HAVE_FSTAT64 */
443 int Lstat(const char *file_name
, struct stat
*buf
) {
445 Debug2("lstat(%s, %p)", file_name
, buf
);
446 result
= lstat(file_name
, buf
);
448 prtstat("lstat", buf
, result
);
454 int Lstat64(const char *file_name
, struct stat64
*buf
) {
456 Debug2("lstat64(%s, %p)", file_name
, buf
);
457 result
= lstat64(file_name
, buf
);
459 prtstat64("lstat64", buf
, result
);
463 #endif /* HAVE_LSTAT64 */
467 Debug1("dup(%d)", oldfd
);
470 Info2("dup(%d) -> %d", oldfd
, newfd
);
475 int Dup2(int oldfd
, int newfd
) {
477 Debug2("dup2(%d, %d)", oldfd
, newfd
);
478 result
= dup2(oldfd
, newfd
);
480 Info3("dup2(%d, %d) -> %d", oldfd
, newfd
, result
);
485 int Pipe(int filedes
[2]) {
487 Debug1("pipe(%p)", filedes
);
488 result
= pipe(filedes
);
490 Info3("pipe({%d,%d}) -> %d", filedes
[0], filedes
[1], result
);
495 ssize_t
Read(int fd
, void *buf
, size_t count
) {
498 Debug3("read(%d, %p, "F_Zu
")", fd
, buf
, count
);
499 result
= read(fd
, buf
, count
);
501 Debug1("read -> "F_Zd
, result
);
506 ssize_t
Write(int fd
, const void *buf
, size_t count
) {
509 Debug3("write(%d, %p, "F_Zu
")", fd
, buf
, count
);
510 result
= write(fd
, buf
, count
);
512 Debug1("write -> "F_Zd
, result
);
517 int Fcntl(int fd
, int cmd
) {
519 Debug2("fcntl(%d, %d)", fd
, cmd
);
520 result
= fcntl(fd
, cmd
);
522 Debug1("fcntl() -> %d", result
);
527 int Fcntl_l(int fd
, int cmd
, long arg
) {
529 Debug3("fcntl(%d, %d, %ld)", fd
, cmd
, arg
);
530 result
= fcntl(fd
, cmd
, arg
);
532 Debug1("fcntl() -> %d", result
);
537 int Fcntl_lock(int fd
, int cmd
, struct flock
*l
) {
539 Debug7("fcntl(%d, %d, {type=%hd,whence=%hd,start="F_off
",len="F_off
",pid="F_pid
"})",
540 fd
, cmd
, l
->l_type
, l
->l_whence
, l
->l_start
, l
->l_len
, l
->l_pid
);
541 result
= fcntl(fd
, cmd
, l
);
543 Debug1("fcntl() -> %d", result
);
548 int Ftruncate(int fd
, off_t length
) {
550 Debug2("ftruncate(%d, "F_off
")", fd
, length
);
551 retval
= ftruncate(fd
, length
);
553 Debug1("ftruncate() -> %d", retval
);
559 int Ftruncate64(int fd
, off64_t length
) {
561 Debug2("ftruncate64(%d, "F_off64
")", fd
, length
);
562 retval
= ftruncate64(fd
, length
);
564 Debug1("ftruncate64() -> %d", retval
);
568 #endif /* HAVE_FTRUNCATE64 */
571 int Flock(int fd
, int operation
) {
573 Debug2("flock(%d, %d)", fd
, operation
);
574 retval
= flock(fd
, operation
);
576 Debug1("flock() -> %d", retval
);
580 #endif /* HAVE_FLOCK */
582 int Ioctl(int d
, int request
, void *argp
) {
584 if (argp
> (void *)0x10000) { /* fuzzy...*/
585 Debug4("ioctl(%d, 0x%x, %p{%lu})", d
, request
, argp
, *(unsigned long *)argp
);
587 Debug3("ioctl(%d, 0x%x, 0x%p)", d
, request
, argp
);
589 retval
= ioctl(d
, request
, argp
);
591 Debug1("ioctl() -> %d", retval
);
596 int Ioctl_int(int d
, int request
, int arg
) {
598 Debug3("ioctl(%d, 0x%x, %d)", d
, request
, arg
);
599 retval
= ioctl(d
, request
, arg
);
601 Debug1("ioctl() -> %d", retval
);
608 Info1("close(%d)", fd
);
611 Debug1("close() -> %d", retval
);
616 int Fchown(int fd
, uid_t owner
, gid_t group
) {
618 Debug3("fchown(%d, "F_uid
", "F_gid
")", fd
, owner
, group
);
619 retval
= fchown(fd
, owner
, group
);
621 Debug1("fchown() -> %d", retval
);
626 int Fchmod(int fd
, mode_t mode
) {
628 Debug2("fchmod(%d, 0%o)", fd
, mode
);
629 retval
= fchmod(fd
, mode
);
631 Debug1("fchmod() -> %d", retval
);
636 int Unlink(const char *pathname
) {
638 Debug1("unlink(\"%s\")", pathname
);
639 retval
= unlink(pathname
);
641 Debug1("unlink() -> %d", retval
);
646 int Symlink(const char *oldpath
, const char *newpath
) {
648 Debug2("symlink(\"%s\", \"%s\")", oldpath
, newpath
);
649 retval
= symlink(oldpath
, newpath
);
651 Debug1("symlink() -> %d", retval
);
656 int Readlink(const char *path
, char *buf
, size_t bufsiz
) {
658 Debug3("readlink(\"%s\", %p, "F_Zu
")", path
, buf
, bufsiz
);
659 retval
= readlink(path
, buf
, bufsiz
);
661 Debug1("readlink() -> %d", retval
);
666 int Chown(const char *path
, uid_t owner
, gid_t group
) {
668 Debug3("chown(\"%s\", "F_uid
", "F_gid
")", path
, owner
, group
);
669 retval
= chown(path
, owner
, group
);
671 Debug1("chown() -> %d", retval
);
676 int Chmod(const char *path
, mode_t mode
) {
678 Debug2("chmod(\"%s\", 0%o)", path
, mode
);
679 retval
= chmod(path
, mode
);
681 Debug1("chmod() -> %d", retval
);
687 /* we only show the first struct pollfd; hope this is enough for most cases. */
688 int Poll(struct pollfd
*ufds
, unsigned int nfds
, int timeout
) {
691 Debug10("poll({%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}, %u, %d)",
692 ufds
[0].fd
, ufds
[0].events
, ufds
[1].fd
, ufds
[1].events
,
693 ufds
[2].fd
, ufds
[2].events
, ufds
[3].fd
, ufds
[3].events
,
696 Debug4("poll({%d,0x%02hx,}, , %u, %d)", ufds
[0].fd
, ufds
[0].events
, nfds
, timeout
);
698 result
= poll(ufds
, nfds
, timeout
);
700 Debug5("poll(, {,,0x%02hx}{,,0x%02hx}{,,0x%02hx}{,,0x%02hx}) -> %d",
701 ufds
[0].revents
, ufds
[1].revents
, ufds
[2].revents
, ufds
[3].revents
, result
);
703 Debug2("poll(, {,,0x%02hx}) -> %d", ufds
[0].revents
, result
);
707 #endif /* HAVE_POLL */
709 /* we only show the first word of the fd_set's; hope this is enough for most
711 int Select(int n
, fd_set
*readfds
, fd_set
*writefds
, fd_set
*exceptfds
,
712 struct timeval
*timeout
) {
715 Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu."F_tv_usec
")",
716 n
, readfds
->fds_bits
[0], writefds
->fds_bits
[0],
717 exceptfds
->fds_bits
[0],
718 timeout
?"&":"NULL/", timeout
?timeout
->tv_sec
:0,
719 timeout
?timeout
->tv_usec
:0);
721 Debug7("select(%d, &0x%lx, &0x%lx, &0x%lx, %s%lu.%06u)",
722 n
, readfds
->__fds_bits
[0], writefds
->__fds_bits
[0],
723 exceptfds
->__fds_bits
[0],
724 timeout
?"&":"NULL/", timeout
?timeout
->tv_sec
:0,
725 timeout
?timeout
->tv_usec
:0);
727 result
= select(n
, readfds
, writefds
, exceptfds
, timeout
);
730 Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu."F_tv_usec
"), %d",
731 readfds
->fds_bits
[0], writefds
->fds_bits
[0], exceptfds
->fds_bits
[0],
732 timeout
?"&":"NULL/", timeout
?timeout
->tv_sec
:0,
733 timeout
?timeout
->tv_usec
:0, result
);
735 Debug7("select -> (, 0x%lx, 0x%lx, 0x%lx, %s%lu.%06u), %d",
736 readfds
->__fds_bits
[0], writefds
->__fds_bits
[0],
737 exceptfds
->__fds_bits
[0],
738 timeout
?"&":"NULL/", timeout
?timeout
->tv_sec
:0,
739 timeout
?timeout
->tv_usec
:0, result
);
751 Debug1("fork() -> %d", pid
); /* attention: called twice! */
756 pid_t
Waitpid(pid_t pid
, int *status
, int options
) {
759 Debug3("waitpid("F_pid
", %p, %d)", pid
, status
, options
);
760 retval
= waitpid(pid
, status
, options
);
762 Debug2("waitpid(, {%d}, ) -> "F_pid
, *status
, retval
);
767 sighandler_t
Signal(int signum
, sighandler_t handler
) {
770 Debug2("signal(%d, %p)", signum
, handler
);
771 retval
= signal(signum
, handler
);
773 Debug1("signal() -> %p", retval
);
779 int Sigaction(int signum
, const struct sigaction
*act
,
780 struct sigaction
*oldact
) {
782 Debug3("sigaction(%d, %p, %p)", signum
, act
, oldact
);
783 retval
= sigaction(signum
, act
, oldact
);
784 Debug1("sigaction() -> %d", retval
);
787 #endif /* HAVE_SIGACTION */
789 int Sigprocmask(int how
, const sigset_t
*set
, sigset_t
*oset
) {
791 Debug3("sigprocmask(%d, %p, %p)", how
, set
, oset
);
792 retval
= sigprocmask(how
, set
, oset
);
793 Debug1("sigprocmask() -> %d", retval
);
797 unsigned int Alarm(unsigned int seconds
) {
799 Debug1("alarm(%u)", seconds
);
800 retval
= alarm(seconds
);
801 Debug1("alarm() -> %u", retval
);
805 int Kill(pid_t pid
, int sig
) {
807 Debug2("kill("F_pid
", %d)", pid
, sig
);
808 retval
= kill(pid
, sig
);
810 Debug1("kill() -> %d", retval
);
815 int Link(const char *oldpath
, const char *newpath
) {
817 Debug2("link(\"%s\", \"%s\")", oldpath
, newpath
);
818 retval
= link(oldpath
, newpath
);
820 Debug1("link() -> %d", retval
);
825 int Execvp(const char *file
, char *const argv
[]) {
828 Debug2("execvp(\"%s\", \"%s\")", file
, argv
[0]);
829 else if (argv
[2] == NULL
)
830 Debug3("execvp(\"%s\", \"%s\" \"%s\")", file
, argv
[0], argv
[1]);
831 else if (argv
[3] == NULL
)
832 Debug4("execvp(\"%s\", \"%s\" \"%s\" \"%s\")", file
, argv
[0], argv
[1], argv
[2]);
833 else if (argv
[4] == NULL
)
834 Debug5("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\")", file
, argv
[0], argv
[1], argv
[2], argv
[3]);
835 else if (argv
[5] == NULL
)
836 Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\")", file
, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
838 Debug6("execvp(\"%s\", \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" ...)", file
, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
840 result
= execvp(file
, argv
);
842 Debug1("execvp() -> %d", result
);
847 int System(const char *string
) {
849 Debug1("system(\"%s\")", string
);
850 result
= system(string
);
852 Debug1("system() -> %d", result
);
857 int Socketpair(int d
, int type
, int protocol
, int sv
[2]) {
859 Debug4("socketpair(%d, %d, %d, %p)", d
, type
, protocol
, sv
);
860 result
= socketpair(d
, type
, protocol
, sv
);
862 Info6("socketpair(%d, %d, %d, {%d,%d}) -> %d", d
, type
, protocol
, sv
[0], sv
[1], result
);
868 int Socket(int domain
, int type
, int protocol
) {
870 Debug3("socket(%d, %d, %d)", domain
, type
, protocol
);
871 result
= socket(domain
, type
, protocol
);
873 Info4("socket(%d, %d, %d) -> %d", domain
, type
, protocol
, result
);
877 #endif /* _WITH_SOCKET */
880 int Bind(int sockfd
, struct sockaddr
*my_addr
, int addrlen
) {
884 sockaddr_info(my_addr
, addrlen
, infobuff
, sizeof(infobuff
));
885 Debug3("bind(%d, %s, "F_Zd
")", sockfd
, infobuff
, addrlen
);
886 result
= bind(sockfd
, my_addr
, addrlen
);
888 Debug1("bind() -> %d", result
);
892 #endif /* _WITH_SOCKET */
895 int Connect(int sockfd
, const struct sockaddr
*serv_addr
, int addrlen
) {
899 /*sockaddr_info(serv_addr, infobuff, sizeof(infobuff));
900 Debug3("connect(%d, %s, "F_Zd")", sockfd, infobuff, addrlen);*/
902 Debug18("connect(%d,{0x%02x%02x%02x%02x %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x}, "F_Zd
")",
904 ((unsigned char *)serv_addr
)[0], ((unsigned char *)serv_addr
)[1],
905 ((unsigned char *)serv_addr
)[2], ((unsigned char *)serv_addr
)[3],
906 ((unsigned char *)serv_addr
)[4], ((unsigned char *)serv_addr
)[5],
907 ((unsigned char *)serv_addr
)[6], ((unsigned char *)serv_addr
)[7],
908 ((unsigned char *)serv_addr
)[8], ((unsigned char *)serv_addr
)[9],
909 ((unsigned char *)serv_addr
)[10], ((unsigned char *)serv_addr
)[11],
910 ((unsigned char *)serv_addr
)[12], ((unsigned char *)serv_addr
)[13],
911 ((unsigned char *)serv_addr
)[14], ((unsigned char *)serv_addr
)[15],
914 Debug4("connect(%d, {%d,%s}, "F_Zd
")",
915 sockfd
, serv_addr
->sa_family
,
916 sockaddr_info(serv_addr
, addrlen
, infobuff
, sizeof(infobuff
)),
919 result
= connect(sockfd
, serv_addr
, addrlen
);
921 Debug1("connect() -> %d", result
);
925 #endif /* _WITH_SOCKET */
928 int Listen(int s
, int backlog
) {
930 Debug2("listen(%d, %d)", s
, backlog
);
931 result
= listen(s
, backlog
);
933 Debug1("listen() -> %d", result
);
937 #endif /* _WITH_SOCKET */
940 /* don't forget to handle EINTR when using Accept() ! */
941 int Accept(int s
, struct sockaddr
*addr
, socklen_t
*addrlen
) {
944 Debug3("accept(%d, %p, %p)", s
, addr
, addrlen
);
945 result
= accept(s
, addr
, addrlen
);
949 sockaddr_info(addr
, *addrlen
, infobuff
, sizeof(infobuff
));
950 Info5("accept(%d, {%d, %s}, "F_Zd
") -> %d", s
,
952 sockaddr_info(addr
, *addrlen
, infobuff
, sizeof(infobuff
)),
955 Debug1("accept(,,) -> %d", result
);
960 #endif /* _WITH_SOCKET */
963 int Getsockname(int s
, struct sockaddr
*name
, socklen_t
*namelen
) {
967 Debug4("getsockname(%d, %p, %p{"F_socklen
"})", s
, name
, namelen
, *namelen
);
968 result
= getsockname(s
, name
, namelen
);
970 /*Debug2("getsockname(,, {"F_socklen"}) -> %d",
972 Debug3("getsockname(, {%s}, {"F_socklen
"}) -> %d",
973 sockaddr_info(name
, *namelen
, infobuff
, sizeof(infobuff
)),
978 #endif /* _WITH_SOCKET */
981 int Getpeername(int s
, struct sockaddr
*name
, socklen_t
*namelen
) {
985 Debug4("getpeername(%d, %p, %p{"F_socklen
"})", s
, name
, namelen
, *namelen
);
986 result
= getpeername(s
, name
, namelen
);
988 sockaddr_info(name
, *namelen
, infobuff
, sizeof(infobuff
));
989 Debug3("getpeername(, {%s}, {"F_socklen
"}) -> %d",
990 infobuff
, *namelen
, result
);
994 #endif /* _WITH_SOCKET */
997 int Getsockopt(int s
, int level
, int optname
, void *optval
, socklen_t
*optlen
) {
999 Debug5("getsockopt(%d, %d, %d, %p, {"F_Zd
"})",
1000 s
, level
, optname
, optval
, *optlen
);
1001 result
= getsockopt(s
, level
, optname
, optval
, optlen
);
1003 Debug3("getsockopt() -> (,,, 0x%08x, %d), %d",
1004 *(int *)optval
, *optlen
, result
);
1008 #endif /* _WITH_SOCKET */
1011 int Setsockopt(int s
, int level
, int optname
, const void *optval
, int optlen
) {
1013 if (optlen
<= sizeof(int)) {
1014 Debug5("setsockopt(%d, %d, %d, {0x%x}, %d)",
1015 s
, level
, optname
, *(unsigned int *)optval
, optlen
);
1017 Debug6("setsockopt(%d, %d, %d, {0x%08x,%08x}, %d)",
1019 ((unsigned int *)optval
)[0], ((unsigned int *)optval
)[1],
1022 result
= setsockopt(s
, level
, optname
, optval
, optlen
);
1024 Debug1("setsockopt() -> %d", result
);
1028 #endif /* _WITH_SOCKET */
1031 int Recv(int s
, void *buf
, size_t len
, int flags
) {
1033 Debug4("recv(%d, %p, "F_Zu
", %d)", s
, buf
, len
, flags
);
1034 retval
= recv(s
, buf
, len
, flags
);
1036 Debug1("recv() -> %d", retval
);
1040 #endif /* _WITH_SOCKET */
1043 int Recvfrom(int s
, void *buf
, size_t len
, int flags
, struct sockaddr
*from
,
1044 socklen_t
*fromlen
) {
1047 Debug6("recvfrom(%d, %p, "F_Zu
", %d, %p, "F_Zu
")",
1048 s
, buf
, len
, flags
, from
, *fromlen
);
1049 retval
= recvfrom(s
, buf
, len
, flags
, from
, fromlen
);
1052 Debug4("recvfrom(,,,, {%d,%s}, "F_Zd
") -> %d",
1054 sockaddr_info(from
, *fromlen
, infobuff
, sizeof(infobuff
)),
1057 Debug1("recvfrom(,,,, NULL, NULL) -> %d", retval
);
1062 #endif /* _WITH_SOCKET */
1065 int Recvmsg(int s
, struct msghdr
*msgh
, int flags
) {
1068 #if defined(HAVE_STRUCT_MSGHDR_MSGCONTROL) && defined(HAVE_STRUCT_MSGHDR_MSGCONTROLLEN) && defined(HAVE_STRUCT_MSGHDR_MSGFLAGS)
1069 Debug10("recvmsg(%d, %p{%p,%u,%p,%u,%p,%u,%d}, %d)", s
, msgh
,
1070 msgh
->msg_name
, msgh
->msg_namelen
, msgh
->msg_iov
, msgh
->msg_iovlen
,
1071 msgh
->msg_control
, msgh
->msg_controllen
, msgh
->msg_flags
, flags
);
1073 Debug7("recvmsg(%d, %p{%p,%u,%p,%u}, %d)", s
, msgh
,
1074 msgh
->msg_name
, msgh
->msg_namelen
, msgh
->msg_iov
, msgh
->msg_iovlen
,
1077 retval
= recvmsg(s
, msgh
, flags
);
1079 #if defined(HAVE_STRUCT_MSGHDR_MSGCONTROLLEN)
1080 Debug5("recvmsg(, {%s,%u,,%u,,%u,}, ) -> %d",
1081 msgh
->msg_name
?sockaddr_info(msgh
->msg_name
, msgh
->msg_namelen
, infobuff
, sizeof(infobuff
)):"NULL",
1082 msgh
->msg_namelen
, msgh
->msg_iovlen
, msgh
->msg_controllen
,
1085 Debug4("recvmsg(, {%s,%u,,%u,,}, ) -> %d",
1086 msgh
->msg_name
?sockaddr_info(msgh
->msg_name
, msgh
->msg_namelen
, infobuff
, sizeof(infobuff
)):"NULL",
1087 msgh
->msg_namelen
, msgh
->msg_iovlen
,
1093 #endif /* _WITH_SOCKET */
1096 int Send(int s
, const void *mesg
, size_t len
, int flags
) {
1098 Debug5("send(%d, %p[%08x...], "F_Zu
", %d)",
1099 s
, mesg
, ntohl(*(unsigned long *)mesg
), len
, flags
);
1100 retval
= send(s
, mesg
, len
, flags
);
1102 Debug1("send() -> %d", retval
);
1106 #endif /* _WITH_SOCKET */
1109 int Sendto(int s
, const void *mesg
, size_t len
, int flags
,
1110 const struct sockaddr
*to
, socklen_t tolen
) {
1114 sockaddr_info(to
, tolen
, infobuff
, sizeof(infobuff
));
1115 Debug7("sendto(%d, %p[%08x...], "F_Zu
", %d, {%s}, %d)",
1116 s
, mesg
, htonl(*(unsigned long *)mesg
), len
, flags
, infobuff
, tolen
);
1117 retval
= sendto(s
, mesg
, len
, flags
, to
, tolen
);
1119 Debug1("sendto() -> %d", retval
);
1123 #endif /* _WITH_SOCKET */
1126 int Shutdown(int fd
, int how
) {
1128 Info2("shutdown(%d, %d)", fd
, how
);
1129 retval
= shutdown(fd
, how
);
1131 Debug1("shutdown() -> %d", retval
);
1135 #endif /* _WITH_SOCKET */
1137 unsigned int Sleep(unsigned int seconds
) {
1138 unsigned int retval
;
1139 Debug1("sleep(%u)", seconds
);
1140 retval
= sleep(seconds
);
1141 Debug1("sleep() -> %u", retval
);
1145 void Usleep(unsigned long usec
) {
1146 Debug1("usleep(%lu)", usec
);
1148 Debug("usleep() ->");
1153 unsigned int Nanosleep(const struct timespec
*req
, struct timespec
*rem
) {
1155 Debug3("nanosleep({"F_time
",%ld},%p)", req
->tv_sec
, req
->tv_nsec
, rem
);
1156 retval
= nanosleep(req
, rem
);
1159 Debug3("nanosleep(,{"F_time
",%ld}) -> %d",
1160 rem
->tv_sec
, rem
->tv_nsec
, retval
);
1162 Debug1("nanosleep() -> %d", retval
);
1167 #endif /* HAVE_NANOSLEEP */
1174 Debug1("pause() -> %d", retval
);
1179 #if WITH_IP4 || WITH_IP6
1180 struct hostent
*Gethostbyname(const char *name
) {
1181 struct hostent
*hent
;
1182 Debug1("gethostbyname(\"%s\")", name
);
1183 hent
= gethostbyname(name
);
1185 Debug("gethostbyname() -> NULL");
1187 Debug4("gethostbyname() -> %d.%d.%d.%d",
1188 ((unsigned char *)hent
->h_addr_list
[0])[0],
1189 ((unsigned char *)hent
->h_addr_list
[0])[1],
1190 ((unsigned char *)hent
->h_addr_list
[0])[2],
1191 ((unsigned char *)hent
->h_addr_list
[0])[3]);
1195 #endif /* WITH_IP4 || WITH_IP6 */
1197 #if (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO
1198 int Getaddrinfo(const char *node
, const char *service
,
1199 const struct addrinfo
*hints
, struct addrinfo
**res
) {
1201 Debug15("getaddrinfo(%s%s%s, %s%s%s, {%d,%d,%d,%d,"F_Zu
",%p,%p,%p}, %p)",
1202 node
?"\"":"", node
?node
:"NULL", node
?"\"":"",
1203 service
?"\"":"", service
?service
:"NULL", service
?"\"":"",
1204 hints
->ai_flags
, hints
->ai_family
, hints
->ai_socktype
,
1205 hints
->ai_protocol
, hints
->ai_addrlen
, hints
->ai_addr
,
1206 hints
->ai_canonname
, hints
->ai_next
, res
);
1207 result
= getaddrinfo(node
, service
, hints
, res
);
1210 sockaddr_info((*res
)->ai_addr
, hints
->ai_addrlen
, sockbuff
, sizeof(sockbuff
));
1211 Debug2("getaddrinfo(,,,{{%s, %s}) -> 0",
1213 (*res
)->ai_canonname
?(*res
)->ai_canonname
:"");
1215 Debug2("getaddrinfo(,,,{%p}) -> %d", *res
, result
);
1219 #endif /* (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO */
1221 #if (WITH_IP4 || WITH_IP6) && HAVE_GETIPNODEBYNAME
1222 struct hostent
*Getipnodebyname(const char *name
, int af
, int flags
,
1224 struct hostent
*result
;
1225 Debug4("getipnodebyname(\"%s\", %d, %d, %p)", name
, af
, flags
, error_num
);
1226 result
= getipnodebyname(name
, af
, flags
, error_num
);
1227 if (result
== NULL
) {
1228 Debug1("getipnodebyname(,,, {%d}) -> NULL", *error_num
);
1230 Debug4("getipnodebyname() -> {\"%s\", %p, %d, %d, ???}",
1231 result
->h_name
, result
->h_aliases
, result
->h_addrtype
,
1236 #endif /* (WITH_IP4 || WITH_IP6) && HAVE_GETIPNODEBYNAME */
1238 void *Malloc(size_t size
) {
1240 Debug1("malloc("F_Zd
")", size
);
1241 result
= malloc(size
);
1242 Debug1("malloc() -> %p", result
);
1243 if (result
== NULL
) {
1244 Error1("malloc("F_Zd
"): out of memory", size
);
1250 void *Calloc(size_t nmemb
, size_t size
) {
1252 Debug2("calloc("F_Zd
", "F_Zd
")", nmemb
, size
);
1253 result
= calloc(nmemb
, size
);
1254 Debug1("calloc() -> %p", result
);
1255 if (result
== NULL
) {
1256 Error2("calloc("F_Zd
", "F_Zd
"): out of memory", nmemb
, size
);
1262 void *Realloc(void *ptr
, size_t size
) {
1264 Debug2("realloc(%p, "F_Zd
")", ptr
, size
);
1265 result
= realloc(ptr
, size
);
1266 Debug1("realloc() -> %p", result
);
1267 if (result
== NULL
) {
1268 Error2("realloc(%p, "F_Zd
"): out of memory", ptr
, size
);
1275 int Tcgetattr(int fd
, struct termios
*termios_p
) {
1276 int i
, result
, _errno
;
1277 char chars
[5*NCCS
], *cp
= chars
;
1279 Debug2("tcgetattr(%d, %p)", fd
, termios_p
);
1280 result
= tcgetattr(fd
, termios_p
);
1283 for (i
= 0; i
< NCCS
-1; ++i
) {
1284 cp
+= sprintf(cp
, "%02x,", termios_p
->c_cc
[i
]);
1286 sprintf(cp
, "%02x", termios_p
->c_cc
[i
]);
1287 Debug6("tcgetattr(, {%08x,%08x,%08x,%08x,%s}) -> %d",
1288 termios_p
->c_iflag
, termios_p
->c_oflag
,
1289 termios_p
->c_cflag
, termios_p
->c_lflag
,
1294 #endif /* _WITH_TERMIOS */
1297 int Tcsetattr(int fd
, int optional_actions
, struct termios
*termios_p
) {
1298 int i
, result
, _errno
;
1299 char chars
[5*NCCS
], *cp
= chars
;
1301 for (i
= 0; i
< NCCS
-1; ++i
) {
1302 cp
+= sprintf(cp
, "%02x,", termios_p
->c_cc
[i
]);
1304 sprintf(cp
, "%02x", termios_p
->c_cc
[i
]);
1305 Debug7("tcsetattr(%d, %d, {%08x,%08x,%08x,%08x,%s})", fd
, optional_actions
,
1306 termios_p
->c_iflag
, termios_p
->c_oflag
,
1307 termios_p
->c_cflag
, termios_p
->c_lflag
, chars
);
1308 result
= tcsetattr(fd
, optional_actions
, termios_p
);
1310 Debug1("tcsetattr() -> %d", result
);
1314 #endif /* _WITH_TERMIOS */
1316 char *Ttyname(int fd
) {
1319 Debug1("ttyname(%d)", fd
);
1320 result
= ttyname(fd
);
1323 Debug1("ttyname() -> %s", result
);
1325 Debug("ttyname() -> NULL");
1330 int Isatty(int fd
) {
1332 Debug1("isatty(%d)", fd
);
1333 result
= isatty(fd
);
1335 Debug1("isatty() -> %d", result
);
1341 int Openpty(int *ptyfd
, int *ttyfd
, char *ptyname
, struct termios
*termp
,
1342 struct winsize
*winp
) {
1344 Debug5("openpty(%p, %p, %p, %p, %p)", ptyfd
, ttyfd
, ptyname
, termp
, winp
);
1345 result
= openpty(ptyfd
, ttyfd
, ptyname
, termp
, winp
);
1347 Info4("openpty({%d}, {%d}, {\"%s\"},,) -> %d", *ptyfd
, *ttyfd
, ptyname
,
1352 #endif /* HAVE_OPENPTY */
1355 int Grantpt(int fd
) {
1357 Debug1("grantpt(%d)", fd
);
1358 result
= grantpt(fd
);
1360 Debug1("grantpt() -> %d", result
);
1364 #endif /* HAVE_GRANTPT */
1367 int Unlockpt(int fd
) {
1369 Debug1("unlockpt(%d)", fd
);
1370 result
= unlockpt(fd
);
1372 Debug1("unlockpt() -> %d", result
);
1376 #endif /* HAVE_UNLOCKPT */
1378 #if HAVE_PTSNAME /* AIX, not Linux */
1379 char *Ptsname(int fd
) {
1382 Debug1("ptsname(%d)", fd
);
1383 result
= ptsname(fd
);
1386 Debug1("ptsname() -> %s", result
);
1388 Debug("ptsname() -> NULL");
1392 #endif /* HAVE_PTSNAME */
1394 int Uname(struct utsname
*buf
) {
1396 Debug1("uname(%p)", buf
);
1397 result
= uname(buf
);
1399 #if UNAME_DOMAINNAME
1400 Debug6("uname({%s, %s, %s, %s, %s, %s})",
1401 buf
->sysname
, buf
->nodename
, buf
->release
,
1402 buf
->version
, buf
->machine
, buf
->domainname
);
1404 Debug5("uname({%s, %s, %s, %s, %s})",
1405 buf
->sysname
, buf
->nodename
, buf
->release
,
1406 buf
->version
, buf
->machine
);
1412 int Gethostname(char *name
, size_t len
) {
1414 Debug2("gethostname(%p, "F_Zu
")", name
, len
);
1415 result
= gethostname(name
, len
);
1417 Debug2("gethostname(\"%s\", ) -> %d", name
, result
);
1422 /* due to Linux docu, it does not set errno */
1423 int Atexit(void (*func
)(void)) {
1425 Debug1("atexit(%p)", func
);
1426 result
= atexit(func
);
1427 Debug1("atexit() -> %d", result
);
1432 void Exit(int status
) {
1433 Debug1("exit(%d)", status
);
1442 int Mkstemp(char *template) {
1444 Debug1("mkstemp(\"%s\")", template);
1445 result
= mkstemp(template);
1447 Info2("mkstemp({%s}) -> %d", template, result
);
1452 int Setenv(const char *name
, const char *value
, int overwrite
) {
1454 Debug3("setenv(\"%s\", \"%s\", %d)", name
, value
, overwrite
);
1455 result
= setenv(name
, value
, overwrite
);
1457 Debug1("setenv() -> %d", result
);
1463 /* on Linux it returns int but on FreeBSD void.
1464 we do not expect many errors, so we take void which works on all systems. */
1465 void Unsetenv(const char *name
) {
1467 Debug1("unsetenv(\"%s\")", name
);
1470 Debug("unsetenv() ->");
1478 char *Readline(const char *prompt
) {
1482 Debug1("readline(\"%s\")", prompt
);
1484 Debug("readline(NULL)");
1486 result
= readline(prompt
);
1488 Debug("readline() -> \"...\"");
1490 Debug("readline() -> NULL");
1495 void Using_history(void) {
1496 Debug("using_history()");
1498 Debug("using_history() ->");
1501 int Read_history(const char *filename
) {
1505 Debug1("read_history(\"%s\")", filename
);
1507 Debug("read_history(NULL)");
1509 result
= read_history(filename
);
1511 Debug1("read_history() -> %d", result
);
1513 Debug("read_history() -> 0");
1518 int Write_history(const char *filename
) {
1522 Debug1("write_history(\"%s\")", filename
);
1524 Debug("write_history(NULL)");
1526 result
= write_history(filename
);
1528 Debug1("write_history() -> %d", result
);
1530 Debug("write_history() -> 0");
1535 int Append_history(int nelements
, const char *filename
) {
1539 Debug2("append_history(%d, \"%s\")", nelements
, filename
);
1541 Debug1("append_history(%d, NULL)", nelements
);
1543 result
= append_history(nelements
, filename
);
1545 Debug1("append_history() -> %d", result
);
1547 Debug("append_history() -> 0");
1552 int Where_history(void) {
1555 Debug("where_history()");
1556 result
= where_history();
1557 Debug1("where_history() -> %d", result
);
1561 void Add_history(const char *string
) {
1562 Debug1("add_history(\"%s\")", string
);
1563 add_history(string
);
1564 Debug("add_history() ->");
1567 #endif /* WITH_READLINE */
1569 #endif /* WITH_SYCLS */