Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readlink.c 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
  3. * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
  4. * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
  5. * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
  6. * Copyright (c) 2006 Ulrich Drepper <drepper@redhat.com>
  7. * Copyright (c) 2006 Bernhard Kaindl <bk@suse.de>
  8. * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org>
  9. * Copyright (c) 2014-2018 The strace developers.
  10. * All rights reserved.
  11. *
  12. * SPDX-License-Identifier: LGPL-2.1-or-later
  13. */
  14. #include "defs.h"
  15. static int
  16. decode_readlink(struct tcb *tcp, int offset)
  17. {
  18. if (entering(tcp)) {
  19. printpath(tcp, tcp->u_arg[offset]);
  20. tprints(", ");
  21. } else {
  22. if (syserror(tcp))
  23. printaddr(tcp->u_arg[offset + 1]);
  24. else
  25. /* Used to use printpathn(), but readlink
  26. * neither includes NUL in the returned count,
  27. * nor actually writes it into memory.
  28. * printpathn() would decide on printing
  29. * "..." continuation based on garbage
  30. * past return buffer's end.
  31. */
  32. printstrn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
  33. tprintf(", %" PRI_klu, tcp->u_arg[offset + 2]);
  34. }
  35. return 0;
  36. }
  37. SYS_FUNC(readlink)
  38. {
  39. return decode_readlink(tcp, 0);
  40. }
  41. SYS_FUNC(readlinkat)
  42. {
  43. if (entering(tcp))
  44. print_dirfd(tcp, tcp->u_arg[0]);
  45. return decode_readlink(tcp, 1);
  46. }