basic questions to strace

Eugene Syromyatnikov evgsyr at gmail.com
Fri Oct 7 13:59:04 UTC 2016



On Fri, Oct 7, 2016 at 1:16 PM, Lentes, Bernd <bernd.lentes at helmholtz-muenchen.de> wrote:
> Hi,
>
> i'm a system administrator, not a developer. I use strace sometimes for debugging problems, and i like it very much. Nice tool.
> I have some principal questions and hope this is the right place to ask. If not please inform me and maybe give me a hint
> where a more aprropriate place would be.
>
> From what i understand until now is that processes normally don't invoke system calls directly, they contact libraries which do it for them.
>
> Starting a process give me this error in the log:
> traps: nsrexecd[12162] general protection ip:7f085e4cb960 sp:7f085a4e9278 error:0 in libpthread-2.23.so[7f085e4b9000+18000]
> It seems that the kernel is stopping the process because of ... what with a signal.
For debugging segmentation faults, i'd recommend installing debuginfo packages,
enabling core file saving and then checking them out with gdb, usually it allows
pinpointing problem rather quickly.

> I observed the process /usr/sbin/nsrexecd with strace.
> Here seems to be the problem:
>
> open("/dev/null", O_RDWR)               = 3
> close(3)                                = 0
> clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fac73d019d0) = 13025
> rt_sigaction(SIGTERM, {0x4275e0, [HUP INT USR1 USR2 PIPE ALRM TERM CHLD XCPU XFSZ], SA_RESTORER, 0x7fac72ce83d0}, NULL, 8) = 0
> rt_sigaction(SIGCHLD, {0x4275e0, [HUP INT USR1 USR2 PIPE ALRM TERM CHLD XCPU XFSZ], SA_RESTORER, 0x7fac72ce83d0}, NULL, 8) = 0
> select(0, NULL, NULL, NULL, {300, 0})   = ? ERESTARTNOHAND (To be restarted if no handler)
Calling select with zero nfds and NULL fd sets is rather strange.

> --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=13025, si_uid=0} ---
> rt_sigreturn({mask=[]})                 = -1 EINTR (Interrupted system call)
> exit_group(0)                           = ?
> +++ exited with 0 +++
>
> clone is a syscall for creating a child process, right ?
>
> man 2 clone says:
>
>        /* Prototype for the glibc wrapper function */
>
>        #include <sched.h>
>
>        int clone(int (*fn)(void *), void *child_stack,
>                  int flags, void *arg, ...
>                  /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ );
>
>        /* Prototype for the raw system call */
>
>        long clone(unsigned long flags, void *child_stack,
>                  void *ptid, void *ctid,
>                  struct pt_regs *regs);
>
>
> What i don't understand:
> The syscall is called with three arguments, right ? But the wrapper function expects ... how many arguments ? What means ... ? Does it expect 7 arguments ?
> And the syscall itself has 5 arguments, but it is called just with three. Does that work ? Which ones are the these which are used ? The first three ?
> The last three ?
Clone is rather comprehensive syscall by means that it is used for several
different tasks. Which arguments are used depends on flags provided, and strace
prints only arguments actually used (for brevity, i suppose). Syscall arguments
parsing for clone call is done as follows (clone.c in strace source):

	const char *sep = "|";
	unsigned long flags = tcp->u_arg[ARG_FLAGS];
	tprints("child_stack=");
	printaddr(tcp->u_arg[ARG_STACK]);
	tprints(", ");
#ifdef ARG_STACKSIZE
	if (ARG_STACKSIZE != -1)
		tprintf("stack_size=%#lx, ",
			tcp->u_arg[ARG_STACKSIZE]);
#endif
	tprints("flags=");
	if (!printflags(clone_flags, flags &~ CSIGNAL, NULL))
		sep = "";
	if ((flags & CSIGNAL) != 0)
		tprintf("%s%s", sep, signame(flags & CSIGNAL));
	if ((flags & (CLONE_PARENT_SETTID|CLONE_CHILD_SETTID
		      |CLONE_CHILD_CLEARTID|CLONE_SETTLS)) == 0)
		return 0;
	if (flags & CLONE_PARENT_SETTID) {
		tprints(", parent_tidptr=");
		printaddr(tcp->u_arg[ARG_PTID]);
	}
	if (flags & CLONE_SETTLS) {
#if defined I386 || defined X86_64 || defined X32
# ifndef I386
		if (current_personality == 1)
# endif
		{
			tprints(", tls=");
			print_user_desc(tcp, tcp->u_arg[ARG_TLS]);
		}
# ifndef I386
		else
# endif
#endif /* I386 || X86_64 || X32 */
		{
			tprints(", tls=");
			printaddr(tcp->u_arg[ARG_TLS]);
		}
	}
	if (flags & (CLONE_CHILD_SETTID|CLONE_CHILD_CLEARTID)) {
		tprints(", child_tidptr=");
		printaddr(tcp->u_arg[ARG_CTID]);
	}

As you can see, parent_tidptr, child_tidptr and tls arguments are
printed only in case appropriate flags are provided (they are used for
thread creation, mostly).

> What means the return code 13025 ? I didn't find anything about it in the net. Is there s.th. where i can get further information ?
On success, clone returns ID of the child process to the parent. You can check
it out in the "RETURN VALUE" section of the manual.

> I installed the kernel sources and searched for a file like clone.h or clone.c, but didn't find anything.
Please check out kernel/fork.c file in kernel tree, it contains
SYSCALL_DEFINE[56](clone, ...), which calls _do_fork().

>
> Thanks for any help.
>
>
> Bernd
>
> --
> Bernd Lentes
>
> Systemadministration
> institute of developmental genetics
> Gebäude 35.34 - Raum 208
> HelmholtzZentrum München
> bernd.lentes at helmholtz-muenchen.de
> phone: +49 (0)89 3187 1241
> fax: +49 (0)89 3187 2294
>
> Erst wenn man sich auf etwas festlegt kann man Unrecht haben
> Scott Adams
>
>
> Helmholtz Zentrum Muenchen
> Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
> Ingolstaedter Landstr. 1
> 85764 Neuherberg
> www.helmholtz-muenchen.de
> Aufsichtsratsvorsitzende: MinDir'in Baerbel Brumme-Bothe
> Geschaeftsfuehrer: Prof. Dr. Guenther Wess, Dr. Alfons Enhsen
> Registergericht: Amtsgericht Muenchen HRB 6466
> USt-IdNr: DE 129521671
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Strace-devel mailing list
> Strace-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/strace-devel



-- 
Eugene "eSyr" Syromyatnikov
mailto:evgSyr at gmail.com
xmpp:eSyr at jabber.{ru|org}




More information about the Strace-devel mailing list