<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - strace-5.14.0.8.a1fdc - src/strace.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - strace.c<span style="font-size: 80%;"> (source / <a href="strace.c.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">strace-5.14.0.8.a1fdc</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">1423</td>
            <td class="headerCovTableEntry">1587</td>
            <td class="headerCovTableEntryMed">89.67 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2021-10-06 21:35:39</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">68</td>
            <td class="headerCovTableEntry">69</td>
            <td class="headerCovTableEntryHi">98.55 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
            | Branches:
            <span class="coverLegendCov">+</span> taken
            <span class="coverLegendNoCov">-</span> not taken
            <span class="coverLegendNoCov">#</span> not executed
</td>
            <td></td>
            <td class="headerItem">Branches:</td>
            <td class="headerCovTableEntry">860</td>
            <td class="headerCovTableEntry">1100</td>
            <td class="headerCovTableEntryMed">78.18 %</td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">           Branch data     Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>                :            : /*</a>
<a name="2"><span class="lineNum">       2 </span>                :            :  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl></a>
<a name="3"><span class="lineNum">       3 </span>                :            :  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl></a>
<a name="4"><span class="lineNum">       4 </span>                :            :  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com></a>
<a name="5"><span class="lineNum">       5 </span>                :            :  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl></a>
<a name="6"><span class="lineNum">       6 </span>                :            :  * Copyright (c) 1999-2021 The strace developers.</a>
<a name="7"><span class="lineNum">       7 </span>                :            :  * All rights reserved.</a>
<a name="8"><span class="lineNum">       8 </span>                :            :  *</a>
<a name="9"><span class="lineNum">       9 </span>                :            :  * SPDX-License-Identifier: LGPL-2.1-or-later</a>
<a name="10"><span class="lineNum">      10 </span>                :            :  */</a>
<a name="11"><span class="lineNum">      11 </span>                :            : </a>
<a name="12"><span class="lineNum">      12 </span>                :            : #include "defs.h"</a>
<a name="13"><span class="lineNum">      13 </span>                :            : #include <stdarg.h></a>
<a name="14"><span class="lineNum">      14 </span>                :            : #include <limits.h></a>
<a name="15"><span class="lineNum">      15 </span>                :            : #include <fcntl.h></a>
<a name="16"><span class="lineNum">      16 </span>                :            : #include "ptrace.h"</a>
<a name="17"><span class="lineNum">      17 </span>                :            : #include <signal.h></a>
<a name="18"><span class="lineNum">      18 </span>                :            : #include <sys/resource.h></a>
<a name="19"><span class="lineNum">      19 </span>                :            : #include <sys/stat.h></a>
<a name="20"><span class="lineNum">      20 </span>                :            : #ifdef HAVE_PATHS_H</a>
<a name="21"><span class="lineNum">      21 </span>                :            : # include <paths.h></a>
<a name="22"><span class="lineNum">      22 </span>                :            : #endif</a>
<a name="23"><span class="lineNum">      23 </span>                :            : #include <getopt.h></a>
<a name="24"><span class="lineNum">      24 </span>                :            : #include <pwd.h></a>
<a name="25"><span class="lineNum">      25 </span>                :            : #include <grp.h></a>
<a name="26"><span class="lineNum">      26 </span>                :            : #include <dirent.h></a>
<a name="27"><span class="lineNum">      27 </span>                :            : #include <locale.h></a>
<a name="28"><span class="lineNum">      28 </span>                :            : #include <sys/utsname.h></a>
<a name="29"><span class="lineNum">      29 </span>                :            : #include <sys/prctl.h></a>
<a name="30"><span class="lineNum">      30 </span>                :            : </a>
<a name="31"><span class="lineNum">      31 </span>                :            : #include "kill_save_errno.h"</a>
<a name="32"><span class="lineNum">      32 </span>                :            : #include "filter_seccomp.h"</a>
<a name="33"><span class="lineNum">      33 </span>                :            : #include "largefile_wrappers.h"</a>
<a name="34"><span class="lineNum">      34 </span>                :            : #include "mmap_cache.h"</a>
<a name="35"><span class="lineNum">      35 </span>                :            : #include "number_set.h"</a>
<a name="36"><span class="lineNum">      36 </span>                :            : #include "ptrace_syscall_info.h"</a>
<a name="37"><span class="lineNum">      37 </span>                :            : #include "scno.h"</a>
<a name="38"><span class="lineNum">      38 </span>                :            : #include "printsiginfo.h"</a>
<a name="39"><span class="lineNum">      39 </span>                :            : #include "trace_event.h"</a>
<a name="40"><span class="lineNum">      40 </span>                :            : #include "xstring.h"</a>
<a name="41"><span class="lineNum">      41 </span>                :            : #include "delay.h"</a>
<a name="42"><span class="lineNum">      42 </span>                :            : #include "wait.h"</a>
<a name="43"><span class="lineNum">      43 </span>                :            : #include "secontext.h"</a>
<a name="44"><span class="lineNum">      44 </span>                :            : </a>
<a name="45"><span class="lineNum">      45 </span>                :            : /* In some libc, these aren't declared. Do it ourself: */</a>
<a name="46"><span class="lineNum">      46 </span>                :            : extern char **environ;</a>
<a name="47"><span class="lineNum">      47 </span>                :            : extern int optind;</a>
<a name="48"><span class="lineNum">      48 </span>                :            : extern char *optarg;</a>
<a name="49"><span class="lineNum">      49 </span>                :            : </a>
<a name="50"><span class="lineNum">      50 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="51"><span class="lineNum">      51 </span>                :            : /* if this is true do the stack trace for every system call */</a>
<a name="52"><span class="lineNum">      52 </span>                :            : bool stack_trace_enabled;</a>
<a name="53"><span class="lineNum">      53 </span>                :            : #endif</a>
<a name="54"><span class="lineNum">      54 </span>                :            : </a>
<a name="55"><span class="lineNum">      55 </span>                :            : #define my_tkill(tid, sig) syscall(__NR_tkill, (tid), (sig))</a>
<a name="56"><span class="lineNum">      56 </span>                :            : </a>
<a name="57"><span class="lineNum">      57 </span>                :            : /* Glue for systems without a MMU that cannot provide fork() */</a>
<a name="58"><span class="lineNum">      58 </span>                :            : #if !defined(HAVE_FORK)</a>
<a name="59"><span class="lineNum">      59 </span>                :            : # undef NOMMU_SYSTEM</a>
<a name="60"><span class="lineNum">      60 </span>                :            : # define NOMMU_SYSTEM 1</a>
<a name="61"><span class="lineNum">      61 </span>                :            : #endif</a>
<a name="62"><span class="lineNum">      62 </span>                :            : #if NOMMU_SYSTEM</a>
<a name="63"><span class="lineNum">      63 </span>                :            : # define fork() vfork()</a>
<a name="64"><span class="lineNum">      64 </span>                :            : #endif</a>
<a name="65"><span class="lineNum">      65 </span>                :            : </a>
<a name="66"><span class="lineNum">      66 </span>                :            : const unsigned int syscall_trap_sig = SIGTRAP | 0x80;</a>
<a name="67"><span class="lineNum">      67 </span>                :            : </a>
<a name="68"><span class="lineNum">      68 </span>                :            : cflag_t cflag = CFLAG_NONE;</a>
<a name="69"><span class="lineNum">      69 </span>                :            : bool followfork;</a>
<a name="70"><span class="lineNum">      70 </span>                :            : bool output_separately;</a>
<a name="71"><span class="lineNum">      71 </span>                :            : unsigned int ptrace_setoptions = PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXEC</a>
<a name="72"><span class="lineNum">      72 </span>                :            :                                  | PTRACE_O_TRACEEXIT;</a>
<a name="73"><span class="lineNum">      73 </span>                :            : static struct xlat_data xflag_str[] = {</a>
<a name="74"><span class="lineNum">      74 </span>                :            :         { HEXSTR_NON_ASCII,     "non-ascii" },</a>
<a name="75"><span class="lineNum">      75 </span>                :            :         { HEXSTR_ALL,           "all" },</a>
<a name="76"><span class="lineNum">      76 </span>                :            : };</a>
<a name="77"><span class="lineNum">      77 </span>                :            : unsigned int xflag;</a>
<a name="78"><span class="lineNum">      78 </span>                :            : bool debug_flag;</a>
<a name="79"><span class="lineNum">      79 </span>                :            : bool Tflag;</a>
<a name="80"><span class="lineNum">      80 </span>                :            : int Tflag_scale = 1000;</a>
<a name="81"><span class="lineNum">      81 </span>                :            : int Tflag_width = 6;</a>
<a name="82"><span class="lineNum">      82 </span>                :            : bool iflag;</a>
<a name="83"><span class="lineNum">      83 </span>                :            : bool nflag;</a>
<a name="84"><span class="lineNum">      84 </span>                :            : bool count_wallclock;</a>
<a name="85"><span class="lineNum">      85 </span>                :            : static int tflag_scale = 1000000000;</a>
<a name="86"><span class="lineNum">      86 </span>                :            : static unsigned tflag_width = 0;</a>
<a name="87"><span class="lineNum">      87 </span>                :            : static const char *tflag_format = NULL;</a>
<a name="88"><span class="lineNum">      88 </span>                :            : static bool rflag;</a>
<a name="89"><span class="lineNum">      89 </span>                :            : static int rflag_scale = 1000;</a>
<a name="90"><span class="lineNum">      90 </span>                :            : static int rflag_width = 6;</a>
<a name="91"><span class="lineNum">      91 </span>                :            : static bool print_pid_pfx;</a>
<a name="92"><span class="lineNum">      92 </span>                :            : </a>
<a name="93"><span class="lineNum">      93 </span>                :            : /* -I n */</a>
<a name="94"><span class="lineNum">      94 </span>                :            : enum {</a>
<a name="95"><span class="lineNum">      95 </span>                :            :         INTR_NOT_SET        = 0,</a>
<a name="96"><span class="lineNum">      96 </span>                :            :         INTR_ANYWHERE       = 1, /* don't block/ignore any signals */</a>
<a name="97"><span class="lineNum">      97 </span>                :            :         INTR_WHILE_WAIT     = 2, /* block fatal signals while decoding syscall. default */</a>
<a name="98"><span class="lineNum">      98 </span>                :            :         INTR_NEVER          = 3, /* block fatal signals. default if '-o FILE PROG' */</a>
<a name="99"><span class="lineNum">      99 </span>                :            :         INTR_BLOCK_TSTP_TOO = 4, /* block fatal signals and SIGTSTP (^Z); default if -D */</a>
<a name="100"><span class="lineNum">     100 </span>                :            :         NUM_INTR_OPTS</a>
<a name="101"><span class="lineNum">     101 </span>                :            : };</a>
<a name="102"><span class="lineNum">     102 </span>                :            : static int opt_intr;</a>
<a name="103"><span class="lineNum">     103 </span>                :            : /* We play with signal mask only if this mode is active: */</a>
<a name="104"><span class="lineNum">     104 </span>                :            : #define interactive (opt_intr == INTR_WHILE_WAIT)</a>
<a name="105"><span class="lineNum">     105 </span>                :            : </a>
<a name="106"><span class="lineNum">     106 </span>                :            : enum {</a>
<a name="107"><span class="lineNum">     107 </span>                :            :         DAEMONIZE_NONE        = 0,</a>
<a name="108"><span class="lineNum">     108 </span>                :            :         DAEMONIZE_GRANDCHILD  = 1,</a>
<a name="109"><span class="lineNum">     109 </span>                :            :         DAEMONIZE_NEW_PGROUP  = 2,</a>
<a name="110"><span class="lineNum">     110 </span>                :            :         DAEMONIZE_NEW_SESSION = 3,</a>
<a name="111"><span class="lineNum">     111 </span>                :            : </a>
<a name="112"><span class="lineNum">     112 </span>                :            :         DAEMONIZE_OPTS_GUARD__,</a>
<a name="113"><span class="lineNum">     113 </span>                :            :         MAX_DAEMONIZE_OPTS    = DAEMONIZE_OPTS_GUARD__ - 1</a>
<a name="114"><span class="lineNum">     114 </span>                :            : };</a>
<a name="115"><span class="lineNum">     115 </span>                :            : static struct xlat_data daemonize_str[] = {</a>
<a name="116"><span class="lineNum">     116 </span>                :            :         { DAEMONIZE_GRANDCHILD,         "grandchild" },</a>
<a name="117"><span class="lineNum">     117 </span>                :            :         { DAEMONIZE_NEW_PGROUP,         "pgroup" },</a>
<a name="118"><span class="lineNum">     118 </span>                :            :         { DAEMONIZE_NEW_PGROUP,         "pgrp" },</a>
<a name="119"><span class="lineNum">     119 </span>                :            :         { DAEMONIZE_NEW_SESSION,        "session" },</a>
<a name="120"><span class="lineNum">     120 </span>                :            : };</a>
<a name="121"><span class="lineNum">     121 </span>                :            : /*</a>
<a name="122"><span class="lineNum">     122 </span>                :            :  * daemonized_tracer supports -D option.</a>
<a name="123"><span class="lineNum">     123 </span>                :            :  * With this option, strace forks twice.</a>
<a name="124"><span class="lineNum">     124 </span>                :            :  * Unlike normal case, with -D *grandparent* process exec's,</a>
<a name="125"><span class="lineNum">     125 </span>                :            :  * becoming a traced process. Child exits (this prevents traced process</a>
<a name="126"><span class="lineNum">     126 </span>                :            :  * from having children it doesn't expect to have), and grandchild</a>
<a name="127"><span class="lineNum">     127 </span>                :            :  * attaches to grandparent similarly to strace -p PID.</a>
<a name="128"><span class="lineNum">     128 </span>                :            :  * This allows for more transparent interaction in cases</a>
<a name="129"><span class="lineNum">     129 </span>                :            :  * when process and its parent are communicating via signals,</a>
<a name="130"><span class="lineNum">     130 </span>                :            :  * wait() etc. Without -D, strace process gets lodged in between,</a>
<a name="131"><span class="lineNum">     131 </span>                :            :  * disrupting parent<->child link.</a>
<a name="132"><span class="lineNum">     132 </span>                :            :  */</a>
<a name="133"><span class="lineNum">     133 </span>                :            : static unsigned int daemonized_tracer;</a>
<a name="134"><span class="lineNum">     134 </span>                :            : </a>
<a name="135"><span class="lineNum">     135 </span>                :            : static int post_attach_sigstop = TCB_IGNORE_ONE_SIGSTOP;</a>
<a name="136"><span class="lineNum">     136 </span>                :            : #define use_seize (post_attach_sigstop == 0)</a>
<a name="137"><span class="lineNum">     137 </span>                :            : </a>
<a name="138"><span class="lineNum">     138 </span>                :            : unsigned int pidns_translation;</a>
<a name="139"><span class="lineNum">     139 </span>                :            : </a>
<a name="140"><span class="lineNum">     140 </span>                :            : static bool detach_on_execve;</a>
<a name="141"><span class="lineNum">     141 </span>                :            : </a>
<a name="142"><span class="lineNum">     142 </span>                :            : static int exit_code;</a>
<a name="143"><span class="lineNum">     143 </span>                :            : static int strace_child;</a>
<a name="144"><span class="lineNum">     144 </span>                :            : static int strace_tracer_pid;</a>
<a name="145"><span class="lineNum">     145 </span>                :            : </a>
<a name="146"><span class="lineNum">     146 </span>                :            : static const char *username;</a>
<a name="147"><span class="lineNum">     147 </span>                :            : static uid_t run_uid;</a>
<a name="148"><span class="lineNum">     148 </span>                :            : static gid_t run_gid;</a>
<a name="149"><span class="lineNum">     149 </span>                :            : </a>
<a name="150"><span class="lineNum">     150 </span>                :            : unsigned int max_strlen = DEFAULT_STRLEN;</a>
<a name="151"><span class="lineNum">     151 </span>                :            : static int acolumn = DEFAULT_ACOLUMN;</a>
<a name="152"><span class="lineNum">     152 </span>                :            : static char *acolumn_spaces;</a>
<a name="153"><span class="lineNum">     153 </span>                :            : </a>
<a name="154"><span class="lineNum">     154 </span>                :            : /* Default output style for xlat entities */</a>
<a name="155"><span class="lineNum">     155 </span>                :            : enum xlat_style xlat_verbosity = XLAT_STYLE_ABBREV;</a>
<a name="156"><span class="lineNum">     156 </span>                :            : </a>
<a name="157"><span class="lineNum">     157 </span>                :            : static const char *outfname;</a>
<a name="158"><span class="lineNum">     158 </span>                :            : /* If -ff, points to stderr. Else, it's our common output log */</a>
<a name="159"><span class="lineNum">     159 </span>                :            : static FILE *shared_log;</a>
<a name="160"><span class="lineNum">     160 </span>                :            : static bool open_append;</a>
<a name="161"><span class="lineNum">     161 </span>                :            : </a>
<a name="162"><span class="lineNum">     162 </span>                :            : struct tcb *printing_tcp;</a>
<a name="163"><span class="lineNum">     163 </span>                :            : static struct tcb *current_tcp;</a>
<a name="164"><span class="lineNum">     164 </span>                :            : </a>
<a name="165"><span class="lineNum">     165 </span>                :            : struct tcb_wait_data {</a>
<a name="166"><span class="lineNum">     166 </span>                :            :         enum trace_event te; /**< Event passed to dispatch_event() */</a>
<a name="167"><span class="lineNum">     167 </span>                :            :         int status;          /**< status, returned by wait4() */</a>
<a name="168"><span class="lineNum">     168 </span>                :            :         unsigned long msg;   /**< Value returned by PTRACE_GETEVENTMSG */</a>
<a name="169"><span class="lineNum">     169 </span>                :            :         siginfo_t si;        /**< siginfo, returned by PTRACE_GETSIGINFO */</a>
<a name="170"><span class="lineNum">     170 </span>                :            : };</a>
<a name="171"><span class="lineNum">     171 </span>                :            : </a>
<a name="172"><span class="lineNum">     172 </span>                :            : static struct tcb **tcbtab;</a>
<a name="173"><span class="lineNum">     173 </span>                :            : static unsigned int nprocs;</a>
<a name="174"><span class="lineNum">     174 </span>                :            : static size_t tcbtabsize;</a>
<a name="175"><span class="lineNum">     175 </span>                :            : </a>
<a name="176"><span class="lineNum">     176 </span>                :            : static struct tcb_wait_data *tcb_wait_tab;</a>
<a name="177"><span class="lineNum">     177 </span>                :            : static size_t tcb_wait_tab_size;</a>
<a name="178"><span class="lineNum">     178 </span>                :            : </a>
<a name="179"><span class="lineNum">     179 </span>                :            : </a>
<a name="180"><span class="lineNum">     180 </span>                :            : #ifndef HAVE_PROGRAM_INVOCATION_NAME</a>
<a name="181"><span class="lineNum">     181 </span>                :            : char *program_invocation_name;</a>
<a name="182"><span class="lineNum">     182 </span>                :            : #endif</a>
<a name="183"><span class="lineNum">     183 </span>                :            : </a>
<a name="184"><span class="lineNum">     184 </span>                :            : unsigned os_release; /* generated from uname()'s u.release */</a>
<a name="185"><span class="lineNum">     185 </span>                :            : </a>
<a name="186"><span class="lineNum">     186 </span>                :            : static void detach(struct tcb *tcp);</a>
<a name="187"><span class="lineNum">     187 </span>                :            : static void cleanup(int sig);</a>
<a name="188"><span class="lineNum">     188 </span>                :            : static void interrupt(int sig);</a>
<a name="189"><span class="lineNum">     189 </span>                :            : </a>
<a name="190"><span class="lineNum">     190 </span>                :            : #ifdef HAVE_SIG_ATOMIC_T</a>
<a name="191"><span class="lineNum">     191 </span>                :            : static volatile sig_atomic_t interrupted, restart_failed;</a>
<a name="192"><span class="lineNum">     192 </span>                :            : #else</a>
<a name="193"><span class="lineNum">     193 </span>                :            : static volatile int interrupted, restart_failed;</a>
<a name="194"><span class="lineNum">     194 </span>                :            : #endif</a>
<a name="195"><span class="lineNum">     195 </span>                :            : </a>
<a name="196"><span class="lineNum">     196 </span>                :            : static sigset_t timer_set;</a>
<a name="197"><span class="lineNum">     197 </span>                :            : static void timer_sighandler(int);</a>
<a name="198"><span class="lineNum">     198 </span>                :            : </a>
<a name="199"><span class="lineNum">     199 </span>                :            : #ifndef HAVE_STRERROR</a>
<a name="200"><span class="lineNum">     200 </span>                :            : </a>
<a name="201"><span class="lineNum">     201 </span>                :            : # if !HAVE_DECL_SYS_ERRLIST</a>
<a name="202"><span class="lineNum">     202 </span>                :            : extern int sys_nerr;</a>
<a name="203"><span class="lineNum">     203 </span>                :            : extern char *sys_errlist[];</a>
<a name="204"><span class="lineNum">     204 </span>                :            : # endif</a>
<a name="205"><span class="lineNum">     205 </span>                :            : </a>
<a name="206"><span class="lineNum">     206 </span>                :            : const char *</a>
<a name="207"><span class="lineNum">     207 </span>                :            : strerror(int err_no)</a>
<a name="208"><span class="lineNum">     208 </span>                :            : {</a>
<a name="209"><span class="lineNum">     209 </span>                :            :         static char buf[sizeof("Unknown error %d") + sizeof(int)*3];</a>
<a name="210"><span class="lineNum">     210 </span>                :            : </a>
<a name="211"><span class="lineNum">     211 </span>                :            :         if (err_no < 1 || err_no >= sys_nerr) {</a>
<a name="212"><span class="lineNum">     212 </span>                :            :                 xsprintf(buf, "Unknown error %d", err_no);</a>
<a name="213"><span class="lineNum">     213 </span>                :            :                 return buf;</a>
<a name="214"><span class="lineNum">     214 </span>                :            :         }</a>
<a name="215"><span class="lineNum">     215 </span>                :            :         return sys_errlist[err_no];</a>
<a name="216"><span class="lineNum">     216 </span>                :            : }</a>
<a name="217"><span class="lineNum">     217 </span>                :            : </a>
<a name="218"><span class="lineNum">     218 </span>                :            : #endif /* HAVE_STERRROR */</a>
<a name="219"><span class="lineNum">     219 </span>                :            : </a>
<a name="220"><span class="lineNum">     220 </span>                :            : static void</a>
<a name="221"><span class="lineNum">     221 </span>                :<span class="lineCov">       1100 : print_version(void)</span></a>
<a name="222"><span class="lineNum">     222 </span>                :            : {</a>
<a name="223"><span class="lineNum">     223 </span>                :<span class="lineCov">       1100 :         static const char features[] =</span></a>
<a name="224"><span class="lineNum">     224 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="225"><span class="lineNum">     225 </span>                :            :                 " stack-trace=" USE_UNWINDER</a>
<a name="226"><span class="lineNum">     226 </span>                :            : #endif</a>
<a name="227"><span class="lineNum">     227 </span>                :            : #ifdef USE_DEMANGLE</a>
<a name="228"><span class="lineNum">     228 </span>                :            :                 " stack-demangle"</a>
<a name="229"><span class="lineNum">     229 </span>                :            : #endif</a>
<a name="230"><span class="lineNum">     230 </span>                :            : #if SUPPORTED_PERSONALITIES > 1</a>
<a name="231"><span class="lineNum">     231 </span>                :            : # if defined HAVE_M32_MPERS</a>
<a name="232"><span class="lineNum">     232 </span>                :            :                 " m32-mpers"</a>
<a name="233"><span class="lineNum">     233 </span>                :            : # else</a>
<a name="234"><span class="lineNum">     234 </span>                :            :                 " no-m32-mpers"</a>
<a name="235"><span class="lineNum">     235 </span>                :            : # endif</a>
<a name="236"><span class="lineNum">     236 </span>                :            : #endif /* SUPPORTED_PERSONALITIES > 1 */</a>
<a name="237"><span class="lineNum">     237 </span>                :            : #if SUPPORTED_PERSONALITIES > 2</a>
<a name="238"><span class="lineNum">     238 </span>                :            : # if defined HAVE_MX32_MPERS</a>
<a name="239"><span class="lineNum">     239 </span>                :            :                 " mx32-mpers"</a>
<a name="240"><span class="lineNum">     240 </span>                :            : # else</a>
<a name="241"><span class="lineNum">     241 </span>                :            :                 " no-mx32-mpers"</a>
<a name="242"><span class="lineNum">     242 </span>                :            : # endif</a>
<a name="243"><span class="lineNum">     243 </span>                :            : #endif /* SUPPORTED_PERSONALITIES > 2 */</a>
<a name="244"><span class="lineNum">     244 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="245"><span class="lineNum">     245 </span>                :            :                 " secontext"</a>
<a name="246"><span class="lineNum">     246 </span>                :            : #endif</a>
<a name="247"><span class="lineNum">     247 </span>                :            :                 "";</a>
<a name="248"><span class="lineNum">     248 </span>                :            : </a>
<a name="249"><span class="lineNum">     249 </span>                :<span class="lineCov">       1100 :         printf("%s -- version %s\n"</span></a>
<a name="250"><span class="lineNum">     250 </span>                :            :                "Copyright (c) 1991-%s The strace developers <%s>.\n"</a>
<a name="251"><span class="lineNum">     251 </span>                :            :                "This is free software; see the source for copying conditions.  There is NO\n"</a>
<a name="252"><span class="lineNum">     252 </span>                :            :                "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",</a>
<a name="253"><span class="lineNum">     253 </span>                :            :                PACKAGE_NAME, PACKAGE_VERSION, COPYRIGHT_YEAR, PACKAGE_URL);</a>
<a name="254"><span class="lineNum">     254 </span>                :<span class="lineCov">       1100 :         printf("\nOptional features enabled:%s\n",</span></a>
<a name="255"><span class="lineNum">     255 </span>                :            :                features[0] ? features : " (none)");</a>
<a name="256"><span class="lineNum">     256 </span>                :<span class="lineCov">       1100 : }</span></a>
<a name="257"><span class="lineNum">     257 </span>                :            : </a>
<a name="258"><span class="lineNum">     258 </span>                :            : static void</a>
<a name="259"><span class="lineNum">     259 </span>                :<span class="lineCov">         16 : usage(void)</span></a>
<a name="260"><span class="lineNum">     260 </span>                :            : {</a>
<a name="261"><span class="lineNum">     261 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="262"><span class="lineNum">     262 </span>                :            : # define K_OPT "k"</a>
<a name="263"><span class="lineNum">     263 </span>                :            : #else</a>
<a name="264"><span class="lineNum">     264 </span>                :            : # define K_OPT ""</a>
<a name="265"><span class="lineNum">     265 </span>                :            : #endif</a>
<a name="266"><span class="lineNum">     266 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="267"><span class="lineNum">     267 </span>                :            : # define SECONTEXT_OPT "[--secontext[=OPTIONS]]\n"</a>
<a name="268"><span class="lineNum">     268 </span>                :            : #else</a>
<a name="269"><span class="lineNum">     269 </span>                :            : # define SECONTEXT_OPT ""</a>
<a name="270"><span class="lineNum">     270 </span>                :            : #endif</a>
<a name="271"><span class="lineNum">     271 </span>                :            : </a>
<a name="272"><span class="lineNum">     272 </span>                :<span class="lineCov">         16 :         printf("\</span></a>
<a name="273"><span class="lineNum">     273 </span>                :            : Usage: strace [-ACdffhi" K_OPT "qqrtttTvVwxxyyzZ] [-I N] [-b execve] [-e EXPR]...\n\</a>
<a name="274"><span class="lineNum">     274 </span>                :            :               [-a COLUMN] [-o FILE] [-s STRSIZE] [-X FORMAT] [-O OVERHEAD]\n\</a>
<a name="275"><span class="lineNum">     275 </span>                :            :               [-S SORTBY] [-P PATH]... [-p PID]... [-U COLUMNS] [--seccomp-bpf]\n"\</a>
<a name="276"><span class="lineNum">     276 </span>                :            :               SECONTEXT_OPT "\</a>
<a name="277"><span class="lineNum">     277 </span>                :            :               { -p PID | [-DDD] [-E VAR=VAL]... [-u USERNAME] PROG [ARGS] }\n\</a>
<a name="278"><span class="lineNum">     278 </span>                :            :    or: strace -c[dfwzZ] [-I N] [-b execve] [-e EXPR]... [-O OVERHEAD]\n\</a>
<a name="279"><span class="lineNum">     279 </span>                :            :               [-S SORTBY] [-P PATH]... [-p PID]... [-U COLUMNS] [--seccomp-bpf]\n\</a>
<a name="280"><span class="lineNum">     280 </span>                :            :               { -p PID | [-DDD] [-E VAR=VAL]... [-u USERNAME] PROG [ARGS] }\n\</a>
<a name="281"><span class="lineNum">     281 </span>                :            : \n\</a>
<a name="282"><span class="lineNum">     282 </span>                :            : General:\n\</a>
<a name="283"><span class="lineNum">     283 </span>                :            :   -e EXPR        a qualifying expression: OPTION=[!]all or OPTION=[!]VAL1[,VAL2]...\n\</a>
<a name="284"><span class="lineNum">     284 </span>                :            :      options:    trace, abbrev, verbose, raw, signal, read, write, fault,\n\</a>
<a name="285"><span class="lineNum">     285 </span>                :            :                  inject, status, quiet, kvm, decode-fds\n\</a>
<a name="286"><span class="lineNum">     286 </span>                :            : \n\</a>
<a name="287"><span class="lineNum">     287 </span>                :            : Startup:\n\</a>
<a name="288"><span class="lineNum">     288 </span>                :            :   -E VAR=VAL, --env=VAR=VAL\n\</a>
<a name="289"><span class="lineNum">     289 </span>                :            :                  put VAR=VAL in the environment for command\n\</a>
<a name="290"><span class="lineNum">     290 </span>                :            :   -E VAR, --env=VAR\n\</a>
<a name="291"><span class="lineNum">     291 </span>                :            :                  remove VAR from the environment for command\n\</a>
<a name="292"><span class="lineNum">     292 </span>                :            :   -p PID, --attach=PID\n\</a>
<a name="293"><span class="lineNum">     293 </span>                :            :                  trace process with process id PID, may be repeated\n\</a>
<a name="294"><span class="lineNum">     294 </span>                :            :   -u USERNAME, --user=USERNAME\n\</a>
<a name="295"><span class="lineNum">     295 </span>                :            :                  run command as USERNAME handling setuid and/or setgid\n\</a>
<a name="296"><span class="lineNum">     296 </span>                :            : \n\</a>
<a name="297"><span class="lineNum">     297 </span>                :            : Tracing:\n\</a>
<a name="298"><span class="lineNum">     298 </span>                :            :   -b execve, --detach-on=execve\n\</a>
<a name="299"><span class="lineNum">     299 </span>                :            :                  detach on execve syscall\n\</a>
<a name="300"><span class="lineNum">     300 </span>                :            :   -D, --daemonize[=grandchild]\n\</a>
<a name="301"><span class="lineNum">     301 </span>                :            :                  run tracer process as a grandchild, not as a parent\n\</a>
<a name="302"><span class="lineNum">     302 </span>                :            :   -DD, --daemonize=pgroup\n\</a>
<a name="303"><span class="lineNum">     303 </span>                :            :                  run tracer process in a separate process group\n\</a>
<a name="304"><span class="lineNum">     304 </span>                :            :   -DDD, --daemonize=session\n\</a>
<a name="305"><span class="lineNum">     305 </span>                :            :                  run tracer process in a separate session\n\</a>
<a name="306"><span class="lineNum">     306 </span>                :            :   -f, --follow-forks\n\</a>
<a name="307"><span class="lineNum">     307 </span>                :            :                  follow forks\n\</a>
<a name="308"><span class="lineNum">     308 </span>                :            :   -ff, --follow-forks --output-separately\n\</a>
<a name="309"><span class="lineNum">     309 </span>                :            :                  follow forks with output into separate files\n\</a>
<a name="310"><span class="lineNum">     310 </span>                :            :   -I INTERRUPTIBLE, --interruptible=INTERRUPTIBLE\n\</a>
<a name="311"><span class="lineNum">     311 </span>                :            :      1, anywhere:   no signals are blocked\n\</a>
<a name="312"><span class="lineNum">     312 </span>                :            :      2, waiting:    fatal signals are blocked while decoding syscall (default)\n\</a>
<a name="313"><span class="lineNum">     313 </span>                :            :      3, never:      fatal signals are always blocked (default if '-o FILE PROG')\n\</a>
<a name="314"><span class="lineNum">     314 </span>                :            :      4, never_tstp: fatal signals and SIGTSTP (^Z) are always blocked\n\</a>
<a name="315"><span class="lineNum">     315 </span>                :            :                     (useful to make 'strace -o FILE PROG' not stop on ^Z)\n\</a>
<a name="316"><span class="lineNum">     316 </span>                :            : \n\</a>
<a name="317"><span class="lineNum">     317 </span>                :            : Filtering:\n\</a>
<a name="318"><span class="lineNum">     318 </span>                :            :   -e trace=[!]{[?]SYSCALL[@64|@32|@x32]|[?]/REGEX|GROUP|all|none},\n\</a>
<a name="319"><span class="lineNum">     319 </span>                :            :   --trace=[!]{[?]SYSCALL[@64|@32|@x32]|[?]/REGEX|GROUP|all|none}\n\</a>
<a name="320"><span class="lineNum">     320 </span>                :            :                  trace only specified syscalls.\n\</a>
<a name="321"><span class="lineNum">     321 </span>                :            :      groups:     %%clock, %%creds, %%desc, %%file, %%fstat, %%fstatfs %%ipc, %%lstat,\n\</a>
<a name="322"><span class="lineNum">     322 </span>                :            :                  %%memory, %%net, %%process, %%pure, %%signal, %%stat, %%%%stat,\n\</a>
<a name="323"><span class="lineNum">     323 </span>                :            :                  %%statfs, %%%%statfs\n\</a>
<a name="324"><span class="lineNum">     324 </span>                :            :   -e signal=SET, --signal=SET\n\</a>
<a name="325"><span class="lineNum">     325 </span>                :            :                  trace only the specified set of signals\n\</a>
<a name="326"><span class="lineNum">     326 </span>                :            :                  print only the signals from SET\n\</a>
<a name="327"><span class="lineNum">     327 </span>                :            :   -e status=SET, --status=SET\n\</a>
<a name="328"><span class="lineNum">     328 </span>                :            :                  print only system calls with the return statuses in SET\n\</a>
<a name="329"><span class="lineNum">     329 </span>                :            :      statuses:   successful, failed, unfinished, unavailable, detached\n\</a>
<a name="330"><span class="lineNum">     330 </span>                :            :   -P PATH, --trace-path=PATH\n\</a>
<a name="331"><span class="lineNum">     331 </span>                :            :                  trace accesses to PATH\n\</a>
<a name="332"><span class="lineNum">     332 </span>                :            :   -z, --successful-only\n\</a>
<a name="333"><span class="lineNum">     333 </span>                :            :                  print only syscalls that returned without an error code\n\</a>
<a name="334"><span class="lineNum">     334 </span>                :            :   -Z, --failed-only\n\</a>
<a name="335"><span class="lineNum">     335 </span>                :            :                  print only syscalls that returned with an error code\n\</a>
<a name="336"><span class="lineNum">     336 </span>                :            : \n\</a>
<a name="337"><span class="lineNum">     337 </span>                :            : Output format:\n\</a>
<a name="338"><span class="lineNum">     338 </span>                :            :   -a COLUMN, --columns=COLUMN\n\</a>
<a name="339"><span class="lineNum">     339 </span>                :            :                  alignment COLUMN for printing syscall results (default %d)\n\</a>
<a name="340"><span class="lineNum">     340 </span>                :            :   -e abbrev=SET, --abbrev=SET\n\</a>
<a name="341"><span class="lineNum">     341 </span>                :            :                  abbreviate output for the syscalls in SET\n\</a>
<a name="342"><span class="lineNum">     342 </span>                :            :   -e verbose=SET, --verbose=SET\n\</a>
<a name="343"><span class="lineNum">     343 </span>                :            :                  dereference structures for the syscall in SET\n\</a>
<a name="344"><span class="lineNum">     344 </span>                :            :   -e raw=SET, --raw=SET\n\</a>
<a name="345"><span class="lineNum">     345 </span>                :            :                  print undecoded arguments for the syscalls in SET\n\</a>
<a name="346"><span class="lineNum">     346 </span>                :            :   -e read=SET, --read=SET\n\</a>
<a name="347"><span class="lineNum">     347 </span>                :            :                  dump the data read from the file descriptors in SET\n\</a>
<a name="348"><span class="lineNum">     348 </span>                :            :   -e write=SET, --write=SET\n\</a>
<a name="349"><span class="lineNum">     349 </span>                :            :                  dump the data written to the file descriptors in SET\n\</a>
<a name="350"><span class="lineNum">     350 </span>                :            :   -e quiet=SET, --quiet=SET\n\</a>
<a name="351"><span class="lineNum">     351 </span>                :            :                  suppress various informational messages\n\</a>
<a name="352"><span class="lineNum">     352 </span>                :            :      messages:   attach, exit, path-resolution, personality, thread-execve\n\</a>
<a name="353"><span class="lineNum">     353 </span>                :            :   -e kvm=vcpu, --kvm=vcpu\n\</a>
<a name="354"><span class="lineNum">     354 </span>                :            :                  print exit reason of kvm vcpu\n\</a>
<a name="355"><span class="lineNum">     355 </span>                :            :   -e decode-fds=SET, --decode-fds=SET\n\</a>
<a name="356"><span class="lineNum">     356 </span>                :            :                  what kinds of file descriptor information details to decode\n\</a>
<a name="357"><span class="lineNum">     357 </span>                :            :      details:    dev (device major/minor for block/char device files)\n\</a>
<a name="358"><span class="lineNum">     358 </span>                :            :                  path (file path),\n\</a>
<a name="359"><span class="lineNum">     359 </span>                :            :                  pidfd (associated PID for pidfds),\n\</a>
<a name="360"><span class="lineNum">     360 </span>                :            :                  socket (protocol-specific information for socket descriptors)\n\</a>
<a name="361"><span class="lineNum">     361 </span>                :            :   -i, --instruction-pointer\n\</a>
<a name="362"><span class="lineNum">     362 </span>                :            :                  print instruction pointer at time of syscall\n\</a>
<a name="363"><span class="lineNum">     363 </span>                :            : "</a>
<a name="364"><span class="lineNum">     364 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="365"><span class="lineNum">     365 </span>                :            : "\</a>
<a name="366"><span class="lineNum">     366 </span>                :            :   -k, --stack-traces\n\</a>
<a name="367"><span class="lineNum">     367 </span>                :            :                  obtain stack trace between each syscall\n\</a>
<a name="368"><span class="lineNum">     368 </span>                :            : "</a>
<a name="369"><span class="lineNum">     369 </span>                :            : #endif</a>
<a name="370"><span class="lineNum">     370 </span>                :            : "\</a>
<a name="371"><span class="lineNum">     371 </span>                :            :   -n, --syscall-number\n\</a>
<a name="372"><span class="lineNum">     372 </span>                :            :                  print syscall number\n\</a>
<a name="373"><span class="lineNum">     373 </span>                :            :   -o FILE, --output=FILE\n\</a>
<a name="374"><span class="lineNum">     374 </span>                :            :                  send trace output to FILE instead of stderr\n\</a>
<a name="375"><span class="lineNum">     375 </span>                :            :   -A, --output-append-mode\n\</a>
<a name="376"><span class="lineNum">     376 </span>                :            :                  open the file provided in the -o option in append mode\n\</a>
<a name="377"><span class="lineNum">     377 </span>                :            :   --output-separately\n\</a>
<a name="378"><span class="lineNum">     378 </span>                :            :                  output into separate files (by appending pid to file names)\n\</a>
<a name="379"><span class="lineNum">     379 </span>                :            :   -q, --quiet=attach,personality\n\</a>
<a name="380"><span class="lineNum">     380 </span>                :            :                  suppress messages about attaching, detaching, etc.\n\</a>
<a name="381"><span class="lineNum">     381 </span>                :            :   -qq, --quiet=attach,personality,exit\n\</a>
<a name="382"><span class="lineNum">     382 </span>                :            :                  suppress messages about process exit status as well.\n\</a>
<a name="383"><span class="lineNum">     383 </span>                :            :   -qqq, --quiet=all\n\</a>
<a name="384"><span class="lineNum">     384 </span>                :            :                  suppress all suppressible messages.\n\</a>
<a name="385"><span class="lineNum">     385 </span>                :            :   -r, --relative-timestamps[=PRECISION]\n\</a>
<a name="386"><span class="lineNum">     386 </span>                :            :                  print relative timestamp\n\</a>
<a name="387"><span class="lineNum">     387 </span>                :            :      precision:  one of s, ms, us, ns; default is microseconds\n\</a>
<a name="388"><span class="lineNum">     388 </span>                :            :   -s STRSIZE, --string-limit=STRSIZE\n\</a>
<a name="389"><span class="lineNum">     389 </span>                :            :                  limit length of print strings to STRSIZE chars (default %d)\n\</a>
<a name="390"><span class="lineNum">     390 </span>                :            :   --absolute-timestamps=[[format:]FORMAT[,[precision:]PRECISION]]\n\</a>
<a name="391"><span class="lineNum">     391 </span>                :            :                  set the format of absolute timestamps\n\</a>
<a name="392"><span class="lineNum">     392 </span>                :            :      format:     none, time, or unix; default is time\n\</a>
<a name="393"><span class="lineNum">     393 </span>                :            :      precision:  one of s, ms, us, ns; default is seconds\n\</a>
<a name="394"><span class="lineNum">     394 </span>                :            :   -t, --absolute-timestamps[=time]\n\</a>
<a name="395"><span class="lineNum">     395 </span>                :            :                  print absolute timestamp\n\</a>
<a name="396"><span class="lineNum">     396 </span>                :            :   -tt, --absolute-timestamps=[time,]us\n\</a>
<a name="397"><span class="lineNum">     397 </span>                :            :                  print absolute timestamp with usecs\n\</a>
<a name="398"><span class="lineNum">     398 </span>                :            :   -ttt, --absolute-timestamps=unix,us\n\</a>
<a name="399"><span class="lineNum">     399 </span>                :            :                  print absolute UNIX time with usecs\n\</a>
<a name="400"><span class="lineNum">     400 </span>                :            :   -T, --syscall-times[=PRECISION]\n\</a>
<a name="401"><span class="lineNum">     401 </span>                :            :                  print time spent in each syscall\n\</a>
<a name="402"><span class="lineNum">     402 </span>                :            :      precision:  one of s, ms, us, ns; default is microseconds\n\</a>
<a name="403"><span class="lineNum">     403 </span>                :            :   -v, --no-abbrev\n\</a>
<a name="404"><span class="lineNum">     404 </span>                :            :                  verbose mode: print entities unabbreviated\n\</a>
<a name="405"><span class="lineNum">     405 </span>                :            :   -x, --strings-in-hex=non-ascii\n\</a>
<a name="406"><span class="lineNum">     406 </span>                :            :                  print non-ascii strings in hex\n\</a>
<a name="407"><span class="lineNum">     407 </span>                :            :   -xx, --strings-in-hex[=all]\n\</a>
<a name="408"><span class="lineNum">     408 </span>                :            :                  print all strings in hex\n\</a>
<a name="409"><span class="lineNum">     409 </span>                :            :   -X FORMAT, --const-print-style=FORMAT\n\</a>
<a name="410"><span class="lineNum">     410 </span>                :            :                  set the FORMAT for printing of named constants and flags\n\</a>
<a name="411"><span class="lineNum">     411 </span>                :            :      formats:    raw, abbrev, verbose\n\</a>
<a name="412"><span class="lineNum">     412 </span>                :            :   -y, --decode-fds[=path]\n\</a>
<a name="413"><span class="lineNum">     413 </span>                :            :                  print paths associated with file descriptor arguments\n\</a>
<a name="414"><span class="lineNum">     414 </span>                :            :   -yy, --decode-fds=all\n\</a>
<a name="415"><span class="lineNum">     415 </span>                :            :                  print all available information associated with file\n\</a>
<a name="416"><span class="lineNum">     416 </span>                :            :                  descriptors in addition to paths\n\</a>
<a name="417"><span class="lineNum">     417 </span>                :            : "</a>
<a name="418"><span class="lineNum">     418 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="419"><span class="lineNum">     419 </span>                :            : "\</a>
<a name="420"><span class="lineNum">     420 </span>                :            :   --secontext[=FORMAT]\n\</a>
<a name="421"><span class="lineNum">     421 </span>                :            :                  print SELinux contexts in square brackets\n\</a>
<a name="422"><span class="lineNum">     422 </span>                :            :      formats:    comma-separated list of short, full, mismatch\n\</a>
<a name="423"><span class="lineNum">     423 </span>                :            :                  short (default): print the type only\n\</a>
<a name="424"><span class="lineNum">     424 </span>                :            :                  full: print the full context\n\</a>
<a name="425"><span class="lineNum">     425 </span>                :            :                  mismatch: print expected context when actual is not matching\n\</a>
<a name="426"><span class="lineNum">     426 </span>                :            : "</a>
<a name="427"><span class="lineNum">     427 </span>                :            : #endif</a>
<a name="428"><span class="lineNum">     428 </span>                :            : "\</a>
<a name="429"><span class="lineNum">     429 </span>                :            : \n\</a>
<a name="430"><span class="lineNum">     430 </span>                :            : Statistics:\n\</a>
<a name="431"><span class="lineNum">     431 </span>                :            :   -c, --summary-only\n\</a>
<a name="432"><span class="lineNum">     432 </span>                :            :                  count time, calls, and errors for each syscall and report\n\</a>
<a name="433"><span class="lineNum">     433 </span>                :            :                  summary\n\</a>
<a name="434"><span class="lineNum">     434 </span>                :            :   -C, --summary  like -c, but also print the regular output\n\</a>
<a name="435"><span class="lineNum">     435 </span>                :            :   -O OVERHEAD[UNIT], --summary-syscall-overhead=OVERHEAD[UNIT]\n\</a>
<a name="436"><span class="lineNum">     436 </span>                :            :                  set overhead for tracing syscalls to OVERHEAD UNITs\n\</a>
<a name="437"><span class="lineNum">     437 </span>                :            :      units:      one of s, ms, us, ns; default is microseconds\n\</a>
<a name="438"><span class="lineNum">     438 </span>                :            :   -S SORTBY, --summary-sort-by=SORTBY\n\</a>
<a name="439"><span class="lineNum">     439 </span>                :            :                  sort syscall counts by: time, min-time, max-time, avg-time,\n\</a>
<a name="440"><span class="lineNum">     440 </span>                :            :                  calls, errors, name, nothing (default %s)\n\</a>
<a name="441"><span class="lineNum">     441 </span>                :            :   -U COLUMNS, --summary-columns=COLUMNS\n\</a>
<a name="442"><span class="lineNum">     442 </span>                :            :                  show specific columns in the summary report: comma-separated\n\</a>
<a name="443"><span class="lineNum">     443 </span>                :            :                  list of time-percent, total-time, min-time, max-time, \n\</a>
<a name="444"><span class="lineNum">     444 </span>                :            :                  avg-time, calls, errors, name\n\</a>
<a name="445"><span class="lineNum">     445 </span>                :            :                  (default time-percent,total-time,avg-time,calls,errors,name)\n\</a>
<a name="446"><span class="lineNum">     446 </span>                :            :   -w, --summary-wall-clock\n\</a>
<a name="447"><span class="lineNum">     447 </span>                :            :                  summarise syscall latency (default is system time)\n\</a>
<a name="448"><span class="lineNum">     448 </span>                :            : \n\</a>
<a name="449"><span class="lineNum">     449 </span>                :            : Tampering:\n\</a>
<a name="450"><span class="lineNum">     450 </span>                :            :   -e inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]\n\</a>
<a name="451"><span class="lineNum">     451 </span>                :            :             [:delay_enter=DELAY][:delay_exit=DELAY]\n\</a>
<a name="452"><span class="lineNum">     452 </span>                :            :             [:poke_enter=@argN=DATAN,@argM=DATAM...]\n\</a>
<a name="453"><span class="lineNum">     453 </span>                :            :             [:poke_exit=@argN=DATAN,@argM=DATAM...]\n\</a>
<a name="454"><span class="lineNum">     454 </span>                :            :             [:when=WHEN],\n\</a>
<a name="455"><span class="lineNum">     455 </span>                :            :   --inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]\n\</a>
<a name="456"><span class="lineNum">     456 </span>                :            :            [:delay_enter=DELAY][:delay_exit=DELAY]\n\</a>
<a name="457"><span class="lineNum">     457 </span>                :            :            [:poke_enter=@argN=DATAN,@argM=DATAM...]\n\</a>
<a name="458"><span class="lineNum">     458 </span>                :            :            [:poke_exit=@argN=DATAN,@argM=DATAM...]\n\</a>
<a name="459"><span class="lineNum">     459 </span>                :            :            [:when=WHEN],\n\</a>
<a name="460"><span class="lineNum">     460 </span>                :            :                  perform syscall tampering for the syscalls in SET\n\</a>
<a name="461"><span class="lineNum">     461 </span>                :            :      delay:      microseconds or NUMBER{s|ms|us|ns}\n\</a>
<a name="462"><span class="lineNum">     462 </span>                :            :      when:       FIRST[..LAST][+[STEP]]\n\</a>
<a name="463"><span class="lineNum">     463 </span>                :            :   -e fault=SET[:error=ERRNO][:when=WHEN], --fault=SET[:error=ERRNO][:when=WHEN]\n\</a>
<a name="464"><span class="lineNum">     464 </span>                :            :                  synonym for -e inject with default ERRNO set to ENOSYS.\n\</a>
<a name="465"><span class="lineNum">     465 </span>                :            : \n\</a>
<a name="466"><span class="lineNum">     466 </span>                :            : Miscellaneous:\n\</a>
<a name="467"><span class="lineNum">     467 </span>                :            :   -d, --debug    enable debug output to stderr\n\</a>
<a name="468"><span class="lineNum">     468 </span>                :            :   -h, --help     print help message\n\</a>
<a name="469"><span class="lineNum">     469 </span>                :            :   --seccomp-bpf  enable seccomp-bpf filtering\n\</a>
<a name="470"><span class="lineNum">     470 </span>                :            :   -V, --version  print version\n\</a>
<a name="471"><span class="lineNum">     471 </span>                :            : "</a>
<a name="472"><span class="lineNum">     472 </span>                :            : /* ancient, no one should use it</a>
<a name="473"><span class="lineNum">     473 </span>                :            : -F -- attempt to follow vforks (deprecated, use -f)\n\</a>
<a name="474"><span class="lineNum">     474 </span>                :            :  */</a>
<a name="475"><span class="lineNum">     475 </span>                :            : , DEFAULT_ACOLUMN, DEFAULT_STRLEN, DEFAULT_SORTBY);</a>
<a name="476"><span class="lineNum">     476 </span>                :<span class="lineCov">         16 :         exit(0);</span></a>
<a name="477"><span class="lineNum">     477 </span>                :            : </a>
<a name="478"><span class="lineNum">     478 </span>                :            : #undef K_OPT</a>
<a name="479"><span class="lineNum">     479 </span>                :            : }</a>
<a name="480"><span class="lineNum">     480 </span>                :            : </a>
<a name="481"><span class="lineNum">     481 </span>                :            : void ATTRIBUTE_NORETURN</a>
<a name="482"><span class="lineNum">     482 </span>                :<span class="lineCov">       5276 : die(void)</span></a>
<a name="483"><span class="lineNum">     483 </span>                :            : {</a>
<a name="484"><span class="lineNum">     484 </span>        [<span class="branchCov" title="Branch 0 was taken 5276 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">       5276 :         if (strace_tracer_pid == getpid()) {</span></a>
<a name="485"><span class="lineNum">     485 </span>                :<span class="lineCov">       5276 :                 cleanup(0);</span></a>
<a name="486"><span class="lineNum">     486 </span>                :<span class="lineCov">       5276 :                 exit(1);</span></a>
<a name="487"><span class="lineNum">     487 </span>                :            :         }</a>
<a name="488"><span class="lineNum">     488 </span>                :            : </a>
<a name="489"><span class="lineNum">     489 </span>                :<span class="lineNoCov">          0 :         _exit(1);</span></a>
<a name="490"><span class="lineNum">     490 </span>                :            : }</a>
<a name="491"><span class="lineNum">     491 </span>                :            : </a>
<a name="492"><span class="lineNum">     492 </span>                :            : static void</a>
<a name="493"><span class="lineNum">     493 </span>                :<span class="lineCov">         35 : error_opt_arg(int opt, const struct option *lopt, const char *arg)</span></a>
<a name="494"><span class="lineNum">     494 </span>                :            : {</a>
<a name="495"><span class="lineNum">     495 </span>  [<span class="branchCov" title="Branch 0 was taken 22 times"> + </span><span class="branchCov" title="Branch 1 was taken 13 times"> + </span><span class="branchCov" title="Branch 2 was taken 22 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">         35 :         if (lopt && lopt->name) {</span></a>
<a name="496"><span class="lineNum">     496 </span>                :<span class="lineCov">         22 :                 error_msg_and_help("invalid --%s argument: '%s'",</span></a>
<a name="497"><span class="lineNum">     497 </span>                :            :                                    lopt->name, arg);</a>
<a name="498"><span class="lineNum">     498 </span>                :            :         } else {</a>
<a name="499"><span class="lineNum">     499 </span>                :<span class="lineCov">         13 :                 error_msg_and_help("invalid -%c argument: '%s'", opt, arg);</span></a>
<a name="500"><span class="lineNum">     500 </span>                :            :         }</a>
<a name="501"><span class="lineNum">     501 </span>                :            : }</a>
<a name="502"><span class="lineNum">     502 </span>                :            : </a>
<a name="503"><span class="lineNum">     503 </span>                :            : static int</a>
<a name="504"><span class="lineNum">     504 </span>                :<span class="lineCov">      16260 : ptrace_attach_or_seize(int pid, const char **ptrace_attach_cmd)</span></a>
<a name="505"><span class="lineNum">     505 </span>                :            : {</a>
<a name="506"><span class="lineNum">     506 </span>                :<span class="lineCov">      16260 :         int r;</span></a>
<a name="507"><span class="lineNum">     507 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16260 times"> + </span>]:<span class="lineCov">      16260 :         if (!use_seize)</span></a>
<a name="508"><span class="lineNum">     508 </span>                :<span class="lineNoCov">          0 :                 return *ptrace_attach_cmd = "PTRACE_ATTACH",</span></a>
<a name="509"><span class="lineNum">     509 </span>                :<span class="lineNoCov">          0 :                        ptrace(PTRACE_ATTACH, pid, 0L, 0L);</span></a>
<a name="510"><span class="lineNum">     510 </span>                :<span class="lineCov">      16260 :         r = ptrace(PTRACE_SEIZE, pid, 0L, (unsigned long) ptrace_setoptions);</span></a>
<a name="511"><span class="lineNum">     511 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 16259 times"> + </span>]:<span class="lineCov">      16260 :         if (r)</span></a>
<a name="512"><span class="lineNum">     512 </span>                :<span class="lineCov">          1 :                 return *ptrace_attach_cmd = "PTRACE_SEIZE", r;</span></a>
<a name="513"><span class="lineNum">     513 </span>                :<span class="lineCov">      16259 :         r = ptrace(PTRACE_INTERRUPT, pid, 0L, 0L);</span></a>
<a name="514"><span class="lineNum">     514 </span>                :<span class="lineCov">      16259 :         return *ptrace_attach_cmd = "PTRACE_INTERRUPT", r;</span></a>
<a name="515"><span class="lineNum">     515 </span>                :            : }</a>
<a name="516"><span class="lineNum">     516 </span>                :            : </a>
<a name="517"><span class="lineNum">     517 </span>                :            : static const char *</a>
<a name="518"><span class="lineNum">     518 </span>                :<span class="lineNoCov">          0 : ptrace_op_str(unsigned int op)</span></a>
<a name="519"><span class="lineNum">     519 </span>                :            : {</a>
<a name="520"><span class="lineNum">     520 </span>                :<span class="lineNoCov">          0 :         const char *str = xlookup(ptrace_cmds, op);</span></a>
<a name="521"><span class="lineNum">     521 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (str)</span></a>
<a name="522"><span class="lineNum">     522 </span>                :            :                 return str;</a>
<a name="523"><span class="lineNum">     523 </span>                :            : </a>
<a name="524"><span class="lineNum">     524 </span>                :<span class="lineNoCov">          0 :         static char buf[sizeof(op) * 3];</span></a>
<a name="525"><span class="lineNum">     525 </span>                :<span class="lineNoCov">          0 :         xsprintf(buf, "%u", op);</span></a>
<a name="526"><span class="lineNum">     526 </span>                :<span class="lineNoCov">          0 :         return buf;</span></a>
<a name="527"><span class="lineNum">     527 </span>                :            : }</a>
<a name="528"><span class="lineNum">     528 </span>                :            : </a>
<a name="529"><span class="lineNum">     529 </span>                :            : /*</a>
<a name="530"><span class="lineNum">     530 </span>                :            :  * Used when we want to unblock stopped traced process.</a>
<a name="531"><span class="lineNum">     531 </span>                :            :  * Should be only used with PTRACE_CONT, PTRACE_DETACH and PTRACE_SYSCALL.</a>
<a name="532"><span class="lineNum">     532 </span>                :            :  * Returns 0 on success or if error was ESRCH</a>
<a name="533"><span class="lineNum">     533 </span>                :            :  * (presumably process was killed while we talk to it).</a>
<a name="534"><span class="lineNum">     534 </span>                :            :  * Otherwise prints error message and returns -1.</a>
<a name="535"><span class="lineNum">     535 </span>                :            :  */</a>
<a name="536"><span class="lineNum">     536 </span>                :            : static int</a>
<a name="537"><span class="lineNum">     537 </span>                :<span class="lineCov">  156724952 : ptrace_restart(const unsigned int op, struct tcb *const tcp, unsigned int sig)</span></a>
<a name="538"><span class="lineNum">     538 </span>                :            : {</a>
<a name="539"><span class="lineNum">     539 </span>                :<span class="lineCov">  156724952 :         int err;</span></a>
<a name="540"><span class="lineNum">     540 </span>                :            : </a>
<a name="541"><span class="lineNum">     541 </span>                :<span class="lineCov">  156724952 :         errno = 0;</span></a>
<a name="542"><span class="lineNum">     542 </span>                :<span class="lineCov">  156724952 :         ptrace(op, tcp->pid, 0L, (unsigned long) sig);</span></a>
<a name="543"><span class="lineNum">     543 </span>                :<span class="lineCov">  156724952 :         err = errno;</span></a>
<a name="544"><span class="lineNum">     544 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 156724952 times"> + </span>]:<span class="lineCov">  156724952 :         if (!err || err == ESRCH)</span></a>
<a name="545"><span class="lineNum">     545 </span>                :            :                 return 0;</a>
<a name="546"><span class="lineNum">     546 </span>                :            : </a>
<a name="547"><span class="lineNum">     547 </span>                :            :         /*</a>
<a name="548"><span class="lineNum">     548 </span>                :            :          * Why curcol != 0? Otherwise sometimes we get this:</a>
<a name="549"><span class="lineNum">     549 </span>                :            :          *</a>
<a name="550"><span class="lineNum">     550 </span>                :            :          * 10252 kill(10253, SIGKILL)              = 0</a>
<a name="551"><span class="lineNum">     551 </span>                :            :          *  <ptrace(SYSCALL,10252):No such process>10253 ...next decode...</a>
<a name="552"><span class="lineNum">     552 </span>                :            :          *</a>
<a name="553"><span class="lineNum">     553 </span>                :            :          * 10252 died after we retrieved syscall exit data,</a>
<a name="554"><span class="lineNum">     554 </span>                :            :          * but before we tried to restart it. Log looks ugly.</a>
<a name="555"><span class="lineNum">     555 </span>                :            :          */</a>
<a name="556"><span class="lineNum">     556 </span>  [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span><span class="branchNoExec" title="Branch 3 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (current_tcp && current_tcp->curcol != 0) {</span></a>
<a name="557"><span class="lineNum">     557 </span>                :<span class="lineNoCov">          0 :                 tprintf(" <Cannot restart pid %d with ptrace(%s): %s>\n",</span></a>
<a name="558"><span class="lineNum">     558 </span>                :            :                         tcp->pid, ptrace_op_str(op), strerror(err));</a>
<a name="559"><span class="lineNum">     559 </span>                :<span class="lineNoCov">          0 :                 line_ended();</span></a>
<a name="560"><span class="lineNum">     560 </span>                :            :         }</a>
<a name="561"><span class="lineNum">     561 </span>                :<span class="lineNoCov">          0 :         errno = err;</span></a>
<a name="562"><span class="lineNum">     562 </span>                :<span class="lineNoCov">          0 :         perror_msg("ptrace(%s,pid:%d,sig:%u)",</span></a>
<a name="563"><span class="lineNum">     563 </span>                :            :                    ptrace_op_str(op), tcp->pid, sig);</a>
<a name="564"><span class="lineNum">     564 </span>                :<span class="lineNoCov">          0 :         return -1;</span></a>
<a name="565"><span class="lineNum">     565 </span>                :            : }</a>
<a name="566"><span class="lineNum">     566 </span>                :            : </a>
<a name="567"><span class="lineNum">     567 </span>                :            : static void</a>
<a name="568"><span class="lineNum">     568 </span>                :<span class="lineCov">      70272 : set_cloexec_flag(int fd)</span></a>
<a name="569"><span class="lineNum">     569 </span>                :            : {</a>
<a name="570"><span class="lineNum">     570 </span>                :<span class="lineCov">      70272 :         int flags, newflags;</span></a>
<a name="571"><span class="lineNum">     571 </span>                :            : </a>
<a name="572"><span class="lineNum">     572 </span>                :<span class="lineCov">      70272 :         flags = fcntl_fd(fd, F_GETFD);</span></a>
<a name="573"><span class="lineNum">     573 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 70272 times"> + </span>]:<span class="lineCov">      70272 :         if (flags < 0) {</span></a>
<a name="574"><span class="lineNum">     574 </span>                :            :                 /* Can happen only if fd is bad.</a>
<a name="575"><span class="lineNum">     575 </span>                :            :                  * Should never happen: if it does, we have a bug</a>
<a name="576"><span class="lineNum">     576 </span>                :            :                  * in the caller. Therefore we just abort</a>
<a name="577"><span class="lineNum">     577 </span>                :            :                  * instead of propagating the error.</a>
<a name="578"><span class="lineNum">     578 </span>                :            :                  */</a>
<a name="579"><span class="lineNum">     579 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("fcntl(%d, F_GETFD)", fd);</span></a>
<a name="580"><span class="lineNum">     580 </span>                :            :         }</a>
<a name="581"><span class="lineNum">     581 </span>                :            : </a>
<a name="582"><span class="lineNum">     582 </span>                :<span class="lineCov">      70272 :         newflags = flags | FD_CLOEXEC;</span></a>
<a name="583"><span class="lineNum">     583 </span>        [<span class="branchCov" title="Branch 0 was taken 70272 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      70272 :         if (flags == newflags)</span></a>
<a name="584"><span class="lineNum">     584 </span>                :            :                 return;</a>
<a name="585"><span class="lineNum">     585 </span>                :            : </a>
<a name="586"><span class="lineNum">     586 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 70272 times"> + </span>]:<span class="lineCov">      70272 :         if (fcntl_fd(fd, F_SETFD, newflags)) /* never fails */</span></a>
<a name="587"><span class="lineNum">     587 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("fcntl(%d, F_SETFD, %#x)", fd, newflags);</span></a>
<a name="588"><span class="lineNum">     588 </span>                :            : }</a>
<a name="589"><span class="lineNum">     589 </span>                :            : </a>
<a name="590"><span class="lineNum">     590 </span>                :            : /*</a>
<a name="591"><span class="lineNum">     591 </span>                :            :  * When strace is setuid executable, we have to swap uids</a>
<a name="592"><span class="lineNum">     592 </span>                :            :  * before and after filesystem and process management operations.</a>
<a name="593"><span class="lineNum">     593 </span>                :            :  */</a>
<a name="594"><span class="lineNum">     594 </span>                :            : static void</a>
<a name="595"><span class="lineNum">     595 </span>                :<span class="lineCov">      43031 : swap_uid(void)</span></a>
<a name="596"><span class="lineNum">     596 </span>                :            : {</a>
<a name="597"><span class="lineNum">     597 </span>                :<span class="lineCov">      43031 :         int euid = geteuid(), uid = getuid();</span></a>
<a name="598"><span class="lineNum">     598 </span>                :            : </a>
<a name="599"><span class="lineNum">     599 </span>  [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 43031 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">      43031 :         if (euid != uid && setreuid(euid, uid) < 0) {</span></a>
<a name="600"><span class="lineNum">     600 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("setreuid");</span></a>
<a name="601"><span class="lineNum">     601 </span>                :            :         }</a>
<a name="602"><span class="lineNum">     602 </span>                :<span class="lineCov">      43031 : }</span></a>
<a name="603"><span class="lineNum">     603 </span>                :            : </a>
<a name="604"><span class="lineNum">     604 </span>                :            : static FILE *</a>
<a name="605"><span class="lineNum">     605 </span>                :<span class="lineCov">      21513 : strace_fopen(const char *path)</span></a>
<a name="606"><span class="lineNum">     606 </span>                :            : {</a>
<a name="607"><span class="lineNum">     607 </span>                :<span class="lineCov">      21513 :         FILE *fp;</span></a>
<a name="608"><span class="lineNum">     608 </span>                :            : </a>
<a name="609"><span class="lineNum">     609 </span>                :<span class="lineCov">      21513 :         swap_uid();</span></a>
<a name="610"><span class="lineNum">     610 </span>        [<span class="branchCov" title="Branch 0 was taken 21513 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      43026 :         fp = fopen_stream(path, open_append ? "a" : "w");</span></a>
<a name="611"><span class="lineNum">     611 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 21513 times"> + </span>]:<span class="lineCov">      21513 :         if (!fp)</span></a>
<a name="612"><span class="lineNum">     612 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("Can't fopen '%s'", path);</span></a>
<a name="613"><span class="lineNum">     613 </span>                :<span class="lineCov">      21513 :         swap_uid();</span></a>
<a name="614"><span class="lineNum">     614 </span>                :<span class="lineCov">      21513 :         set_cloexec_flag(fileno(fp));</span></a>
<a name="615"><span class="lineNum">     615 </span>                :<span class="lineCov">      21513 :         return fp;</span></a>
<a name="616"><span class="lineNum">     616 </span>                :            : }</a>
<a name="617"><span class="lineNum">     617 </span>                :            : </a>
<a name="618"><span class="lineNum">     618 </span>                :            : static int popen_pid;</a>
<a name="619"><span class="lineNum">     619 </span>                :            : </a>
<a name="620"><span class="lineNum">     620 </span>                :            : #ifndef _PATH_BSHELL</a>
<a name="621"><span class="lineNum">     621 </span>                :            : # define _PATH_BSHELL "/bin/sh"</a>
<a name="622"><span class="lineNum">     622 </span>                :            : #endif</a>
<a name="623"><span class="lineNum">     623 </span>                :            : </a>
<a name="624"><span class="lineNum">     624 </span>                :            : /*</a>
<a name="625"><span class="lineNum">     625 </span>                :            :  * We cannot use standard popen(3) here because we have to distinguish</a>
<a name="626"><span class="lineNum">     626 </span>                :            :  * popen child process from other processes we trace, and standard popen(3)</a>
<a name="627"><span class="lineNum">     627 </span>                :            :  * does not export its child's pid.</a>
<a name="628"><span class="lineNum">     628 </span>                :            :  */</a>
<a name="629"><span class="lineNum">     629 </span>                :            : static FILE *</a>
<a name="630"><span class="lineNum">     630 </span>                :<span class="lineCov">          5 : strace_popen(const char *command)</span></a>
<a name="631"><span class="lineNum">     631 </span>                :            : {</a>
<a name="632"><span class="lineNum">     632 </span>                :<span class="lineCov">          5 :         FILE *fp;</span></a>
<a name="633"><span class="lineNum">     633 </span>                :<span class="lineCov">          5 :         int pid;</span></a>
<a name="634"><span class="lineNum">     634 </span>                :<span class="lineCov">          5 :         int fds[2];</span></a>
<a name="635"><span class="lineNum">     635 </span>                :            : </a>
<a name="636"><span class="lineNum">     636 </span>                :<span class="lineCov">          5 :         swap_uid();</span></a>
<a name="637"><span class="lineNum">     637 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          5 :         if (pipe(fds) < 0)</span></a>
<a name="638"><span class="lineNum">     638 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("pipe");</span></a>
<a name="639"><span class="lineNum">     639 </span>                :            : </a>
<a name="640"><span class="lineNum">     640 </span>                :<span class="lineCov">          5 :         set_cloexec_flag(fds[1]); /* never fails */</span></a>
<a name="641"><span class="lineNum">     641 </span>                :            : </a>
<a name="642"><span class="lineNum">     642 </span>                :<span class="lineCov">          5 :         pid = vfork();</span></a>
<a name="643"><span class="lineNum">     643 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          5 :         if (pid < 0)</span></a>
<a name="644"><span class="lineNum">     644 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("vfork");</span></a>
<a name="645"><span class="lineNum">     645 </span>                :            : </a>
<a name="646"><span class="lineNum">     646 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          5 :         if (pid == 0) {</span></a>
<a name="647"><span class="lineNum">     647 </span>                :            :                 /* child */</a>
<a name="648"><span class="lineNum">     648 </span>                :<span class="lineCov">          5 :                 close(fds[1]);</span></a>
<a name="649"><span class="lineNum">     649 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          5 :                 if (fds[0] != 0) {</span></a>
<a name="650"><span class="lineNum">     650 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          5 :                         if (dup2(fds[0], 0))</span></a>
<a name="651"><span class="lineNum">     651 </span>                :<span class="lineNoCov">          0 :                                 perror_msg_and_die("dup2");</span></a>
<a name="652"><span class="lineNum">     652 </span>                :<span class="lineCov">          5 :                         close(fds[0]);</span></a>
<a name="653"><span class="lineNum">     653 </span>                :            :                 }</a>
<a name="654"><span class="lineNum">     654 </span>                :<span class="lineCov">          5 :                 execl(_PATH_BSHELL, "sh", "-c", command, NULL);</span></a>
<a name="655"><span class="lineNum">     655 </span>                :<span class="lineCov">          5 :                 perror_msg_and_die("Can't execute '%s'", _PATH_BSHELL);</span></a>
<a name="656"><span class="lineNum">     656 </span>                :            :         }</a>
<a name="657"><span class="lineNum">     657 </span>                :            : </a>
<a name="658"><span class="lineNum">     658 </span>                :            :         /* parent */</a>
<a name="659"><span class="lineNum">     659 </span>                :<span class="lineNoCov">          0 :         popen_pid = pid;</span></a>
<a name="660"><span class="lineNum">     660 </span>                :<span class="lineNoCov">          0 :         close(fds[0]);</span></a>
<a name="661"><span class="lineNum">     661 </span>                :<span class="lineNoCov">          0 :         swap_uid();</span></a>
<a name="662"><span class="lineNum">     662 </span>                :<span class="lineNoCov">          0 :         fp = fdopen(fds[1], "w");</span></a>
<a name="663"><span class="lineNum">     663 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (!fp)</span></a>
<a name="664"><span class="lineNum">     664 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("fdopen");</span></a>
<a name="665"><span class="lineNum">     665 </span>                :<span class="lineNoCov">          0 :         return fp;</span></a>
<a name="666"><span class="lineNum">     666 </span>                :            : }</a>
<a name="667"><span class="lineNum">     667 </span>                :            : </a>
<a name="668"><span class="lineNum">     668 </span>                :            : static void</a>
<a name="669"><span class="lineNum">     669 </span>                :<span class="lineCov">          1 : outf_perror(const struct tcb * const tcp)</span></a>
<a name="670"><span class="lineNum">     670 </span>                :            : {</a>
<a name="671"><span class="lineNum">     671 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          1 :         if (tcp->outf == stderr)</span></a>
<a name="672"><span class="lineNum">     672 </span>                :            :                 return;</a>
<a name="673"><span class="lineNum">     673 </span>                :            : </a>
<a name="674"><span class="lineNum">     674 </span>                :            :         /* This is ugly, but we don't store separate file names */</a>
<a name="675"><span class="lineNum">     675 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">          1 :         if (output_separately)</span></a>
<a name="676"><span class="lineNum">     676 </span>                :<span class="lineNoCov">          0 :                 perror_msg("%s.%u", outfname, tcp->pid);</span></a>
<a name="677"><span class="lineNum">     677 </span>                :            :         else</a>
<a name="678"><span class="lineNum">     678 </span>                :<span class="lineCov">          1 :                 perror_msg("%s", outfname);</span></a>
<a name="679"><span class="lineNum">     679 </span>                :            : }</a>
<a name="680"><span class="lineNum">     680 </span>                :            : </a>
<a name="681"><span class="lineNum">     681 </span>                :            : ATTRIBUTE_FORMAT((printf, 1, 0))</a>
<a name="682"><span class="lineNum">     682 </span>                :            : static void</a>
<a name="683"><span class="lineNum">     683 </span>                :<span class="lineCov">    7164213 : tvprintf(const char *const fmt, va_list args)</span></a>
<a name="684"><span class="lineNum">     684 </span>                :            : {</a>
<a name="685"><span class="lineNum">     685 </span>        [<span class="branchCov" title="Branch 0 was taken 7164213 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">    7164213 :         if (current_tcp) {</span></a>
<a name="686"><span class="lineNum">     686 </span>                :<span class="lineCov">    7164213 :                 int n = vfprintf(current_tcp->outf, fmt, args);</span></a>
<a name="687"><span class="lineNum">     687 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 7164213 times"> + </span>]:<span class="lineCov">    7164213 :                 if (n < 0) {</span></a>
<a name="688"><span class="lineNum">     688 </span>                :            :                         /* very unlikely due to vfprintf buffering */</a>
<a name="689"><span class="lineNum">     689 </span>                :<span class="lineNoCov">          0 :                         outf_perror(current_tcp);</span></a>
<a name="690"><span class="lineNum">     690 </span>                :            :                 } else</a>
<a name="691"><span class="lineNum">     691 </span>                :<span class="lineCov">    7164213 :                         current_tcp->curcol += n;</span></a>
<a name="692"><span class="lineNum">     692 </span>                :            :         }</a>
<a name="693"><span class="lineNum">     693 </span>                :<span class="lineCov">    7164213 : }</span></a>
<a name="694"><span class="lineNum">     694 </span>                :            : </a>
<a name="695"><span class="lineNum">     695 </span>                :            : void</a>
<a name="696"><span class="lineNum">     696 </span>                :<span class="lineCov">    7137504 : tprintf(const char *fmt, ...)</span></a>
<a name="697"><span class="lineNum">     697 </span>                :            : {</a>
<a name="698"><span class="lineNum">     698 </span>                :<span class="lineCov">    7137504 :         va_list args;</span></a>
<a name="699"><span class="lineNum">     699 </span>                :<span class="lineCov">    7137504 :         va_start(args, fmt);</span></a>
<a name="700"><span class="lineNum">     700 </span>                :<span class="lineCov">    7137504 :         tvprintf(fmt, args);</span></a>
<a name="701"><span class="lineNum">     701 </span>                :<span class="lineCov">    7137504 :         va_end(args);</span></a>
<a name="702"><span class="lineNum">     702 </span>                :<span class="lineCov">    7137504 : }</span></a>
<a name="703"><span class="lineNum">     703 </span>                :            : </a>
<a name="704"><span class="lineNum">     704 </span>                :            : #ifndef HAVE_FPUTS_UNLOCKED</a>
<a name="705"><span class="lineNum">     705 </span>                :            : # define fputs_unlocked fputs</a>
<a name="706"><span class="lineNum">     706 </span>                :            : #endif</a>
<a name="707"><span class="lineNum">     707 </span>                :            : </a>
<a name="708"><span class="lineNum">     708 </span>                :            : void</a>
<a name="709"><span class="lineNum">     709 </span>                :<span class="lineCov">   10434242 : tprints(const char *str)</span></a>
<a name="710"><span class="lineNum">     710 </span>                :            : {</a>
<a name="711"><span class="lineNum">     711 </span>        [<span class="branchCov" title="Branch 0 was taken 10434242 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">   10434242 :         if (current_tcp) {</span></a>
<a name="712"><span class="lineNum">     712 </span>                :<span class="lineCov">   10434242 :                 int n = fputs_unlocked(str, current_tcp->outf);</span></a>
<a name="713"><span class="lineNum">     713 </span>        [<span class="branchCov" title="Branch 0 was taken 10434242 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">   10434242 :                 if (n >= 0) {</span></a>
<a name="714"><span class="lineNum">     714 </span>                :<span class="lineCov">   10434242 :                         current_tcp->curcol += strlen(str);</span></a>
<a name="715"><span class="lineNum">     715 </span>                :<span class="lineCov">   10434242 :                         return;</span></a>
<a name="716"><span class="lineNum">     716 </span>                :            :                 }</a>
<a name="717"><span class="lineNum">     717 </span>                :            :                 /* very unlikely due to fputs_unlocked buffering */</a>
<a name="718"><span class="lineNum">     718 </span>                :<span class="lineNoCov">          0 :                 outf_perror(current_tcp);</span></a>
<a name="719"><span class="lineNum">     719 </span>                :            :         }</a>
<a name="720"><span class="lineNum">     720 </span>                :            : }</a>
<a name="721"><span class="lineNum">     721 </span>                :            : </a>
<a name="722"><span class="lineNum">     722 </span>                :            : void</a>
<a name="723"><span class="lineNum">     723 </span>                :<span class="lineCov">      70636 : tprints_comment(const char *const str)</span></a>
<a name="724"><span class="lineNum">     724 </span>                :            : {</a>
<a name="725"><span class="lineNum">     725 </span>  [<span class="branchCov" title="Branch 0 was taken 68788 times"> + </span><span class="branchCov" title="Branch 1 was taken 1848 times"> + </span><span class="branchCov" title="Branch 2 was taken 68785 times"> + </span><span class="branchCov" title="Branch 3 was taken 3 times"> + </span>]:<span class="lineCov">      70636 :         if (str && *str)</span></a>
<a name="726"><span class="lineNum">     726 </span>                :<span class="lineCov">      68785 :                 tprintf(" /* %s */", str);</span></a>
<a name="727"><span class="lineNum">     727 </span>                :<span class="lineCov">      70636 : }</span></a>
<a name="728"><span class="lineNum">     728 </span>                :            : </a>
<a name="729"><span class="lineNum">     729 </span>                :            : void</a>
<a name="730"><span class="lineNum">     730 </span>                :<span class="lineCov">      26709 : tprintf_comment(const char *fmt, ...)</span></a>
<a name="731"><span class="lineNum">     731 </span>                :            : {</a>
<a name="732"><span class="lineNum">     732 </span>  [<span class="branchCov" title="Branch 0 was taken 26709 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 26709 times"> + </span>]:<span class="lineCov">      26709 :         if (!fmt || !*fmt)</span></a>
<a name="733"><span class="lineNum">     733 </span>                :<span class="lineNoCov">          0 :                 return;</span></a>
<a name="734"><span class="lineNum">     734 </span>                :            : </a>
<a name="735"><span class="lineNum">     735 </span>                :<span class="lineCov">      26709 :         va_list args;</span></a>
<a name="736"><span class="lineNum">     736 </span>                :<span class="lineCov">      26709 :         va_start(args, fmt);</span></a>
<a name="737"><span class="lineNum">     737 </span>                :<span class="lineCov">      26709 :         tprint_comment_begin();</span></a>
<a name="738"><span class="lineNum">     738 </span>                :<span class="lineCov">      26709 :         tvprintf(fmt, args);</span></a>
<a name="739"><span class="lineNum">     739 </span>                :<span class="lineCov">      26709 :         tprint_comment_end();</span></a>
<a name="740"><span class="lineNum">     740 </span>                :<span class="lineCov">      26709 :         va_end(args);</span></a>
<a name="741"><span class="lineNum">     741 </span>                :            : }</a>
<a name="742"><span class="lineNum">     742 </span>                :            : </a>
<a name="743"><span class="lineNum">     743 </span>                :            : static void</a>
<a name="744"><span class="lineNum">     744 </span>                :<span class="lineCov">    1049280 : flush_tcp_output(const struct tcb *const tcp)</span></a>
<a name="745"><span class="lineNum">     745 </span>                :            : {</a>
<a name="746"><span class="lineNum">     746 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 1049279 times"> + </span>]:<span class="lineCov">    1049280 :         if (fflush(tcp->outf))</span></a>
<a name="747"><span class="lineNum">     747 </span>                :<span class="lineCov">          1 :                 outf_perror(tcp);</span></a>
<a name="748"><span class="lineNum">     748 </span>                :<span class="lineCov">    1049280 : }</span></a>
<a name="749"><span class="lineNum">     749 </span>                :            : </a>
<a name="750"><span class="lineNum">     750 </span>                :            : void</a>
<a name="751"><span class="lineNum">     751 </span>                :<span class="lineCov">    1011280 : line_ended(void)</span></a>
<a name="752"><span class="lineNum">     752 </span>                :            : {</a>
<a name="753"><span class="lineNum">     753 </span>        [<span class="branchCov" title="Branch 0 was taken 1011280 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">    1011280 :         if (current_tcp) {</span></a>
<a name="754"><span class="lineNum">     754 </span>                :<span class="lineCov">    1011280 :                 current_tcp->curcol = 0;</span></a>
<a name="755"><span class="lineNum">     755 </span>                :<span class="lineCov">    1011280 :                 flush_tcp_output(current_tcp);</span></a>
<a name="756"><span class="lineNum">     756 </span>                :            :         }</a>
<a name="757"><span class="lineNum">     757 </span>        [<span class="branchCov" title="Branch 0 was taken 1011280 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">    1011280 :         if (printing_tcp) {</span></a>
<a name="758"><span class="lineNum">     758 </span>                :<span class="lineCov">    1011280 :                 printing_tcp->curcol = 0;</span></a>
<a name="759"><span class="lineNum">     759 </span>                :<span class="lineCov">    1011280 :                 printing_tcp = NULL;</span></a>
<a name="760"><span class="lineNum">     760 </span>                :            :         }</a>
<a name="761"><span class="lineNum">     761 </span>                :<span class="lineCov">    1011280 : }</span></a>
<a name="762"><span class="lineNum">     762 </span>                :            : </a>
<a name="763"><span class="lineNum">     763 </span>                :            : static void</a>
<a name="764"><span class="lineNum">     764 </span>                :<span class="lineCov">  158370206 : set_current_tcp(const struct tcb *tcp)</span></a>
<a name="765"><span class="lineNum">     765 </span>                :            : {</a>
<a name="766"><span class="lineNum">     766 </span>                :<span class="lineCov">  158370206 :         current_tcp = (struct tcb *) tcp;</span></a>
<a name="767"><span class="lineNum">     767 </span>                :            : </a>
<a name="768"><span class="lineNum">     768 </span>                :            :         /* Sync current_personality and stuff */</a>
<a name="769"><span class="lineNum">     769 </span>        [<span class="branchCov" title="Branch 0 was taken 158324532 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">  158324532 :         if (current_tcp)</span></a>
<a name="770"><span class="lineNum">     770 </span>                :<span class="lineCov">  158324532 :                 set_personality(current_tcp->currpers);</span></a>
<a name="771"><span class="lineNum">     771 </span>                :<span class="lineCov">  158370206 : }</span></a>
<a name="772"><span class="lineNum">     772 </span>                :            : </a>
<a name="773"><span class="lineNum">     773 </span>                :            : void</a>
<a name="774"><span class="lineNum">     774 </span>                :<span class="lineCov">    1012074 : printleader(struct tcb *tcp)</span></a>
<a name="775"><span class="lineNum">     775 </span>                :            : {</a>
<a name="776"><span class="lineNum">     776 </span>                :            :         /* If -ff, "previous tcb we printed" is always the same as current,</a>
<a name="777"><span class="lineNum">     777 </span>                :            :          * because we have per-tcb output files.</a>
<a name="778"><span class="lineNum">     778 </span>                :            :          */</a>
<a name="779"><span class="lineNum">     779 </span>        [<span class="branchCov" title="Branch 0 was taken 540962 times"> + </span><span class="branchCov" title="Branch 1 was taken 471112 times"> + </span>]:<span class="lineCov">    1012074 :         if (output_separately)</span></a>
<a name="780"><span class="lineNum">     780 </span>                :<span class="lineCov">     540962 :                 printing_tcp = tcp;</span></a>
<a name="781"><span class="lineNum">     781 </span>                :            : </a>
<a name="782"><span class="lineNum">     782 </span>        [<span class="branchCov" title="Branch 0 was taken 541696 times"> + </span><span class="branchCov" title="Branch 1 was taken 470378 times"> + </span>]:<span class="lineCov">    1012074 :         if (printing_tcp) {</span></a>
<a name="783"><span class="lineNum">     783 </span>                :<span class="lineCov">     541696 :                 set_current_tcp(printing_tcp);</span></a>
<a name="784"><span class="lineNum">     784 </span>  [<span class="branchCov" title="Branch 0 was taken 541694 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span><span class="branchCov" title="Branch 2 was taken 715 times"> + </span><span class="branchCov" title="Branch 3 was taken 540979 times"> + </span>]:<span class="lineCov">     541696 :                 if (!tcp->staged_output_data && printing_tcp->curcol != 0 &&</span></a>
<a name="785"><span class="lineNum">     785 </span>  [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 715 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">        715 :                     (!output_separately || printing_tcp == tcp)) {</span></a>
<a name="786"><span class="lineNum">     786 </span>                :            :                         /*</a>
<a name="787"><span class="lineNum">     787 </span>                :            :                          * case 1: we have a shared log (i.e. not -ff), and last line</a>
<a name="788"><span class="lineNum">     788 </span>                :            :                          * wasn't finished (same or different tcb, doesn't matter).</a>
<a name="789"><span class="lineNum">     789 </span>                :            :                          * case 2: split log, we are the same tcb, but our last line</a>
<a name="790"><span class="lineNum">     790 </span>                :            :                          * didn't finish ("SIGKILL nuked us after syscall entry" etc).</a>
<a name="791"><span class="lineNum">     791 </span>                :            :                          */</a>
<a name="792"><span class="lineNum">     792 </span>                :<span class="lineCov">        715 :                         tprints(" <unfinished ...>\n");</span></a>
<a name="793"><span class="lineNum">     793 </span>                :<span class="lineCov">        715 :                         printing_tcp->curcol = 0;</span></a>
<a name="794"><span class="lineNum">     794 </span>                :            :                 }</a>
<a name="795"><span class="lineNum">     795 </span>                :            :         }</a>
<a name="796"><span class="lineNum">     796 </span>                :            : </a>
<a name="797"><span class="lineNum">     797 </span>                :<span class="lineCov">    1012074 :         printing_tcp = tcp;</span></a>
<a name="798"><span class="lineNum">     798 </span>                :<span class="lineCov">    1012074 :         set_current_tcp(tcp);</span></a>
<a name="799"><span class="lineNum">     799 </span>                :<span class="lineCov">    1012074 :         current_tcp->curcol = 0;</span></a>
<a name="800"><span class="lineNum">     800 </span>                :            : </a>
<a name="801"><span class="lineNum">     801 </span>        [<span class="branchCov" title="Branch 0 was taken 55251 times"> + </span><span class="branchCov" title="Branch 1 was taken 956823 times"> + </span>]:<span class="lineCov">    1012074 :         if (print_pid_pfx)</span></a>
<a name="802"><span class="lineNum">     802 </span>                :<span class="lineCov">      55251 :                 tprintf("%-5d ", tcp->pid);</span></a>
<a name="803"><span class="lineNum">     803 </span>  [<span class="branchCov" title="Branch 0 was taken 536151 times"> + </span><span class="branchCov" title="Branch 1 was taken 420672 times"> + </span><span class="branchCov" title="Branch 2 was taken 3 times"> + </span><span class="branchCov" title="Branch 3 was taken 536148 times"> + </span>]:<span class="lineCov">     956823 :         else if (nprocs > 1 && !outfname)</span></a>
<a name="804"><span class="lineNum">     804 </span>                :<span class="lineCov">          3 :                 tprintf("[pid %5u] ", tcp->pid);</span></a>
<a name="805"><span class="lineNum">     805 </span>                :            : </a>
<a name="806"><span class="lineNum">     806 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="807"><span class="lineNum">     807 </span>                :<span class="lineCov">    1012074 :         char *context;</span></a>
<a name="808"><span class="lineNum">     808 </span>        [<span class="branchCov" title="Branch 0 was taken 656 times"> + </span><span class="branchCov" title="Branch 1 was taken 1011418 times"> + </span>]:<span class="lineCov">    1012074 :         if (!selinux_getpidcon(tcp, &context)) {</span></a>
<a name="809"><span class="lineNum">     809 </span>                :<span class="lineCov">        656 :                 tprintf("[%s] ", context);</span></a>
<a name="810"><span class="lineNum">     810 </span>                :<span class="lineCov">        656 :                 free(context);</span></a>
<a name="811"><span class="lineNum">     811 </span>                :            :         }</a>
<a name="812"><span class="lineNum">     812 </span>                :            : #endif</a>
<a name="813"><span class="lineNum">     813 </span>                :            : </a>
<a name="814"><span class="lineNum">     814 </span>        [<span class="branchCov" title="Branch 0 was taken 64 times"> + </span><span class="branchCov" title="Branch 1 was taken 1012010 times"> + </span>]:<span class="lineCov">    1012074 :         if (tflag_format) {</span></a>
<a name="815"><span class="lineNum">     815 </span>                :<span class="lineCov">         64 :                 struct timespec ts;</span></a>
<a name="816"><span class="lineNum">     816 </span>                :<span class="lineCov">         64 :                 clock_gettime(CLOCK_REALTIME, &ts);</span></a>
<a name="817"><span class="lineNum">     817 </span>                :            : </a>
<a name="818"><span class="lineNum">     818 </span>                :<span class="lineCov">         64 :                 time_t local = ts.tv_sec;</span></a>
<a name="819"><span class="lineNum">     819 </span>                :<span class="lineCov">         64 :                 char str[MAX(sizeof("HH:MM:SS"), sizeof(local) * 3)];</span></a>
<a name="820"><span class="lineNum">     820 </span>                :<span class="lineCov">         64 :                 struct tm *tm = localtime(&local);</span></a>
<a name="821"><span class="lineNum">     821 </span>                :            : </a>
<a name="822"><span class="lineNum">     822 </span>        [<span class="branchCov" title="Branch 0 was taken 64 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         64 :                 if (tm)</span></a>
<a name="823"><span class="lineNum">     823 </span>                :<span class="lineCov">         64 :                         strftime(str, sizeof(str), tflag_format, tm);</span></a>
<a name="824"><span class="lineNum">     824 </span>                :            :                 else</a>
<a name="825"><span class="lineNum">     825 </span>                :<span class="lineNoCov">          0 :                         xsprintf(str, "%lld", (long long) local);</span></a>
<a name="826"><span class="lineNum">     826 </span>        [<span class="branchCov" title="Branch 0 was taken 46 times"> + </span><span class="branchCov" title="Branch 1 was taken 18 times"> + </span>]:<span class="lineCov">         64 :                 if (tflag_width)</span></a>
<a name="827"><span class="lineNum">     827 </span>                :<span class="lineCov">         46 :                         tprintf("%s.%0*ld ", str, tflag_width,</span></a>
<a name="828"><span class="lineNum">     828 </span>                :<span class="lineCov">         46 :                                 (long) ts.tv_nsec / tflag_scale);</span></a>
<a name="829"><span class="lineNum">     829 </span>                :            :                 else</a>
<a name="830"><span class="lineNum">     830 </span>                :<span class="lineCov">         18 :                         tprintf("%s ", str);</span></a>
<a name="831"><span class="lineNum">     831 </span>                :            :         }</a>
<a name="832"><span class="lineNum">     832 </span>                :            : </a>
<a name="833"><span class="lineNum">     833 </span>        [<span class="branchCov" title="Branch 0 was taken 176 times"> + </span><span class="branchCov" title="Branch 1 was taken 1011898 times"> + </span>]:<span class="lineCov">    1012074 :         if (rflag) {</span></a>
<a name="834"><span class="lineNum">     834 </span>                :<span class="lineCov">        176 :                 struct timespec ts;</span></a>
<a name="835"><span class="lineNum">     835 </span>                :<span class="lineCov">        176 :                 clock_gettime(CLOCK_MONOTONIC, &ts);</span></a>
<a name="836"><span class="lineNum">     836 </span>                :            : </a>
<a name="837"><span class="lineNum">     837 </span>                :<span class="lineCov">        176 :                 static struct timespec ots;</span></a>
<a name="838"><span class="lineNum">     838 </span>        [<span class="branchCov" title="Branch 0 was taken 10 times"> + </span><span class="branchCov" title="Branch 1 was taken 166 times"> + </span>]:<span class="lineCov">        176 :                 if (ots.tv_sec == 0)</span></a>
<a name="839"><span class="lineNum">     839 </span>                :<span class="lineCov">         10 :                         ots = ts;</span></a>
<a name="840"><span class="lineNum">     840 </span>                :            : </a>
<a name="841"><span class="lineNum">     841 </span>                :<span class="lineCov">        176 :                 struct timespec dts;</span></a>
<a name="842"><span class="lineNum">     842 </span>                :<span class="lineCov">        176 :                 ts_sub(&dts, &ts, &ots);</span></a>
<a name="843"><span class="lineNum">     843 </span>                :<span class="lineCov">        176 :                 ots = ts;</span></a>
<a name="844"><span class="lineNum">     844 </span>                :            : </a>
<a name="845"><span class="lineNum">     845 </span>        [<span class="branchCov" title="Branch 0 was taken 176 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">        352 :                 tprintf("%s%6ld", tflag_format ? "(+" : "", (long) dts.tv_sec);</span></a>
<a name="846"><span class="lineNum">     846 </span>        [<span class="branchCov" title="Branch 0 was taken 174 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">        176 :                 if (rflag_width) {</span></a>
<a name="847"><span class="lineNum">     847 </span>                :<span class="lineCov">        174 :                         tprintf(".%0*ld",</span></a>
<a name="848"><span class="lineNum">     848 </span>                :<span class="lineCov">        174 :                                 rflag_width, (long) dts.tv_nsec / rflag_scale);</span></a>
<a name="849"><span class="lineNum">     849 </span>                :            :                 }</a>
<a name="850"><span class="lineNum">     850 </span>        [<span class="branchCov" title="Branch 0 was taken 176 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">        352 :                 tprints(tflag_format ? ") " : " ");</span></a>
<a name="851"><span class="lineNum">     851 </span>                :            :         }</a>
<a name="852"><span class="lineNum">     852 </span>                :            : </a>
<a name="853"><span class="lineNum">     853 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 1012073 times"> + </span>]:<span class="lineCov">    1012074 :         if (nflag)</span></a>
<a name="854"><span class="lineNum">     854 </span>                :<span class="lineCov">          1 :                 print_syscall_number(tcp);</span></a>
<a name="855"><span class="lineNum">     855 </span>                :            : </a>
<a name="856"><span class="lineNum">     856 </span>        [<span class="branchCov" title="Branch 0 was taken 53 times"> + </span><span class="branchCov" title="Branch 1 was taken 1012021 times"> + </span>]:<span class="lineCov">    1012074 :         if (iflag)</span></a>
<a name="857"><span class="lineNum">     857 </span>                :<span class="lineCov">         53 :                 print_instruction_pointer(tcp);</span></a>
<a name="858"><span class="lineNum">     858 </span>                :<span class="lineCov">    1012074 : }</span></a>
<a name="859"><span class="lineNum">     859 </span>                :            : </a>
<a name="860"><span class="lineNum">     860 </span>                :            : void</a>
<a name="861"><span class="lineNum">     861 </span>                :<span class="lineCov">     994299 : tabto(void)</span></a>
<a name="862"><span class="lineNum">     862 </span>                :            : {</a>
<a name="863"><span class="lineNum">     863 </span>        [<span class="branchCov" title="Branch 0 was taken 16724 times"> + </span><span class="branchCov" title="Branch 1 was taken 977575 times"> + </span>]:<span class="lineCov">     994299 :         if (current_tcp->curcol < acolumn)</span></a>
<a name="864"><span class="lineNum">     864 </span>                :<span class="lineCov">      16724 :                 tprints(acolumn_spaces + current_tcp->curcol);</span></a>
<a name="865"><span class="lineNum">     865 </span>                :<span class="lineCov">     994299 : }</span></a>
<a name="866"><span class="lineNum">     866 </span>                :            : </a>
<a name="867"><span class="lineNum">     867 </span>                :            : /* Should be only called directly *after successful attach* to a tracee.</a>
<a name="868"><span class="lineNum">     868 </span>                :            :  * Otherwise, "strace -oFILE -ff -p<nonexistant_pid>"</a>
<a name="869"><span class="lineNum">     869 </span>                :            :  * may create bogus empty FILE.<nonexistant_pid>, and then die.</a>
<a name="870"><span class="lineNum">     870 </span>                :            :  */</a>
<a name="871"><span class="lineNum">     871 </span>                :            : static void</a>
<a name="872"><span class="lineNum">     872 </span>                :<span class="lineCov">      45674 : after_successful_attach(struct tcb *tcp, const unsigned int flags)</span></a>
<a name="873"><span class="lineNum">     873 </span>                :            : {</a>
<a name="874"><span class="lineNum">     874 </span>                :<span class="lineCov">      45674 :         tcp->flags |= TCB_ATTACHED | TCB_STARTUP | flags;</span></a>
<a name="875"><span class="lineNum">     875 </span>                :<span class="lineCov">      45674 :         tcp->outf = shared_log; /* if not -ff mode, the same file is for all */</span></a>
<a name="876"><span class="lineNum">     876 </span>        [<span class="branchCov" title="Branch 0 was taken 7686 times"> + </span><span class="branchCov" title="Branch 1 was taken 37988 times"> + </span>]:<span class="lineCov">      45674 :         if (output_separately) {</span></a>
<a name="877"><span class="lineNum">     877 </span>                :<span class="lineCov">       7686 :                 char name[PATH_MAX];</span></a>
<a name="878"><span class="lineNum">     878 </span>                :<span class="lineCov">       7686 :                 xsprintf(name, "%s.%u", outfname, tcp->pid);</span></a>
<a name="879"><span class="lineNum">     879 </span>                :<span class="lineCov">       7686 :                 tcp->outf = strace_fopen(name);</span></a>
<a name="880"><span class="lineNum">     880 </span>                :            :         }</a>
<a name="881"><span class="lineNum">     881 </span>                :            : </a>
<a name="882"><span class="lineNum">     882 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="883"><span class="lineNum">     883 </span>                :            :         if (stack_trace_enabled)</a>
<a name="884"><span class="lineNum">     884 </span>                :            :                 unwind_tcb_init(tcp);</a>
<a name="885"><span class="lineNum">     885 </span>                :            : #endif</a>
<a name="886"><span class="lineNum">     886 </span>                :<span class="lineCov">      45674 : }</span></a>
<a name="887"><span class="lineNum">     887 </span>                :            : </a>
<a name="888"><span class="lineNum">     888 </span>                :            : static void</a>
<a name="889"><span class="lineNum">     889 </span>                :<span class="lineCov">      16635 : expand_tcbtab(void)</span></a>
<a name="890"><span class="lineNum">     890 </span>                :            : {</a>
<a name="891"><span class="lineNum">     891 </span>                :            :         /* Allocate some (more) TCBs (and expand the table).</a>
<a name="892"><span class="lineNum">     892 </span>                :            :            We don't want to relocate the TCBs because our</a>
<a name="893"><span class="lineNum">     893 </span>                :            :            callers have pointers and it would be a pain.</a>
<a name="894"><span class="lineNum">     894 </span>                :            :            So tcbtab is a table of pointers.  Since we never</a>
<a name="895"><span class="lineNum">     895 </span>                :            :            free the TCBs, we allocate a single chunk of many.  */</a>
<a name="896"><span class="lineNum">     896 </span>                :<span class="lineCov">      16635 :         size_t old_tcbtabsize;</span></a>
<a name="897"><span class="lineNum">     897 </span>                :<span class="lineCov">      16635 :         struct tcb *newtcbs;</span></a>
<a name="898"><span class="lineNum">     898 </span>                :<span class="lineCov">      16635 :         struct tcb **tcb_ptr;</span></a>
<a name="899"><span class="lineNum">     899 </span>                :            : </a>
<a name="900"><span class="lineNum">     900 </span>                :<span class="lineCov">      16635 :         old_tcbtabsize = tcbtabsize;</span></a>
<a name="901"><span class="lineNum">     901 </span>                :            : </a>
<a name="902"><span class="lineNum">     902 </span>                :<span class="lineCov">      16635 :         tcbtab = xgrowarray(tcbtab, &tcbtabsize, sizeof(tcbtab[0]));</span></a>
<a name="903"><span class="lineNum">     903 </span>                :<span class="lineCov">      16635 :         newtcbs = xcalloc(tcbtabsize - old_tcbtabsize, sizeof(newtcbs[0]));</span></a>
<a name="904"><span class="lineNum">     904 </span>                :            : </a>
<a name="905"><span class="lineNum">     905 </span>                :<span class="lineCov">      16635 :         for (tcb_ptr = tcbtab + old_tcbtabsize;</span></a>
<a name="906"><span class="lineNum">     906 </span>        [<span class="branchCov" title="Branch 0 was taken 275693 times"> + </span><span class="branchCov" title="Branch 1 was taken 16635 times"> + </span>]:<span class="lineCov">     292328 :             tcb_ptr < tcbtab + tcbtabsize; tcb_ptr++, newtcbs++)</span></a>
<a name="907"><span class="lineNum">     907 </span>                :<span class="lineCov">     275693 :                 *tcb_ptr = newtcbs;</span></a>
<a name="908"><span class="lineNum">     908 </span>                :<span class="lineCov">      16635 : }</span></a>
<a name="909"><span class="lineNum">     909 </span>                :            : </a>
<a name="910"><span class="lineNum">     910 </span>                :            : static struct tcb *</a>
<a name="911"><span class="lineNum">     911 </span>                :<span class="lineCov">      45695 : alloctcb(int pid)</span></a>
<a name="912"><span class="lineNum">     912 </span>                :            : {</a>
<a name="913"><span class="lineNum">     913 </span>                :<span class="lineCov">      45695 :         unsigned int i;</span></a>
<a name="914"><span class="lineNum">     914 </span>                :<span class="lineCov">      45695 :         struct tcb *tcp;</span></a>
<a name="915"><span class="lineNum">     915 </span>                :            : </a>
<a name="916"><span class="lineNum">     916 </span>        [<span class="branchCov" title="Branch 0 was taken 16635 times"> + </span><span class="branchCov" title="Branch 1 was taken 29060 times"> + </span>]:<span class="lineCov">      45695 :         if (nprocs == tcbtabsize)</span></a>
<a name="917"><span class="lineNum">     917 </span>                :<span class="lineCov">      16635 :                 expand_tcbtab();</span></a>
<a name="918"><span class="lineNum">     918 </span>                :            : </a>
<a name="919"><span class="lineNum">     919 </span>        [<span class="branchCov" title="Branch 0 was taken 2143392 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">    2143392 :         for (i = 0; i < tcbtabsize; i++) {</span></a>
<a name="920"><span class="lineNum">     920 </span>                :<span class="lineCov">    2143392 :                 tcp = tcbtab[i];</span></a>
<a name="921"><span class="lineNum">     921 </span>        [<span class="branchCov" title="Branch 0 was taken 45695 times"> + </span><span class="branchCov" title="Branch 1 was taken 2097697 times"> + </span>]:<span class="lineCov">    2143392 :                 if (!tcp->pid) {</span></a>
<a name="922"><span class="lineNum">     922 </span>                :<span class="lineCov">      45695 :                         memset(tcp, 0, sizeof(*tcp));</span></a>
<a name="923"><span class="lineNum">     923 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 45683 times"> + </span>]:<span class="lineCov">      45695 :                         list_init(&tcp->wait_list);</span></a>
<a name="924"><span class="lineNum">     924 </span>                :<span class="lineCov">      45695 :                         tcp->pid = pid;</span></a>
<a name="925"><span class="lineNum">     925 </span>                :            : #if SUPPORTED_PERSONALITIES > 1</a>
<a name="926"><span class="lineNum">     926 </span>                :<span class="lineCov">      45695 :                         tcp->currpers = current_personality;</span></a>
<a name="927"><span class="lineNum">     927 </span>                :            : #endif</a>
<a name="928"><span class="lineNum">     928 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="929"><span class="lineNum">     929 </span>                :<span class="lineCov">      45695 :                         tcp->last_dirfd = AT_FDCWD;</span></a>
<a name="930"><span class="lineNum">     930 </span>                :            : #endif</a>
<a name="931"><span class="lineNum">     931 </span>                :<span class="lineCov">      45695 :                         nprocs++;</span></a>
<a name="932"><span class="lineNum">     932 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 45683 times"> + </span>]:<span class="lineCov">      45695 :                         debug_msg("new tcb for pid %d, active tcbs:%d",</span></a>
<a name="933"><span class="lineNum">     933 </span>                :            :                                   tcp->pid, nprocs);</a>
<a name="934"><span class="lineNum">     934 </span>                :<span class="lineCov">      45695 :                         return tcp;</span></a>
<a name="935"><span class="lineNum">     935 </span>                :            :                 }</a>
<a name="936"><span class="lineNum">     936 </span>                :            :         }</a>
<a name="937"><span class="lineNum">     937 </span>                :<span class="lineNoCov">          0 :         error_msg_and_die("bug in alloctcb");</span></a>
<a name="938"><span class="lineNum">     938 </span>                :            : }</a>
<a name="939"><span class="lineNum">     939 </span>                :            : </a>
<a name="940"><span class="lineNum">     940 </span>                :            : void *</a>
<a name="941"><span class="lineNum">     941 </span>                :<span class="lineCov">       3689 : get_tcb_priv_data(const struct tcb *tcp)</span></a>
<a name="942"><span class="lineNum">     942 </span>                :            : {</a>
<a name="943"><span class="lineNum">     943 </span>                :<span class="lineCov">       3689 :         return tcp->_priv_data;</span></a>
<a name="944"><span class="lineNum">     944 </span>                :            : }</a>
<a name="945"><span class="lineNum">     945 </span>                :            : </a>
<a name="946"><span class="lineNum">     946 </span>                :            : int</a>
<a name="947"><span class="lineNum">     947 </span>                :<span class="lineCov">       4048 : set_tcb_priv_data(struct tcb *tcp, void *const priv_data,</span></a>
<a name="948"><span class="lineNum">     948 </span>                :            :                   void (*const free_priv_data)(void *))</a>
<a name="949"><span class="lineNum">     949 </span>                :            : {</a>
<a name="950"><span class="lineNum">     950 </span>        [<span class="branchCov" title="Branch 0 was taken 4048 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">       4048 :         if (tcp->_priv_data)</span></a>
<a name="951"><span class="lineNum">     951 </span>                :            :                 return -1;</a>
<a name="952"><span class="lineNum">     952 </span>                :            : </a>
<a name="953"><span class="lineNum">     953 </span>                :<span class="lineCov">       4048 :         tcp->_free_priv_data = free_priv_data;</span></a>
<a name="954"><span class="lineNum">     954 </span>                :<span class="lineCov">       4048 :         tcp->_priv_data = priv_data;</span></a>
<a name="955"><span class="lineNum">     955 </span>                :            : </a>
<a name="956"><span class="lineNum">     956 </span>                :<span class="lineCov">       4048 :         return 0;</span></a>
<a name="957"><span class="lineNum">     957 </span>                :            : }</a>
<a name="958"><span class="lineNum">     958 </span>                :            : </a>
<a name="959"><span class="lineNum">     959 </span>                :            : void</a>
<a name="960"><span class="lineNum">     960 </span>                :<span class="lineCov">   78286170 : free_tcb_priv_data(struct tcb *tcp)</span></a>
<a name="961"><span class="lineNum">     961 </span>                :            : {</a>
<a name="962"><span class="lineNum">     962 </span>        [<span class="branchCov" title="Branch 0 was taken 3768 times"> + </span><span class="branchCov" title="Branch 1 was taken 78282402 times"> + </span>]:<span class="lineCov">   78286170 :         if (tcp->_priv_data) {</span></a>
<a name="963"><span class="lineNum">     963 </span>        [<span class="branchCov" title="Branch 0 was taken 1060 times"> + </span><span class="branchCov" title="Branch 1 was taken 2708 times"> + </span>]:<span class="lineCov">       3768 :                 if (tcp->_free_priv_data) {</span></a>
<a name="964"><span class="lineNum">     964 </span>                :<span class="lineCov">       1060 :                         tcp->_free_priv_data(tcp->_priv_data);</span></a>
<a name="965"><span class="lineNum">     965 </span>                :<span class="lineCov">       1060 :                         tcp->_free_priv_data = NULL;</span></a>
<a name="966"><span class="lineNum">     966 </span>                :            :                 }</a>
<a name="967"><span class="lineNum">     967 </span>                :<span class="lineCov">       3768 :                 tcp->_priv_data = NULL;</span></a>
<a name="968"><span class="lineNum">     968 </span>                :            :         }</a>
<a name="969"><span class="lineNum">     969 </span>                :<span class="lineCov">   78286170 : }</span></a>
<a name="970"><span class="lineNum">     970 </span>                :            : </a>
<a name="971"><span class="lineNum">     971 </span>                :            : static void</a>
<a name="972"><span class="lineNum">     972 </span>                :<span class="lineCov">      45703 : droptcb(struct tcb *tcp)</span></a>
<a name="973"><span class="lineNum">     973 </span>                :            : {</a>
<a name="974"><span class="lineNum">     974 </span>        [<span class="branchCov" title="Branch 0 was taken 45703 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      45703 :         if (tcp->pid == 0)</span></a>
<a name="975"><span class="lineNum">     975 </span>                :            :                 return;</a>
<a name="976"><span class="lineNum">     976 </span>                :            : </a>
<a name="977"><span class="lineNum">     977 </span>  [<span class="branchCov" title="Branch 0 was taken 74 times"> + </span><span class="branchCov" title="Branch 1 was taken 45629 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 74 times"> + </span>]:<span class="lineCov">      45703 :         if (cflag && debug_flag) {</span></a>
<a name="978"><span class="lineNum">     978 </span>                :<span class="lineNoCov">          0 :                 struct timespec dt;</span></a>
<a name="979"><span class="lineNum">     979 </span>                :            : </a>
<a name="980"><span class="lineNum">     980 </span>                :<span class="lineNoCov">          0 :                 ts_sub(&dt, &tcp->stime, &tcp->atime);</span></a>
<a name="981"><span class="lineNum">     981 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 debug_func_msg("pid %d: %.9f seconds of system time spent "</span></a>
<a name="982"><span class="lineNum">     982 </span>                :            :                                "since attach", tcp->pid, ts_float(&dt));</a>
<a name="983"><span class="lineNum">     983 </span>                :            :         }</a>
<a name="984"><span class="lineNum">     984 </span>                :            : </a>
<a name="985"><span class="lineNum">     985 </span>                :            :         int p;</a>
<a name="986"><span class="lineNum">     986 </span>        [<span class="branchCov" title="Branch 0 was taken 137109 times"> + </span><span class="branchCov" title="Branch 1 was taken 45703 times"> + </span>]:<span class="lineCov">     182812 :         for (p = 0; p < SUPPORTED_PERSONALITIES; ++p)</span></a>
<a name="987"><span class="lineNum">     987 </span>                :<span class="lineCov">     137109 :                 free(tcp->inject_vec[p]);</span></a>
<a name="988"><span class="lineNum">     988 </span>                :            : </a>
<a name="989"><span class="lineNum">     989 </span>                :<span class="lineCov">      45703 :         free_tcb_priv_data(tcp);</span></a>
<a name="990"><span class="lineNum">     990 </span>                :            : </a>
<a name="991"><span class="lineNum">     991 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="992"><span class="lineNum">     992 </span>                :            :         if (stack_trace_enabled)</a>
<a name="993"><span class="lineNum">     993 </span>                :            :                 unwind_tcb_fin(tcp);</a>
<a name="994"><span class="lineNum">     994 </span>                :            : #endif</a>
<a name="995"><span class="lineNum">     995 </span>                :            : </a>
<a name="996"><span class="lineNum">     996 </span>                :            : #ifdef HAVE_LINUX_KVM_H</a>
<a name="997"><span class="lineNum">     997 </span>                :<span class="lineCov">      45703 :         kvm_vcpu_info_free(tcp);</span></a>
<a name="998"><span class="lineNum">     998 </span>                :            : #endif</a>
<a name="999"><span class="lineNum">     999 </span>                :            : </a>
<a name="1000"><span class="lineNum">    1000 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 45702 times"> + </span>]:<span class="lineCov">      45703 :         if (tcp->mmap_cache)</span></a>
<a name="1001"><span class="lineNum">    1001 </span>                :<span class="lineCov">          1 :                 tcp->mmap_cache->free_fn(tcp, __func__);</span></a>
<a name="1002"><span class="lineNum">    1002 </span>                :            : </a>
<a name="1003"><span class="lineNum">    1003 </span>                :<span class="lineCov">      45703 :         nprocs--;</span></a>
<a name="1004"><span class="lineNum">    1004 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 45691 times"> + </span>]:<span class="lineCov">      45703 :         debug_msg("dropped tcb for pid %d, %d remain", tcp->pid, nprocs);</span></a>
<a name="1005"><span class="lineNum">    1005 </span>                :            : </a>
<a name="1006"><span class="lineNum">    1006 </span>        [<span class="branchCov" title="Branch 0 was taken 45674 times"> + </span><span class="branchCov" title="Branch 1 was taken 29 times"> + </span>]:<span class="lineCov">      45703 :         if (tcp->outf) {</span></a>
<a name="1007"><span class="lineNum">    1007 </span>                :<span class="lineCov">      45674 :                 bool publish = true;</span></a>
<a name="1008"><span class="lineNum">    1008 </span>        [<span class="branchCov" title="Branch 0 was taken 16 times"> + </span><span class="branchCov" title="Branch 1 was taken 45658 times"> + </span>]:<span class="lineCov">      45674 :                 if (!is_complete_set(status_set, NUMBER_OF_STATUSES)) {</span></a>
<a name="1009"><span class="lineNum">    1009 </span>                :<span class="lineCov">         16 :                         publish = is_number_in_set(STATUS_DETACHED, status_set);</span></a>
<a name="1010"><span class="lineNum">    1010 </span>                :<span class="lineCov">         16 :                         strace_close_memstream(tcp, publish);</span></a>
<a name="1011"><span class="lineNum">    1011 </span>                :            :                 }</a>
<a name="1012"><span class="lineNum">    1012 </span>                :            : </a>
<a name="1013"><span class="lineNum">    1013 </span>        [<span class="branchCov" title="Branch 0 was taken 7686 times"> + </span><span class="branchCov" title="Branch 1 was taken 37988 times"> + </span>]:<span class="lineCov">      45674 :                 if (output_separately) {</span></a>
<a name="1014"><span class="lineNum">    1014 </span>  [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 7686 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">       7686 :                         if (tcp->curcol != 0 && publish)</span></a>
<a name="1015"><span class="lineNum">    1015 </span>                :<span class="lineNoCov">          0 :                                 fprintf(tcp->outf, " <detached ...>\n");</span></a>
<a name="1016"><span class="lineNum">    1016 </span>                :<span class="lineCov">       7686 :                         fclose(tcp->outf);</span></a>
<a name="1017"><span class="lineNum">    1017 </span>                :            :                 } else {</a>
<a name="1018"><span class="lineNum">    1018 </span>  [<span class="branchCov" title="Branch 0 was taken 60 times"> + </span><span class="branchCov" title="Branch 1 was taken 37928 times"> + </span><span class="branchCov" title="Branch 2 was taken 60 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span> :<span class="lineCov">      37988 :                         if (printing_tcp == tcp && tcp->curcol != 0 && publish)</span></a>
<span class="lineNum">         </span>         <span class="branchCov" title="Branch 4 was taken 60 times"> + </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>]
<a name="1019"><span class="lineNum">    1019 </span>                :<span class="lineCov">         60 :                                 fprintf(tcp->outf, " <detached ...>\n");</span></a>
<a name="1020"><span class="lineNum">    1020 </span>                :<span class="lineCov">      37988 :                         flush_tcp_output(tcp);</span></a>
<a name="1021"><span class="lineNum">    1021 </span>                :            :                 }</a>
<a name="1022"><span class="lineNum">    1022 </span>                :            :         }</a>
<a name="1023"><span class="lineNum">    1023 </span>                :            : </a>
<a name="1024"><span class="lineNum">    1024 </span>        [<span class="branchCov" title="Branch 0 was taken 45674 times"> + </span><span class="branchCov" title="Branch 1 was taken 29 times"> + </span>]:<span class="lineCov">      45703 :         if (current_tcp == tcp)</span></a>
<a name="1025"><span class="lineNum">    1025 </span>                :<span class="lineCov">      45674 :                 set_current_tcp(NULL);</span></a>
<a name="1026"><span class="lineNum">    1026 </span>        [<span class="branchCov" title="Branch 0 was taken 60 times"> + </span><span class="branchCov" title="Branch 1 was taken 45643 times"> + </span>]:<span class="lineCov">      45703 :         if (printing_tcp == tcp)</span></a>
<a name="1027"><span class="lineNum">    1027 </span>                :<span class="lineCov">         60 :                 printing_tcp = NULL;</span></a>
<a name="1028"><span class="lineNum">    1028 </span>                :            : </a>
<a name="1029"><span class="lineNum">    1029 </span>                :<span class="lineCov">      45703 :         list_remove(&tcp->wait_list);</span></a>
<a name="1030"><span class="lineNum">    1030 </span>                :            : </a>
<a name="1031"><span class="lineNum">    1031 </span>                :<span class="lineCov">      45703 :         memset(tcp, 0, sizeof(*tcp));</span></a>
<a name="1032"><span class="lineNum">    1032 </span>                :            : }</a>
<a name="1033"><span class="lineNum">    1033 </span>                :            : </a>
<a name="1034"><span class="lineNum">    1034 </span>                :            : /* Detach traced process.</a>
<a name="1035"><span class="lineNum">    1035 </span>                :            :  * Never call DETACH twice on the same process as both unattached and</a>
<a name="1036"><span class="lineNum">    1036 </span>                :            :  * attached-unstopped processes give the same ESRCH.  For unattached process we</a>
<a name="1037"><span class="lineNum">    1037 </span>                :            :  * would SIGSTOP it and wait for its SIGSTOP notification forever.</a>
<a name="1038"><span class="lineNum">    1038 </span>                :            :  */</a>
<a name="1039"><span class="lineNum">    1039 </span>                :            : static void</a>
<a name="1040"><span class="lineNum">    1040 </span>                :<span class="lineCov">         34 : detach(struct tcb *tcp)</span></a>
<a name="1041"><span class="lineNum">    1041 </span>                :            : {</a>
<a name="1042"><span class="lineNum">    1042 </span>                :<span class="lineCov">         34 :         int error;</span></a>
<a name="1043"><span class="lineNum">    1043 </span>                :<span class="lineCov">         34 :         int status;</span></a>
<a name="1044"><span class="lineNum">    1044 </span>                :            : </a>
<a name="1045"><span class="lineNum">    1045 </span>                :            :         /*</a>
<a name="1046"><span class="lineNum">    1046 </span>                :            :          * Linux wrongly insists the child be stopped</a>
<a name="1047"><span class="lineNum">    1047 </span>                :            :          * before detaching.  Arghh.  We go through hoops</a>
<a name="1048"><span class="lineNum">    1048 </span>                :            :          * to make a clean break of things.</a>
<a name="1049"><span class="lineNum">    1049 </span>                :            :          */</a>
<a name="1050"><span class="lineNum">    1050 </span>                :            : </a>
<a name="1051"><span class="lineNum">    1051 </span>        [<span class="branchCov" title="Branch 0 was taken 28 times"> + </span><span class="branchCov" title="Branch 1 was taken 6 times"> + </span>]:<span class="lineCov">         34 :         if (!(tcp->flags & TCB_ATTACHED))</span></a>
<a name="1052"><span class="lineNum">    1052 </span>                :<span class="lineCov">         28 :                 goto drop;</span></a>
<a name="1053"><span class="lineNum">    1053 </span>                :            : </a>
<a name="1054"><span class="lineNum">    1054 </span>                :            :         /* We attached but possibly didn't see the expected SIGSTOP.</a>
<a name="1055"><span class="lineNum">    1055 </span>                :            :          * We must catch exactly one as otherwise the detached process</a>
<a name="1056"><span class="lineNum">    1056 </span>                :            :          * would be left stopped (process state T).</a>
<a name="1057"><span class="lineNum">    1057 </span>                :            :          */</a>
<a name="1058"><span class="lineNum">    1058 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 6 times"> + </span>]:<span class="lineCov">          6 :         if (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)</span></a>
<a name="1059"><span class="lineNum">    1059 </span>                :<span class="lineNoCov">          0 :                 goto wait_loop;</span></a>
<a name="1060"><span class="lineNum">    1060 </span>                :            : </a>
<a name="1061"><span class="lineNum">    1061 </span>                :<span class="lineCov">          6 :         error = ptrace(PTRACE_DETACH, tcp->pid, 0, 0);</span></a>
<a name="1062"><span class="lineNum">    1062 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          6 :         if (!error) {</span></a>
<a name="1063"><span class="lineNum">    1063 </span>                :            :                 /* On a clear day, you can see forever. */</a>
<a name="1064"><span class="lineNum">    1064 </span>                :<span class="lineCov">          2 :                 goto drop;</span></a>
<a name="1065"><span class="lineNum">    1065 </span>                :            :         }</a>
<a name="1066"><span class="lineNum">    1066 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          4 :         if (errno != ESRCH) {</span></a>
<a name="1067"><span class="lineNum">    1067 </span>                :            :                 /* Shouldn't happen. */</a>
<a name="1068"><span class="lineNum">    1068 </span>                :<span class="lineNoCov">          0 :                 perror_func_msg("ptrace(PTRACE_DETACH,%u)", tcp->pid);</span></a>
<a name="1069"><span class="lineNum">    1069 </span>                :<span class="lineNoCov">          0 :                 goto drop;</span></a>
<a name="1070"><span class="lineNum">    1070 </span>                :            :         }</a>
<a name="1071"><span class="lineNum">    1071 </span>                :            :         /* ESRCH: process is either not stopped or doesn't exist. */</a>
<a name="1072"><span class="lineNum">    1072 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          4 :         if (my_tkill(tcp->pid, 0) < 0) {</span></a>
<a name="1073"><span class="lineNum">    1073 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (errno != ESRCH)</span></a>
<a name="1074"><span class="lineNum">    1074 </span>                :            :                         /* Shouldn't happen. */</a>
<a name="1075"><span class="lineNum">    1075 </span>                :<span class="lineNoCov">          0 :                         perror_func_msg("tkill(%u,0)", tcp->pid);</span></a>
<a name="1076"><span class="lineNum">    1076 </span>                :            :                 /* else: process doesn't exist. */</a>
<a name="1077"><span class="lineNum">    1077 </span>                :<span class="lineNoCov">          0 :                 goto drop;</span></a>
<a name="1078"><span class="lineNum">    1078 </span>                :            :         }</a>
<a name="1079"><span class="lineNum">    1079 </span>                :            :         /* Process is not stopped, need to stop it. */</a>
<a name="1080"><span class="lineNum">    1080 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          4 :         if (use_seize) {</span></a>
<a name="1081"><span class="lineNum">    1081 </span>                :            :                 /*</a>
<a name="1082"><span class="lineNum">    1082 </span>                :            :                  * With SEIZE, tracee can be in group-stop already.</a>
<a name="1083"><span class="lineNum">    1083 </span>                :            :                  * In this state sending it another SIGSTOP does nothing.</a>
<a name="1084"><span class="lineNum">    1084 </span>                :            :                  * Need to use INTERRUPT.</a>
<a name="1085"><span class="lineNum">    1085 </span>                :            :                  * Testcase: trying to ^C a "strace -p <stopped_process>".</a>
<a name="1086"><span class="lineNum">    1086 </span>                :            :                  */</a>
<a name="1087"><span class="lineNum">    1087 </span>                :<span class="lineCov">          4 :                 error = ptrace(PTRACE_INTERRUPT, tcp->pid, 0, 0);</span></a>
<a name="1088"><span class="lineNum">    1088 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          4 :                 if (!error)</span></a>
<a name="1089"><span class="lineNum">    1089 </span>                :<span class="lineCov">          4 :                         goto wait_loop;</span></a>
<a name="1090"><span class="lineNum">    1090 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (errno != ESRCH)</span></a>
<a name="1091"><span class="lineNum">    1091 </span>                :<span class="lineNoCov">          0 :                         perror_func_msg("ptrace(PTRACE_INTERRUPT,%u)", tcp->pid);</span></a>
<a name="1092"><span class="lineNum">    1092 </span>                :            :         } else {</a>
<a name="1093"><span class="lineNum">    1093 </span>                :<span class="lineNoCov">          0 :                 error = my_tkill(tcp->pid, SIGSTOP);</span></a>
<a name="1094"><span class="lineNum">    1094 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (!error)</span></a>
<a name="1095"><span class="lineNum">    1095 </span>                :<span class="lineNoCov">          0 :                         goto wait_loop;</span></a>
<a name="1096"><span class="lineNum">    1096 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (errno != ESRCH)</span></a>
<a name="1097"><span class="lineNum">    1097 </span>                :<span class="lineNoCov">          0 :                         perror_func_msg("tkill(%u,SIGSTOP)", tcp->pid);</span></a>
<a name="1098"><span class="lineNum">    1098 </span>                :            :         }</a>
<a name="1099"><span class="lineNum">    1099 </span>                :            :         /* Either process doesn't exist, or some weird error. */</a>
<a name="1100"><span class="lineNum">    1100 </span>                :<span class="lineNoCov">          0 :         goto drop;</span></a>
<a name="1101"><span class="lineNum">    1101 </span>                :            : </a>
<a name="1102"><span class="lineNum">    1102 </span>                :            :  wait_loop:</a>
<a name="1103"><span class="lineNum">    1103 </span>                :            :         /* We end up here in three cases:</a>
<a name="1104"><span class="lineNum">    1104 </span>                :            :          * 1. We sent PTRACE_INTERRUPT (use_seize case)</a>
<a name="1105"><span class="lineNum">    1105 </span>                :            :          * 2. We sent SIGSTOP (!use_seize)</a>
<a name="1106"><span class="lineNum">    1106 </span>                :            :          * 3. Attach SIGSTOP was already pending (TCB_IGNORE_ONE_SIGSTOP set)</a>
<a name="1107"><span class="lineNum">    1107 </span>                :            :          */</a>
<a name="1108"><span class="lineNum">    1108 </span>                :<span class="lineCov">          4 :         for (;;) {</span></a>
<a name="1109"><span class="lineNum">    1109 </span>                :<span class="lineCov">          4 :                 unsigned int sig;</span></a>
<a name="1110"><span class="lineNum">    1110 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          4 :                 if (waitpid(tcp->pid, &status, __WALL) < 0) {</span></a>
<a name="1111"><span class="lineNum">    1111 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                         if (errno == EINTR)</span></a>
<a name="1112"><span class="lineNum">    1112 </span>                :<span class="lineNoCov">          0 :                                 continue;</span></a>
<a name="1113"><span class="lineNum">    1113 </span>                :            :                         /*</a>
<a name="1114"><span class="lineNum">    1114 </span>                :            :                          * if (errno == ECHILD) break;</a>
<a name="1115"><span class="lineNum">    1115 </span>                :            :                          * ^^^  WRONG! We expect this PID to exist,</a>
<a name="1116"><span class="lineNum">    1116 </span>                :            :                          * and want to emit a message otherwise:</a>
<a name="1117"><span class="lineNum">    1117 </span>                :            :                          */</a>
<a name="1118"><span class="lineNum">    1118 </span>                :<span class="lineNoCov">          0 :                         perror_func_msg("waitpid(%u)", tcp->pid);</span></a>
<a name="1119"><span class="lineNum">    1119 </span>                :<span class="lineNoCov">          0 :                         break;</span></a>
<a name="1120"><span class="lineNum">    1120 </span>                :            :                 }</a>
<a name="1121"><span class="lineNum">    1121 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          4 :                 if (!WIFSTOPPED(status)) {</span></a>
<a name="1122"><span class="lineNum">    1122 </span>                :            :                         /*</a>
<a name="1123"><span class="lineNum">    1123 </span>                :            :                          * Tracee exited or was killed by signal.</a>
<a name="1124"><span class="lineNum">    1124 </span>                :            :                          * We shouldn't normally reach this place:</a>
<a name="1125"><span class="lineNum">    1125 </span>                :            :                          * we don't want to consume exit status.</a>
<a name="1126"><span class="lineNum">    1126 </span>                :            :                          * Consider "strace -p PID" being ^C-ed:</a>
<a name="1127"><span class="lineNum">    1127 </span>                :            :                          * we want merely to detach from PID.</a>
<a name="1128"><span class="lineNum">    1128 </span>                :            :                          *</a>
<a name="1129"><span class="lineNum">    1129 </span>                :            :                          * However, we _can_ end up here if tracee</a>
<a name="1130"><span class="lineNum">    1130 </span>                :            :                          * was SIGKILLed.</a>
<a name="1131"><span class="lineNum">    1131 </span>                :            :                          */</a>
<a name="1132"><span class="lineNum">    1132 </span>                :            :                         break;</a>
<a name="1133"><span class="lineNum">    1133 </span>                :            :                 }</a>
<a name="1134"><span class="lineNum">    1134 </span>                :<span class="lineCov">          4 :                 sig = WSTOPSIG(status);</span></a>
<a name="1135"><span class="lineNum">    1135 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          4 :                 debug_msg("detach wait: event:%d sig:%d",</span></a>
<a name="1136"><span class="lineNum">    1136 </span>                :            :                           (unsigned) status >> 16, sig);</a>
<a name="1137"><span class="lineNum">    1137 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          4 :                 if (use_seize) {</span></a>
<a name="1138"><span class="lineNum">    1138 </span>                :<span class="lineCov">          4 :                         unsigned event = (unsigned)status >> 16;</span></a>
<a name="1139"><span class="lineNum">    1139 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          4 :                         if (event == PTRACE_EVENT_STOP /*&& sig == SIGTRAP*/) {</span></a>
<a name="1140"><span class="lineNum">    1140 </span>                :            :                                 /*</a>
<a name="1141"><span class="lineNum">    1141 </span>                :            :                                  * sig == SIGTRAP: PTRACE_INTERRUPT stop.</a>
<a name="1142"><span class="lineNum">    1142 </span>                :            :                                  * sig == other: process was already stopped</a>
<a name="1143"><span class="lineNum">    1143 </span>                :            :                                  * with this stopping sig (see tests/detach-stopped).</a>
<a name="1144"><span class="lineNum">    1144 </span>                :            :                                  * Looks like re-injecting this sig is not necessary</a>
<a name="1145"><span class="lineNum">    1145 </span>                :            :                                  * in DETACH for the tracee to remain stopped.</a>
<a name="1146"><span class="lineNum">    1146 </span>                :            :                                  */</a>
<a name="1147"><span class="lineNum">    1147 </span>                :            :                                 sig = 0;</a>
<a name="1148"><span class="lineNum">    1148 </span>                :            :                         }</a>
<a name="1149"><span class="lineNum">    1149 </span>                :            :                         /*</a>
<a name="1150"><span class="lineNum">    1150 </span>                :            :                          * PTRACE_INTERRUPT is not guaranteed to produce</a>
<a name="1151"><span class="lineNum">    1151 </span>                :            :                          * the above event if other ptrace-stop is pending.</a>
<a name="1152"><span class="lineNum">    1152 </span>                :            :                          * See tests/detach-sleeping testcase:</a>
<a name="1153"><span class="lineNum">    1153 </span>                :            :                          * strace got SIGINT while tracee is sleeping.</a>
<a name="1154"><span class="lineNum">    1154 </span>                :            :                          * We sent PTRACE_INTERRUPT.</a>
<a name="1155"><span class="lineNum">    1155 </span>                :            :                          * We see syscall exit, not PTRACE_INTERRUPT stop.</a>
<a name="1156"><span class="lineNum">    1156 </span>                :            :                          * We won't get PTRACE_INTERRUPT stop</a>
<a name="1157"><span class="lineNum">    1157 </span>                :            :                          * if we would CONT now. Need to DETACH.</a>
<a name="1158"><span class="lineNum">    1158 </span>                :            :                          */</a>
<a name="1159"><span class="lineNum">    1159 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          2 :                         if (sig == syscall_trap_sig)</span></a>
<a name="1160"><span class="lineNum">    1160 </span>                :<span class="lineCov">          2 :                                 sig = 0;</span></a>
<a name="1161"><span class="lineNum">    1161 </span>                :            :                         /* else: not sure in which case we can be here.</a>
<a name="1162"><span class="lineNum">    1162 </span>                :            :                          * Signal stop? Inject it while detaching.</a>
<a name="1163"><span class="lineNum">    1163 </span>                :            :                          */</a>
<a name="1164"><span class="lineNum">    1164 </span>                :<span class="lineCov">          4 :                         ptrace_restart(PTRACE_DETACH, tcp, sig);</span></a>
<a name="1165"><span class="lineNum">    1165 </span>                :<span class="lineCov">          4 :                         break;</span></a>
<a name="1166"><span class="lineNum">    1166 </span>                :            :                 }</a>
<a name="1167"><span class="lineNum">    1167 </span>                :            :                 /* Note: this check has to be after use_seize check */</a>
<a name="1168"><span class="lineNum">    1168 </span>                :            :                 /* (else, in use_seize case SIGSTOP will be mistreated) */</a>
<a name="1169"><span class="lineNum">    1169 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (sig == SIGSTOP) {</span></a>
<a name="1170"><span class="lineNum">    1170 </span>                :            :                         /* Detach, suppressing SIGSTOP */</a>
<a name="1171"><span class="lineNum">    1171 </span>                :<span class="lineNoCov">          0 :                         ptrace_restart(PTRACE_DETACH, tcp, 0);</span></a>
<a name="1172"><span class="lineNum">    1172 </span>                :<span class="lineNoCov">          0 :                         break;</span></a>
<a name="1173"><span class="lineNum">    1173 </span>                :            :                 }</a>
<a name="1174"><span class="lineNum">    1174 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (sig == syscall_trap_sig)</span></a>
<a name="1175"><span class="lineNum">    1175 </span>                :<span class="lineNoCov">          0 :                         sig = 0;</span></a>
<a name="1176"><span class="lineNum">    1176 </span>                :            :                 /* Can't detach just yet, may need to wait for SIGSTOP */</a>
<a name="1177"><span class="lineNum">    1177 </span>                :<span class="lineNoCov">          0 :                 error = ptrace_restart(PTRACE_CONT, tcp, sig);</span></a>
<a name="1178"><span class="lineNum">    1178 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (error < 0) {</span></a>
<a name="1179"><span class="lineNum">    1179 </span>                :            :                         /* Should not happen.</a>
<a name="1180"><span class="lineNum">    1180 </span>                :            :                          * Note: ptrace_restart returns 0 on ESRCH, so it's not it.</a>
<a name="1181"><span class="lineNum">    1181 </span>                :            :                          * ptrace_restart already emitted error message.</a>
<a name="1182"><span class="lineNum">    1182 </span>                :            :                          */</a>
<a name="1183"><span class="lineNum">    1183 </span>                :            :                         break;</a>
<a name="1184"><span class="lineNum">    1184 </span>                :            :                 }</a>
<a name="1185"><span class="lineNum">    1185 </span>                :            :         }</a>
<a name="1186"><span class="lineNum">    1186 </span>                :            : </a>
<a name="1187"><span class="lineNum">    1187 </span>                :<span class="lineNoCov">          0 :  drop:</span></a>
<a name="1188"><span class="lineNum">    1188 </span>        [<span class="branchCov" title="Branch 0 was taken 31 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">         34 :         if (!is_number_in_set(QUIET_ATTACH, quiet_set)</span></a>
<a name="1189"><span class="lineNum">    1189 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 26 times"> + </span>]:<span class="lineCov">         31 :             && (tcp->flags & TCB_ATTACHED))</span></a>
<a name="1190"><span class="lineNum">    1190 </span>                :<span class="lineCov">          5 :                 error_msg("Process %u detached", tcp->pid);</span></a>
<a name="1191"><span class="lineNum">    1191 </span>                :            : </a>
<a name="1192"><span class="lineNum">    1192 </span>                :<span class="lineCov">         34 :         droptcb(tcp);</span></a>
<a name="1193"><span class="lineNum">    1193 </span>                :<span class="lineCov">         34 : }</span></a>
<a name="1194"><span class="lineNum">    1194 </span>                :            : </a>
<a name="1195"><span class="lineNum">    1195 </span>                :            : static void</a>
<a name="1196"><span class="lineNum">    1196 </span>                :<span class="lineCov">         42 : process_opt_p_list(char *opt)</span></a>
<a name="1197"><span class="lineNum">    1197 </span>                :            : {</a>
<a name="1198"><span class="lineNum">    1198 </span>        [<span class="branchCov" title="Branch 0 was taken 44 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         44 :         while (*opt) {</span></a>
<a name="1199"><span class="lineNum">    1199 </span>                :            :                 /*</a>
<a name="1200"><span class="lineNum">    1200 </span>                :            :                  * We accept -p PID,PID; -p "`pidof PROG`"; -p "`pgrep PROG`".</a>
<a name="1201"><span class="lineNum">    1201 </span>                :            :                  * pidof uses space as delim, pgrep uses newline. :(</a>
<a name="1202"><span class="lineNum">    1202 </span>                :            :                  */</a>
<a name="1203"><span class="lineNum">    1203 </span>                :<span class="lineCov">         44 :                 int pid;</span></a>
<a name="1204"><span class="lineNum">    1204 </span>                :<span class="lineCov">         44 :                 char *delim = opt + strcspn(opt, "\n\t ,");</span></a>
<a name="1205"><span class="lineNum">    1205 </span>                :<span class="lineCov">         44 :                 char c = *delim;</span></a>
<a name="1206"><span class="lineNum">    1206 </span>                :            : </a>
<a name="1207"><span class="lineNum">    1207 </span>                :<span class="lineCov">         44 :                 *delim = '\0';</span></a>
<a name="1208"><span class="lineNum">    1208 </span>                :<span class="lineCov">         44 :                 pid = string_to_uint(opt);</span></a>
<a name="1209"><span class="lineNum">    1209 </span>        [<span class="branchCov" title="Branch 0 was taken 8 times"> + </span><span class="branchCov" title="Branch 1 was taken 36 times"> + </span>]:<span class="lineCov">         44 :                 if (pid <= 0) {</span></a>
<a name="1210"><span class="lineNum">    1210 </span>                :<span class="lineCov">          8 :                         error_msg_and_die("Invalid process id: '%s'", opt);</span></a>
<a name="1211"><span class="lineNum">    1211 </span>                :            :                 }</a>
<a name="1212"><span class="lineNum">    1212 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 36 times"> + </span>]:<span class="lineCov">         36 :                 if (pid == strace_tracer_pid) {</span></a>
<a name="1213"><span class="lineNum">    1213 </span>                :<span class="lineNoCov">          0 :                         error_msg_and_die("I'm sorry, I can't let you do that, Dave.");</span></a>
<a name="1214"><span class="lineNum">    1214 </span>                :            :                 }</a>
<a name="1215"><span class="lineNum">    1215 </span>                :<span class="lineCov">         36 :                 *delim = c;</span></a>
<a name="1216"><span class="lineNum">    1216 </span>                :<span class="lineCov">         36 :                 alloctcb(pid);</span></a>
<a name="1217"><span class="lineNum">    1217 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 34 times"> + </span>]:<span class="lineCov">         36 :                 if (c == '\0')</span></a>
<a name="1218"><span class="lineNum">    1218 </span>                :            :                         break;</a>
<a name="1219"><span class="lineNum">    1219 </span>                :<span class="lineCov">          2 :                 opt = delim + 1;</span></a>
<a name="1220"><span class="lineNum">    1220 </span>                :            :         }</a>
<a name="1221"><span class="lineNum">    1221 </span>                :<span class="lineCov">         34 : }</span></a>
<a name="1222"><span class="lineNum">    1222 </span>                :            : </a>
<a name="1223"><span class="lineNum">    1223 </span>                :            : static void</a>
<a name="1224"><span class="lineNum">    1224 </span>                :<span class="lineCov">         16 : attach_tcb(struct tcb *const tcp)</span></a>
<a name="1225"><span class="lineNum">    1225 </span>                :            : {</a>
<a name="1226"><span class="lineNum">    1226 </span>                :<span class="lineCov">         16 :         const char *ptrace_attach_cmd;</span></a>
<a name="1227"><span class="lineNum">    1227 </span>                :            : </a>
<a name="1228"><span class="lineNum">    1228 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov">         16 :         if (ptrace_attach_or_seize(tcp->pid, &ptrace_attach_cmd) < 0) {</span></a>
<a name="1229"><span class="lineNum">    1229 </span>                :<span class="lineCov">          1 :                 perror_msg("attach: ptrace(%s, %d)",</span></a>
<a name="1230"><span class="lineNum">    1230 </span>                :            :                            ptrace_attach_cmd, tcp->pid);</a>
<a name="1231"><span class="lineNum">    1231 </span>                :<span class="lineCov">          1 :                 droptcb(tcp);</span></a>
<a name="1232"><span class="lineNum">    1232 </span>                :<span class="lineCov">          1 :                 return;</span></a>
<a name="1233"><span class="lineNum">    1233 </span>                :            :         }</a>
<a name="1234"><span class="lineNum">    1234 </span>                :            : </a>
<a name="1235"><span class="lineNum">    1235 </span>                :<span class="lineCov">         15 :         after_successful_attach(tcp, TCB_GRABBED | post_attach_sigstop);</span></a>
<a name="1236"><span class="lineNum">    1236 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov">         15 :         debug_msg("attach to pid %d (main) succeeded", tcp->pid);</span></a>
<a name="1237"><span class="lineNum">    1237 </span>                :            : </a>
<a name="1238"><span class="lineNum">    1238 </span>                :<span class="lineCov">         15 :         static const char task_path[] = "/proc/%d/task";</span></a>
<a name="1239"><span class="lineNum">    1239 </span>                :<span class="lineCov">         15 :         char procdir[sizeof(task_path) + sizeof(int) * 3];</span></a>
<a name="1240"><span class="lineNum">    1240 </span>                :<span class="lineCov">         15 :         DIR *dir;</span></a>
<a name="1241"><span class="lineNum">    1241 </span>                :<span class="lineCov">         15 :         unsigned int ntid = 0, nerr = 0;</span></a>
<a name="1242"><span class="lineNum">    1242 </span>                :            : </a>
<a name="1243"><span class="lineNum">    1243 </span>  [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 12 times"> + </span><span class="branchCov" title="Branch 2 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span> :<span class="lineCov">         18 :         if (followfork && tcp->pid != strace_child &&</span></a>
<span class="lineNum">         </span>         <span class="branchCov" title="Branch 4 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>]
<a name="1244"><span class="lineNum">    1244 </span>                :<span class="lineCov">          3 :             xsprintf(procdir, task_path, get_proc_pid(tcp->pid)) > 0 &&</span></a>
<a name="1245"><span class="lineNum">    1245 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          3 :             (dir = opendir(procdir)) != NULL) {</span></a>
<a name="1246"><span class="lineNum">    1246 </span>                :            :                 struct_dirent *de;</a>
<a name="1247"><span class="lineNum">    1247 </span>                :            : </a>
<a name="1248"><span class="lineNum">    1248 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">         15 :                 while ((de = read_dir(dir)) != NULL) {</span></a>
<a name="1249"><span class="lineNum">    1249 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 12 times"> + </span>]:<span class="lineCov">         12 :                         if (de->d_fileno == 0)</span></a>
<a name="1250"><span class="lineNum">    1250 </span>                :<span class="lineNoCov">          0 :                                 continue;</span></a>
<a name="1251"><span class="lineNum">    1251 </span>                :            : </a>
<a name="1252"><span class="lineNum">    1252 </span>                :<span class="lineCov">         12 :                         int tid = string_to_uint(de->d_name);</span></a>
<a name="1253"><span class="lineNum">    1253 </span>  [<span class="branchCov" title="Branch 0 was taken 6 times"> + </span><span class="branchCov" title="Branch 1 was taken 6 times"> + </span><span class="branchCov" title="Branch 2 was taken 3 times"> + </span><span class="branchCov" title="Branch 3 was taken 3 times"> + </span>]:<span class="lineCov">         12 :                         if (tid <= 0 || tid == tcp->pid)</span></a>
<a name="1254"><span class="lineNum">    1254 </span>                :<span class="lineCov">          9 :                                 continue;</span></a>
<a name="1255"><span class="lineNum">    1255 </span>                :            : </a>
<a name="1256"><span class="lineNum">    1256 </span>                :<span class="lineCov">          3 :                         ++ntid;</span></a>
<a name="1257"><span class="lineNum">    1257 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :                         if (ptrace_attach_or_seize(tid, &ptrace_attach_cmd) < 0)</span></a>
<a name="1258"><span class="lineNum">    1258 </span>                :            :                         {</a>
<a name="1259"><span class="lineNum">    1259 </span>                :<span class="lineNoCov">          0 :                                 ++nerr;</span></a>
<a name="1260"><span class="lineNum">    1260 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                                 debug_perror_msg("attach: ptrace(%s, %d)",</span></a>
<a name="1261"><span class="lineNum">    1261 </span>                :            :                                                  ptrace_attach_cmd, tid);</a>
<a name="1262"><span class="lineNum">    1262 </span>                :<span class="lineNoCov">          0 :                                 continue;</span></a>
<a name="1263"><span class="lineNum">    1263 </span>                :            :                         }</a>
<a name="1264"><span class="lineNum">    1264 </span>                :            : </a>
<a name="1265"><span class="lineNum">    1265 </span>                :<span class="lineCov">          3 :                         after_successful_attach(alloctcb(tid),</span></a>
<a name="1266"><span class="lineNum">    1266 </span>                :<span class="lineCov">          3 :                                                 TCB_GRABBED | post_attach_sigstop);</span></a>
<a name="1267"><span class="lineNum">    1267 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">         18 :                         debug_msg("attach to pid %d succeeded", tid);</span></a>
<a name="1268"><span class="lineNum">    1268 </span>                :            :                 }</a>
<a name="1269"><span class="lineNum">    1269 </span>                :            : </a>
<a name="1270"><span class="lineNum">    1270 </span>                :<span class="lineCov">          3 :                 closedir(dir);</span></a>
<a name="1271"><span class="lineNum">    1271 </span>                :            :         }</a>
<a name="1272"><span class="lineNum">    1272 </span>                :            : </a>
<a name="1273"><span class="lineNum">    1273 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 10 times"> + </span>]:<span class="lineCov">         15 :         if (!is_number_in_set(QUIET_ATTACH, quiet_set)) {</span></a>
<a name="1274"><span class="lineNum">    1274 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          5 :                 if (ntid > nerr)</span></a>
<a name="1275"><span class="lineNum">    1275 </span>                :<span class="lineNoCov">          0 :                         error_msg("Process %u attached"</span></a>
<a name="1276"><span class="lineNum">    1276 </span>                :            :                                   " with %u threads",</a>
<a name="1277"><span class="lineNum">    1277 </span>                :<span class="lineNoCov">          0 :                                   tcp->pid, ntid - nerr + 1);</span></a>
<a name="1278"><span class="lineNum">    1278 </span>                :            :                 else</a>
<a name="1279"><span class="lineNum">    1279 </span>                :<span class="lineCov">          5 :                         error_msg("Process %u attached",</span></a>
<a name="1280"><span class="lineNum">    1280 </span>                :            :                                   tcp->pid);</a>
<a name="1281"><span class="lineNum">    1281 </span>                :            :         }</a>
<a name="1282"><span class="lineNum">    1282 </span>                :            : }</a>
<a name="1283"><span class="lineNum">    1283 </span>                :            : </a>
<a name="1284"><span class="lineNum">    1284 </span>                :            : static void</a>
<a name="1285"><span class="lineNum">    1285 </span>                :<span class="lineCov">      16247 : startup_attach(void)</span></a>
<a name="1286"><span class="lineNum">    1286 </span>                :            : {</a>
<a name="1287"><span class="lineNum">    1287 </span>                :<span class="lineCov">      16247 :         pid_t parent_pid = strace_tracer_pid;</span></a>
<a name="1288"><span class="lineNum">    1288 </span>                :<span class="lineCov">      16247 :         unsigned int tcbi;</span></a>
<a name="1289"><span class="lineNum">    1289 </span>                :<span class="lineCov">      16247 :         struct tcb *tcp;</span></a>
<a name="1290"><span class="lineNum">    1290 </span>                :            : </a>
<a name="1291"><span class="lineNum">    1291 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16247 times"> + </span>]:<span class="lineCov">      16247 :         if (daemonized_tracer) {</span></a>
<a name="1292"><span class="lineNum">    1292 </span>                :<span class="lineNoCov">          0 :                 pid_t pid = fork();</span></a>
<a name="1293"><span class="lineNum">    1293 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>]:<span class="lineCov">          8 :                 if (pid < 0)</span></a>
<a name="1294"><span class="lineNum">    1294 </span>                :<span class="lineNoCov">          0 :                         perror_func_msg_and_die("fork");</span></a>
<a name="1295"><span class="lineNum">    1295 </span>                :            : </a>
<a name="1296"><span class="lineNum">    1296 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>]:<span class="lineCov">          8 :                 if (pid) { /* parent */</span></a>
<a name="1297"><span class="lineNum">    1297 </span>                :            :                         /*</a>
<a name="1298"><span class="lineNum">    1298 </span>                :            :                          * Wait for grandchild to attach to straced process</a>
<a name="1299"><span class="lineNum">    1299 </span>                :            :                          * (grandparent). Grandchild SIGKILLs us after it attached.</a>
<a name="1300"><span class="lineNum">    1300 </span>                :            :                          * Grandparent's wait() is unblocked by our death,</a>
<a name="1301"><span class="lineNum">    1301 </span>                :            :                          * it proceeds to exec the straced program.</a>
<a name="1302"><span class="lineNum">    1302 </span>                :            :                          */</a>
<a name="1303"><span class="lineNum">    1303 </span>                :<span class="lineNoCov">          0 :                         pause();</span></a>
<a name="1304"><span class="lineNum">    1304 </span>                :<span class="lineNoCov">          0 :                         _exit(0); /* paranoia */</span></a>
<a name="1305"><span class="lineNum">    1305 </span>                :            :                 }</a>
<a name="1306"><span class="lineNum">    1306 </span>                :            :                 /* grandchild */</a>
<a name="1307"><span class="lineNum">    1307 </span>                :            :                 /* We will be the tracer process. Remember our new pid: */</a>
<a name="1308"><span class="lineNum">    1308 </span>                :<span class="lineCov">          8 :                 strace_tracer_pid = getpid();</span></a>
<a name="1309"><span class="lineNum">    1309 </span>                :            : </a>
<a name="1310"><span class="lineNum">    1310 </span>     [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span><span class="branchCov" title="Branch 2 was taken 3 times"> + </span>]:<span class="lineCov">          8 :                 switch (daemonized_tracer) {</span></a>
<a name="1311"><span class="lineNum">    1311 </span>                :<span class="lineCov">          3 :                 case DAEMONIZE_NEW_PGROUP:</span></a>
<a name="1312"><span class="lineNum">    1312 </span>                :            :                         /*</a>
<a name="1313"><span class="lineNum">    1313 </span>                :            :                          * If -D is passed twice, create a new process group,</a>
<a name="1314"><span class="lineNum">    1314 </span>                :            :                          * so we won't be killed by kill(0, ...).</a>
<a name="1315"><span class="lineNum">    1315 </span>                :            :                          */</a>
<a name="1316"><span class="lineNum">    1316 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          3 :                         if (setpgid(0, 0) < 0)</span></a>
<a name="1317"><span class="lineNum">    1317 </span>                :<span class="lineNoCov">          0 :                                 perror_msg_and_die("Cannot create a new"</span></a>
<a name="1318"><span class="lineNum">    1318 </span>                :            :                                                    " process group");</a>
<a name="1319"><span class="lineNum">    1319 </span>                :            :                         break;</a>
<a name="1320"><span class="lineNum">    1320 </span>                :<span class="lineCov">          3 :                 case DAEMONIZE_NEW_SESSION:</span></a>
<a name="1321"><span class="lineNum">    1321 </span>                :            :                         /*</a>
<a name="1322"><span class="lineNum">    1322 </span>                :            :                          * If -D is passed thrice, create a new session,</a>
<a name="1323"><span class="lineNum">    1323 </span>                :            :                          * so we won't be killed upon session termination.</a>
<a name="1324"><span class="lineNum">    1324 </span>                :            :                          */</a>
<a name="1325"><span class="lineNum">    1325 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          3 :                         if (setsid() < 0)</span></a>
<a name="1326"><span class="lineNum">    1326 </span>                :<span class="lineNoCov">          0 :                                 perror_msg_and_die("Cannot create a new"</span></a>
<a name="1327"><span class="lineNum">    1327 </span>                :            :                                                    " session");</a>
<a name="1328"><span class="lineNum">    1328 </span>                :            :                         break;</a>
<a name="1329"><span class="lineNum">    1329 </span>                :            :                 }</a>
<a name="1330"><span class="lineNum">    1330 </span>                :            :         }</a>
<a name="1331"><span class="lineNum">    1331 </span>                :            : </a>
<a name="1332"><span class="lineNum">    1332 </span>        [<span class="branchCov" title="Branch 0 was taken 260080 times"> + </span><span class="branchCov" title="Branch 1 was taken 16255 times"> + </span>]:<span class="lineCov">     276335 :         for (tcbi = 0; tcbi < tcbtabsize; tcbi++) {</span></a>
<a name="1333"><span class="lineNum">    1333 </span>                :<span class="lineCov">     260080 :                 tcp = tcbtab[tcbi];</span></a>
<a name="1334"><span class="lineNum">    1334 </span>                :            : </a>
<a name="1335"><span class="lineNum">    1335 </span>        [<span class="branchCov" title="Branch 0 was taken 243820 times"> + </span><span class="branchCov" title="Branch 1 was taken 16260 times"> + </span>]:<span class="lineCov">     260080 :                 if (!tcp->pid)</span></a>
<a name="1336"><span class="lineNum">    1336 </span>                :<span class="lineCov">     243820 :                         continue;</span></a>
<a name="1337"><span class="lineNum">    1337 </span>                :            : </a>
<a name="1338"><span class="lineNum">    1338 </span>                :            :                 /* Is this a process we should attach to, but not yet attached? */</a>
<a name="1339"><span class="lineNum">    1339 </span>        [<span class="branchCov" title="Branch 0 was taken 16244 times"> + </span><span class="branchCov" title="Branch 1 was taken 16 times"> + </span>]:<span class="lineCov">      16260 :                 if (tcp->flags & TCB_ATTACHED)</span></a>
<a name="1340"><span class="lineNum">    1340 </span>                :<span class="lineCov">      16244 :                         continue; /* no, we already attached it */</span></a>
<a name="1341"><span class="lineNum">    1341 </span>                :            : </a>
<a name="1342"><span class="lineNum">    1342 </span>  [<span class="branchCov" title="Branch 0 was taken 16 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 16 times"> + </span>]:<span class="lineCov">         16 :                 if (tcp->pid == parent_pid || tcp->pid == strace_tracer_pid) {</span></a>
<a name="1343"><span class="lineNum">    1343 </span>                :<span class="lineNoCov">          0 :                         errno = EPERM;</span></a>
<a name="1344"><span class="lineNum">    1344 </span>                :<span class="lineNoCov">          0 :                         perror_msg("attach: pid %d", tcp->pid);</span></a>
<a name="1345"><span class="lineNum">    1345 </span>                :<span class="lineNoCov">          0 :                         droptcb(tcp);</span></a>
<a name="1346"><span class="lineNum">    1346 </span>                :<span class="lineNoCov">          0 :                         continue;</span></a>
<a name="1347"><span class="lineNum">    1347 </span>                :            :                 }</a>
<a name="1348"><span class="lineNum">    1348 </span>                :            : </a>
<a name="1349"><span class="lineNum">    1349 </span>                :<span class="lineCov">         16 :                 attach_tcb(tcp);</span></a>
<a name="1350"><span class="lineNum">    1350 </span>                :            : </a>
<a name="1351"><span class="lineNum">    1351 </span>        [<span class="branchCov" title="Branch 0 was taken 16 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         16 :                 if (interrupted)</span></a>
<a name="1352"><span class="lineNum">    1352 </span>                :            :                         return;</a>
<a name="1353"><span class="lineNum">    1353 </span>                :            :         } /* for each tcbtab[] */</a>
<a name="1354"><span class="lineNum">    1354 </span>                :            : </a>
<a name="1355"><span class="lineNum">    1355 </span>        [<span class="branchCov" title="Branch 0 was taken 8 times"> + </span><span class="branchCov" title="Branch 1 was taken 16247 times"> + </span>]:<span class="lineCov">      16255 :         if (daemonized_tracer) {</span></a>
<a name="1356"><span class="lineNum">    1356 </span>                :            :                 /*</a>
<a name="1357"><span class="lineNum">    1357 </span>                :            :                  * Make parent go away.</a>
<a name="1358"><span class="lineNum">    1358 </span>                :            :                  * Also makes grandparent's wait() unblock.</a>
<a name="1359"><span class="lineNum">    1359 </span>                :            :                  */</a>
<a name="1360"><span class="lineNum">    1360 </span>                :<span class="lineCov">          8 :                 kill(parent_pid, SIGKILL);</span></a>
<a name="1361"><span class="lineNum">    1361 </span>                :<span class="lineCov">          8 :                 strace_child = 0;</span></a>
<a name="1362"><span class="lineNum">    1362 </span>                :            :         }</a>
<a name="1363"><span class="lineNum">    1363 </span>                :            : }</a>
<a name="1364"><span class="lineNum">    1364 </span>                :            : </a>
<a name="1365"><span class="lineNum">    1365 </span>                :            : /* Stack-o-phobic exec helper, in the hope to work around</a>
<a name="1366"><span class="lineNum">    1366 </span>                :            :  * NOMMU + "daemonized tracer" difficulty.</a>
<a name="1367"><span class="lineNum">    1367 </span>                :            :  */</a>
<a name="1368"><span class="lineNum">    1368 </span>                :            : struct exec_params {</a>
<a name="1369"><span class="lineNum">    1369 </span>                :            :         int fd_to_close;</a>
<a name="1370"><span class="lineNum">    1370 </span>                :            :         uid_t run_euid;</a>
<a name="1371"><span class="lineNum">    1371 </span>                :            :         gid_t run_egid;</a>
<a name="1372"><span class="lineNum">    1372 </span>                :            :         char **argv;</a>
<a name="1373"><span class="lineNum">    1373 </span>                :            :         char **env;</a>
<a name="1374"><span class="lineNum">    1374 </span>                :            :         char *pathname;</a>
<a name="1375"><span class="lineNum">    1375 </span>                :            :         struct sigaction child_sa;</a>
<a name="1376"><span class="lineNum">    1376 </span>                :            : };</a>
<a name="1377"><span class="lineNum">    1377 </span>                :            : static struct exec_params params_for_tracee;</a>
<a name="1378"><span class="lineNum">    1378 </span>                :            : </a>
<a name="1379"><span class="lineNum">    1379 </span>                :            : static void ATTRIBUTE_NOINLINE ATTRIBUTE_NORETURN</a>
<a name="1380"><span class="lineNum">    1380 </span>                :<span class="lineCov">      16255 : exec_or_die(void)</span></a>
<a name="1381"><span class="lineNum">    1381 </span>                :            : {</a>
<a name="1382"><span class="lineNum">    1382 </span>                :<span class="lineCov">      16255 :         struct exec_params *params = &params_for_tracee;</span></a>
<a name="1383"><span class="lineNum">    1383 </span>                :            : </a>
<a name="1384"><span class="lineNum">    1384 </span>        [<span class="branchCov" title="Branch 0 was taken 13832 times"> + </span><span class="branchCov" title="Branch 1 was taken 2423 times"> + </span>]:<span class="lineCov">      16255 :         if (params->fd_to_close >= 0)</span></a>
<a name="1385"><span class="lineNum">    1385 </span>                :<span class="lineCov">      13832 :                 close(params->fd_to_close);</span></a>
<a name="1386"><span class="lineNum">    1386 </span>  [<span class="branchCov" title="Branch 0 was taken 16246 times"> + </span><span class="branchCov" title="Branch 1 was taken 9 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 16246 times"> + </span>]:<span class="lineCov">      16255 :         if (!daemonized_tracer && !use_seize) {</span></a>
<a name="1387"><span class="lineNum">    1387 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (ptrace(PTRACE_TRACEME, 0L, 0L, 0L) < 0) {</span></a>
<a name="1388"><span class="lineNum">    1388 </span>                :<span class="lineNoCov">          0 :                         perror_msg_and_die("ptrace(PTRACE_TRACEME, ...)");</span></a>
<a name="1389"><span class="lineNum">    1389 </span>                :            :                 }</a>
<a name="1390"><span class="lineNum">    1390 </span>                :            :         }</a>
<a name="1391"><span class="lineNum">    1391 </span>                :            : </a>
<a name="1392"><span class="lineNum">    1392 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16255 times"> + </span>]:<span class="lineCov">      16255 :         if (username != NULL) {</span></a>
<a name="1393"><span class="lineNum">    1393 </span>                :            :                 /*</a>
<a name="1394"><span class="lineNum">    1394 </span>                :            :                  * It is important to set groups before we</a>
<a name="1395"><span class="lineNum">    1395 </span>                :            :                  * lose privileges on setuid.</a>
<a name="1396"><span class="lineNum">    1396 </span>                :            :                  */</a>
<a name="1397"><span class="lineNum">    1397 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (initgroups(username, run_gid) < 0) {</span></a>
<a name="1398"><span class="lineNum">    1398 </span>                :<span class="lineNoCov">          0 :                         perror_msg_and_die("initgroups");</span></a>
<a name="1399"><span class="lineNum">    1399 </span>                :            :                 }</a>
<a name="1400"><span class="lineNum">    1400 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (setregid(run_gid, params->run_egid) < 0) {</span></a>
<a name="1401"><span class="lineNum">    1401 </span>                :<span class="lineNoCov">          0 :                         perror_msg_and_die("setregid");</span></a>
<a name="1402"><span class="lineNum">    1402 </span>                :            :                 }</a>
<a name="1403"><span class="lineNum">    1403 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (setreuid(run_uid, params->run_euid) < 0) {</span></a>
<a name="1404"><span class="lineNum">    1404 </span>                :<span class="lineNoCov">          0 :                         perror_msg_and_die("setreuid");</span></a>
<a name="1405"><span class="lineNum">    1405 </span>                :            :                 }</a>
<a name="1406"><span class="lineNum">    1406 </span>        [<span class="branchCov" title="Branch 0 was taken 16213 times"> + </span><span class="branchCov" title="Branch 1 was taken 42 times"> + </span>]:<span class="lineCov">      16255 :         } else if (geteuid() != 0)</span></a>
<a name="1407"><span class="lineNum">    1407 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16213 times"> + </span>]:<span class="lineCov">      16213 :                 if (setreuid(run_uid, run_uid) < 0) {</span></a>
<a name="1408"><span class="lineNum">    1408 </span>                :<span class="lineNoCov">          0 :                         perror_msg_and_die("setreuid");</span></a>
<a name="1409"><span class="lineNum">    1409 </span>                :            :                 }</a>
<a name="1410"><span class="lineNum">    1410 </span>                :            : </a>
<a name="1411"><span class="lineNum">    1411 </span>        [<span class="branchCov" title="Branch 0 was taken 16246 times"> + </span><span class="branchCov" title="Branch 1 was taken 9 times"> + </span>]:<span class="lineCov">      16255 :         if (!daemonized_tracer) {</span></a>
<a name="1412"><span class="lineNum">    1412 </span>                :            :                 /*</a>
<a name="1413"><span class="lineNum">    1413 </span>                :            :                  * Induce a ptrace stop. Tracer (our parent)</a>
<a name="1414"><span class="lineNum">    1414 </span>                :            :                  * will resume us with PTRACE_SYSCALL and display</a>
<a name="1415"><span class="lineNum">    1415 </span>                :            :                  * the immediately following execve syscall.</a>
<a name="1416"><span class="lineNum">    1416 </span>                :            :                  * Can't do this on NOMMU systems, we are after</a>
<a name="1417"><span class="lineNum">    1417 </span>                :            :                  * vfork: parent is blocked, stopping would deadlock.</a>
<a name="1418"><span class="lineNum">    1418 </span>                :            :                  */</a>
<a name="1419"><span class="lineNum">    1419 </span>                :<span class="lineCov">      16246 :                 if (!NOMMU_SYSTEM)</span></a>
<a name="1420"><span class="lineNum">    1420 </span>                :<span class="lineCov">      16246 :                         kill(getpid(), SIGSTOP);</span></a>
<a name="1421"><span class="lineNum">    1421 </span>                :            :         } else {</a>
<a name="1422"><span class="lineNum">    1422 </span>                :<span class="lineCov">          9 :                 alarm(3);</span></a>
<a name="1423"><span class="lineNum">    1423 </span>                :            :                 /* we depend on SIGCHLD set to SIG_DFL by init code */</a>
<a name="1424"><span class="lineNum">    1424 </span>                :            :                 /* if it happens to be SIG_IGN'ed, wait won't block */</a>
<a name="1425"><span class="lineNum">    1425 </span>                :<span class="lineCov">          9 :                 wait(NULL);</span></a>
<a name="1426"><span class="lineNum">    1426 </span>                :<span class="lineCov">          9 :                 alarm(0);</span></a>
<a name="1427"><span class="lineNum">    1427 </span>                :            :         }</a>
<a name="1428"><span class="lineNum">    1428 </span>                :            : </a>
<a name="1429"><span class="lineNum">    1429 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 16250 times"> + </span>]:<span class="lineCov">      16255 :         if (params_for_tracee.child_sa.sa_handler != SIG_DFL)</span></a>
<a name="1430"><span class="lineNum">    1430 </span>                :<span class="lineCov">          5 :                 sigaction(SIGCHLD, &params_for_tracee.child_sa, NULL);</span></a>
<a name="1431"><span class="lineNum">    1431 </span>                :            : </a>
<a name="1432"><span class="lineNum">    1432 </span>  [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 16243 times"> + </span><span class="branchCov" title="Branch 2 was taken 12 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">      16267 :         debug_msg("seccomp filter %s",</span></a>
<a name="1433"><span class="lineNum">    1433 </span>                :            :                   seccomp_filtering ? "enabled" : "disabled");</a>
<a name="1434"><span class="lineNum">    1434 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 16248 times"> + </span>]:<span class="lineCov">      16255 :         if (seccomp_filtering)</span></a>
<a name="1435"><span class="lineNum">    1435 </span>                :<span class="lineCov">          7 :                 init_seccomp_filter();</span></a>
<a name="1436"><span class="lineNum">    1436 </span>                :<span class="lineCov">      16255 :         execve(params->pathname, params->argv, params->env);</span></a>
<a name="1437"><span class="lineNum">    1437 </span>                :<span class="lineCov">      16255 :         perror_msg_and_die("exec");</span></a>
<a name="1438"><span class="lineNum">    1438 </span>                :            : }</a>
<a name="1439"><span class="lineNum">    1439 </span>                :            : </a>
<a name="1440"><span class="lineNum">    1440 </span>                :            : /*</a>
<a name="1441"><span class="lineNum">    1441 </span>                :            :  * Open a dummy descriptor for use as a placeholder.</a>
<a name="1442"><span class="lineNum">    1442 </span>                :            :  * The descriptor is O_RDONLY with FD_CLOEXEC flag set.</a>
<a name="1443"><span class="lineNum">    1443 </span>                :            :  * A read attempt from such descriptor ends with EOF,</a>
<a name="1444"><span class="lineNum">    1444 </span>                :            :  * a write attempt is rejected with EBADF.</a>
<a name="1445"><span class="lineNum">    1445 </span>                :            :  */</a>
<a name="1446"><span class="lineNum">    1446 </span>                :            : static int</a>
<a name="1447"><span class="lineNum">    1447 </span>                :<span class="lineCov">      48754 : open_dummy_desc(void)</span></a>
<a name="1448"><span class="lineNum">    1448 </span>                :            : {</a>
<a name="1449"><span class="lineNum">    1449 </span>                :<span class="lineCov">      48754 :         int fds[2];</span></a>
<a name="1450"><span class="lineNum">    1450 </span>                :            : </a>
<a name="1451"><span class="lineNum">    1451 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 48754 times"> + </span>]:<span class="lineCov">      48754 :         if (pipe(fds))</span></a>
<a name="1452"><span class="lineNum">    1452 </span>                :<span class="lineNoCov">          0 :                 perror_func_msg_and_die("pipe");</span></a>
<a name="1453"><span class="lineNum">    1453 </span>                :<span class="lineCov">      48754 :         close(fds[1]);</span></a>
<a name="1454"><span class="lineNum">    1454 </span>                :<span class="lineCov">      48754 :         set_cloexec_flag(fds[0]);</span></a>
<a name="1455"><span class="lineNum">    1455 </span>                :<span class="lineCov">      48754 :         return fds[0];</span></a>
<a name="1456"><span class="lineNum">    1456 </span>                :            : }</a>
<a name="1457"><span class="lineNum">    1457 </span>                :            : </a>
<a name="1458"><span class="lineNum">    1458 </span>                :            : /* placeholder fds status for stdin and stdout */</a>
<a name="1459"><span class="lineNum">    1459 </span>                :            : static bool fd_is_placeholder[2];</a>
<a name="1460"><span class="lineNum">    1460 </span>                :            : </a>
<a name="1461"><span class="lineNum">    1461 </span>                :            : /*</a>
<a name="1462"><span class="lineNum">    1462 </span>                :            :  * Ensure that all standard file descriptors are open by opening placeholder</a>
<a name="1463"><span class="lineNum">    1463 </span>                :            :  * file descriptors for those standard file descriptors that are not open.</a>
<a name="1464"><span class="lineNum">    1464 </span>                :            :  *</a>
<a name="1465"><span class="lineNum">    1465 </span>                :            :  * The information which descriptors have been made open is saved</a>
<a name="1466"><span class="lineNum">    1466 </span>                :            :  * in fd_is_placeholder for later use.</a>
<a name="1467"><span class="lineNum">    1467 </span>                :            :  */</a>
<a name="1468"><span class="lineNum">    1468 </span>                :            : static void</a>
<a name="1469"><span class="lineNum">    1469 </span>                :<span class="lineCov">      16272 : ensure_standard_fds_opened(void)</span></a>
<a name="1470"><span class="lineNum">    1470 </span>                :            : {</a>
<a name="1471"><span class="lineNum">    1471 </span>                :<span class="lineCov">      16272 :         int fd;</span></a>
<a name="1472"><span class="lineNum">    1472 </span>                :            : </a>
<a name="1473"><span class="lineNum">    1473 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 16268 times"> + </span>]:<span class="lineCov">      16280 :         while ((fd = open_dummy_desc()) <= 2) {</span></a>
<a name="1474"><span class="lineNum">    1474 </span>        [<span class="branchCov" title="Branch 0 was taken 8 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">         12 :                 if (fd == 2)</span></a>
<a name="1475"><span class="lineNum">    1475 </span>                :            :                         break;</a>
<a name="1476"><span class="lineNum">    1476 </span>                :<span class="lineCov">          8 :                 fd_is_placeholder[fd] = true;</span></a>
<a name="1477"><span class="lineNum">    1477 </span>                :            :         }</a>
<a name="1478"><span class="lineNum">    1478 </span>                :            : </a>
<a name="1479"><span class="lineNum">    1479 </span>        [<span class="branchCov" title="Branch 0 was taken 16268 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">      16272 :         if (fd > 2)</span></a>
<a name="1480"><span class="lineNum">    1480 </span>                :<span class="lineCov">      16268 :                 close(fd);</span></a>
<a name="1481"><span class="lineNum">    1481 </span>                :<span class="lineCov">      16272 : }</span></a>
<a name="1482"><span class="lineNum">    1482 </span>                :            : </a>
<a name="1483"><span class="lineNum">    1483 </span>                :            : /*</a>
<a name="1484"><span class="lineNum">    1484 </span>                :            :  * Redirect stdin and stdout unless they have been opened earlier</a>
<a name="1485"><span class="lineNum">    1485 </span>                :            :  * by ensure_standard_fds_opened as placeholders.</a>
<a name="1486"><span class="lineNum">    1486 </span>                :            :  */</a>
<a name="1487"><span class="lineNum">    1487 </span>                :            : static void</a>
<a name="1488"><span class="lineNum">    1488 </span>                :<span class="lineCov">      16241 : redirect_standard_fds(void)</span></a>
<a name="1489"><span class="lineNum">    1489 </span>                :            : {</a>
<a name="1490"><span class="lineNum">    1490 </span>                :<span class="lineCov">      16241 :         int i;</span></a>
<a name="1491"><span class="lineNum">    1491 </span>                :            : </a>
<a name="1492"><span class="lineNum">    1492 </span>                :            :         /*</a>
<a name="1493"><span class="lineNum">    1493 </span>                :            :          * It might be a good idea to redirect stderr as well,</a>
<a name="1494"><span class="lineNum">    1494 </span>                :            :          * but we sometimes need to print error messages.</a>
<a name="1495"><span class="lineNum">    1495 </span>                :            :          */</a>
<a name="1496"><span class="lineNum">    1496 </span>        [<span class="branchCov" title="Branch 0 was taken 32482 times"> + </span><span class="branchCov" title="Branch 1 was taken 16241 times"> + </span>]:<span class="lineCov">      48723 :         for (i = 0; i <= 1; ++i) {</span></a>
<a name="1497"><span class="lineNum">    1497 </span>        [<span class="branchCov" title="Branch 0 was taken 32474 times"> + </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>]:<span class="lineCov">      32482 :                 if (!fd_is_placeholder[i]) {</span></a>
<a name="1498"><span class="lineNum">    1498 </span>                :<span class="lineCov">      32474 :                         close(i);</span></a>
<a name="1499"><span class="lineNum">    1499 </span>                :<span class="lineCov">      32474 :                         open_dummy_desc();</span></a>
<a name="1500"><span class="lineNum">    1500 </span>                :            :                 }</a>
<a name="1501"><span class="lineNum">    1501 </span>                :            :         }</a>
<a name="1502"><span class="lineNum">    1502 </span>                :<span class="lineCov">      16241 : }</span></a>
<a name="1503"><span class="lineNum">    1503 </span>                :            : </a>
<a name="1504"><span class="lineNum">    1504 </span>                :            : static void</a>
<a name="1505"><span class="lineNum">    1505 </span>                :<span class="lineCov">      16251 : startup_child(char **argv, char **env)</span></a>
<a name="1506"><span class="lineNum">    1506 </span>                :            : {</a>
<a name="1507"><span class="lineNum">    1507 </span>                :<span class="lineCov">      16251 :         strace_stat_t statbuf;</span></a>
<a name="1508"><span class="lineNum">    1508 </span>                :<span class="lineCov">      16251 :         const char *filename;</span></a>
<a name="1509"><span class="lineNum">    1509 </span>                :<span class="lineCov">      16251 :         size_t filename_len;</span></a>
<a name="1510"><span class="lineNum">    1510 </span>                :<span class="lineCov">      16251 :         char pathname[PATH_MAX];</span></a>
<a name="1511"><span class="lineNum">    1511 </span>                :<span class="lineCov">      16251 :         int pid;</span></a>
<a name="1512"><span class="lineNum">    1512 </span>                :<span class="lineCov">      16251 :         struct tcb *tcp;</span></a>
<a name="1513"><span class="lineNum">    1513 </span>                :            : </a>
<a name="1514"><span class="lineNum">    1514 </span>                :<span class="lineCov">      16251 :         filename = argv[0];</span></a>
<a name="1515"><span class="lineNum">    1515 </span>                :<span class="lineCov">      16251 :         filename_len = strlen(filename);</span></a>
<a name="1516"><span class="lineNum">    1516 </span>                :            : </a>
<a name="1517"><span class="lineNum">    1517 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 16250 times"> + </span>]:<span class="lineCov">      16251 :         if (filename_len > sizeof(pathname) - 1) {</span></a>
<a name="1518"><span class="lineNum">    1518 </span>                :<span class="lineCov">          1 :                 errno = ENAMETOOLONG;</span></a>
<a name="1519"><span class="lineNum">    1519 </span>                :<span class="lineCov">          1 :                 perror_msg_and_die("exec");</span></a>
<a name="1520"><span class="lineNum">    1520 </span>                :            :         }</a>
<a name="1521"><span class="lineNum">    1521 </span>        [<span class="branchCov" title="Branch 0 was taken 16247 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">      16250 :         if (strchr(filename, '/')) {</span></a>
<a name="1522"><span class="lineNum">    1522 </span>                :<span class="lineCov">      16247 :                 strcpy(pathname, filename);</span></a>
<a name="1523"><span class="lineNum">    1523 </span>                :            :         }</a>
<a name="1524"><span class="lineNum">    1524 </span>                :            : #ifdef USE_DEBUGGING_EXEC</a>
<a name="1525"><span class="lineNum">    1525 </span>                :            :         /*</a>
<a name="1526"><span class="lineNum">    1526 </span>                :            :          * Debuggers customarily check the current directory</a>
<a name="1527"><span class="lineNum">    1527 </span>                :            :          * first regardless of the path but doing that gives</a>
<a name="1528"><span class="lineNum">    1528 </span>                :            :          * security geeks a panic attack.</a>
<a name="1529"><span class="lineNum">    1529 </span>                :            :          */</a>
<a name="1530"><span class="lineNum">    1530 </span>                :            :         else if (stat_file(filename, &statbuf) == 0)</a>
<a name="1531"><span class="lineNum">    1531 </span>                :            :                 strcpy(pathname, filename);</a>
<a name="1532"><span class="lineNum">    1532 </span>                :            : #endif /* USE_DEBUGGING_EXEC */</a>
<a name="1533"><span class="lineNum">    1533 </span>                :            :         else {</a>
<a name="1534"><span class="lineNum">    1534 </span>                :<span class="lineCov">          3 :                 const char *path;</span></a>
<a name="1535"><span class="lineNum">    1535 </span>                :<span class="lineCov">          3 :                 size_t m, n, len;</span></a>
<a name="1536"><span class="lineNum">    1536 </span>                :            : </a>
<a name="1537"><span class="lineNum">    1537 </span>  [<span class="branchCov" title="Branch 0 was taken 18 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 18 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">         18 :                 for (path = getenv("PATH"); path && *path; path += m) {</span></a>
<a name="1538"><span class="lineNum">    1538 </span>                :<span class="lineCov">         18 :                         const char *colon = strchr(path, ':');</span></a>
<a name="1539"><span class="lineNum">    1539 </span>        [<span class="branchCov" title="Branch 0 was taken 18 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         18 :                         if (colon) {</span></a>
<a name="1540"><span class="lineNum">    1540 </span>                :<span class="lineCov">         18 :                                 n = colon - path;</span></a>
<a name="1541"><span class="lineNum">    1541 </span>                :<span class="lineCov">         18 :                                 m = n + 1;</span></a>
<a name="1542"><span class="lineNum">    1542 </span>                :            :                         } else</a>
<a name="1543"><span class="lineNum">    1543 </span>                :<span class="lineNoCov">          0 :                                 m = n = strlen(path);</span></a>
<a name="1544"><span class="lineNum">    1544 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 18 times"> + </span>]:<span class="lineCov">         18 :                         if (n == 0) {</span></a>
<a name="1545"><span class="lineNum">    1545 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                                 if (!getcwd(pathname, PATH_MAX))</span></a>
<a name="1546"><span class="lineNum">    1546 </span>                :<span class="lineNoCov">          0 :                                         continue;</span></a>
<a name="1547"><span class="lineNum">    1547 </span>                :<span class="lineNoCov">          0 :                                 len = strlen(pathname);</span></a>
<a name="1548"><span class="lineNum">    1548 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 18 times"> + </span>]:<span class="lineCov">         18 :                         } else if (n > sizeof(pathname) - 1)</span></a>
<a name="1549"><span class="lineNum">    1549 </span>                :<span class="lineNoCov">          0 :                                 continue;</span></a>
<a name="1550"><span class="lineNum">    1550 </span>                :            :                         else {</a>
<a name="1551"><span class="lineNum">    1551 </span>                :<span class="lineCov">         18 :                                 strncpy(pathname, path, n);</span></a>
<a name="1552"><span class="lineNum">    1552 </span>                :<span class="lineCov">         18 :                                 len = n;</span></a>
<a name="1553"><span class="lineNum">    1553 </span>                :            :                         }</a>
<a name="1554"><span class="lineNum">    1554 </span>  [<span class="branchCov" title="Branch 0 was taken 18 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 18 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">         18 :                         if (len && pathname[len - 1] != '/')</span></a>
<a name="1555"><span class="lineNum">    1555 </span>                :<span class="lineCov">         18 :                                 pathname[len++] = '/';</span></a>
<a name="1556"><span class="lineNum">    1556 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 18 times"> + </span>]:<span class="lineCov">         18 :                         if (filename_len + len > sizeof(pathname) - 1)</span></a>
<a name="1557"><span class="lineNum">    1557 </span>                :<span class="lineNoCov">          0 :                                 continue;</span></a>
<a name="1558"><span class="lineNum">    1558 </span>                :<span class="lineCov">         18 :                         strcpy(pathname + len, filename);</span></a>
<a name="1559"><span class="lineNum">    1559 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov">         18 :                         if (stat_file(pathname, &statbuf) == 0 &&</span></a>
<a name="1560"><span class="lineNum">    1560 </span>                :            :                             /* Accept only regular files</a>
<a name="1561"><span class="lineNum">    1561 </span>                :            :                                with some execute bits set.</a>
<a name="1562"><span class="lineNum">    1562 </span>                :            :                                XXX not perfect, might still fail */</a>
<a name="1563"><span class="lineNum">    1563 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          3 :                             S_ISREG(statbuf.st_mode) &&</span></a>
<a name="1564"><span class="lineNum">    1564 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :                             (statbuf.st_mode & 0111))</span></a>
<a name="1565"><span class="lineNum">    1565 </span>                :            :                                 break;</a>
<a name="1566"><span class="lineNum">    1566 </span>                :            :                 }</a>
<a name="1567"><span class="lineNum">    1567 </span>  [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 3 times"> + </span>]:<span class="lineCov">          3 :                 if (!path || !*path)</span></a>
<a name="1568"><span class="lineNum">    1568 </span>                :<span class="lineNoCov">          0 :                         pathname[0] = '\0';</span></a>
<a name="1569"><span class="lineNum">    1569 </span>                :            :         }</a>
<a name="1570"><span class="lineNum">    1570 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16250 times"> + </span>]:<span class="lineCov">      16250 :         if (stat_file(pathname, &statbuf) < 0) {</span></a>
<a name="1571"><span class="lineNum">    1571 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("Can't stat '%s'", filename);</span></a>
<a name="1572"><span class="lineNum">    1572 </span>                :            :         }</a>
<a name="1573"><span class="lineNum">    1573 </span>                :            : </a>
<a name="1574"><span class="lineNum">    1574 </span>        [<span class="branchCov" title="Branch 0 was taken 13827 times"> + </span><span class="branchCov" title="Branch 1 was taken 2423 times"> + </span>]:<span class="lineCov">      16250 :         params_for_tracee.fd_to_close = (shared_log != stderr) ? fileno(shared_log) : -1;</span></a>
<a name="1575"><span class="lineNum">    1575 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16250 times"> + </span>]:<span class="lineCov">      16250 :         params_for_tracee.run_euid = (statbuf.st_mode & S_ISUID) ? statbuf.st_uid : run_uid;</span></a>
<a name="1576"><span class="lineNum">    1576 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16250 times"> + </span>]:<span class="lineCov">      16250 :         params_for_tracee.run_egid = (statbuf.st_mode & S_ISGID) ? statbuf.st_gid : run_gid;</span></a>
<a name="1577"><span class="lineNum">    1577 </span>                :<span class="lineCov">      16250 :         params_for_tracee.argv = argv;</span></a>
<a name="1578"><span class="lineNum">    1578 </span>                :<span class="lineCov">      16250 :         params_for_tracee.env = env;</span></a>
<a name="1579"><span class="lineNum">    1579 </span>                :            :         /*</a>
<a name="1580"><span class="lineNum">    1580 </span>                :            :          * On NOMMU, can be safely freed only after execve in tracee.</a>
<a name="1581"><span class="lineNum">    1581 </span>                :            :          * It's hard to know when that happens, so we just leak it.</a>
<a name="1582"><span class="lineNum">    1582 </span>                :            :          */</a>
<a name="1583"><span class="lineNum">    1583 </span>                :<span class="lineCov">      16250 :         params_for_tracee.pathname = NOMMU_SYSTEM ? xstrdup(pathname) : pathname;</span></a>
<a name="1584"><span class="lineNum">    1584 </span>                :            : </a>
<a name="1585"><span class="lineNum">    1585 </span>        [<span class="branchCov" title="Branch 0 was taken 9 times"> + </span><span class="branchCov" title="Branch 1 was taken 16241 times"> + </span>]:<span class="lineCov">      16250 :         if (daemonized_tracer)</span></a>
<a name="1586"><span class="lineNum">    1586 </span>                :<span class="lineCov">          9 :                 prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);</span></a>
<a name="1587"><span class="lineNum">    1587 </span>                :            : </a>
<a name="1588"><span class="lineNum">    1588 </span>                :<span class="lineCov">      16250 :         pid = fork();</span></a>
<a name="1589"><span class="lineNum">    1589 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 32496 times"> + </span>]:<span class="lineCov">      32496 :         if (pid < 0)</span></a>
<a name="1590"><span class="lineNum">    1590 </span>                :<span class="lineNoCov">          0 :                 perror_func_msg_and_die("fork");</span></a>
<a name="1591"><span class="lineNum">    1591 </span>                :            : </a>
<a name="1592"><span class="lineNum">    1592 </span>  [<span class="branchCov" title="Branch 0 was taken 16250 times"> + </span><span class="branchCov" title="Branch 1 was taken 16246 times"> + </span><span class="branchCov" title="Branch 2 was taken 16241 times"> + </span><span class="branchCov" title="Branch 3 was taken 9 times"> + </span>]:<span class="lineCov">      32496 :         if ((pid != 0 && daemonized_tracer)</span></a>
<a name="1593"><span class="lineNum">    1593 </span>  [<span class="branchCov" title="Branch 0 was taken 16246 times"> + </span><span class="branchCov" title="Branch 1 was taken 16241 times"> + </span><span class="branchCov" title="Branch 2 was taken 16246 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">      32487 :          || (pid == 0 && !daemonized_tracer)</span></a>
<a name="1594"><span class="lineNum">    1594 </span>                :            :         ) {</a>
<a name="1595"><span class="lineNum">    1595 </span>                :            :                 /* We are to become the tracee. Two cases:</a>
<a name="1596"><span class="lineNum">    1596 </span>                :            :                  * -D: we are parent</a>
<a name="1597"><span class="lineNum">    1597 </span>                :            :                  * not -D: we are child</a>
<a name="1598"><span class="lineNum">    1598 </span>                :            :                  */</a>
<a name="1599"><span class="lineNum">    1599 </span>                :<span class="lineCov">      16255 :                 exec_or_die();</span></a>
<a name="1600"><span class="lineNum">    1600 </span>                :            :         }</a>
<a name="1601"><span class="lineNum">    1601 </span>                :            : </a>
<a name="1602"><span class="lineNum">    1602 </span>                :            :         /* We are the tracer */</a>
<a name="1603"><span class="lineNum">    1603 </span>                :            : </a>
<a name="1604"><span class="lineNum">    1604 </span>        [<span class="branchCov" title="Branch 0 was taken 16241 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      16241 :         if (!daemonized_tracer) {</span></a>
<a name="1605"><span class="lineNum">    1605 </span>                :<span class="lineCov">      16241 :                 strace_child = pid;</span></a>
<a name="1606"><span class="lineNum">    1606 </span>        [<span class="branchCov" title="Branch 0 was taken 16241 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      16241 :                 if (!use_seize) {</span></a>
<a name="1607"><span class="lineNum">    1607 </span>                :            :                         /* child did PTRACE_TRACEME, nothing to do in parent */</a>
<a name="1608"><span class="lineNum">    1608 </span>                :            :                 } else {</a>
<a name="1609"><span class="lineNum">    1609 </span>                :            :                         if (!NOMMU_SYSTEM) {</a>
<a name="1610"><span class="lineNum">    1610 </span>                :            :                                 /* Wait until child stopped itself */</a>
<a name="1611"><span class="lineNum">    1611 </span>                :            :                                 int status;</a>
<a name="1612"><span class="lineNum">    1612 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16241 times"> + </span>]:<span class="lineCov">      16241 :                                 while (waitpid(pid, &status, WSTOPPED) < 0) {</span></a>
<a name="1613"><span class="lineNum">    1613 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                                         if (errno == EINTR)</span></a>
<a name="1614"><span class="lineNum">    1614 </span>                :<span class="lineNoCov">          0 :                                                 continue;</span></a>
<a name="1615"><span class="lineNum">    1615 </span>                :<span class="lineNoCov">          0 :                                         perror_msg_and_die("waitpid");</span></a>
<a name="1616"><span class="lineNum">    1616 </span>                :            :                                 }</a>
<a name="1617"><span class="lineNum">    1617 </span>  [<span class="branchCov" title="Branch 0 was taken 16241 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 16241 times"> + </span>]:<span class="lineCov">      16241 :                                 if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP) {</span></a>
<a name="1618"><span class="lineNum">    1618 </span>                :<span class="lineNoCov">          0 :                                         kill_save_errno(pid, SIGKILL);</span></a>
<a name="1619"><span class="lineNum">    1619 </span>                :<span class="lineNoCov">          0 :                                         perror_msg_and_die("Unexpected wait status %#x",</span></a>
<a name="1620"><span class="lineNum">    1620 </span>                :            :                                                            status);</a>
<a name="1621"><span class="lineNum">    1621 </span>                :            :                                 }</a>
<a name="1622"><span class="lineNum">    1622 </span>                :            :                         }</a>
<a name="1623"><span class="lineNum">    1623 </span>                :            :                         /* Else: NOMMU case, we have no way to sync.</a>
<a name="1624"><span class="lineNum">    1624 </span>                :            :                          * Just attach to it as soon as possible.</a>
<a name="1625"><span class="lineNum">    1625 </span>                :            :                          * This means that we may miss a few first syscalls...</a>
<a name="1626"><span class="lineNum">    1626 </span>                :            :                          */</a>
<a name="1627"><span class="lineNum">    1627 </span>                :            : </a>
<a name="1628"><span class="lineNum">    1628 </span>                :<span class="lineCov">      16241 :                         const char *ptrace_attach_cmd;</span></a>
<a name="1629"><span class="lineNum">    1629 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16241 times"> + </span>]:<span class="lineCov">      16241 :                         if (ptrace_attach_or_seize(pid, &ptrace_attach_cmd)) {</span></a>
<a name="1630"><span class="lineNum">    1630 </span>                :<span class="lineNoCov">          0 :                                 kill_save_errno(pid, SIGKILL);</span></a>
<a name="1631"><span class="lineNum">    1631 </span>                :<span class="lineNoCov">          0 :                                 perror_msg_and_die("attach: ptrace(%s, %d)",</span></a>
<a name="1632"><span class="lineNum">    1632 </span>                :            :                                                    ptrace_attach_cmd, pid);</a>
<a name="1633"><span class="lineNum">    1633 </span>                :            :                         }</a>
<a name="1634"><span class="lineNum">    1634 </span>                :<span class="lineCov">      16241 :                         if (!NOMMU_SYSTEM)</span></a>
<a name="1635"><span class="lineNum">    1635 </span>                :<span class="lineCov">      16241 :                                 kill(pid, SIGCONT);</span></a>
<a name="1636"><span class="lineNum">    1636 </span>                :            :                 }</a>
<a name="1637"><span class="lineNum">    1637 </span>                :<span class="lineCov">      16241 :                 tcp = alloctcb(pid);</span></a>
<a name="1638"><span class="lineNum">    1638 </span>                :<span class="lineCov">      16241 :                 after_successful_attach(tcp, TCB_SKIP_DETACH_ON_FIRST_EXEC</span></a>
<a name="1639"><span class="lineNum">    1639 </span>                :<span class="lineCov">      16241 :                                              | (NOMMU_SYSTEM ? 0</span></a>
<a name="1640"><span class="lineNum">    1640 </span>                :            :                                                 : (TCB_HIDE_LOG</a>
<a name="1641"><span class="lineNum">    1641 </span>                :            :                                                    | post_attach_sigstop)));</a>
<a name="1642"><span class="lineNum">    1642 </span>                :            :         } else {</a>
<a name="1643"><span class="lineNum">    1643 </span>                :            :                 /* With -D, we are *child* here, the tracee is our parent. */</a>
<a name="1644"><span class="lineNum">    1644 </span>                :<span class="lineNoCov">          0 :                 strace_child = strace_tracer_pid;</span></a>
<a name="1645"><span class="lineNum">    1645 </span>                :<span class="lineNoCov">          0 :                 strace_tracer_pid = getpid();</span></a>
<a name="1646"><span class="lineNum">    1646 </span>                :<span class="lineNoCov">          0 :                 tcp = alloctcb(strace_child);</span></a>
<a name="1647"><span class="lineNum">    1647 </span>                :<span class="lineNoCov">          0 :                 tcp->flags |= TCB_SKIP_DETACH_ON_FIRST_EXEC | TCB_HIDE_LOG;</span></a>
<a name="1648"><span class="lineNum">    1648 </span>                :            :                 /*</a>
<a name="1649"><span class="lineNum">    1649 </span>                :            :                  * Attaching will be done later, by startup_attach.</a>
<a name="1650"><span class="lineNum">    1650 </span>                :            :                  * Note: we don't do after_successful_attach() here either!</a>
<a name="1651"><span class="lineNum">    1651 </span>                :            :                  */</a>
<a name="1652"><span class="lineNum">    1652 </span>                :            : </a>
<a name="1653"><span class="lineNum">    1653 </span>                :            :                 /* NOMMU BUG! -D mode is active, we (child) return,</a>
<a name="1654"><span class="lineNum">    1654 </span>                :            :                  * and we will scribble over parent's stack!</a>
<a name="1655"><span class="lineNum">    1655 </span>                :            :                  * When parent later unpauses, it segfaults.</a>
<a name="1656"><span class="lineNum">    1656 </span>                :            :                  *</a>
<a name="1657"><span class="lineNum">    1657 </span>                :            :                  * We work around it</a>
<a name="1658"><span class="lineNum">    1658 </span>                :            :                  * (1) by declaring exec_or_die() NORETURN,</a>
<a name="1659"><span class="lineNum">    1659 </span>                :            :                  * hopefully compiler will just jump to it</a>
<a name="1660"><span class="lineNum">    1660 </span>                :            :                  * instead of call (won't push anything to stack),</a>
<a name="1661"><span class="lineNum">    1661 </span>                :            :                  * (2) by trying very hard in exec_or_die()</a>
<a name="1662"><span class="lineNum">    1662 </span>                :            :                  * to not use any stack,</a>
<a name="1663"><span class="lineNum">    1663 </span>                :            :                  * (3) having a really big (PATH_MAX) stack object</a>
<a name="1664"><span class="lineNum">    1664 </span>                :            :                  * in this function, which creates a "buffer" between</a>
<a name="1665"><span class="lineNum">    1665 </span>                :            :                  * child's and parent's stack pointers.</a>
<a name="1666"><span class="lineNum">    1666 </span>                :            :                  * This may save us if (1) and (2) failed</a>
<a name="1667"><span class="lineNum">    1667 </span>                :            :                  * and compiler decided to use stack in exec_or_die() anyway</a>
<a name="1668"><span class="lineNum">    1668 </span>                :            :                  * (happens on i386 because of stack parameter passing).</a>
<a name="1669"><span class="lineNum">    1669 </span>                :            :                  *</a>
<a name="1670"><span class="lineNum">    1670 </span>                :            :                  * A cleaner solution is to use makecontext + setcontext</a>
<a name="1671"><span class="lineNum">    1671 </span>                :            :                  * to create a genuine separate stack and execute on it.</a>
<a name="1672"><span class="lineNum">    1672 </span>                :            :                  */</a>
<a name="1673"><span class="lineNum">    1673 </span>                :            :         }</a>
<a name="1674"><span class="lineNum">    1674 </span>                :            : </a>
<a name="1675"><span class="lineNum">    1675 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 16234 times"> + </span>]:<span class="lineCov">      16241 :         if (seccomp_filtering)</span></a>
<a name="1676"><span class="lineNum">    1676 </span>                :<span class="lineCov">          7 :                 tcp->flags |= TCB_SECCOMP_FILTER;</span></a>
<a name="1677"><span class="lineNum">    1677 </span>                :            : </a>
<a name="1678"><span class="lineNum">    1678 </span>                :            :         /*</a>
<a name="1679"><span class="lineNum">    1679 </span>                :            :          * A case where straced process is part of a pipe:</a>
<a name="1680"><span class="lineNum">    1680 </span>                :            :          * { sleep 1; yes | head -n99999; } | strace -o/dev/null sh -c 'exec <&-; sleep 9'</a>
<a name="1681"><span class="lineNum">    1681 </span>                :            :          * If strace won't close its fd#0, closing it in tracee is not enough:</a>
<a name="1682"><span class="lineNum">    1682 </span>                :            :          * the pipe is still open, it has a reader. Thus, "head" will not get its</a>
<a name="1683"><span class="lineNum">    1683 </span>                :            :          * SIGPIPE at once, on the first write.</a>
<a name="1684"><span class="lineNum">    1684 </span>                :            :          *</a>
<a name="1685"><span class="lineNum">    1685 </span>                :            :          * Preventing it by redirecting strace's stdin/out.</a>
<a name="1686"><span class="lineNum">    1686 </span>                :            :          * (Don't leave fds 0 and 1 closed, this is bad practice: future opens</a>
<a name="1687"><span class="lineNum">    1687 </span>                :            :          * will reuse them, unexpectedly making a newly opened object "stdin").</a>
<a name="1688"><span class="lineNum">    1688 </span>                :            :          */</a>
<a name="1689"><span class="lineNum">    1689 </span>                :<span class="lineCov">      16241 :         redirect_standard_fds();</span></a>
<a name="1690"><span class="lineNum">    1690 </span>                :<span class="lineCov">      16241 : }</span></a>
<a name="1691"><span class="lineNum">    1691 </span>                :            : </a>
<a name="1692"><span class="lineNum">    1692 </span>                :            : static void</a>
<a name="1693"><span class="lineNum">    1693 </span>                :<span class="lineCov">      16272 : test_ptrace_seize(void)</span></a>
<a name="1694"><span class="lineNum">    1694 </span>                :            : {</a>
<a name="1695"><span class="lineNum">    1695 </span>                :<span class="lineCov">      16272 :         int pid;</span></a>
<a name="1696"><span class="lineNum">    1696 </span>                :            : </a>
<a name="1697"><span class="lineNum">    1697 </span>                :            :         /* Need fork for test. NOMMU has no forks */</a>
<a name="1698"><span class="lineNum">    1698 </span>                :<span class="lineCov">      16272 :         if (NOMMU_SYSTEM) {</span></a>
<a name="1699"><span class="lineNum">    1699 </span>                :            :                 post_attach_sigstop = 0; /* this sets use_seize to 1 */</a>
<a name="1700"><span class="lineNum">    1700 </span>                :            :                 return;</a>
<a name="1701"><span class="lineNum">    1701 </span>                :            :         }</a>
<a name="1702"><span class="lineNum">    1702 </span>                :            : </a>
<a name="1703"><span class="lineNum">    1703 </span>                :<span class="lineCov">      16272 :         pid = fork();</span></a>
<a name="1704"><span class="lineNum">    1704 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16272 times"> + </span>]:<span class="lineCov">      16272 :         if (pid < 0)</span></a>
<a name="1705"><span class="lineNum">    1705 </span>                :<span class="lineNoCov">          0 :                 perror_func_msg_and_die("fork");</span></a>
<a name="1706"><span class="lineNum">    1706 </span>                :            : </a>
<a name="1707"><span class="lineNum">    1707 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16272 times"> + </span>]:<span class="lineCov">      16272 :         if (pid == 0) {</span></a>
<a name="1708"><span class="lineNum">    1708 </span>                :<span class="lineNoCov">          0 :                 pause();</span></a>
<a name="1709"><span class="lineNum">    1709 </span>                :<span class="lineNoCov">          0 :                 _exit(0);</span></a>
<a name="1710"><span class="lineNum">    1710 </span>                :            :         }</a>
<a name="1711"><span class="lineNum">    1711 </span>                :            : </a>
<a name="1712"><span class="lineNum">    1712 </span>                :            :         /* PTRACE_SEIZE, unlike ATTACH, doesn't force tracee to trap.  After</a>
<a name="1713"><span class="lineNum">    1713 </span>                :            :          * attaching tracee continues to run unless a trap condition occurs.</a>
<a name="1714"><span class="lineNum">    1714 </span>                :            :          * PTRACE_SEIZE doesn't affect signal or group stop state.</a>
<a name="1715"><span class="lineNum">    1715 </span>                :            :          */</a>
<a name="1716"><span class="lineNum">    1716 </span>        [<span class="branchCov" title="Branch 0 was taken 16272 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      16272 :         if (ptrace(PTRACE_SEIZE, pid, 0, 0) == 0) {</span></a>
<a name="1717"><span class="lineNum">    1717 </span>                :<span class="lineCov">      16272 :                 post_attach_sigstop = 0; /* this sets use_seize to 1 */</span></a>
<a name="1718"><span class="lineNum">    1718 </span>                :            :         } else {</a>
<a name="1719"><span class="lineNum">    1719 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 debug_msg("PTRACE_SEIZE doesn't work");</span></a>
<a name="1720"><span class="lineNum">    1720 </span>                :            :         }</a>
<a name="1721"><span class="lineNum">    1721 </span>                :            : </a>
<a name="1722"><span class="lineNum">    1722 </span>                :<span class="lineCov">      16272 :         kill(pid, SIGKILL);</span></a>
<a name="1723"><span class="lineNum">    1723 </span>                :            : </a>
<a name="1724"><span class="lineNum">    1724 </span>                :<span class="lineCov">      16272 :         while (1) {</span></a>
<a name="1725"><span class="lineNum">    1725 </span>                :<span class="lineCov">      16272 :                 int status, tracee_pid;</span></a>
<a name="1726"><span class="lineNum">    1726 </span>                :            : </a>
<a name="1727"><span class="lineNum">    1727 </span>                :<span class="lineCov">      16272 :                 errno = 0;</span></a>
<a name="1728"><span class="lineNum">    1728 </span>                :<span class="lineCov">      16272 :                 tracee_pid = waitpid(pid, &status, 0);</span></a>
<a name="1729"><span class="lineNum">    1729 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16272 times"> + </span>]:<span class="lineCov">      16272 :                 if (tracee_pid <= 0) {</span></a>
<a name="1730"><span class="lineNum">    1730 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                         if (errno == EINTR)</span></a>
<a name="1731"><span class="lineNum">    1731 </span>                :<span class="lineNoCov">          0 :                                 continue;</span></a>
<a name="1732"><span class="lineNum">    1732 </span>                :<span class="lineNoCov">          0 :                         perror_func_msg_and_die("unexpected wait result %d",</span></a>
<a name="1733"><span class="lineNum">    1733 </span>                :            :                                                 tracee_pid);</a>
<a name="1734"><span class="lineNum">    1734 </span>                :            :                 }</a>
<a name="1735"><span class="lineNum">    1735 </span>        [<span class="branchCov" title="Branch 0 was taken 16272 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      16272 :                 if (WIFSIGNALED(status))</span></a>
<a name="1736"><span class="lineNum">    1736 </span>                :<span class="lineCov">      16272 :                         return;</span></a>
<a name="1737"><span class="lineNum">    1737 </span>                :            : </a>
<a name="1738"><span class="lineNum">    1738 </span>                :<span class="lineNoCov">          0 :                 error_func_msg_and_die("unexpected wait status %#x", status);</span></a>
<a name="1739"><span class="lineNum">    1739 </span>                :            :         }</a>
<a name="1740"><span class="lineNum">    1740 </span>                :            : }</a>
<a name="1741"><span class="lineNum">    1741 </span>                :            : </a>
<a name="1742"><span class="lineNum">    1742 </span>                :            : static unsigned int</a>
<a name="1743"><span class="lineNum">    1743 </span>                :<span class="lineCov">      22653 : get_os_release(void)</span></a>
<a name="1744"><span class="lineNum">    1744 </span>                :            : {</a>
<a name="1745"><span class="lineNum">    1745 </span>                :<span class="lineCov">      22653 :         struct utsname u;</span></a>
<a name="1746"><span class="lineNum">    1746 </span>        [<span class="branchCov" title="Branch 0 was taken 22653 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      22653 :         if (uname(&u) < 0)</span></a>
<a name="1747"><span class="lineNum">    1747 </span>                :<span class="lineNoCov">          0 :                 perror_msg_and_die("uname");</span></a>
<a name="1748"><span class="lineNum">    1748 </span>                :            :         /*</a>
<a name="1749"><span class="lineNum">    1749 </span>                :            :          * u.release string consists of at most three parts</a>
<a name="1750"><span class="lineNum">    1750 </span>                :            :          * and normally has this form: "3.2.9[-some-garbage]",</a>
<a name="1751"><span class="lineNum">    1751 </span>                :            :          * "X.Y-something" means "X.Y.0".</a>
<a name="1752"><span class="lineNum">    1752 </span>                :            :          */</a>
<a name="1753"><span class="lineNum">    1753 </span>                :            :         const char *p = u.release;</a>
<a name="1754"><span class="lineNum">    1754 </span>                :            :         unsigned int rel = 0;</a>
<a name="1755"><span class="lineNum">    1755 </span>        [<span class="branchCov" title="Branch 0 was taken 67959 times"> + </span><span class="branchCov" title="Branch 1 was taken 22653 times"> + </span>]:<span class="lineCov">      90612 :         for (unsigned int parts = 0; parts < 3; ++parts) {</span></a>
<a name="1756"><span class="lineNum">    1756 </span>                :            :                 unsigned int n = 0;</a>
<a name="1757"><span class="lineNum">    1757 </span>        [<span class="branchCov" title="Branch 0 was taken 113265 times"> + </span><span class="branchCov" title="Branch 1 was taken 67959 times"> + </span>]:<span class="lineCov">     181224 :                 for (; (*p >= '0') && (*p <= '9'); ++p) {</span></a>
<a name="1758"><span class="lineNum">    1758 </span>                :<span class="lineCov">     113265 :                         n *= 10;</span></a>
<a name="1759"><span class="lineNum">    1759 </span>                :<span class="lineCov">     113265 :                         n += *p - '0';</span></a>
<a name="1760"><span class="lineNum">    1760 </span>                :            :                 }</a>
<a name="1761"><span class="lineNum">    1761 </span>                :<span class="lineCov">      67959 :                 rel <<= 8;</span></a>
<a name="1762"><span class="lineNum">    1762 </span>                :<span class="lineCov">      67959 :                 rel |= n;</span></a>
<a name="1763"><span class="lineNum">    1763 </span>        [<span class="branchCov" title="Branch 0 was taken 45306 times"> + </span><span class="branchCov" title="Branch 1 was taken 22653 times"> + </span>]:<span class="lineCov">      67959 :                 if (*p == '.')</span></a>
<a name="1764"><span class="lineNum">    1764 </span>                :<span class="lineCov">      45306 :                         ++p;</span></a>
<a name="1765"><span class="lineNum">    1765 </span>                :            :         }</a>
<a name="1766"><span class="lineNum">    1766 </span>                :<span class="lineCov">      22653 :         return rel;</span></a>
<a name="1767"><span class="lineNum">    1767 </span>                :            : }</a>
<a name="1768"><span class="lineNum">    1768 </span>                :            : </a>
<a name="1769"><span class="lineNum">    1769 </span>                :            : static void</a>
<a name="1770"><span class="lineNum">    1770 </span>                :<span class="lineCov">     145796 : set_sighandler(int signo, void (*sighandler)(int), struct sigaction *oldact)</span></a>
<a name="1771"><span class="lineNum">    1771 </span>                :            : {</a>
<a name="1772"><span class="lineNum">    1772 </span>                :<span class="lineCov">     145796 :         const struct sigaction sa = { .sa_handler = sighandler };</span></a>
<a name="1773"><span class="lineNum">    1773 </span>                :<span class="lineCov">     145796 :         sigaction(signo, &sa, oldact);</span></a>
<a name="1774"><span class="lineNum">    1774 </span>                :<span class="lineCov">     145796 : }</span></a>
<a name="1775"><span class="lineNum">    1775 </span>                :            : </a>
<a name="1776"><span class="lineNum">    1776 </span>                :            : static int</a>
<a name="1777"><span class="lineNum">    1777 </span>                :<span class="lineCov">        508 : parse_interruptible_arg(const char *arg)</span></a>
<a name="1778"><span class="lineNum">    1778 </span>                :            : {</a>
<a name="1779"><span class="lineNum">    1779 </span>                :<span class="lineCov">        508 :         static const struct xlat_data intr_str[] = {</span></a>
<a name="1780"><span class="lineNum">    1780 </span>                :            :                 { INTR_ANYWHERE,        "anywhere" },</a>
<a name="1781"><span class="lineNum">    1781 </span>                :            :                 { INTR_ANYWHERE,        "always" },</a>
<a name="1782"><span class="lineNum">    1782 </span>                :            :                 { INTR_WHILE_WAIT,      "waiting" },</a>
<a name="1783"><span class="lineNum">    1783 </span>                :            :                 { INTR_NEVER,           "never" },</a>
<a name="1784"><span class="lineNum">    1784 </span>                :            :                 { INTR_BLOCK_TSTP_TOO,  "never_tstp" },</a>
<a name="1785"><span class="lineNum">    1785 </span>                :            :         };</a>
<a name="1786"><span class="lineNum">    1786 </span>                :            : </a>
<a name="1787"><span class="lineNum">    1787 </span>                :<span class="lineCov">        508 :         const struct xlat_data *intr_arg = find_xlat_val(intr_str, arg);</span></a>
<a name="1788"><span class="lineNum">    1788 </span>                :            : </a>
<a name="1789"><span class="lineNum">    1789 </span>                :<span class="lineCov">        752 :         return intr_arg ? (int) intr_arg->val</span></a>
<a name="1790"><span class="lineNum">    1790 </span>        [<span class="branchCov" title="Branch 0 was taken 244 times"> + </span><span class="branchCov" title="Branch 1 was taken 264 times"> + </span>]:<span class="lineCov">        772 :                         : (int) string_to_uint_upto(arg, NUM_INTR_OPTS - 1);</span></a>
<a name="1791"><span class="lineNum">    1791 </span>                :            : }</a>
<a name="1792"><span class="lineNum">    1792 </span>                :            : </a>
<a name="1793"><span class="lineNum">    1793 </span>                :            : static int</a>
<a name="1794"><span class="lineNum">    1794 </span>                :<span class="lineCov">         58 : parse_ts_arg(const char *in_arg)</span></a>
<a name="1795"><span class="lineNum">    1795 </span>                :            : {</a>
<a name="1796"><span class="lineNum">    1796 </span>                :<span class="lineCov">         58 :         static const char format_pfx[] = "format:";</span></a>
<a name="1797"><span class="lineNum">    1797 </span>                :<span class="lineCov">         58 :         static const char scale_pfx[] = "precision:";</span></a>
<a name="1798"><span class="lineNum">    1798 </span>                :            : </a>
<a name="1799"><span class="lineNum">    1799 </span>                :<span class="lineCov">         58 :         enum {</span></a>
<a name="1800"><span class="lineNum">    1800 </span>                :            :                 TOKEN_FORMAT = 1 << 0,</a>
<a name="1801"><span class="lineNum">    1801 </span>                :            :                 TOKEN_SCALE  = 1 << 1,</a>
<a name="1802"><span class="lineNum">    1802 </span>                :            :         } token_type;</a>
<a name="1803"><span class="lineNum">    1803 </span>                :<span class="lineCov">         58 :         enum {</span></a>
<a name="1804"><span class="lineNum">    1804 </span>                :            :                 FK_UNSET,</a>
<a name="1805"><span class="lineNum">    1805 </span>                :            :                 FK_NONE,</a>
<a name="1806"><span class="lineNum">    1806 </span>                :            :                 FK_TIME,</a>
<a name="1807"><span class="lineNum">    1807 </span>                :            :                 FK_UNIX,</a>
<a name="1808"><span class="lineNum">    1808 </span>                :<span class="lineCov">         58 :         } format_kind = FK_UNSET;</span></a>
<a name="1809"><span class="lineNum">    1809 </span>                :<span class="lineCov">         58 :         int precision_width;</span></a>
<a name="1810"><span class="lineNum">    1810 </span>                :<span class="lineCov">         58 :         int precision_scale = 0;</span></a>
<a name="1811"><span class="lineNum">    1811 </span>                :<span class="lineCov">         58 :         char *arg = xstrdup(in_arg);</span></a>
<a name="1812"><span class="lineNum">    1812 </span>                :<span class="lineCov">         58 :         char *saveptr = NULL;</span></a>
<a name="1813"><span class="lineNum">    1813 </span>                :            : </a>
<a name="1814"><span class="lineNum">    1814 </span>                :<span class="lineCov">         58 :         for (const char *token = strtok_r(arg, ",", &saveptr);</span></a>
<a name="1815"><span class="lineNum">    1815 </span>        [<span class="branchCov" title="Branch 0 was taken 76 times"> + </span><span class="branchCov" title="Branch 1 was taken 54 times"> + </span>]:<span class="lineCov">        130 :              token; token = strtok_r(NULL, ",", &saveptr)) {</span></a>
<a name="1816"><span class="lineNum">    1816 </span>                :<span class="lineCov">         76 :                 token_type = TOKEN_FORMAT | TOKEN_SCALE;</span></a>
<a name="1817"><span class="lineNum">    1817 </span>                :            : </a>
<a name="1818"><span class="lineNum">    1818 </span>        [<span class="branchCov" title="Branch 0 was taken 26 times"> + </span><span class="branchCov" title="Branch 1 was taken 50 times"> + </span>]:<span class="lineCov">         76 :                 if (!strncasecmp(token, format_pfx, sizeof(format_pfx) - 1)) {</span></a>
<a name="1819"><span class="lineNum">    1819 </span>                :<span class="lineCov">         26 :                         token += sizeof(format_pfx) - 1;</span></a>
<a name="1820"><span class="lineNum">    1820 </span>                :<span class="lineCov">         26 :                         token_type = TOKEN_FORMAT;</span></a>
<a name="1821"><span class="lineNum">    1821 </span>        [<span class="branchCov" title="Branch 0 was taken 17 times"> + </span><span class="branchCov" title="Branch 1 was taken 33 times"> + </span>]:<span class="lineCov">         50 :                 } else if (!strncasecmp(token, scale_pfx,</span></a>
<a name="1822"><span class="lineNum">    1822 </span>                :            :                                         sizeof(scale_pfx) - 1)) {</a>
<a name="1823"><span class="lineNum">    1823 </span>                :<span class="lineCov">         17 :                         token += sizeof(scale_pfx) - 1;</span></a>
<a name="1824"><span class="lineNum">    1824 </span>                :<span class="lineCov">         17 :                         token_type = TOKEN_SCALE;</span></a>
<a name="1825"><span class="lineNum">    1825 </span>                :            : </a>
<a name="1826"><span class="lineNum">    1826 </span>                :            :                 }</a>
<a name="1827"><span class="lineNum">    1827 </span>                :            : </a>
<a name="1828"><span class="lineNum">    1828 </span>        [<span class="branchCov" title="Branch 0 was taken 59 times"> + </span><span class="branchCov" title="Branch 1 was taken 17 times"> + </span>]:<span class="lineCov">         76 :                 if (token_type & TOKEN_FORMAT) {</span></a>
<a name="1829"><span class="lineNum">    1829 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 56 times"> + </span>]:<span class="lineCov">         59 :                         if (!strcasecmp(token, "none")) {</span></a>
<a name="1830"><span class="lineNum">    1830 </span>                :<span class="lineCov">          3 :                                 format_kind = FK_NONE;</span></a>
<a name="1831"><span class="lineNum">    1831 </span>                :<span class="lineCov">          3 :                                 continue;</span></a>
<a name="1832"><span class="lineNum">    1832 </span>        [<span class="branchCov" title="Branch 0 was taken 24 times"> + </span><span class="branchCov" title="Branch 1 was taken 32 times"> + </span>]:<span class="lineCov">         56 :                         } else if (!strcasecmp(token, "time")) {</span></a>
<a name="1833"><span class="lineNum">    1833 </span>                :<span class="lineCov">         24 :                                 format_kind = FK_TIME;</span></a>
<a name="1834"><span class="lineNum">    1834 </span>                :<span class="lineCov">         24 :                                 continue;</span></a>
<a name="1835"><span class="lineNum">    1835 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 20 times"> + </span>]:<span class="lineCov">         32 :                         } else if (!strcasecmp(token, "unix")) {</span></a>
<a name="1836"><span class="lineNum">    1836 </span>                :<span class="lineCov">         12 :                                 format_kind = FK_UNIX;</span></a>
<a name="1837"><span class="lineNum">    1837 </span>                :<span class="lineCov">         12 :                                 continue;</span></a>
<a name="1838"><span class="lineNum">    1838 </span>                :            :                         }</a>
<a name="1839"><span class="lineNum">    1839 </span>                :            :                 }</a>
<a name="1840"><span class="lineNum">    1840 </span>                :            : </a>
<a name="1841"><span class="lineNum">    1841 </span>        [<span class="branchCov" title="Branch 0 was taken 36 times"> + </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">         37 :                 if (token_type & TOKEN_SCALE) {</span></a>
<a name="1842"><span class="lineNum">    1842 </span>                :<span class="lineCov">         36 :                         precision_scale =</span></a>
<a name="1843"><span class="lineNum">    1843 </span>                :<span class="lineCov">         36 :                                 str2timescale_optarg(token, &precision_width);</span></a>
<a name="1844"><span class="lineNum">    1844 </span>                :            : </a>
<a name="1845"><span class="lineNum">    1845 </span>        [<span class="branchCov" title="Branch 0 was taken 33 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">         36 :                         if (precision_scale > 0)</span></a>
<a name="1846"><span class="lineNum">    1846 </span>                :<span class="lineCov">         33 :                                 continue;</span></a>
<a name="1847"><span class="lineNum">    1847 </span>                :            :                 }</a>
<a name="1848"><span class="lineNum">    1848 </span>                :            : </a>
<a name="1849"><span class="lineNum">    1849 </span>                :<span class="lineCov">          4 :                 free(arg);</span></a>
<a name="1850"><span class="lineNum">    1850 </span>                :<span class="lineCov">          4 :                 return -1;</span></a>
<a name="1851"><span class="lineNum">    1851 </span>                :            :         }</a>
<a name="1852"><span class="lineNum">    1852 </span>                :            : </a>
<a name="1853"><span class="lineNum">    1853 </span>  [<span class="branchCov" title="Branch 0 was taken 16 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span><span class="branchCov" title="Branch 2 was taken 24 times"> + </span><span class="branchCov" title="Branch 3 was taken 12 times"> + </span> :<span class="lineCov">         54 :         switch (format_kind) {</span></a>
<span class="lineNum">         </span>            <span class="branchNoCov" title="Branch 4 was not taken"> - </span>]
<a name="1854"><span class="lineNum">    1854 </span>                :<span class="lineCov">         16 :         case FK_UNSET:</span></a>
<a name="1855"><span class="lineNum">    1855 </span>        [<span class="branchCov" title="Branch 0 was taken 9 times"> + </span><span class="branchCov" title="Branch 1 was taken 7 times"> + </span>]:<span class="lineCov">         16 :                 if (!tflag_format)</span></a>
<a name="1856"><span class="lineNum">    1856 </span>                :<span class="lineCov">          9 :                         tflag_format = "%T";</span></a>
<a name="1857"><span class="lineNum">    1857 </span>                :            :                 break;</a>
<a name="1858"><span class="lineNum">    1858 </span>                :<span class="lineCov">          2 :         case FK_NONE:</span></a>
<a name="1859"><span class="lineNum">    1859 </span>                :<span class="lineCov">          2 :                 tflag_format = NULL;</span></a>
<a name="1860"><span class="lineNum">    1860 </span>                :<span class="lineCov">          2 :                 break;</span></a>
<a name="1861"><span class="lineNum">    1861 </span>                :<span class="lineCov">         24 :         case FK_TIME:</span></a>
<a name="1862"><span class="lineNum">    1862 </span>                :<span class="lineCov">         24 :                 tflag_format = "%T";</span></a>
<a name="1863"><span class="lineNum">    1863 </span>                :<span class="lineCov">         24 :                 break;</span></a>
<a name="1864"><span class="lineNum">    1864 </span>                :<span class="lineCov">         12 :         case FK_UNIX:</span></a>
<a name="1865"><span class="lineNum">    1865 </span>                :<span class="lineCov">         12 :                 tflag_format = "%s";</span></a>
<a name="1866"><span class="lineNum">    1866 </span>                :<span class="lineCov">         12 :                 break;</span></a>
<a name="1867"><span class="lineNum">    1867 </span>                :            :         }</a>
<a name="1868"><span class="lineNum">    1868 </span>                :            : </a>
<a name="1869"><span class="lineNum">    1869 </span>        [<span class="branchCov" title="Branch 0 was taken 30 times"> + </span><span class="branchCov" title="Branch 1 was taken 24 times"> + </span>]:<span class="lineCov">         54 :         if (precision_scale > 0) {</span></a>
<a name="1870"><span class="lineNum">    1870 </span>                :<span class="lineCov">         30 :                 tflag_scale = precision_scale;</span></a>
<a name="1871"><span class="lineNum">    1871 </span>                :<span class="lineCov">         30 :                 tflag_width = precision_width;</span></a>
<a name="1872"><span class="lineNum">    1872 </span>                :            :         }</a>
<a name="1873"><span class="lineNum">    1873 </span>                :            : </a>
<a name="1874"><span class="lineNum">    1874 </span>                :<span class="lineCov">         54 :         free(arg);</span></a>
<a name="1875"><span class="lineNum">    1875 </span>                :<span class="lineCov">         54 :         return 0;</span></a>
<a name="1876"><span class="lineNum">    1876 </span>                :            : }</a>
<a name="1877"><span class="lineNum">    1877 </span>                :            : </a>
<a name="1878"><span class="lineNum">    1878 </span>                :            : static void</a>
<a name="1879"><span class="lineNum">    1879 </span>                :<span class="lineCov">          4 : remove_from_env(char **env, size_t *env_count, const char *var)</span></a>
<a name="1880"><span class="lineNum">    1880 </span>                :            : {</a>
<a name="1881"><span class="lineNum">    1881 </span>                :<span class="lineCov">          4 :         const size_t len = strlen(var);</span></a>
<a name="1882"><span class="lineNum">    1882 </span>                :<span class="lineCov">          4 :         size_t w = 0;</span></a>
<a name="1883"><span class="lineNum">    1883 </span>                :            : </a>
<a name="1884"><span class="lineNum">    1884 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          4 :         debug_func_msg("Removing variable \"%s\" from the command environment",</span></a>
<a name="1885"><span class="lineNum">    1885 </span>                :            :                        var);</a>
<a name="1886"><span class="lineNum">    1886 </span>                :            : </a>
<a name="1887"><span class="lineNum">    1887 </span>        [<span class="branchCov" title="Branch 0 was taken 354 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">        358 :         for (size_t r = 0; r < *env_count; ++r) {</span></a>
<a name="1888"><span class="lineNum">    1888 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 350 times"> + </span>]:<span class="lineCov">        354 :                 if (!strncmp(env[r], var, len) &&</span></a>
<a name="1889"><span class="lineNum">    1889 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          4 :                     (env[r][len] == '=' || env[r][len] == '\0')) {</span></a>
<a name="1890"><span class="lineNum">    1890 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          2 :                         debug_func_msg("Skipping entry %zu (\"%s\")",</span></a>
<a name="1891"><span class="lineNum">    1891 </span>                :            :                                        r, env[r]);</a>
<a name="1892"><span class="lineNum">    1892 </span>                :<span class="lineCov">          2 :                         continue;</span></a>
<a name="1893"><span class="lineNum">    1893 </span>                :            :                 }</a>
<a name="1894"><span class="lineNum">    1894 </span>        [<span class="branchCov" title="Branch 0 was taken 20 times"> + </span><span class="branchCov" title="Branch 1 was taken 332 times"> + </span>]:<span class="lineCov">        352 :                 if (w < r) {</span></a>
<a name="1895"><span class="lineNum">    1895 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 20 times"> + </span>]:<span class="lineCov">         20 :                         debug_func_msg("Copying entry %zu to %zu", r, w);</span></a>
<a name="1896"><span class="lineNum">    1896 </span>                :<span class="lineCov">         20 :                         env[w] = env[r];</span></a>
<a name="1897"><span class="lineNum">    1897 </span>                :            :                 }</a>
<a name="1898"><span class="lineNum">    1898 </span>                :<span class="lineCov">        352 :                 ++w;</span></a>
<a name="1899"><span class="lineNum">    1899 </span>                :            :         }</a>
<a name="1900"><span class="lineNum">    1900 </span>                :            : </a>
<a name="1901"><span class="lineNum">    1901 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          4 :         if (w < *env_count) {</span></a>
<a name="1902"><span class="lineNum">    1902 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          2 :                 debug_func_msg("Decreasing env count from %zu to %zu",</span></a>
<a name="1903"><span class="lineNum">    1903 </span>                :            :                                *env_count, w);</a>
<a name="1904"><span class="lineNum">    1904 </span>                :<span class="lineCov">          2 :                 *env_count = w;</span></a>
<a name="1905"><span class="lineNum">    1905 </span>                :            :         }</a>
<a name="1906"><span class="lineNum">    1906 </span>                :<span class="lineCov">          4 : }</span></a>
<a name="1907"><span class="lineNum">    1907 </span>                :            : </a>
<a name="1908"><span class="lineNum">    1908 </span>                :            : static void</a>
<a name="1909"><span class="lineNum">    1909 </span>                :<span class="lineCov">          5 : add_to_env(char **env, size_t *env_count, char *var, const size_t len)</span></a>
<a name="1910"><span class="lineNum">    1910 </span>                :            : {</a>
<a name="1911"><span class="lineNum">    1911 </span>                :<span class="lineCov">          5 :         size_t r;</span></a>
<a name="1912"><span class="lineNum">    1912 </span>                :            : </a>
<a name="1913"><span class="lineNum">    1913 </span>        [<span class="branchCov" title="Branch 0 was taken 264 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">        266 :         for (r = 0; r < *env_count; ++r) {</span></a>
<a name="1914"><span class="lineNum">    1914 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 261 times"> + </span>]:<span class="lineCov">        264 :                 if (!strncmp(env[r], var, len) &&</span></a>
<a name="1915"><span class="lineNum">    1915 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :                     (env[r][len] == '=' || env[r][len] == '\0'))</span></a>
<a name="1916"><span class="lineNum">    1916 </span>                :            :                         break;</a>
<a name="1917"><span class="lineNum">    1917 </span>                :            :         }</a>
<a name="1918"><span class="lineNum">    1918 </span>                :            : </a>
<a name="1919"><span class="lineNum">    1919 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          5 :         if (r < *env_count) {</span></a>
<a name="1920"><span class="lineNum">    1920 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :                 debug_func_msg("Replacing entry %zu (\"%s\")"</span></a>
<a name="1921"><span class="lineNum">    1921 </span>                :            :                                ", key=\"%.*s\", var=\"%s\"",</a>
<a name="1922"><span class="lineNum">    1922 </span>                :            :                                r, env[r], (int) len, var, var);</a>
<a name="1923"><span class="lineNum">    1923 </span>                :            :         } else {</a>
<a name="1924"><span class="lineNum">    1924 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          2 :                 debug_func_msg("Adding entry %zu"</span></a>
<a name="1925"><span class="lineNum">    1925 </span>                :            :                                ", key=\"%.*s\", var=\"%s\"",</a>
<a name="1926"><span class="lineNum">    1926 </span>                :            :                                r, (int) len, var, var);</a>
<a name="1927"><span class="lineNum">    1927 </span>                :<span class="lineCov">          2 :                 *env_count += 1;</span></a>
<a name="1928"><span class="lineNum">    1928 </span>                :            :         }</a>
<a name="1929"><span class="lineNum">    1929 </span>                :            : </a>
<a name="1930"><span class="lineNum">    1930 </span>                :<span class="lineCov">          5 :         env[r] = var;</span></a>
<a name="1931"><span class="lineNum">    1931 </span>                :<span class="lineCov">          5 : }</span></a>
<a name="1932"><span class="lineNum">    1932 </span>                :            : </a>
<a name="1933"><span class="lineNum">    1933 </span>                :            : static void</a>
<a name="1934"><span class="lineNum">    1934 </span>                :<span class="lineCov">          9 : update_env(char **env, size_t *env_count, char *var)</span></a>
<a name="1935"><span class="lineNum">    1935 </span>                :            : {</a>
<a name="1936"><span class="lineNum">    1936 </span>                :<span class="lineCov">          9 :         char *val = strchr(var, '=');</span></a>
<a name="1937"><span class="lineNum">    1937 </span>                :            : </a>
<a name="1938"><span class="lineNum">    1938 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          9 :         if (val)</span></a>
<a name="1939"><span class="lineNum">    1939 </span>                :<span class="lineCov">          5 :                 add_to_env(env, env_count, var, val - var);</span></a>
<a name="1940"><span class="lineNum">    1940 </span>                :            :         else</a>
<a name="1941"><span class="lineNum">    1941 </span>                :<span class="lineCov">          4 :                 remove_from_env(env, env_count, var);</span></a>
<a name="1942"><span class="lineNum">    1942 </span>                :<span class="lineCov">          9 : }</span></a>
<a name="1943"><span class="lineNum">    1943 </span>                :            : </a>
<a name="1944"><span class="lineNum">    1944 </span>                :            : static char **</a>
<a name="1945"><span class="lineNum">    1945 </span>                :<span class="lineCov">      16251 : make_env(char **orig_env, char *const *env_changes, size_t env_change_count)</span></a>
<a name="1946"><span class="lineNum">    1946 </span>                :            : {</a>
<a name="1947"><span class="lineNum">    1947 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 16246 times"> + </span>]:<span class="lineCov">      16251 :         if (!env_change_count)</span></a>
<a name="1948"><span class="lineNum">    1948 </span>                :            :                 return orig_env;</a>
<a name="1949"><span class="lineNum">    1949 </span>                :            : </a>
<a name="1950"><span class="lineNum">    1950 </span>                :<span class="lineCov">          5 :         char **new_env;</span></a>
<a name="1951"><span class="lineNum">    1951 </span>                :<span class="lineCov">          5 :         size_t new_env_count = 0;</span></a>
<a name="1952"><span class="lineNum">    1952 </span>                :<span class="lineCov">          5 :         size_t new_env_size;</span></a>
<a name="1953"><span class="lineNum">    1953 </span>                :            : </a>
<a name="1954"><span class="lineNum">    1954 </span>                :            :         /* Determining the environment variable count.  */</a>
<a name="1955"><span class="lineNum">    1955 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          5 :         if (orig_env) {</span></a>
<a name="1956"><span class="lineNum">    1956 </span>        [<span class="branchCov" title="Branch 0 was taken 430 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">        435 :                 for (; orig_env[new_env_count]; ++new_env_count)</span></a>
<a name="1957"><span class="lineNum">    1957 </span>                :            :                         ;</a>
<a name="1958"><span class="lineNum">    1958 </span>                :            :         }</a>
<a name="1959"><span class="lineNum">    1959 </span>                :<span class="lineCov">          5 :         new_env_size = new_env_count + env_change_count;</span></a>
<a name="1960"><span class="lineNum">    1960 </span>                :            : </a>
<a name="1961"><span class="lineNum">    1961 </span>  [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 5 times"> + </span>]:<span class="lineCov">          5 :         if (new_env_size < new_env_count || new_env_size < env_change_count ||</span></a>
<a name="1962"><span class="lineNum">    1962 </span>                :            :             new_env_size + 1 < new_env_size)</a>
<a name="1963"><span class="lineNum">    1963 </span>                :<span class="lineNoCov">          0 :                 error_msg_and_die("Cannot construct new environment: the sum "</span></a>
<a name="1964"><span class="lineNum">    1964 </span>                :            :                                   "of old environment variable count (%zu) and "</a>
<a name="1965"><span class="lineNum">    1965 </span>                :            :                                   "environment changes count (%zu) is too big",</a>
<a name="1966"><span class="lineNum">    1966 </span>                :            :                                   new_env_count, env_change_count);</a>
<a name="1967"><span class="lineNum">    1967 </span>                :            : </a>
<a name="1968"><span class="lineNum">    1968 </span>                :<span class="lineCov">          5 :         new_env_size++;</span></a>
<a name="1969"><span class="lineNum">    1969 </span>                :<span class="lineCov">          5 :         new_env = xallocarray(new_env_size, sizeof(*new_env));</span></a>
<a name="1970"><span class="lineNum">    1970 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          5 :         if (new_env_count)</span></a>
<a name="1971"><span class="lineNum">    1971 </span>                :<span class="lineCov">          5 :                 memcpy(new_env, orig_env, new_env_count * sizeof(*orig_env));</span></a>
<a name="1972"><span class="lineNum">    1972 </span>                :            : </a>
<a name="1973"><span class="lineNum">    1973 </span>        [<span class="branchCov" title="Branch 0 was taken 9 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">         14 :         for (size_t i = 0; i < env_change_count; ++i)</span></a>
<a name="1974"><span class="lineNum">    1974 </span>                :<span class="lineCov">          9 :                 update_env(new_env, &new_env_count, env_changes[i]);</span></a>
<a name="1975"><span class="lineNum">    1975 </span>                :            : </a>
<a name="1976"><span class="lineNum">    1976 </span>                :<span class="lineCov">          5 :         new_env[new_env_count] = NULL;</span></a>
<a name="1977"><span class="lineNum">    1977 </span>                :            : </a>
<a name="1978"><span class="lineNum">    1978 </span>                :<span class="lineCov">          5 :         return new_env;</span></a>
<a name="1979"><span class="lineNum">    1979 </span>                :            : }</a>
<a name="1980"><span class="lineNum">    1980 </span>                :            : </a>
<a name="1981"><span class="lineNum">    1981 </span>                :            : /*</a>
<a name="1982"><span class="lineNum">    1982 </span>                :            :  * Initialization part of main() was eating much stack (~0.5k),</a>
<a name="1983"><span class="lineNum">    1983 </span>                :            :  * which was unused after init.</a>
<a name="1984"><span class="lineNum">    1984 </span>                :            :  * We can reuse it if we move init code into a separate function.</a>
<a name="1985"><span class="lineNum">    1985 </span>                :            :  *</a>
<a name="1986"><span class="lineNum">    1986 </span>                :            :  * Don't want main() to inline us and defeat the reason</a>
<a name="1987"><span class="lineNum">    1987 </span>                :            :  * we have a separate function.</a>
<a name="1988"><span class="lineNum">    1988 </span>                :            :  */</a>
<a name="1989"><span class="lineNum">    1989 </span>                :            : static void ATTRIBUTE_NOINLINE</a>
<a name="1990"><span class="lineNum">    1990 </span>                :<span class="lineCov">      22653 : init(int argc, char *argv[])</span></a>
<a name="1991"><span class="lineNum">    1991 </span>                :            : {</a>
<a name="1992"><span class="lineNum">    1992 </span>                :<span class="lineCov">      22653 :         static const char qflag_qual[] = "attach,personality";</span></a>
<a name="1993"><span class="lineNum">    1993 </span>                :<span class="lineCov">      22653 :         static const char qqflag_qual[] = "exit,attach,personality";</span></a>
<a name="1994"><span class="lineNum">    1994 </span>                :<span class="lineCov">      22653 :         static const char qqqflag_qual[] = "all";</span></a>
<a name="1995"><span class="lineNum">    1995 </span>                :<span class="lineCov">      22653 :         static const char yflag_qual[] = "path";</span></a>
<a name="1996"><span class="lineNum">    1996 </span>                :<span class="lineCov">      22653 :         static const char yyflag_qual[] = "all";</span></a>
<a name="1997"><span class="lineNum">    1997 </span>                :<span class="lineCov">      22653 :         static const char tflag_str[] = "format:time";</span></a>
<a name="1998"><span class="lineNum">    1998 </span>                :<span class="lineCov">      22653 :         static const char ttflag_str[] = "precision:us,format:time";</span></a>
<a name="1999"><span class="lineNum">    1999 </span>                :<span class="lineCov">      22653 :         static const char tttflag_str[] = "format:unix,precision:us";</span></a>
<a name="2000"><span class="lineNum">    2000 </span>                :            : </a>
<a name="2001"><span class="lineNum">    2001 </span>                :<span class="lineCov">      22653 :         int c, i;</span></a>
<a name="2002"><span class="lineNum">    2002 </span>                :<span class="lineCov">      22653 :         int optF = 0, zflags = 0;</span></a>
<a name="2003"><span class="lineNum">    2003 </span>                :<span class="lineCov">      22653 :         int lopt_idx;</span></a>
<a name="2004"><span class="lineNum">    2004 </span>                :<span class="lineCov">      22653 :         int daemonized_tracer_long = DAEMONIZE_NONE;</span></a>
<a name="2005"><span class="lineNum">    2005 </span>                :<span class="lineCov">      22653 :         int xflag_long = HEXSTR_NONE;</span></a>
<a name="2006"><span class="lineNum">    2006 </span>                :<span class="lineCov">      22653 :         int qflag_short = 0;</span></a>
<a name="2007"><span class="lineNum">    2007 </span>                :<span class="lineCov">      22653 :         int followfork_short = 0;</span></a>
<a name="2008"><span class="lineNum">    2008 </span>                :<span class="lineCov">      22653 :         int yflag_short = 0;</span></a>
<a name="2009"><span class="lineNum">    2009 </span>                :<span class="lineCov">      22653 :         bool tflag_long_set = false;</span></a>
<a name="2010"><span class="lineNum">    2010 </span>                :<span class="lineCov">      22653 :         int tflag_short = 0;</span></a>
<a name="2011"><span class="lineNum">    2011 </span>                :<span class="lineCov">      22653 :         bool columns_set = false;</span></a>
<a name="2012"><span class="lineNum">    2012 </span>                :<span class="lineCov">      22653 :         bool sortby_set = false;</span></a>
<a name="2013"><span class="lineNum">    2013 </span>                :            : </a>
<a name="2014"><span class="lineNum">    2014 </span>                :            :         /*</a>
<a name="2015"><span class="lineNum">    2015 </span>                :            :          * We can initialise global_path_set only after tracing backend</a>
<a name="2016"><span class="lineNum">    2016 </span>                :            :          * initialisation, so we store pointers to all the paths from</a>
<a name="2017"><span class="lineNum">    2017 </span>                :            :          * command-line arguments during parsing in this array and then,</a>
<a name="2018"><span class="lineNum">    2018 </span>                :            :          * after the successful backend initialisation, iterate over it</a>
<a name="2019"><span class="lineNum">    2019 </span>                :            :          * in order to add them to global_path_set.</a>
<a name="2020"><span class="lineNum">    2020 </span>                :            :          */</a>
<a name="2021"><span class="lineNum">    2021 </span>                :<span class="lineCov">      22653 :         const char **pathtrace_paths = NULL;</span></a>
<a name="2022"><span class="lineNum">    2022 </span>                :<span class="lineCov">      22653 :         size_t pathtrace_size = 0;</span></a>
<a name="2023"><span class="lineNum">    2023 </span>                :<span class="lineCov">      22653 :         size_t pathtrace_count = 0;</span></a>
<a name="2024"><span class="lineNum">    2024 </span>                :            : </a>
<a name="2025"><span class="lineNum">    2025 </span>                :            :         /**</a>
<a name="2026"><span class="lineNum">    2026 </span>                :            :          * Storage for environment changes requested for command.  They</a>
<a name="2027"><span class="lineNum">    2027 </span>                :            :          * are stored in a temporary array and not applied as is during</a>
<a name="2028"><span class="lineNum">    2028 </span>                :            :          * command line parsing for two reasons:</a>
<a name="2029"><span class="lineNum">    2029 </span>                :            :          *  - putenv() changes environment of the tracer as well,</a>
<a name="2030"><span class="lineNum">    2030 </span>                :            :          *    which is unacceptable.</a>
<a name="2031"><span class="lineNum">    2031 </span>                :            :          *  - Environment changes have to be applied</a>
<a name="2032"><span class="lineNum">    2032 </span>                :            :          *    in a tracing-backend-specific way.</a>
<a name="2033"><span class="lineNum">    2033 </span>                :            :          */</a>
<a name="2034"><span class="lineNum">    2034 </span>                :<span class="lineCov">      22653 :         char **env_changes = NULL;</span></a>
<a name="2035"><span class="lineNum">    2035 </span>                :<span class="lineCov">      22653 :         size_t env_change_size = 0;</span></a>
<a name="2036"><span class="lineNum">    2036 </span>                :<span class="lineCov">      22653 :         size_t env_change_count = 0;</span></a>
<a name="2037"><span class="lineNum">    2037 </span>                :            : </a>
<a name="2038"><span class="lineNum">    2038 </span>  [<span class="branchCov" title="Branch 0 was taken 22653 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span><span class="branchCov" title="Branch 3 was taken 22652 times"> + </span>]:<span class="lineCov">      22653 :         if (!program_invocation_name || !*program_invocation_name) {</span></a>
<a name="2039"><span class="lineNum">    2039 </span>                :<span class="lineCov">          1 :                 static char name[] = "strace";</span></a>
<a name="2040"><span class="lineNum">    2040 </span>                :<span class="lineCov">          1 :                 program_invocation_name =</span></a>
<a name="2041"><span class="lineNum">    2041 </span>  [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span> :<span class="lineCov">          1 :                         (argc > 0 && argv[0] && *argv[0]) ? argv[0] : name;</span></a>
<span class="lineNum">         </span>         <span class="branchNoCov" title="Branch 4 was not taken"> - </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>]
<a name="2042"><span class="lineNum">    2042 </span>                :            :         }</a>
<a name="2043"><span class="lineNum">    2043 </span>                :            : </a>
<a name="2044"><span class="lineNum">    2044 </span>                :<span class="lineCov">      22653 :         strace_tracer_pid = getpid();</span></a>
<a name="2045"><span class="lineNum">    2045 </span>                :            : </a>
<a name="2046"><span class="lineNum">    2046 </span>                :<span class="lineCov">      22653 :         os_release = get_os_release();</span></a>
<a name="2047"><span class="lineNum">    2047 </span>                :            : </a>
<a name="2048"><span class="lineNum">    2048 </span>                :<span class="lineCov">      22653 :         pidns_init();</span></a>
<a name="2049"><span class="lineNum">    2049 </span>                :            : </a>
<a name="2050"><span class="lineNum">    2050 </span>                :<span class="lineCov">      22653 :         shared_log = stderr;</span></a>
<a name="2051"><span class="lineNum">    2051 </span>                :<span class="lineCov">      22653 :         set_sortby(DEFAULT_SORTBY);</span></a>
<a name="2052"><span class="lineNum">    2052 </span>                :<span class="lineCov">      22653 :         set_personality(DEFAULT_PERSONALITY);</span></a>
<a name="2053"><span class="lineNum">    2053 </span>                :<span class="lineCov">      22653 :         qualify_trace("all");</span></a>
<a name="2054"><span class="lineNum">    2054 </span>                :<span class="lineCov">      22653 :         qualify_abbrev("all");</span></a>
<a name="2055"><span class="lineNum">    2055 </span>                :<span class="lineCov">      22653 :         qualify_verbose("all");</span></a>
<a name="2056"><span class="lineNum">    2056 </span>                :            : #if DEFAULT_QUAL_FLAGS != (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)</a>
<a name="2057"><span class="lineNum">    2057 </span>                :            : # error Bug in DEFAULT_QUAL_FLAGS</a>
<a name="2058"><span class="lineNum">    2058 </span>                :            : #endif</a>
<a name="2059"><span class="lineNum">    2059 </span>                :<span class="lineCov">      22653 :         qualify_status("all");</span></a>
<a name="2060"><span class="lineNum">    2060 </span>                :<span class="lineCov">      22653 :         qualify_quiet("none");</span></a>
<a name="2061"><span class="lineNum">    2061 </span>                :<span class="lineCov">      22653 :         qualify_decode_fd("none");</span></a>
<a name="2062"><span class="lineNum">    2062 </span>                :<span class="lineCov">      22653 :         qualify_signals("all");</span></a>
<a name="2063"><span class="lineNum">    2063 </span>                :            : </a>
<a name="2064"><span class="lineNum">    2064 </span>                :<span class="lineCov">      22653 :         static const char optstring[] =</span></a>
<a name="2065"><span class="lineNum">    2065 </span>                :            :                 "+a:Ab:cCdDe:E:fFhiI:kno:O:p:P:qrs:S:tTu:U:vVwxX:yzZ";</a>
<a name="2066"><span class="lineNum">    2066 </span>                :            : </a>
<a name="2067"><span class="lineNum">    2067 </span>                :<span class="lineCov">      22653 :         enum {</span></a>
<a name="2068"><span class="lineNum">    2068 </span>                :            :                 GETOPT_SECCOMP = 0x100,</a>
<a name="2069"><span class="lineNum">    2069 </span>                :            :                 GETOPT_DAEMONIZE,</a>
<a name="2070"><span class="lineNum">    2070 </span>                :            :                 GETOPT_HEX_STR,</a>
<a name="2071"><span class="lineNum">    2071 </span>                :            :                 GETOPT_FOLLOWFORKS,</a>
<a name="2072"><span class="lineNum">    2072 </span>                :            :                 GETOPT_OUTPUT_SEPARATELY,</a>
<a name="2073"><span class="lineNum">    2073 </span>                :            :                 GETOPT_TS,</a>
<a name="2074"><span class="lineNum">    2074 </span>                :            :                 GETOPT_PIDNS_TRANSLATION,</a>
<a name="2075"><span class="lineNum">    2075 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="2076"><span class="lineNum">    2076 </span>                :            :                 GETOPT_SECONTEXT,</a>
<a name="2077"><span class="lineNum">    2077 </span>                :            : #endif</a>
<a name="2078"><span class="lineNum">    2078 </span>                :            : </a>
<a name="2079"><span class="lineNum">    2079 </span>                :            :                 GETOPT_QUAL_TRACE,</a>
<a name="2080"><span class="lineNum">    2080 </span>                :            :                 GETOPT_QUAL_ABBREV,</a>
<a name="2081"><span class="lineNum">    2081 </span>                :            :                 GETOPT_QUAL_VERBOSE,</a>
<a name="2082"><span class="lineNum">    2082 </span>                :            :                 GETOPT_QUAL_RAW,</a>
<a name="2083"><span class="lineNum">    2083 </span>                :            :                 GETOPT_QUAL_SIGNAL,</a>
<a name="2084"><span class="lineNum">    2084 </span>                :            :                 GETOPT_QUAL_STATUS,</a>
<a name="2085"><span class="lineNum">    2085 </span>                :            :                 GETOPT_QUAL_READ,</a>
<a name="2086"><span class="lineNum">    2086 </span>                :            :                 GETOPT_QUAL_WRITE,</a>
<a name="2087"><span class="lineNum">    2087 </span>                :            :                 GETOPT_QUAL_FAULT,</a>
<a name="2088"><span class="lineNum">    2088 </span>                :            :                 GETOPT_QUAL_INJECT,</a>
<a name="2089"><span class="lineNum">    2089 </span>                :            :                 GETOPT_QUAL_KVM,</a>
<a name="2090"><span class="lineNum">    2090 </span>                :            :                 GETOPT_QUAL_QUIET,</a>
<a name="2091"><span class="lineNum">    2091 </span>                :            :                 GETOPT_QUAL_DECODE_FD,</a>
<a name="2092"><span class="lineNum">    2092 </span>                :            :         };</a>
<a name="2093"><span class="lineNum">    2093 </span>                :<span class="lineCov">      22653 :         static const struct option longopts[] = {</span></a>
<a name="2094"><span class="lineNum">    2094 </span>                :            :                 { "columns",          required_argument, 0, 'a' },</a>
<a name="2095"><span class="lineNum">    2095 </span>                :            :                 { "output-append-mode",       no_argument,       0, 'A' },</a>
<a name="2096"><span class="lineNum">    2096 </span>                :            :                 { "detach-on",                required_argument, 0, 'b' },</a>
<a name="2097"><span class="lineNum">    2097 </span>                :            :                 { "summary-only",     no_argument,       0, 'c' },</a>
<a name="2098"><span class="lineNum">    2098 </span>                :            :                 { "summary",          no_argument,       0, 'C' },</a>
<a name="2099"><span class="lineNum">    2099 </span>                :            :                 { "debug",            no_argument,       0, 'd' },</a>
<a name="2100"><span class="lineNum">    2100 </span>                :            :                 { "daemonize",                optional_argument, 0, GETOPT_DAEMONIZE },</a>
<a name="2101"><span class="lineNum">    2101 </span>                :            :                 { "daemonised",               optional_argument, 0, GETOPT_DAEMONIZE },</a>
<a name="2102"><span class="lineNum">    2102 </span>                :            :                 { "daemonized",               optional_argument, 0, GETOPT_DAEMONIZE },</a>
<a name="2103"><span class="lineNum">    2103 </span>                :            :                 { "env",              required_argument, 0, 'E' },</a>
<a name="2104"><span class="lineNum">    2104 </span>                :            :                 { "follow-forks",     no_argument,       0, GETOPT_FOLLOWFORKS },</a>
<a name="2105"><span class="lineNum">    2105 </span>                :            :                 { "output-separately",        no_argument,       0,</a>
<a name="2106"><span class="lineNum">    2106 </span>                :            :                         GETOPT_OUTPUT_SEPARATELY },</a>
<a name="2107"><span class="lineNum">    2107 </span>                :            :                 { "help",             no_argument,       0, 'h' },</a>
<a name="2108"><span class="lineNum">    2108 </span>                :            :                 { "instruction-pointer", no_argument,      0, 'i' },</a>
<a name="2109"><span class="lineNum">    2109 </span>                :            :                 { "interruptible",    required_argument, 0, 'I' },</a>
<a name="2110"><span class="lineNum">    2110 </span>                :            :                 { "stack-traces",     no_argument,       0, 'k' },</a>
<a name="2111"><span class="lineNum">    2111 </span>                :            :                 { "syscall-number",   no_argument,       0, 'n' },</a>
<a name="2112"><span class="lineNum">    2112 </span>                :            :                 { "output",           required_argument, 0, 'o' },</a>
<a name="2113"><span class="lineNum">    2113 </span>                :            :                 { "summary-syscall-overhead", required_argument, 0, 'O' },</a>
<a name="2114"><span class="lineNum">    2114 </span>                :            :                 { "attach",           required_argument, 0, 'p' },</a>
<a name="2115"><span class="lineNum">    2115 </span>                :            :                 { "trace-path",               required_argument, 0, 'P' },</a>
<a name="2116"><span class="lineNum">    2116 </span>                :            :                 { "relative-timestamps", optional_argument, 0, 'r' },</a>
<a name="2117"><span class="lineNum">    2117 </span>                :            :                 { "string-limit",     required_argument, 0, 's' },</a>
<a name="2118"><span class="lineNum">    2118 </span>                :            :                 { "summary-sort-by",  required_argument, 0, 'S' },</a>
<a name="2119"><span class="lineNum">    2119 </span>                :            :                 { "absolute-timestamps", optional_argument, 0, GETOPT_TS },</a>
<a name="2120"><span class="lineNum">    2120 </span>                :            :                 { "timestamps",               optional_argument, 0, GETOPT_TS },</a>
<a name="2121"><span class="lineNum">    2121 </span>                :            :                 { "syscall-times",    optional_argument, 0, 'T' },</a>
<a name="2122"><span class="lineNum">    2122 </span>                :            :                 { "user",             required_argument, 0, 'u' },</a>
<a name="2123"><span class="lineNum">    2123 </span>                :            :                 { "summary-columns",  required_argument, 0, 'U' },</a>
<a name="2124"><span class="lineNum">    2124 </span>                :            :                 { "no-abbrev",                no_argument,       0, 'v' },</a>
<a name="2125"><span class="lineNum">    2125 </span>                :            :                 { "version",          no_argument,       0, 'V' },</a>
<a name="2126"><span class="lineNum">    2126 </span>                :            :                 { "summary-wall-clock", no_argument,     0, 'w' },</a>
<a name="2127"><span class="lineNum">    2127 </span>                :            :                 { "strings-in-hex",   optional_argument, 0, GETOPT_HEX_STR },</a>
<a name="2128"><span class="lineNum">    2128 </span>                :            :                 { "const-print-style",        required_argument, 0, 'X' },</a>
<a name="2129"><span class="lineNum">    2129 </span>                :            :                 { "pidns-translation",        no_argument      , 0, GETOPT_PIDNS_TRANSLATION },</a>
<a name="2130"><span class="lineNum">    2130 </span>                :            :                 { "successful-only",  no_argument,       0, 'z' },</a>
<a name="2131"><span class="lineNum">    2131 </span>                :            :                 { "failed-only",      no_argument,       0, 'Z' },</a>
<a name="2132"><span class="lineNum">    2132 </span>                :            :                 { "failing-only",     no_argument,       0, 'Z' },</a>
<a name="2133"><span class="lineNum">    2133 </span>                :            :                 { "seccomp-bpf",      no_argument,       0, GETOPT_SECCOMP },</a>
<a name="2134"><span class="lineNum">    2134 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="2135"><span class="lineNum">    2135 </span>                :            :                 { "secontext",                optional_argument, 0, GETOPT_SECONTEXT },</a>
<a name="2136"><span class="lineNum">    2136 </span>                :            : #endif</a>
<a name="2137"><span class="lineNum">    2137 </span>                :            : </a>
<a name="2138"><span class="lineNum">    2138 </span>                :            :                 { "trace",    required_argument, 0, GETOPT_QUAL_TRACE },</a>
<a name="2139"><span class="lineNum">    2139 </span>                :            :                 { "abbrev",   required_argument, 0, GETOPT_QUAL_ABBREV },</a>
<a name="2140"><span class="lineNum">    2140 </span>                :            :                 { "verbose",  required_argument, 0, GETOPT_QUAL_VERBOSE },</a>
<a name="2141"><span class="lineNum">    2141 </span>                :            :                 { "raw",      required_argument, 0, GETOPT_QUAL_RAW },</a>
<a name="2142"><span class="lineNum">    2142 </span>                :            :                 { "signals",  required_argument, 0, GETOPT_QUAL_SIGNAL },</a>
<a name="2143"><span class="lineNum">    2143 </span>                :            :                 { "status",   required_argument, 0, GETOPT_QUAL_STATUS },</a>
<a name="2144"><span class="lineNum">    2144 </span>                :            :                 { "read",     required_argument, 0, GETOPT_QUAL_READ },</a>
<a name="2145"><span class="lineNum">    2145 </span>                :            :                 { "write",    required_argument, 0, GETOPT_QUAL_WRITE },</a>
<a name="2146"><span class="lineNum">    2146 </span>                :            :                 { "fault",    required_argument, 0, GETOPT_QUAL_FAULT },</a>
<a name="2147"><span class="lineNum">    2147 </span>                :            :                 { "inject",   required_argument, 0, GETOPT_QUAL_INJECT },</a>
<a name="2148"><span class="lineNum">    2148 </span>                :            :                 { "kvm",      required_argument, 0, GETOPT_QUAL_KVM },</a>
<a name="2149"><span class="lineNum">    2149 </span>                :            :                 { "quiet",    optional_argument, 0, GETOPT_QUAL_QUIET },</a>
<a name="2150"><span class="lineNum">    2150 </span>                :            :                 { "silent",   optional_argument, 0, GETOPT_QUAL_QUIET },</a>
<a name="2151"><span class="lineNum">    2151 </span>                :            :                 { "silence",  optional_argument, 0, GETOPT_QUAL_QUIET },</a>
<a name="2152"><span class="lineNum">    2152 </span>                :            :                 { "decode-fds",       optional_argument, 0, GETOPT_QUAL_DECODE_FD },</a>
<a name="2153"><span class="lineNum">    2153 </span>                :            : </a>
<a name="2154"><span class="lineNum">    2154 </span>                :            :                 { 0, 0, 0, 0 }</a>
<a name="2155"><span class="lineNum">    2155 </span>                :            :         };</a>
<a name="2156"><span class="lineNum">    2156 </span>                :            : </a>
<a name="2157"><span class="lineNum">    2157 </span>                :<span class="lineCov">      22653 :         lopt_idx = -1;</span></a>
<a name="2158"><span class="lineNum">    2158 </span>        [<span class="branchCov" title="Branch 0 was taken 95275 times"> + </span><span class="branchCov" title="Branch 1 was taken 16513 times"> + </span>]:<span class="lineCov">     134441 :         while ((c = getopt_long(argc, argv, optstring, longopts, &lopt_idx)) != EOF) {</span></a>
<a name="2159"><span class="lineNum">    2159 </span>                :<span class="lineCov">     190550 :                 const struct option *lopt = lopt_idx >= 0</span></a>
<a name="2160"><span class="lineNum">    2160 </span>                :<span class="lineCov">      95275 :                         && (unsigned) lopt_idx < ARRAY_SIZE(longopts)</span></a>
<a name="2161"><span class="lineNum">    2161 </span>        [<span class="branchCov" title="Branch 0 was taken 2783 times"> + </span><span class="branchCov" title="Branch 1 was taken 92492 times"> + </span>]:<span class="lineCov">      95275 :                         ? longopts + lopt_idx : NULL;</span></a>
<a name="2162"><span class="lineNum">    2162 </span>                :<span class="lineCov">      95275 :                 lopt_idx = -1;</span></a>
<a name="2163"><span class="lineNum">    2163 </span>                :            : </a>
<a name="2164"><span class="lineNum">    2164 </span>  [<span class="branchCov" title="Branch 0 was taken 3558 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span><span class="branchCov" title="Branch 2 was taken 8 times"> + </span><span class="branchCov" title="Branch 3 was taken 111 times"> + </span> :<span class="lineCov">      95275 :                 switch (c) {</span></a>
<span class="lineNum">         </span><span class="branchCov" title="Branch 4 was taken 7 times"> + </span><span class="branchCov" title="Branch 5 was taken 12 times"> + </span><span class="branchCov" title="Branch 6 was taken 35 times"> + </span><span class="branchCov" title="Branch 7 was taken 9 times"> + </span><span class="branchCov" title="Branch 8 was taken 34693 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 9 was taken 9 times"> + </span><span class="branchCov" title="Branch 10 was taken 4947 times"> + </span><span class="branchCov" title="Branch 11 was taken 67 times"> + </span><span class="branchCov" title="Branch 12 was taken 8 times"> + </span><span class="branchCov" title="Branch 13 was taken 16 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 14 was taken 4 times"> + </span><span class="branchCov" title="Branch 15 was taken 508 times"> + </span><span class="branchCov" title="Branch 16 was taken 2 times"> + </span><span class="branchCov" title="Branch 17 was taken 4 times"> + </span><span class="branchCov" title="Branch 18 was taken 16248 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 19 was taken 12 times"> + </span><span class="branchCov" title="Branch 20 was taken 42 times"> + </span><span class="branchCov" title="Branch 21 was taken 4999 times"> + </span><span class="branchCov" title="Branch 22 was taken 23339 times"> + </span><span class="branchCov" title="Branch 23 was taken 19 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 24 was taken 65 times"> + </span><span class="branchCov" title="Branch 25 was taken 83 times"> + </span><span class="branchCov" title="Branch 26 was taken 19 times"> + </span><span class="branchCov" title="Branch 27 was taken 51 times"> + </span><span class="branchCov" title="Branch 28 was taken 15 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 29 was taken 20 times"> + </span><span class="branchCov" title="Branch 30 was taken 74 times"> + </span><span class="branchCov" title="Branch 31 was taken 2573 times"> + </span><span class="branchCov" title="Branch 32 was taken 1100 times"> + </span><span class="branchCov" title="Branch 33 was taken 34 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 34 was taken 11 times"> + </span><span class="branchCov" title="Branch 35 was taken 11 times"> + </span><span class="branchCov" title="Branch 36 was taken 297 times"> + </span><span class="branchCov" title="Branch 37 was taken 88 times"> + </span><span class="branchCov" title="Branch 38 was taken 88 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 39 was taken 9 times"> + </span><span class="branchCov" title="Branch 40 was taken 5 times"> + </span><span class="branchCov" title="Branch 41 was taken 10 times"> + </span><span class="branchCov" title="Branch 42 was taken 75 times"> + </span><span class="branchCov" title="Branch 43 was taken 335 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 44 was taken 127 times"> + </span><span class="branchCov" title="Branch 45 was taken 127 times"> + </span><span class="branchCov" title="Branch 46 was taken 127 times"> + </span><span class="branchCov" title="Branch 47 was taken 107 times"> + </span><span class="branchCov" title="Branch 48 was taken 4 times"> + </span> 
<span class="lineNum">         </span><span class="branchCov" title="Branch 49 was taken 34 times"> + </span><span class="branchCov" title="Branch 50 was taken 34 times"> + </span><span class="branchCov" title="Branch 51 was taken 515 times"> + </span><span class="branchCov" title="Branch 52 was taken 528 times"> + </span><span class="branchCov" title="Branch 53 was taken 1 time"> + </span> 
<span class="lineNum">         </span>   <span class="branchCov" title="Branch 54 was taken 27 times"> + </span><span class="branchCov" title="Branch 55 was taken 18 times"> + </span><span class="branchNoCov" title="Branch 56 was not taken"> - </span><span class="branchCov" title="Branch 57 was taken 4 times"> + </span>]
<a name="2165"><span class="lineNum">    2165 </span>                :<span class="lineCov">       3558 :                 case 'a':</span></a>
<a name="2166"><span class="lineNum">    2166 </span>                :<span class="lineCov">       3558 :                         acolumn = string_to_uint(optarg);</span></a>
<a name="2167"><span class="lineNum">    2167 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 3557 times"> + </span>]:<span class="lineCov">       3558 :                         if (acolumn < 0)</span></a>
<a name="2168"><span class="lineNum">    2168 </span>                :<span class="lineCov">          1 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2169"><span class="lineNum">    2169 </span>                :            :                         break;</a>
<a name="2170"><span class="lineNum">    2170 </span>                :<span class="lineCov">          2 :                 case 'A':</span></a>
<a name="2171"><span class="lineNum">    2171 </span>                :<span class="lineCov">          2 :                         open_append = true;</span></a>
<a name="2172"><span class="lineNum">    2172 </span>                :<span class="lineCov">          2 :                         break;</span></a>
<a name="2173"><span class="lineNum">    2173 </span>                :<span class="lineCov">          8 :                 case 'b':</span></a>
<a name="2174"><span class="lineNum">    2174 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          8 :                         if (strcmp(optarg, "execve") != 0)</span></a>
<a name="2175"><span class="lineNum">    2175 </span>                :<span class="lineCov">          4 :                                 error_msg_and_die("Syscall '%s' for -b isn't supported",</span></a>
<a name="2176"><span class="lineNum">    2176 </span>                :            :                                         optarg);</a>
<a name="2177"><span class="lineNum">    2177 </span>                :<span class="lineCov">          4 :                         detach_on_execve = 1;</span></a>
<a name="2178"><span class="lineNum">    2178 </span>                :<span class="lineCov">          4 :                         break;</span></a>
<a name="2179"><span class="lineNum">    2179 </span>                :<span class="lineCov">        111 :                 case 'c':</span></a>
<a name="2180"><span class="lineNum">    2180 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 109 times"> + </span>]:<span class="lineCov">        111 :                         if (cflag == CFLAG_BOTH) {</span></a>
<a name="2181"><span class="lineNum">    2181 </span>                :<span class="lineCov">          2 :                                 error_msg_and_help("-c/--summary-only and "</span></a>
<a name="2182"><span class="lineNum">    2182 </span>                :            :                                                    "-C/--summary are mutually "</a>
<a name="2183"><span class="lineNum">    2183 </span>                :            :                                                    "exclusive");</a>
<a name="2184"><span class="lineNum">    2184 </span>                :            :                         }</a>
<a name="2185"><span class="lineNum">    2185 </span>                :<span class="lineCov">        109 :                         cflag = CFLAG_ONLY_STATS;</span></a>
<a name="2186"><span class="lineNum">    2186 </span>                :<span class="lineCov">        109 :                         break;</span></a>
<a name="2187"><span class="lineNum">    2187 </span>                :<span class="lineCov">          7 :                 case 'C':</span></a>
<a name="2188"><span class="lineNum">    2188 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          7 :                         if (cflag == CFLAG_ONLY_STATS) {</span></a>
<a name="2189"><span class="lineNum">    2189 </span>                :<span class="lineCov">          2 :                                 error_msg_and_help("-c/--summary-only and "</span></a>
<a name="2190"><span class="lineNum">    2190 </span>                :            :                                                    "-C/--summary are mutually "</a>
<a name="2191"><span class="lineNum">    2191 </span>                :            :                                                    "exclusive");</a>
<a name="2192"><span class="lineNum">    2192 </span>                :            :                         }</a>
<a name="2193"><span class="lineNum">    2193 </span>                :<span class="lineCov">          5 :                         cflag = CFLAG_BOTH;</span></a>
<a name="2194"><span class="lineNum">    2194 </span>                :<span class="lineCov">          5 :                         break;</span></a>
<a name="2195"><span class="lineNum">    2195 </span>                :<span class="lineCov">         12 :                 case 'd':</span></a>
<a name="2196"><span class="lineNum">    2196 </span>                :<span class="lineCov">         12 :                         debug_flag = 1;</span></a>
<a name="2197"><span class="lineNum">    2197 </span>                :<span class="lineCov">         12 :                         break;</span></a>
<a name="2198"><span class="lineNum">    2198 </span>                :<span class="lineCov">         35 :                 case 'D':</span></a>
<a name="2199"><span class="lineNum">    2199 </span>                :<span class="lineCov">         35 :                         daemonized_tracer++;</span></a>
<a name="2200"><span class="lineNum">    2200 </span>                :<span class="lineCov">         35 :                         break;</span></a>
<a name="2201"><span class="lineNum">    2201 </span>                :<span class="lineCov">          9 :                 case GETOPT_DAEMONIZE:</span></a>
<a name="2202"><span class="lineNum">    2202 </span>                :<span class="lineCov">         18 :                         daemonized_tracer_long =</span></a>
<a name="2203"><span class="lineNum">    2203 </span>                :<span class="lineCov">          9 :                                 find_arg_val(optarg, daemonize_str,</span></a>
<a name="2204"><span class="lineNum">    2204 </span>                :            :                                              DAEMONIZE_GRANDCHILD,</a>
<a name="2205"><span class="lineNum">    2205 </span>                :            :                                              DAEMONIZE_NONE);</a>
<a name="2206"><span class="lineNum">    2206 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>]:<span class="lineCov">          9 :                         if (daemonized_tracer_long <= DAEMONIZE_NONE)</span></a>
<a name="2207"><span class="lineNum">    2207 </span>                :<span class="lineCov">          1 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2208"><span class="lineNum">    2208 </span>                :            :                         break;</a>
<a name="2209"><span class="lineNum">    2209 </span>                :<span class="lineCov">      34693 :                 case 'e':</span></a>
<a name="2210"><span class="lineNum">    2210 </span>                :<span class="lineCov">      34693 :                         qualify(optarg);</span></a>
<a name="2211"><span class="lineNum">    2211 </span>                :<span class="lineCov">      34693 :                         break;</span></a>
<a name="2212"><span class="lineNum">    2212 </span>                :<span class="lineCov">          9 :                 case 'E':</span></a>
<a name="2213"><span class="lineNum">    2213 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          9 :                         if (env_change_count >= env_change_size)</span></a>
<a name="2214"><span class="lineNum">    2214 </span>                :<span class="lineCov">          5 :                                 env_changes = xgrowarray(env_changes,</span></a>
<a name="2215"><span class="lineNum">    2215 </span>                :            :                                                          &env_change_size,</a>
<a name="2216"><span class="lineNum">    2216 </span>                :            :                                                          sizeof(*env_changes));</a>
<a name="2217"><span class="lineNum">    2217 </span>                :            : </a>
<a name="2218"><span class="lineNum">    2218 </span>                :<span class="lineCov">          9 :                         env_changes[env_change_count++] = optarg;</span></a>
<a name="2219"><span class="lineNum">    2219 </span>                :<span class="lineCov">          9 :                         break;</span></a>
<a name="2220"><span class="lineNum">    2220 </span>                :<span class="lineCov">       4947 :                 case 'f':</span></a>
<a name="2221"><span class="lineNum">    2221 </span>                :<span class="lineCov">       4947 :                         followfork_short++;</span></a>
<a name="2222"><span class="lineNum">    2222 </span>                :<span class="lineCov">       4947 :                         break;</span></a>
<a name="2223"><span class="lineNum">    2223 </span>                :<span class="lineCov">         67 :                 case GETOPT_FOLLOWFORKS:</span></a>
<a name="2224"><span class="lineNum">    2224 </span>                :<span class="lineCov">         67 :                         followfork = true;</span></a>
<a name="2225"><span class="lineNum">    2225 </span>                :<span class="lineCov">         67 :                         break;</span></a>
<a name="2226"><span class="lineNum">    2226 </span>                :<span class="lineCov">          8 :                 case GETOPT_OUTPUT_SEPARATELY:</span></a>
<a name="2227"><span class="lineNum">    2227 </span>                :<span class="lineCov">          8 :                         output_separately = true;</span></a>
<a name="2228"><span class="lineNum">    2228 </span>                :<span class="lineCov">          8 :                         break;</span></a>
<a name="2229"><span class="lineNum">    2229 </span>                :            :                 case 'F':</a>
<a name="2230"><span class="lineNum">    2230 </span>                :            :                         optF = 1;</a>
<a name="2231"><span class="lineNum">    2231 </span>                :            :                         break;</a>
<a name="2232"><span class="lineNum">    2232 </span>                :<span class="lineCov">         16 :                 case 'h':</span></a>
<a name="2233"><span class="lineNum">    2233 </span>                :<span class="lineCov">         16 :                         usage();</span></a>
<a name="2234"><span class="lineNum">    2234 </span>                :            :                         break;</a>
<a name="2235"><span class="lineNum">    2235 </span>                :<span class="lineCov">          4 :                 case 'i':</span></a>
<a name="2236"><span class="lineNum">    2236 </span>                :<span class="lineCov">          4 :                         iflag = 1;</span></a>
<a name="2237"><span class="lineNum">    2237 </span>                :<span class="lineCov">          4 :                         break;</span></a>
<a name="2238"><span class="lineNum">    2238 </span>                :<span class="lineCov">        508 :                 case 'I':</span></a>
<a name="2239"><span class="lineNum">    2239 </span>                :<span class="lineCov">        508 :                         opt_intr = parse_interruptible_arg(optarg);</span></a>
<a name="2240"><span class="lineNum">    2240 </span>        [<span class="branchCov" title="Branch 0 was taken 11 times"> + </span><span class="branchCov" title="Branch 1 was taken 497 times"> + </span>]:<span class="lineCov">        508 :                         if (opt_intr <= 0)</span></a>
<a name="2241"><span class="lineNum">    2241 </span>                :<span class="lineCov">         11 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2242"><span class="lineNum">    2242 </span>                :            :                         break;</a>
<a name="2243"><span class="lineNum">    2243 </span>                :<span class="lineCov">          2 :                 case 'k':</span></a>
<a name="2244"><span class="lineNum">    2244 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="2245"><span class="lineNum">    2245 </span>                :            :                         stack_trace_enabled = true;</a>
<a name="2246"><span class="lineNum">    2246 </span>                :            : #else</a>
<a name="2247"><span class="lineNum">    2247 </span>                :<span class="lineCov">          2 :                         error_msg_and_die("Stack traces (-k/--stack-traces "</span></a>
<a name="2248"><span class="lineNum">    2248 </span>                :            :                                           "option) are not supported by this "</a>
<a name="2249"><span class="lineNum">    2249 </span>                :            :                                           "build of strace");</a>
<a name="2250"><span class="lineNum">    2250 </span>                :            : #endif</a>
<a name="2251"><span class="lineNum">    2251 </span>                :<span class="lineCov">          4 :                         break;</span></a>
<a name="2252"><span class="lineNum">    2252 </span>                :<span class="lineCov">          4 :                 case 'n':</span></a>
<a name="2253"><span class="lineNum">    2253 </span>                :<span class="lineCov">          4 :                         nflag = 1;</span></a>
<a name="2254"><span class="lineNum">    2254 </span>                :<span class="lineCov">          4 :                         break;</span></a>
<a name="2255"><span class="lineNum">    2255 </span>                :<span class="lineCov">      16248 :                 case 'o':</span></a>
<a name="2256"><span class="lineNum">    2256 </span>                :<span class="lineCov">      16248 :                         outfname = optarg;</span></a>
<a name="2257"><span class="lineNum">    2257 </span>                :<span class="lineCov">      16248 :                         break;</span></a>
<a name="2258"><span class="lineNum">    2258 </span>                :<span class="lineCov">         12 :                 case 'O':</span></a>
<a name="2259"><span class="lineNum">    2259 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 11 times"> + </span>]:<span class="lineCov">         12 :                         if (set_overhead(optarg) < 0)</span></a>
<a name="2260"><span class="lineNum">    2260 </span>                :<span class="lineCov">          1 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2261"><span class="lineNum">    2261 </span>                :            :                         break;</a>
<a name="2262"><span class="lineNum">    2262 </span>                :<span class="lineCov">         42 :                 case 'p':</span></a>
<a name="2263"><span class="lineNum">    2263 </span>                :<span class="lineCov">         42 :                         process_opt_p_list(optarg);</span></a>
<a name="2264"><span class="lineNum">    2264 </span>                :<span class="lineCov">         42 :                         break;</span></a>
<a name="2265"><span class="lineNum">    2265 </span>                :<span class="lineCov">       4999 :                 case 'P':</span></a>
<a name="2266"><span class="lineNum">    2266 </span>        [<span class="branchCov" title="Branch 0 was taken 2516 times"> + </span><span class="branchCov" title="Branch 1 was taken 2483 times"> + </span>]:<span class="lineCov">       4999 :                         if (pathtrace_count >= pathtrace_size)</span></a>
<a name="2267"><span class="lineNum">    2267 </span>                :<span class="lineCov">       2516 :                                 pathtrace_paths = xgrowarray(pathtrace_paths,</span></a>
<a name="2268"><span class="lineNum">    2268 </span>                :            :                                         &pathtrace_size,</a>
<a name="2269"><span class="lineNum">    2269 </span>                :            :                                         sizeof(pathtrace_paths[0]));</a>
<a name="2270"><span class="lineNum">    2270 </span>                :            : </a>
<a name="2271"><span class="lineNum">    2271 </span>                :<span class="lineCov">       4999 :                         pathtrace_paths[pathtrace_count++] = optarg;</span></a>
<a name="2272"><span class="lineNum">    2272 </span>                :<span class="lineCov">       4999 :                         break;</span></a>
<a name="2273"><span class="lineNum">    2273 </span>                :<span class="lineCov">      23339 :                 case 'q':</span></a>
<a name="2274"><span class="lineNum">    2274 </span>                :<span class="lineCov">      23339 :                         qflag_short++;</span></a>
<a name="2275"><span class="lineNum">    2275 </span>                :<span class="lineCov">      23339 :                         break;</span></a>
<a name="2276"><span class="lineNum">    2276 </span>                :<span class="lineCov">         19 :                 case 'r':</span></a>
<a name="2277"><span class="lineNum">    2277 </span>                :<span class="lineCov">         19 :                         rflag = 1;</span></a>
<a name="2278"><span class="lineNum">    2278 </span>                :<span class="lineCov">         19 :                         rflag_width = 6;</span></a>
<a name="2279"><span class="lineNum">    2279 </span>                :<span class="lineCov">         19 :                         rflag_scale = str2timescale_optarg(optarg,</span></a>
<a name="2280"><span class="lineNum">    2280 </span>                :            :                                                            &rflag_width);</a>
<a name="2281"><span class="lineNum">    2281 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 17 times"> + </span>]:<span class="lineCov">         19 :                         if (rflag_scale < 0)</span></a>
<a name="2282"><span class="lineNum">    2282 </span>                :<span class="lineCov">          2 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2283"><span class="lineNum">    2283 </span>                :            :                         break;</a>
<a name="2284"><span class="lineNum">    2284 </span>                :<span class="lineCov">         65 :                 case 's':</span></a>
<a name="2285"><span class="lineNum">    2285 </span>                :<span class="lineCov">         65 :                         i = string_to_uint(optarg);</span></a>
<a name="2286"><span class="lineNum">    2286 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 61 times"> + </span>]:<span class="lineCov">         65 :                         if (i < 0 || (unsigned int) i > -1U / 4)</span></a>
<a name="2287"><span class="lineNum">    2287 </span>                :<span class="lineCov">          4 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2288"><span class="lineNum">    2288 </span>                :<span class="lineCov">         61 :                         max_strlen = i;</span></a>
<a name="2289"><span class="lineNum">    2289 </span>                :<span class="lineCov">         61 :                         break;</span></a>
<a name="2290"><span class="lineNum">    2290 </span>                :<span class="lineCov">         83 :                 case 'S':</span></a>
<a name="2291"><span class="lineNum">    2291 </span>                :<span class="lineCov">         83 :                         set_sortby(optarg);</span></a>
<a name="2292"><span class="lineNum">    2292 </span>                :<span class="lineCov">         83 :                         sortby_set = true;</span></a>
<a name="2293"><span class="lineNum">    2293 </span>                :<span class="lineCov">         83 :                         break;</span></a>
<a name="2294"><span class="lineNum">    2294 </span>                :<span class="lineCov">         19 :                 case 't':</span></a>
<a name="2295"><span class="lineNum">    2295 </span>                :<span class="lineCov">         19 :                         tflag_short++;</span></a>
<a name="2296"><span class="lineNum">    2296 </span>                :<span class="lineCov">         19 :                         break;</span></a>
<a name="2297"><span class="lineNum">    2297 </span>                :<span class="lineCov">         51 :                 case GETOPT_TS:</span></a>
<a name="2298"><span class="lineNum">    2298 </span>                :<span class="lineCov">         51 :                         tflag_long_set = true;</span></a>
<a name="2299"><span class="lineNum">    2299 </span>  [<span class="branchCov" title="Branch 0 was taken 6 times"> + </span><span class="branchCov" title="Branch 1 was taken 45 times"> + </span><span class="branchCov" title="Branch 2 was taken 4 times"> + </span><span class="branchCov" title="Branch 3 was taken 47 times"> + </span>]:<span class="lineCov">         57 :                         if (parse_ts_arg(optarg ?: tflag_str))</span></a>
<a name="2300"><span class="lineNum">    2300 </span>                :<span class="lineCov">          4 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2301"><span class="lineNum">    2301 </span>                :            :                         break;</a>
<a name="2302"><span class="lineNum">    2302 </span>                :<span class="lineCov">         15 :                 case 'T':</span></a>
<a name="2303"><span class="lineNum">    2303 </span>                :<span class="lineCov">         15 :                         Tflag = 1;</span></a>
<a name="2304"><span class="lineNum">    2304 </span>                :<span class="lineCov">         15 :                         Tflag_width = 6;</span></a>
<a name="2305"><span class="lineNum">    2305 </span>                :<span class="lineCov">         15 :                         Tflag_scale = str2timescale_optarg(optarg,</span></a>
<a name="2306"><span class="lineNum">    2306 </span>                :            :                                                            &Tflag_width);</a>
<a name="2307"><span class="lineNum">    2307 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 13 times"> + </span>]:<span class="lineCov">         15 :                         if (Tflag_scale < 0)</span></a>
<a name="2308"><span class="lineNum">    2308 </span>                :<span class="lineCov">          2 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2309"><span class="lineNum">    2309 </span>                :            :                         break;</a>
<a name="2310"><span class="lineNum">    2310 </span>                :<span class="lineCov">         20 :                 case 'u':</span></a>
<a name="2311"><span class="lineNum">    2311 </span>                :<span class="lineCov">         20 :                         username = optarg;</span></a>
<a name="2312"><span class="lineNum">    2312 </span>                :<span class="lineCov">         20 :                         break;</span></a>
<a name="2313"><span class="lineNum">    2313 </span>                :<span class="lineCov">         74 :                 case 'U':</span></a>
<a name="2314"><span class="lineNum">    2314 </span>                :<span class="lineCov">         74 :                         columns_set = true;</span></a>
<a name="2315"><span class="lineNum">    2315 </span>                :<span class="lineCov">         74 :                         set_count_summary_columns(optarg);</span></a>
<a name="2316"><span class="lineNum">    2316 </span>                :<span class="lineCov">         74 :                         break;</span></a>
<a name="2317"><span class="lineNum">    2317 </span>                :<span class="lineCov">       2573 :                 case 'v':</span></a>
<a name="2318"><span class="lineNum">    2318 </span>                :<span class="lineCov">       2573 :                         qualify_abbrev("none");</span></a>
<a name="2319"><span class="lineNum">    2319 </span>                :<span class="lineCov">       2573 :                         break;</span></a>
<a name="2320"><span class="lineNum">    2320 </span>                :<span class="lineCov">       1100 :                 case 'V':</span></a>
<a name="2321"><span class="lineNum">    2321 </span>                :<span class="lineCov">       1100 :                         print_version();</span></a>
<a name="2322"><span class="lineNum">    2322 </span>                :<span class="lineCov">       1100 :                         exit(0);</span></a>
<a name="2323"><span class="lineNum">    2323 </span>                :<span class="lineCov">         34 :                         break;</span></a>
<a name="2324"><span class="lineNum">    2324 </span>                :<span class="lineCov">         34 :                 case 'w':</span></a>
<a name="2325"><span class="lineNum">    2325 </span>                :<span class="lineCov">         34 :                         count_wallclock = 1;</span></a>
<a name="2326"><span class="lineNum">    2326 </span>                :<span class="lineCov">         34 :                         break;</span></a>
<a name="2327"><span class="lineNum">    2327 </span>                :<span class="lineCov">         11 :                 case 'x':</span></a>
<a name="2328"><span class="lineNum">    2328 </span>                :<span class="lineCov">         11 :                         xflag++;</span></a>
<a name="2329"><span class="lineNum">    2329 </span>                :<span class="lineCov">         11 :                         break;</span></a>
<a name="2330"><span class="lineNum">    2330 </span>                :<span class="lineCov">         11 :                 case GETOPT_HEX_STR:</span></a>
<a name="2331"><span class="lineNum">    2331 </span>                :<span class="lineCov">         11 :                         xflag_long = find_arg_val(optarg, xflag_str,</span></a>
<a name="2332"><span class="lineNum">    2332 </span>                :            :                                                   HEXSTR_ALL, HEXSTR_NONE);</a>
<a name="2333"><span class="lineNum">    2333 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>]:<span class="lineCov">         11 :                         if (xflag_long <= HEXSTR_NONE)</span></a>
<a name="2334"><span class="lineNum">    2334 </span>                :<span class="lineCov">          3 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2335"><span class="lineNum">    2335 </span>                :            :                         break;</a>
<a name="2336"><span class="lineNum">    2336 </span>                :<span class="lineCov">        297 :                 case 'X':</span></a>
<a name="2337"><span class="lineNum">    2337 </span>        [<span class="branchCov" title="Branch 0 was taken 96 times"> + </span><span class="branchCov" title="Branch 1 was taken 201 times"> + </span>]:<span class="lineCov">        297 :                         if (!strcmp(optarg, "raw"))</span></a>
<a name="2338"><span class="lineNum">    2338 </span>                :<span class="lineCov">         96 :                                 xlat_verbosity = XLAT_STYLE_RAW;</span></a>
<a name="2339"><span class="lineNum">    2339 </span>        [<span class="branchCov" title="Branch 0 was taken 96 times"> + </span><span class="branchCov" title="Branch 1 was taken 105 times"> + </span>]:<span class="lineCov">        201 :                         else if (!strcmp(optarg, "abbrev"))</span></a>
<a name="2340"><span class="lineNum">    2340 </span>                :<span class="lineCov">         96 :                                 xlat_verbosity = XLAT_STYLE_ABBREV;</span></a>
<a name="2341"><span class="lineNum">    2341 </span>        [<span class="branchCov" title="Branch 0 was taken 99 times"> + </span><span class="branchCov" title="Branch 1 was taken 6 times"> + </span>]:<span class="lineCov">        105 :                         else if (!strcmp(optarg, "verbose"))</span></a>
<a name="2342"><span class="lineNum">    2342 </span>                :<span class="lineCov">         99 :                                 xlat_verbosity = XLAT_STYLE_VERBOSE;</span></a>
<a name="2343"><span class="lineNum">    2343 </span>                :            :                         else</a>
<a name="2344"><span class="lineNum">    2344 </span>                :<span class="lineCov">          6 :                                 error_opt_arg(c, lopt, optarg);</span></a>
<a name="2345"><span class="lineNum">    2345 </span>                :            :                         break;</a>
<a name="2346"><span class="lineNum">    2346 </span>                :<span class="lineCov">         88 :                 case 'y':</span></a>
<a name="2347"><span class="lineNum">    2347 </span>                :<span class="lineCov">         88 :                         yflag_short++;</span></a>
<a name="2348"><span class="lineNum">    2348 </span>                :<span class="lineCov">         88 :                         break;</span></a>
<a name="2349"><span class="lineNum">    2349 </span>                :<span class="lineCov">         88 :                 case GETOPT_PIDNS_TRANSLATION:</span></a>
<a name="2350"><span class="lineNum">    2350 </span>                :<span class="lineCov">         88 :                         pidns_translation++;</span></a>
<a name="2351"><span class="lineNum">    2351 </span>                :<span class="lineCov">         88 :                         break;</span></a>
<a name="2352"><span class="lineNum">    2352 </span>                :<span class="lineCov">          9 :                 case 'z':</span></a>
<a name="2353"><span class="lineNum">    2353 </span>                :<span class="lineCov">          9 :                         clear_number_set_array(status_set, 1);</span></a>
<a name="2354"><span class="lineNum">    2354 </span>                :<span class="lineCov">          9 :                         add_number_to_set(STATUS_SUCCESSFUL, status_set);</span></a>
<a name="2355"><span class="lineNum">    2355 </span>                :<span class="lineCov">          9 :                         zflags++;</span></a>
<a name="2356"><span class="lineNum">    2356 </span>                :<span class="lineCov">          9 :                         break;</span></a>
<a name="2357"><span class="lineNum">    2357 </span>                :<span class="lineCov">          5 :                 case 'Z':</span></a>
<a name="2358"><span class="lineNum">    2358 </span>                :<span class="lineCov">          5 :                         clear_number_set_array(status_set, 1);</span></a>
<a name="2359"><span class="lineNum">    2359 </span>                :<span class="lineCov">          5 :                         add_number_to_set(STATUS_FAILED, status_set);</span></a>
<a name="2360"><span class="lineNum">    2360 </span>                :<span class="lineCov">          5 :                         zflags++;</span></a>
<a name="2361"><span class="lineNum">    2361 </span>                :<span class="lineCov">          5 :                         break;</span></a>
<a name="2362"><span class="lineNum">    2362 </span>                :<span class="lineCov">         10 :                 case GETOPT_SECCOMP:</span></a>
<a name="2363"><span class="lineNum">    2363 </span>                :<span class="lineCov">         10 :                         seccomp_filtering = true;</span></a>
<a name="2364"><span class="lineNum">    2364 </span>                :<span class="lineCov">         10 :                         break;</span></a>
<a name="2365"><span class="lineNum">    2365 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="2366"><span class="lineNum">    2366 </span>                :<span class="lineCov">         75 :                 case GETOPT_SECONTEXT:</span></a>
<a name="2367"><span class="lineNum">    2367 </span>                :<span class="lineCov">         75 :                         selinux_context = true;</span></a>
<a name="2368"><span class="lineNum">    2368 </span>                :<span class="lineCov">         75 :                         selinux_set_format(optarg);</span></a>
<a name="2369"><span class="lineNum">    2369 </span>                :<span class="lineCov">         75 :                         break;</span></a>
<a name="2370"><span class="lineNum">    2370 </span>                :            : #endif</a>
<a name="2371"><span class="lineNum">    2371 </span>                :<span class="lineCov">        335 :                 case GETOPT_QUAL_TRACE:</span></a>
<a name="2372"><span class="lineNum">    2372 </span>                :<span class="lineCov">        335 :                         qualify_trace(optarg);</span></a>
<a name="2373"><span class="lineNum">    2373 </span>                :<span class="lineCov">        335 :                         break;</span></a>
<a name="2374"><span class="lineNum">    2374 </span>                :<span class="lineCov">        127 :                 case GETOPT_QUAL_ABBREV:</span></a>
<a name="2375"><span class="lineNum">    2375 </span>                :<span class="lineCov">        127 :                         qualify_abbrev(optarg);</span></a>
<a name="2376"><span class="lineNum">    2376 </span>                :<span class="lineCov">        127 :                         break;</span></a>
<a name="2377"><span class="lineNum">    2377 </span>                :<span class="lineCov">        127 :                 case GETOPT_QUAL_VERBOSE:</span></a>
<a name="2378"><span class="lineNum">    2378 </span>                :<span class="lineCov">        127 :                         qualify_verbose(optarg);</span></a>
<a name="2379"><span class="lineNum">    2379 </span>                :<span class="lineCov">        127 :                         break;</span></a>
<a name="2380"><span class="lineNum">    2380 </span>                :<span class="lineCov">        127 :                 case GETOPT_QUAL_RAW:</span></a>
<a name="2381"><span class="lineNum">    2381 </span>                :<span class="lineCov">        127 :                         qualify_raw(optarg);</span></a>
<a name="2382"><span class="lineNum">    2382 </span>                :<span class="lineCov">        127 :                         break;</span></a>
<a name="2383"><span class="lineNum">    2383 </span>                :<span class="lineCov">        107 :                 case GETOPT_QUAL_SIGNAL:</span></a>
<a name="2384"><span class="lineNum">    2384 </span>                :<span class="lineCov">        107 :                         qualify_signals(optarg);</span></a>
<a name="2385"><span class="lineNum">    2385 </span>                :<span class="lineCov">        107 :                         break;</span></a>
<a name="2386"><span class="lineNum">    2386 </span>                :<span class="lineCov">          4 :                 case GETOPT_QUAL_STATUS:</span></a>
<a name="2387"><span class="lineNum">    2387 </span>                :<span class="lineCov">          4 :                         qualify_status(optarg);</span></a>
<a name="2388"><span class="lineNum">    2388 </span>                :<span class="lineCov">          4 :                         break;</span></a>
<a name="2389"><span class="lineNum">    2389 </span>                :<span class="lineCov">         34 :                 case GETOPT_QUAL_READ:</span></a>
<a name="2390"><span class="lineNum">    2390 </span>                :<span class="lineCov">         34 :                         qualify_read(optarg);</span></a>
<a name="2391"><span class="lineNum">    2391 </span>                :<span class="lineCov">         34 :                         break;</span></a>
<a name="2392"><span class="lineNum">    2392 </span>                :<span class="lineCov">         34 :                 case GETOPT_QUAL_WRITE:</span></a>
<a name="2393"><span class="lineNum">    2393 </span>                :<span class="lineCov">         34 :                         qualify_write(optarg);</span></a>
<a name="2394"><span class="lineNum">    2394 </span>                :<span class="lineCov">         34 :                         break;</span></a>
<a name="2395"><span class="lineNum">    2395 </span>                :<span class="lineCov">        515 :                 case GETOPT_QUAL_FAULT:</span></a>
<a name="2396"><span class="lineNum">    2396 </span>                :<span class="lineCov">        515 :                         qualify_fault(optarg);</span></a>
<a name="2397"><span class="lineNum">    2397 </span>                :<span class="lineCov">        515 :                         break;</span></a>
<a name="2398"><span class="lineNum">    2398 </span>                :<span class="lineCov">        528 :                 case GETOPT_QUAL_INJECT:</span></a>
<a name="2399"><span class="lineNum">    2399 </span>                :<span class="lineCov">        528 :                         qualify_inject(optarg);</span></a>
<a name="2400"><span class="lineNum">    2400 </span>                :<span class="lineCov">        528 :                         break;</span></a>
<a name="2401"><span class="lineNum">    2401 </span>                :<span class="lineCov">          1 :                 case GETOPT_QUAL_KVM:</span></a>
<a name="2402"><span class="lineNum">    2402 </span>                :<span class="lineCov">          1 :                         qualify_kvm(optarg);</span></a>
<a name="2403"><span class="lineNum">    2403 </span>                :<span class="lineCov">          1 :                         break;</span></a>
<a name="2404"><span class="lineNum">    2404 </span>                :<span class="lineCov">         27 :                 case GETOPT_QUAL_QUIET:</span></a>
<a name="2405"><span class="lineNum">    2405 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 25 times"> + </span>]:<span class="lineCov">         27 :                         qualify_quiet(optarg ?: qflag_qual);</span></a>
<a name="2406"><span class="lineNum">    2406 </span>                :<span class="lineCov">         27 :                         break;</span></a>
<a name="2407"><span class="lineNum">    2407 </span>                :<span class="lineCov">         18 :                 case GETOPT_QUAL_DECODE_FD:</span></a>
<a name="2408"><span class="lineNum">    2408 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 15 times"> + </span>]:<span class="lineCov">         18 :                         qualify_decode_fd(optarg ?: yflag_qual);</span></a>
<a name="2409"><span class="lineNum">    2409 </span>                :<span class="lineCov">         18 :                         break;</span></a>
<a name="2410"><span class="lineNum">    2410 </span>                :<span class="lineNoCov">          0 :                 default:</span></a>
<a name="2411"><span class="lineNum">    2411 </span>                :<span class="lineNoCov">          0 :                         error_msg_and_help(NULL);</span></a>
<a name="2412"><span class="lineNum">    2412 </span>                :<span class="lineCov">     111788 :                         break;</span></a>
<a name="2413"><span class="lineNum">    2413 </span>                :            :                 }</a>
<a name="2414"><span class="lineNum">    2414 </span>                :            :         }</a>
<a name="2415"><span class="lineNum">    2415 </span>                :            : </a>
<a name="2416"><span class="lineNum">    2416 </span>                :<span class="lineCov">      16513 :         argv += optind;</span></a>
<a name="2417"><span class="lineNum">    2417 </span>                :<span class="lineCov">      16513 :         argc -= optind;</span></a>
<a name="2418"><span class="lineNum">    2418 </span>                :            : </a>
<a name="2419"><span class="lineNum">    2419 </span>  [<span class="branchCov" title="Branch 0 was taken 16512 times"> + </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span><span class="branchCov" title="Branch 2 was taken 16478 times"> + </span><span class="branchCov" title="Branch 3 was taken 34 times"> + </span> :<span class="lineCov">      16513 :         if (argc < 0 || (!nprocs && !argc)) {</span></a>
<span class="lineNum">         </span>         <span class="branchCov" title="Branch 4 was taken 183 times"> + </span><span class="branchCov" title="Branch 5 was taken 16295 times"> + </span>]
<a name="2420"><span class="lineNum">    2420 </span>                :<span class="lineCov">        184 :                 error_msg_and_help("must have PROG [ARGS] or -p PID");</span></a>
<a name="2421"><span class="lineNum">    2421 </span>                :            :         }</a>
<a name="2422"><span class="lineNum">    2422 </span>                :            : </a>
<a name="2423"><span class="lineNum">    2423 </span>        [<span class="branchCov" title="Branch 0 was taken 8 times"> + </span><span class="branchCov" title="Branch 1 was taken 16321 times"> + </span>]:<span class="lineCov">      16329 :         if (daemonized_tracer_long) {</span></a>
<a name="2424"><span class="lineNum">    2424 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          8 :                 if (daemonized_tracer) {</span></a>
<a name="2425"><span class="lineNum">    2425 </span>                :<span class="lineCov">          3 :                         error_msg_and_die("-D and --daemonize cannot"</span></a>
<a name="2426"><span class="lineNum">    2426 </span>                :            :                                           " be provided simultaneously");</a>
<a name="2427"><span class="lineNum">    2427 </span>                :            :                 } else {</a>
<a name="2428"><span class="lineNum">    2428 </span>                :<span class="lineCov">          5 :                         daemonized_tracer = daemonized_tracer_long;</span></a>
<a name="2429"><span class="lineNum">    2429 </span>                :            :                 }</a>
<a name="2430"><span class="lineNum">    2430 </span>                :            :         }</a>
<a name="2431"><span class="lineNum">    2431 </span>                :            : </a>
<a name="2432"><span class="lineNum">    2432 </span>  [<span class="branchCov" title="Branch 0 was taken 30 times"> + </span><span class="branchCov" title="Branch 1 was taken 16296 times"> + </span><span class="branchCov" title="Branch 2 was taken 9 times"> + </span><span class="branchCov" title="Branch 3 was taken 21 times"> + </span>]:<span class="lineCov">      16326 :         if (!argc && daemonized_tracer) {</span></a>
<a name="2433"><span class="lineNum">    2433 </span>                :<span class="lineCov">          9 :                 error_msg_and_help("PROG [ARGS] must be specified with "</span></a>
<a name="2434"><span class="lineNum">    2434 </span>                :            :                                    "-D/--daemonize");</a>
<a name="2435"><span class="lineNum">    2435 </span>                :            :         }</a>
<a name="2436"><span class="lineNum">    2436 </span>                :            : </a>
<a name="2437"><span class="lineNum">    2437 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 16316 times"> + </span>]:<span class="lineCov">      16317 :         if (daemonized_tracer > (unsigned int) MAX_DAEMONIZE_OPTS)</span></a>
<a name="2438"><span class="lineNum">    2438 </span>                :<span class="lineCov">          1 :                 error_msg_and_help("Too many -D's (%u), maximum supported -D "</span></a>
<a name="2439"><span class="lineNum">    2439 </span>                :            :                                    "count is %d",</a>
<a name="2440"><span class="lineNum">    2440 </span>                :            :                                    daemonized_tracer, MAX_DAEMONIZE_OPTS);</a>
<a name="2441"><span class="lineNum">    2441 </span>                :            : </a>
<a name="2442"><span class="lineNum">    2442 </span>        [<span class="branchCov" title="Branch 0 was taken 11 times"> + </span><span class="branchCov" title="Branch 1 was taken 16305 times"> + </span>]:<span class="lineCov">      16316 :         if (tflag_short) {</span></a>
<a name="2443"><span class="lineNum">    2443 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 7 times"> + </span>]:<span class="lineCov">         11 :                 if (tflag_long_set) {</span></a>
<a name="2444"><span class="lineNum">    2444 </span>                :<span class="lineCov">          4 :                         error_msg_and_die("-t and --absolute-timestamps cannot"</span></a>
<a name="2445"><span class="lineNum">    2445 </span>                :            :                                           " be provided simultaneously");</a>
<a name="2446"><span class="lineNum">    2446 </span>                :            :                 }</a>
<a name="2447"><span class="lineNum">    2447 </span>                :            : </a>
<a name="2448"><span class="lineNum">    2448 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">         11 :                 parse_ts_arg(tflag_short == 1 ? tflag_str :</span></a>
<a name="2449"><span class="lineNum">    2449 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          4 :                              tflag_short == 2 ? ttflag_str : tttflag_str);</span></a>
<a name="2450"><span class="lineNum">    2450 </span>                :            :         }</a>
<a name="2451"><span class="lineNum">    2451 </span>                :            : </a>
<a name="2452"><span class="lineNum">    2452 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 16307 times"> + </span>]:<span class="lineCov">      16312 :         if (xflag_long) {</span></a>
<a name="2453"><span class="lineNum">    2453 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          5 :                 if (xflag) {</span></a>
<a name="2454"><span class="lineNum">    2454 </span>                :<span class="lineCov">          2 :                         error_msg_and_die("-x and --strings-in-hex cannot"</span></a>
<a name="2455"><span class="lineNum">    2455 </span>                :            :                                           " be provided simultaneously");</a>
<a name="2456"><span class="lineNum">    2456 </span>                :            :                 } else {</a>
<a name="2457"><span class="lineNum">    2457 </span>                :<span class="lineCov">          3 :                         xflag = xflag_long;</span></a>
<a name="2458"><span class="lineNum">    2458 </span>                :            :                 }</a>
<a name="2459"><span class="lineNum">    2459 </span>                :            :         }</a>
<a name="2460"><span class="lineNum">    2460 </span>                :            : </a>
<a name="2461"><span class="lineNum">    2461 </span>        [<span class="branchCov" title="Branch 0 was taken 74 times"> + </span><span class="branchCov" title="Branch 1 was taken 16236 times"> + </span>]:<span class="lineCov">      16310 :         if (yflag_short) {</span></a>
<a name="2462"><span class="lineNum">    2462 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 71 times"> + </span>]:<span class="lineCov">         74 :                 if (decode_fd_set_updated) {</span></a>
<a name="2463"><span class="lineNum">    2463 </span>                :<span class="lineCov">          3 :                         error_msg_and_die("-y and --decode-fds cannot"</span></a>
<a name="2464"><span class="lineNum">    2464 </span>                :            :                                           " be provided simultaneously");</a>
<a name="2465"><span class="lineNum">    2465 </span>                :            :                 }</a>
<a name="2466"><span class="lineNum">    2466 </span>                :            : </a>
<a name="2467"><span class="lineNum">    2467 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 59 times"> + </span>]:<span class="lineCov">         83 :                 qualify_decode_fd(yflag_short == 1 ? yflag_qual : yyflag_qual);</span></a>
<a name="2468"><span class="lineNum">    2468 </span>                :            :         }</a>
<a name="2469"><span class="lineNum">    2469 </span>                :            : </a>
<a name="2470"><span class="lineNum">    2470 </span>  [<span class="branchCov" title="Branch 0 was taken 10 times"> + </span><span class="branchCov" title="Branch 1 was taken 16297 times"> + </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span><span class="branchCov" title="Branch 3 was taken 9 times"> + </span>]:<span class="lineCov">      16307 :         if (seccomp_filtering && detach_on_execve) {</span></a>
<a name="2471"><span class="lineNum">    2471 </span>                :<span class="lineCov">          1 :                 error_msg("--seccomp-bpf is not enabled because"</span></a>
<a name="2472"><span class="lineNum">    2472 </span>                :            :                           " it is not compatible with -b");</a>
<a name="2473"><span class="lineNum">    2473 </span>                :<span class="lineCov">          1 :                 seccomp_filtering = false;</span></a>
<a name="2474"><span class="lineNum">    2474 </span>                :            :         }</a>
<a name="2475"><span class="lineNum">    2475 </span>                :            : </a>
<a name="2476"><span class="lineNum">    2476 </span>        [<span class="branchCov" title="Branch 0 was taken 2531 times"> + </span><span class="branchCov" title="Branch 1 was taken 13776 times"> + </span>]:<span class="lineCov">      16307 :         if (followfork_short) {</span></a>
<a name="2477"><span class="lineNum">    2477 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 2530 times"> + </span>]:<span class="lineCov">       2531 :                 if (followfork) {</span></a>
<a name="2478"><span class="lineNum">    2478 </span>                :<span class="lineCov">          1 :                         error_msg_and_die("-f and --follow-forks cannot"</span></a>
<a name="2479"><span class="lineNum">    2479 </span>                :            :                                           " be provided simultaneously");</a>
<a name="2480"><span class="lineNum">    2480 </span>  [<span class="branchCov" title="Branch 0 was taken 2415 times"> + </span><span class="branchCov" title="Branch 1 was taken 115 times"> + </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span><span class="branchCov" title="Branch 3 was taken 2414 times"> + </span>]:<span class="lineCov">       2530 :                 } else if (followfork_short >= 2 && output_separately) {</span></a>
<a name="2481"><span class="lineNum">    2481 </span>                :<span class="lineCov">          1 :                         error_msg_and_die("-ff and --output-separately cannot"</span></a>
<a name="2482"><span class="lineNum">    2482 </span>                :            :                                           " be provided simultaneously");</a>
<a name="2483"><span class="lineNum">    2483 </span>                :            :                 } else {</a>
<a name="2484"><span class="lineNum">    2484 </span>                :<span class="lineCov">       2529 :                         followfork = true;</span></a>
<a name="2485"><span class="lineNum">    2485 </span>                :<span class="lineCov">       2529 :                         output_separately = followfork_short >= 2;</span></a>
<a name="2486"><span class="lineNum">    2486 </span>                :            :                 }</a>
<a name="2487"><span class="lineNum">    2487 </span>                :            :         }</a>
<a name="2488"><span class="lineNum">    2488 </span>                :            : </a>
<a name="2489"><span class="lineNum">    2489 </span>        [<span class="branchCov" title="Branch 0 was taken 9 times"> + </span><span class="branchCov" title="Branch 1 was taken 16296 times"> + </span>]:<span class="lineCov">      16305 :         if (seccomp_filtering) {</span></a>
<a name="2490"><span class="lineNum">    2490 </span>  [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 1 time"> + </span> :<span class="lineCov">          9 :                 if (nprocs && (!argc || debug_flag))</span></a>
<span class="lineNum">         </span>         <span class="branchNoCov" title="Branch 4 was not taken"> - </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>]
<a name="2491"><span class="lineNum">    2491 </span>                :<span class="lineCov">          1 :                         error_msg("--seccomp-bpf is not enabled for processes"</span></a>
<a name="2492"><span class="lineNum">    2492 </span>                :            :                                   " attached with -p");</a>
<a name="2493"><span class="lineNum">    2493 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>]:<span class="lineCov">          9 :                 if (!followfork) {</span></a>
<a name="2494"><span class="lineNum">    2494 </span>                :<span class="lineCov">          1 :                         error_msg("--seccomp-bpf cannot be used without "</span></a>
<a name="2495"><span class="lineNum">    2495 </span>                :            :                                   "-f/--follow-forks, disabling");</a>
<a name="2496"><span class="lineNum">    2496 </span>                :<span class="lineCov">          1 :                         seccomp_filtering = false;</span></a>
<a name="2497"><span class="lineNum">    2497 </span>                :            :                 }</a>
<a name="2498"><span class="lineNum">    2498 </span>                :            :         }</a>
<a name="2499"><span class="lineNum">    2499 </span>                :            : </a>
<a name="2500"><span class="lineNum">    2500 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 16302 times"> + </span>]:<span class="lineCov">      16305 :         if (optF) {</span></a>
<a name="2501"><span class="lineNum">    2501 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          3 :                 if (followfork) {</span></a>
<a name="2502"><span class="lineNum">    2502 </span>                :<span class="lineCov">          1 :                         error_msg("deprecated option -F ignored");</span></a>
<a name="2503"><span class="lineNum">    2503 </span>                :            :                 } else {</a>
<a name="2504"><span class="lineNum">    2504 </span>                :<span class="lineCov">          2 :                         error_msg("option -F is deprecated, "</span></a>
<a name="2505"><span class="lineNum">    2505 </span>                :            :                                   "please use -f/--follow-forks instead");</a>
<a name="2506"><span class="lineNum">    2506 </span>                :<span class="lineCov">          2 :                         followfork = true;</span></a>
<a name="2507"><span class="lineNum">    2507 </span>                :            :                 }</a>
<a name="2508"><span class="lineNum">    2508 </span>                :            :         }</a>
<a name="2509"><span class="lineNum">    2509 </span>                :            : </a>
<a name="2510"><span class="lineNum">    2510 </span>  [<span class="branchCov" title="Branch 0 was taken 2418 times"> + </span><span class="branchCov" title="Branch 1 was taken 13887 times"> + </span><span class="branchCov" title="Branch 2 was taken 4 times"> + </span><span class="branchCov" title="Branch 3 was taken 2414 times"> + </span>]:<span class="lineCov">      16305 :         if (output_separately && cflag) {</span></a>
<a name="2511"><span class="lineNum">    2511 </span>                :<span class="lineCov">          4 :                 error_msg_and_help("(-c/--summary-only or -C/--summary) and"</span></a>
<a name="2512"><span class="lineNum">    2512 </span>                :            :                                    " -ff/--output-separately"</a>
<a name="2513"><span class="lineNum">    2513 </span>                :            :                                    " are mutually exclusive");</a>
<a name="2514"><span class="lineNum">    2514 </span>                :            :         }</a>
<a name="2515"><span class="lineNum">    2515 </span>                :            : </a>
<a name="2516"><span class="lineNum">    2516 </span>  [<span class="branchCov" title="Branch 0 was taken 34 times"> + </span><span class="branchCov" title="Branch 1 was taken 16267 times"> + </span><span class="branchCov" title="Branch 2 was taken 7 times"> + </span><span class="branchCov" title="Branch 3 was taken 27 times"> + </span>]:<span class="lineCov">      16301 :         if (count_wallclock && !cflag) {</span></a>
<a name="2517"><span class="lineNum">    2517 </span>                :<span class="lineCov">          7 :                 error_msg_and_help("-w/--summary-wall-clock must be given with"</span></a>
<a name="2518"><span class="lineNum">    2518 </span>                :            :                                    " (-c/--summary-only or -C/--summary)");</a>
<a name="2519"><span class="lineNum">    2519 </span>                :            :         }</a>
<a name="2520"><span class="lineNum">    2520 </span>                :            : </a>
<a name="2521"><span class="lineNum">    2521 </span>  [<span class="branchCov" title="Branch 0 was taken 6 times"> + </span><span class="branchCov" title="Branch 1 was taken 16288 times"> + </span><span class="branchCov" title="Branch 2 was taken 2 times"> + </span><span class="branchCov" title="Branch 3 was taken 4 times"> + </span>]:<span class="lineCov">      16294 :         if (columns_set && !cflag) {</span></a>
<a name="2522"><span class="lineNum">    2522 </span>                :<span class="lineCov">          2 :                 error_msg_and_help("-U/--summary-columns must be given with"</span></a>
<a name="2523"><span class="lineNum">    2523 </span>                :            :                                    " (-c/--summary-only or -C/--summary)");</a>
<a name="2524"><span class="lineNum">    2524 </span>                :            :         }</a>
<a name="2525"><span class="lineNum">    2525 </span>                :            : </a>
<a name="2526"><span class="lineNum">    2526 </span>  [<span class="branchCov" title="Branch 0 was taken 17 times"> + </span><span class="branchCov" title="Branch 1 was taken 16275 times"> + </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span><span class="branchCov" title="Branch 3 was taken 16 times"> + </span>]:<span class="lineCov">      16292 :         if (sortby_set && !cflag) {</span></a>
<a name="2527"><span class="lineNum">    2527 </span>                :<span class="lineCov">          1 :                 error_msg("-S/--summary-sort-by has no effect without"</span></a>
<a name="2528"><span class="lineNum">    2528 </span>                :            :                           " (-c/--summary-only or -C/--summary)");</a>
<a name="2529"><span class="lineNum">    2529 </span>                :            :         }</a>
<a name="2530"><span class="lineNum">    2530 </span>                :            : </a>
<a name="2531"><span class="lineNum">    2531 </span>        [<span class="branchCov" title="Branch 0 was taken 43 times"> + </span><span class="branchCov" title="Branch 1 was taken 16249 times"> + </span>]:<span class="lineCov">      16292 :         if (cflag == CFLAG_ONLY_STATS) {</span></a>
<a name="2532"><span class="lineNum">    2532 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 40 times"> + </span>]:<span class="lineCov">         43 :                 if (iflag)</span></a>
<a name="2533"><span class="lineNum">    2533 </span>                :<span class="lineCov">          3 :                         error_msg("-i/--instruction-pointer has no effect "</span></a>
<a name="2534"><span class="lineNum">    2534 </span>                :            :                                   "with -c/--summary-only");</a>
<a name="2535"><span class="lineNum">    2535 </span>                :<span class="lineCov">         43 :                 if (stack_trace_enabled)</span></a>
<a name="2536"><span class="lineNum">    2536 </span>                :            :                         error_msg("-k/--stack-traces has no effect "</a>
<a name="2537"><span class="lineNum">    2537 </span>                :            :                                   "with -c/--summary-only");</a>
<a name="2538"><span class="lineNum">    2538 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 40 times"> + </span>]:<span class="lineCov">         43 :                 if (nflag)</span></a>
<a name="2539"><span class="lineNum">    2539 </span>                :<span class="lineCov">          3 :                         error_msg("-n/--syscall-number has no effect "</span></a>
<a name="2540"><span class="lineNum">    2540 </span>                :            :                                   "with -c/--summary-only");</a>
<a name="2541"><span class="lineNum">    2541 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 41 times"> + </span>]:<span class="lineCov">         43 :                 if (rflag)</span></a>
<a name="2542"><span class="lineNum">    2542 </span>                :<span class="lineCov">          2 :                         error_msg("-r/--relative-timestamps has no effect "</span></a>
<a name="2543"><span class="lineNum">    2543 </span>                :            :                                   "with -c/--summary-only");</a>
<a name="2544"><span class="lineNum">    2544 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 41 times"> + </span>]:<span class="lineCov">         43 :                 if (tflag_format)</span></a>
<a name="2545"><span class="lineNum">    2545 </span>                :<span class="lineCov">          2 :                         error_msg("-t/--absolute-timestamps has no effect "</span></a>
<a name="2546"><span class="lineNum">    2546 </span>                :            :                                   "with -c/--summary-only");</a>
<a name="2547"><span class="lineNum">    2547 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 41 times"> + </span>]:<span class="lineCov">         43 :                 if (Tflag)</span></a>
<a name="2548"><span class="lineNum">    2548 </span>                :<span class="lineCov">          2 :                         error_msg("-T/--syscall-times has no effect "</span></a>
<a name="2549"><span class="lineNum">    2549 </span>                :            :                                   "with -c/--summary-only");</a>
<a name="2550"><span class="lineNum">    2550 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 41 times"> + </span>]:<span class="lineCov">         43 :                 if (!number_set_array_is_empty(decode_fd_set, 0))</span></a>
<a name="2551"><span class="lineNum">    2551 </span>                :<span class="lineCov">          2 :                         error_msg("-y/--decode-fds has no effect "</span></a>
<a name="2552"><span class="lineNum">    2552 </span>                :            :                                   "with -c/--summary-only");</a>
<a name="2553"><span class="lineNum">    2553 </span>                :            : #ifdef ENABLE_SECONTEXT</a>
<a name="2554"><span class="lineNum">    2554 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 42 times"> + </span>]:<span class="lineCov">         43 :                 if (selinux_context)</span></a>
<a name="2555"><span class="lineNum">    2555 </span>                :<span class="lineCov">          1 :                         error_msg("--secontext has no effect with "</span></a>
<a name="2556"><span class="lineNum">    2556 </span>                :            :                                   "-c/--summary-only");</a>
<a name="2557"><span class="lineNum">    2557 </span>                :            : #endif</a>
<a name="2558"><span class="lineNum">    2558 </span>                :            :         }</a>
<a name="2559"><span class="lineNum">    2559 </span>                :            : </a>
<a name="2560"><span class="lineNum">    2560 </span>        [<span class="branchCov" title="Branch 0 was taken 50 times"> + </span><span class="branchCov" title="Branch 1 was taken 16242 times"> + </span>]:<span class="lineCov">      16292 :         if (!outfname) {</span></a>
<a name="2561"><span class="lineNum">    2561 </span>  [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 46 times"> + </span><span class="branchCov" title="Branch 2 was taken 2 times"> + </span><span class="branchCov" title="Branch 3 was taken 2 times"> + </span>]:<span class="lineCov">         50 :                 if (output_separately && !followfork)</span></a>
<a name="2562"><span class="lineNum">    2562 </span>                :<span class="lineCov">          2 :                         error_msg("--output-separately has no effect "</span></a>
<a name="2563"><span class="lineNum">    2563 </span>                :            :                                   "without -o/--output");</a>
<a name="2564"><span class="lineNum">    2564 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 48 times"> + </span>]:<span class="lineCov">         50 :                 if (open_append)</span></a>
<a name="2565"><span class="lineNum">    2565 </span>                :<span class="lineCov">          2 :                         error_msg("-A/--output-append-mode has no effect "</span></a>
<a name="2566"><span class="lineNum">    2566 </span>                :            :                                   "without -o/--output");</a>
<a name="2567"><span class="lineNum">    2567 </span>                :            :         }</a>
<a name="2568"><span class="lineNum">    2568 </span>                :            : </a>
<a name="2569"><span class="lineNum">    2569 </span>                :            : #ifndef HAVE_OPEN_MEMSTREAM</a>
<a name="2570"><span class="lineNum">    2570 </span>                :            :         if (!is_complete_set(status_set, NUMBER_OF_STATUSES))</a>
<a name="2571"><span class="lineNum">    2571 </span>                :            :                 error_msg_and_help("open_memstream is required to use -z, -Z, or -e status");</a>
<a name="2572"><span class="lineNum">    2572 </span>                :            : #endif</a>
<a name="2573"><span class="lineNum">    2573 </span>                :            : </a>
<a name="2574"><span class="lineNum">    2574 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 16288 times"> + </span>]:<span class="lineCov">      16292 :         if (zflags > 1)</span></a>
<a name="2575"><span class="lineNum">    2575 </span>                :<span class="lineCov">          4 :                 error_msg("Only the last of "</span></a>
<a name="2576"><span class="lineNum">    2576 </span>                :            :                           "-z/--successful-only/-Z/--failed-only options will "</a>
<a name="2577"><span class="lineNum">    2577 </span>                :            :                           "take effect. "</a>
<a name="2578"><span class="lineNum">    2578 </span>                :            :                           "See status qualifier for more complex filters.");</a>
<a name="2579"><span class="lineNum">    2579 </span>                :            : </a>
<a name="2580"><span class="lineNum">    2580 </span>        [<span class="branchCov" title="Branch 0 was taken 4993 times"> + </span><span class="branchCov" title="Branch 1 was taken 16292 times"> + </span>]:<span class="lineCov">      21285 :         for (size_t cnt = 0; cnt < pathtrace_count; ++cnt)</span></a>
<a name="2581"><span class="lineNum">    2581 </span>                :<span class="lineCov">       4993 :                 pathtrace_select(pathtrace_paths[cnt]);</span></a>
<a name="2582"><span class="lineNum">    2582 </span>                :<span class="lineCov">      16292 :         free(pathtrace_paths);</span></a>
<a name="2583"><span class="lineNum">    2583 </span>                :            : </a>
<a name="2584"><span class="lineNum">    2584 </span>                :<span class="lineCov">      16292 :         acolumn_spaces = xmalloc(acolumn + 1);</span></a>
<a name="2585"><span class="lineNum">    2585 </span>                :<span class="lineCov">      16292 :         memset(acolumn_spaces, ' ', acolumn);</span></a>
<a name="2586"><span class="lineNum">    2586 </span>                :<span class="lineCov">      16292 :         acolumn_spaces[acolumn] = '\0';</span></a>
<a name="2587"><span class="lineNum">    2587 </span>                :            : </a>
<a name="2588"><span class="lineNum">    2588 </span>                :<span class="lineCov">      16292 :         set_sighandler(SIGCHLD, SIG_DFL, &params_for_tracee.child_sa);</span></a>
<a name="2589"><span class="lineNum">    2589 </span>                :            : </a>
<a name="2590"><span class="lineNum">    2590 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="2591"><span class="lineNum">    2591 </span>                :            :         if (stack_trace_enabled)</a>
<a name="2592"><span class="lineNum">    2592 </span>                :            :                 unwind_init();</a>
<a name="2593"><span class="lineNum">    2593 </span>                :            : #endif</a>
<a name="2594"><span class="lineNum">    2594 </span>                :            : </a>
<a name="2595"><span class="lineNum">    2595 </span>                :            :         /* See if they want to run as another user. */</a>
<a name="2596"><span class="lineNum">    2596 </span>        [<span class="branchCov" title="Branch 0 was taken 20 times"> + </span><span class="branchCov" title="Branch 1 was taken 16272 times"> + </span>]:<span class="lineCov">      16292 :         if (username != NULL) {</span></a>
<a name="2597"><span class="lineNum">    2597 </span>                :<span class="lineCov">         20 :                 struct passwd *pent;</span></a>
<a name="2598"><span class="lineNum">    2598 </span>                :            : </a>
<a name="2599"><span class="lineNum">    2599 </span>  [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 20 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">         20 :                 if (getuid() != 0 || geteuid() != 0) {</span></a>
<a name="2600"><span class="lineNum">    2600 </span>                :<span class="lineCov">         20 :                         error_msg_and_die("You must be root to use "</span></a>
<a name="2601"><span class="lineNum">    2601 </span>                :            :                                           "the -u/--username option");</a>
<a name="2602"><span class="lineNum">    2602 </span>                :            :                 }</a>
<a name="2603"><span class="lineNum">    2603 </span>                :<span class="lineNoCov">          0 :                 pent = getpwnam(username);</span></a>
<a name="2604"><span class="lineNum">    2604 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (pent == NULL) {</span></a>
<a name="2605"><span class="lineNum">    2605 </span>                :<span class="lineNoCov">          0 :                         error_msg_and_die("Cannot find user '%s'", username);</span></a>
<a name="2606"><span class="lineNum">    2606 </span>                :            :                 }</a>
<a name="2607"><span class="lineNum">    2607 </span>                :<span class="lineNoCov">          0 :                 run_uid = pent->pw_uid;</span></a>
<a name="2608"><span class="lineNum">    2608 </span>                :<span class="lineNoCov">          0 :                 run_gid = pent->pw_gid;</span></a>
<a name="2609"><span class="lineNum">    2609 </span>                :            :         } else {</a>
<a name="2610"><span class="lineNum">    2610 </span>                :<span class="lineCov">      16272 :                 run_uid = getuid();</span></a>
<a name="2611"><span class="lineNum">    2611 </span>                :<span class="lineCov">      16272 :                 run_gid = getgid();</span></a>
<a name="2612"><span class="lineNum">    2612 </span>                :            :         }</a>
<a name="2613"><span class="lineNum">    2613 </span>                :            : </a>
<a name="2614"><span class="lineNum">    2614 </span>        [<span class="branchCov" title="Branch 0 was taken 2585 times"> + </span><span class="branchCov" title="Branch 1 was taken 13687 times"> + </span>]:<span class="lineCov">      16272 :         if (followfork)</span></a>
<a name="2615"><span class="lineNum">    2615 </span>                :<span class="lineCov">       2585 :                 ptrace_setoptions |= PTRACE_O_TRACECLONE |</span></a>
<a name="2616"><span class="lineNum">    2616 </span>                :            :                                      PTRACE_O_TRACEFORK |</a>
<a name="2617"><span class="lineNum">    2617 </span>                :            :                                      PTRACE_O_TRACEVFORK;</a>
<a name="2618"><span class="lineNum">    2618 </span>                :            : </a>
<a name="2619"><span class="lineNum">    2619 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 16265 times"> + </span>]:<span class="lineCov">      16272 :         if (seccomp_filtering)</span></a>
<a name="2620"><span class="lineNum">    2620 </span>                :<span class="lineCov">          7 :                 check_seccomp_filter();</span></a>
<a name="2621"><span class="lineNum">    2621 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 16265 times"> + </span>]:<span class="lineCov">      16272 :         if (seccomp_filtering)</span></a>
<a name="2622"><span class="lineNum">    2622 </span>                :<span class="lineCov">          7 :                 ptrace_setoptions |= PTRACE_O_TRACESECCOMP;</span></a>
<a name="2623"><span class="lineNum">    2623 </span>                :            : </a>
<a name="2624"><span class="lineNum">    2624 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 16260 times"> + </span>]:<span class="lineCov">      16272 :         debug_msg("ptrace_setoptions = %#x", ptrace_setoptions);</span></a>
<a name="2625"><span class="lineNum">    2625 </span>                :<span class="lineCov">      16272 :         test_ptrace_seize();</span></a>
<a name="2626"><span class="lineNum">    2626 </span>                :<span class="lineCov">      16272 :         test_ptrace_get_syscall_info();</span></a>
<a name="2627"><span class="lineNum">    2627 </span>                :            : </a>
<a name="2628"><span class="lineNum">    2628 </span>                :            :         /*</a>
<a name="2629"><span class="lineNum">    2629 </span>                :            :          * Is something weird with our stdin and/or stdout -</a>
<a name="2630"><span class="lineNum">    2630 </span>                :            :          * for example, may they be not open? In this case,</a>
<a name="2631"><span class="lineNum">    2631 </span>                :            :          * ensure that none of the future opens uses them.</a>
<a name="2632"><span class="lineNum">    2632 </span>                :            :          *</a>
<a name="2633"><span class="lineNum">    2633 </span>                :            :          * This was seen in the wild when /proc/sys/kernel/core_pattern</a>
<a name="2634"><span class="lineNum">    2634 </span>                :            :          * was set to "|/bin/strace -o/tmp/LOG PROG":</a>
<a name="2635"><span class="lineNum">    2635 </span>                :            :          * kernel runs coredump helper with fd#0 open but fd#1 closed (!),</a>
<a name="2636"><span class="lineNum">    2636 </span>                :            :          * therefore LOG gets opened to fd#1, and fd#1 is closed by</a>
<a name="2637"><span class="lineNum">    2637 </span>                :            :          * "don't hold up stdin/out open" code soon after.</a>
<a name="2638"><span class="lineNum">    2638 </span>                :            :          */</a>
<a name="2639"><span class="lineNum">    2639 </span>                :<span class="lineCov">      16272 :         ensure_standard_fds_opened();</span></a>
<a name="2640"><span class="lineNum">    2640 </span>                :            : </a>
<a name="2641"><span class="lineNum">    2641 </span>                :            :         /* Check if they want to redirect the output. */</a>
<a name="2642"><span class="lineNum">    2642 </span>        [<span class="branchCov" title="Branch 0 was taken 16242 times"> + </span><span class="branchCov" title="Branch 1 was taken 30 times"> + </span>]:<span class="lineCov">      16272 :         if (outfname) {</span></a>
<a name="2643"><span class="lineNum">    2643 </span>                :            :                 /* See if they want to pipe the output. */</a>
<a name="2644"><span class="lineNum">    2644 </span>        [<span class="branchCov" title="Branch 0 was taken 9 times"> + </span><span class="branchCov" title="Branch 1 was taken 16233 times"> + </span>]:<span class="lineCov">      16242 :                 if (outfname[0] == '|' || outfname[0] == '!') {</span></a>
<a name="2645"><span class="lineNum">    2645 </span>                :            :                         /*</a>
<a name="2646"><span class="lineNum">    2646 </span>                :            :                          * We can't do the <outfname>.PID funny business</a>
<a name="2647"><span class="lineNum">    2647 </span>                :            :                          * when using popen, so prohibit it.</a>
<a name="2648"><span class="lineNum">    2648 </span>                :            :                          */</a>
<a name="2649"><span class="lineNum">    2649 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          9 :                         if (output_separately)</span></a>
<a name="2650"><span class="lineNum">    2650 </span>                :<span class="lineCov">          4 :                                 error_msg_and_help("piping the output and "</span></a>
<a name="2651"><span class="lineNum">    2651 </span>                :            :                                                    "-ff/--output-separately "</a>
<a name="2652"><span class="lineNum">    2652 </span>                :            :                                                    "are mutually exclusive");</a>
<a name="2653"><span class="lineNum">    2653 </span>                :<span class="lineCov">          5 :                         shared_log = strace_popen(outfname + 1);</span></a>
<a name="2654"><span class="lineNum">    2654 </span>        [<span class="branchCov" title="Branch 0 was taken 13827 times"> + </span><span class="branchCov" title="Branch 1 was taken 2406 times"> + </span>]:<span class="lineCov">      16233 :                 } else if (!output_separately) {</span></a>
<a name="2655"><span class="lineNum">    2655 </span>                :<span class="lineCov">      13827 :                         shared_log = strace_fopen(outfname);</span></a>
<a name="2656"><span class="lineNum">    2656 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 2404 times"> + </span>]:<span class="lineCov">       2406 :                 } else if (strlen(outfname) >= PATH_MAX - sizeof(int) * 3) {</span></a>
<a name="2657"><span class="lineNum">    2657 </span>                :<span class="lineCov">          2 :                         errno = ENAMETOOLONG;</span></a>
<a name="2658"><span class="lineNum">    2658 </span>                :<span class="lineCov">          2 :                         perror_msg_and_die("%s", outfname);</span></a>
<a name="2659"><span class="lineNum">    2659 </span>                :            :                 }</a>
<a name="2660"><span class="lineNum">    2660 </span>                :            :         } else {</a>
<a name="2661"><span class="lineNum">    2661 </span>                :            :                 /* -ff without -o FILE is the same as single -f */</a>
<a name="2662"><span class="lineNum">    2662 </span>                :<span class="lineCov">         30 :                 output_separately = false;</span></a>
<a name="2663"><span class="lineNum">    2663 </span>                :            :         }</a>
<a name="2664"><span class="lineNum">    2664 </span>                :            : </a>
<a name="2665"><span class="lineNum">    2665 </span>  [<span class="branchCov" title="Branch 0 was taken 16231 times"> + </span><span class="branchCov" title="Branch 1 was taken 30 times"> + </span><span class="branchCov" title="Branch 2 was taken 16231 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span> :<span class="lineCov">      16261 :         if (!outfname || outfname[0] == '|' || outfname[0] == '!') {</span></a>
<span class="lineNum">         </span>         <span class="branchNoCov" title="Branch 4 was not taken"> - </span><span class="branchCov" title="Branch 5 was taken 16231 times"> + </span>]
<a name="2666"><span class="lineNum">    2666 </span>                :<span class="lineCov">         30 :                 setvbuf(shared_log, NULL, _IOLBF, 0);</span></a>
<a name="2667"><span class="lineNum">    2667 </span>                :            :         }</a>
<a name="2668"><span class="lineNum">    2668 </span>                :            : </a>
<a name="2669"><span class="lineNum">    2669 </span>                :            :         /*</a>
<a name="2670"><span class="lineNum">    2670 </span>                :            :          * argv[0]      -pPID   -oFILE  Default interactive setting</a>
<a name="2671"><span class="lineNum">    2671 </span>                :            :          * yes          *       0       INTR_WHILE_WAIT</a>
<a name="2672"><span class="lineNum">    2672 </span>                :            :          * no           1       0       INTR_WHILE_WAIT</a>
<a name="2673"><span class="lineNum">    2673 </span>                :            :          * yes          *       1       INTR_NEVER</a>
<a name="2674"><span class="lineNum">    2674 </span>                :            :          * no           1       1       INTR_WHILE_WAIT</a>
<a name="2675"><span class="lineNum">    2675 </span>                :            :          */</a>
<a name="2676"><span class="lineNum">    2676 </span>                :            : </a>
<a name="2677"><span class="lineNum">    2677 </span>  [<span class="branchCov" title="Branch 0 was taken 9 times"> + </span><span class="branchCov" title="Branch 1 was taken 16252 times"> + </span><span class="branchCov" title="Branch 2 was taken 6 times"> + </span><span class="branchCov" title="Branch 3 was taken 3 times"> + </span>]:<span class="lineCov">      16261 :         if (daemonized_tracer && !opt_intr)</span></a>
<a name="2678"><span class="lineNum">    2678 </span>                :<span class="lineCov">          6 :                 opt_intr = INTR_BLOCK_TSTP_TOO;</span></a>
<a name="2679"><span class="lineNum">    2679 </span>  [<span class="branchCov" title="Branch 0 was taken 16231 times"> + </span><span class="branchCov" title="Branch 1 was taken 30 times"> + </span><span class="branchCov" title="Branch 2 was taken 16229 times"> + </span><span class="branchCov" title="Branch 3 was taken 2 times"> + </span>]:<span class="lineCov">      16261 :         if (outfname && argc) {</span></a>
<a name="2680"><span class="lineNum">    2680 </span>        [<span class="branchCov" title="Branch 0 was taken 15741 times"> + </span><span class="branchCov" title="Branch 1 was taken 488 times"> + </span>]:<span class="lineCov">      16229 :                 if (!opt_intr)</span></a>
<a name="2681"><span class="lineNum">    2681 </span>                :<span class="lineCov">      15741 :                         opt_intr = INTR_NEVER;</span></a>
<a name="2682"><span class="lineNum">    2682 </span>  [<span class="branchCov" title="Branch 0 was taken 4566 times"> + </span><span class="branchCov" title="Branch 1 was taken 11663 times"> + </span><span class="branchCov" title="Branch 2 was taken 4553 times"> + </span><span class="branchCov" title="Branch 3 was taken 13 times"> + </span>]:<span class="lineCov">      16229 :                 if (!qflag_short && !quiet_set_updated)</span></a>
<a name="2683"><span class="lineNum">    2683 </span>                :<span class="lineCov">       4553 :                         qflag_short = 1;</span></a>
<a name="2684"><span class="lineNum">    2684 </span>                :            :         }</a>
<a name="2685"><span class="lineNum">    2685 </span>        [<span class="branchCov" title="Branch 0 was taken 32 times"> + </span><span class="branchCov" title="Branch 1 was taken 16229 times"> + </span>]:<span class="lineCov">      16261 :         if (!opt_intr)</span></a>
<a name="2686"><span class="lineNum">    2686 </span>                :<span class="lineCov">         32 :                 opt_intr = INTR_WHILE_WAIT;</span></a>
<a name="2687"><span class="lineNum">    2687 </span>                :            : </a>
<a name="2688"><span class="lineNum">    2688 </span>        [<span class="branchCov" title="Branch 0 was taken 16222 times"> + </span><span class="branchCov" title="Branch 1 was taken 39 times"> + </span>]:<span class="lineCov">      16261 :         if (qflag_short) {</span></a>
<a name="2689"><span class="lineNum">    2689 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 16218 times"> + </span>]:<span class="lineCov">      16222 :                 if (quiet_set_updated) {</span></a>
<a name="2690"><span class="lineNum">    2690 </span>                :<span class="lineCov">          4 :                         error_msg_and_die("-q and -e quiet/--quiet cannot"</span></a>
<a name="2691"><span class="lineNum">    2691 </span>                :            :                                           " be provided simultaneously");</a>
<a name="2692"><span class="lineNum">    2692 </span>                :            :                 }</a>
<a name="2693"><span class="lineNum">    2693 </span>                :            : </a>
<a name="2694"><span class="lineNum">    2694 </span>        [<span class="branchCov" title="Branch 0 was taken 11659 times"> + </span><span class="branchCov" title="Branch 1 was taken 4559 times"> + </span>]:<span class="lineCov">      27877 :                 qualify_quiet(qflag_short == 1 ? qflag_qual :</span></a>
<a name="2695"><span class="lineNum">    2695 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 11657 times"> + </span>]:<span class="lineCov">      11659 :                               qflag_short == 2 ? qqflag_qual : qqqflag_qual);</span></a>
<a name="2696"><span class="lineNum">    2696 </span>                :            :         }</a>
<a name="2697"><span class="lineNum">    2697 </span>                :            : </a>
<a name="2698"><span class="lineNum">    2698 </span>                :            :         /*</a>
<a name="2699"><span class="lineNum">    2699 </span>                :            :          * startup_child() must be called before the signal handlers get</a>
<a name="2700"><span class="lineNum">    2700 </span>                :            :          * installed below as they are inherited into the spawned process.</a>
<a name="2701"><span class="lineNum">    2701 </span>                :            :          * Also we do not need to be protected by them as during interruption</a>
<a name="2702"><span class="lineNum">    2702 </span>                :            :          * in the startup_child() mode we kill the spawned process anyway.</a>
<a name="2703"><span class="lineNum">    2703 </span>                :            :          */</a>
<a name="2704"><span class="lineNum">    2704 </span>        [<span class="branchCov" title="Branch 0 was taken 16251 times"> + </span><span class="branchCov" title="Branch 1 was taken 6 times"> + </span>]:<span class="lineCov">      16257 :         if (argc) {</span></a>
<a name="2705"><span class="lineNum">    2705 </span>                :<span class="lineCov">      16251 :                 char **new_environ = make_env(environ, env_changes,</span></a>
<a name="2706"><span class="lineNum">    2706 </span>                :            :                                               env_change_count);</a>
<a name="2707"><span class="lineNum">    2707 </span>                :<span class="lineCov">      16251 :                 free(env_changes);</span></a>
<a name="2708"><span class="lineNum">    2708 </span>                :            : </a>
<a name="2709"><span class="lineNum">    2709 </span>                :<span class="lineCov">      16251 :                 startup_child(argv, new_environ);</span></a>
<a name="2710"><span class="lineNum">    2710 </span>                :            : </a>
<a name="2711"><span class="lineNum">    2711 </span>                :            :                 /*</a>
<a name="2712"><span class="lineNum">    2712 </span>                :            :                  * On a NOMMU system, new_environ can be freed only after exec</a>
<a name="2713"><span class="lineNum">    2713 </span>                :            :                  * in child, so we leak it in that case, similar to pathname</a>
<a name="2714"><span class="lineNum">    2714 </span>                :            :                  * in startup_child().</a>
<a name="2715"><span class="lineNum">    2715 </span>                :            :                  */</a>
<a name="2716"><span class="lineNum">    2716 </span>        [<span class="branchCov" title="Branch 0 was taken 5 times"> + </span><span class="branchCov" title="Branch 1 was taken 16236 times"> + </span>]:<span class="lineCov">      16241 :                 if (new_environ != environ && !NOMMU_SYSTEM)</span></a>
<a name="2717"><span class="lineNum">    2717 </span>                :<span class="lineCov">          5 :                         free(new_environ);</span></a>
<a name="2718"><span class="lineNum">    2718 </span>                :            :         }</a>
<a name="2719"><span class="lineNum">    2719 </span>                :            : </a>
<a name="2720"><span class="lineNum">    2720 </span>                :<span class="lineCov">      16247 :         set_sighandler(SIGTTOU, SIG_IGN, NULL);</span></a>
<a name="2721"><span class="lineNum">    2721 </span>                :<span class="lineCov">      16247 :         set_sighandler(SIGTTIN, SIG_IGN, NULL);</span></a>
<a name="2722"><span class="lineNum">    2722 </span>        [<span class="branchCov" title="Branch 0 was taken 16129 times"> + </span><span class="branchCov" title="Branch 1 was taken 118 times"> + </span>]:<span class="lineCov">      16247 :         if (opt_intr != INTR_ANYWHERE) {</span></a>
<a name="2723"><span class="lineNum">    2723 </span>        [<span class="branchCov" title="Branch 0 was taken 118 times"> + </span><span class="branchCov" title="Branch 1 was taken 16011 times"> + </span>]:<span class="lineCov">      16129 :                 if (opt_intr == INTR_BLOCK_TSTP_TOO)</span></a>
<a name="2724"><span class="lineNum">    2724 </span>                :<span class="lineCov">        118 :                         set_sighandler(SIGTSTP, SIG_IGN, NULL);</span></a>
<a name="2725"><span class="lineNum">    2725 </span>                :            :                 /*</a>
<a name="2726"><span class="lineNum">    2726 </span>                :            :                  * In interactive mode (if no -o OUTFILE, or -p PID is used),</a>
<a name="2727"><span class="lineNum">    2727 </span>                :            :                  * fatal signals are handled asynchronously and acted</a>
<a name="2728"><span class="lineNum">    2728 </span>                :            :                  * when waiting for process state changes.</a>
<a name="2729"><span class="lineNum">    2729 </span>                :            :                  * In non-interactive mode these signals are ignored.</a>
<a name="2730"><span class="lineNum">    2730 </span>                :            :                  */</a>
<a name="2731"><span class="lineNum">    2731 </span>        [<span class="branchCov" title="Branch 0 was taken 15977 times"> + </span><span class="branchCov" title="Branch 1 was taken 152 times"> + </span>]:<span class="lineCov">      32106 :                 set_sighandler(SIGHUP, interactive ? interrupt : SIG_IGN, NULL);</span></a>
<a name="2732"><span class="lineNum">    2732 </span>        [<span class="branchCov" title="Branch 0 was taken 15977 times"> + </span><span class="branchCov" title="Branch 1 was taken 152 times"> + </span>]:<span class="lineCov">      32106 :                 set_sighandler(SIGINT, interactive ? interrupt : SIG_IGN, NULL);</span></a>
<a name="2733"><span class="lineNum">    2733 </span>        [<span class="branchCov" title="Branch 0 was taken 15977 times"> + </span><span class="branchCov" title="Branch 1 was taken 152 times"> + </span>]:<span class="lineCov">      32106 :                 set_sighandler(SIGQUIT, interactive ? interrupt : SIG_IGN, NULL);</span></a>
<a name="2734"><span class="lineNum">    2734 </span>        [<span class="branchCov" title="Branch 0 was taken 15977 times"> + </span><span class="branchCov" title="Branch 1 was taken 152 times"> + </span>]:<span class="lineCov">      32106 :                 set_sighandler(SIGPIPE, interactive ? interrupt : SIG_IGN, NULL);</span></a>
<a name="2735"><span class="lineNum">    2735 </span>        [<span class="branchCov" title="Branch 0 was taken 15977 times"> + </span><span class="branchCov" title="Branch 1 was taken 152 times"> + </span>]:<span class="lineCov">      32106 :                 set_sighandler(SIGTERM, interactive ? interrupt : SIG_IGN, NULL);</span></a>
<a name="2736"><span class="lineNum">    2736 </span>                :            :         }</a>
<a name="2737"><span class="lineNum">    2737 </span>                :            : </a>
<a name="2738"><span class="lineNum">    2738 </span>                :<span class="lineCov">      16247 :         sigemptyset(&timer_set);</span></a>
<a name="2739"><span class="lineNum">    2739 </span>                :<span class="lineCov">      16247 :         sigaddset(&timer_set, SIGALRM);</span></a>
<a name="2740"><span class="lineNum">    2740 </span>                :<span class="lineCov">      16247 :         sigprocmask(SIG_BLOCK, &timer_set, NULL);</span></a>
<a name="2741"><span class="lineNum">    2741 </span>                :<span class="lineCov">      16247 :         set_sighandler(SIGALRM, timer_sighandler, NULL);</span></a>
<a name="2742"><span class="lineNum">    2742 </span>                :            : </a>
<a name="2743"><span class="lineNum">    2743 </span>  [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16247 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">      16247 :         if (nprocs != 0 || daemonized_tracer)</span></a>
<a name="2744"><span class="lineNum">    2744 </span>                :<span class="lineCov">      16247 :                 startup_attach();</span></a>
<a name="2745"><span class="lineNum">    2745 </span>                :            : </a>
<a name="2746"><span class="lineNum">    2746 </span>                :            :         /* Do we want pids printed in our -o OUTFILE?</a>
<a name="2747"><span class="lineNum">    2747 </span>                :            :          * -ff: no (every pid has its own file); or</a>
<a name="2748"><span class="lineNum">    2748 </span>                :            :          * -f: yes (there can be more pids in the future); or</a>
<a name="2749"><span class="lineNum">    2749 </span>                :            :          * -p PID1,PID2: yes (there are already more than one pid)</a>
<a name="2750"><span class="lineNum">    2750 </span>                :            :          */</a>
<a name="2751"><span class="lineNum">    2751 </span>  [<span class="branchCov" title="Branch 0 was taken 16230 times"> + </span><span class="branchCov" title="Branch 1 was taken 25 times"> + </span><span class="branchCov" title="Branch 2 was taken 13826 times"> + </span><span class="branchCov" title="Branch 3 was taken 2404 times"> + </span>]:<span class="lineCov">      16255 :         print_pid_pfx = outfname && !output_separately &&</span></a>
<a name="2752"><span class="lineNum">    2752 </span>  [<span class="branchCov" title="Branch 0 was taken 13654 times"> + </span><span class="branchCov" title="Branch 1 was taken 172 times"> + </span><span class="branchCov" title="Branch 2 was taken 13653 times"> + </span><span class="branchCov" title="Branch 3 was taken 1 time"> + </span>]:<span class="lineCov">      13826 :                 ((followfork && !output_separately) || nprocs > 1);</span></a>
<a name="2753"><span class="lineNum">    2753 </span>                :<span class="lineCov">      16255 : }</span></a>
<a name="2754"><span class="lineNum">    2754 </span>                :            : </a>
<a name="2755"><span class="lineNum">    2755 </span>                :            : static struct tcb *</a>
<a name="2756"><span class="lineNum">    2756 </span>                :<span class="lineCov">  156770917 : pid2tcb(const int pid)</span></a>
<a name="2757"><span class="lineNum">    2757 </span>                :            : {</a>
<a name="2758"><span class="lineNum">    2758 </span>        [<span class="branchCov" title="Branch 0 was taken 156770917 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">  156770917 :         if (pid <= 0)</span></a>
<a name="2759"><span class="lineNum">    2759 </span>                :            :                 return NULL;</a>
<a name="2760"><span class="lineNum">    2760 </span>                :            : </a>
<a name="2761"><span class="lineNum">    2761 </span>                :            : #define PID2TCB_CACHE_SIZE 1024U</a>
<a name="2762"><span class="lineNum">    2762 </span>                :            : #define PID2TCB_CACHE_MASK (PID2TCB_CACHE_SIZE - 1)</a>
<a name="2763"><span class="lineNum">    2763 </span>                :            : </a>
<a name="2764"><span class="lineNum">    2764 </span>                :<span class="lineCov">  156770917 :         static struct tcb *pid2tcb_cache[PID2TCB_CACHE_SIZE];</span></a>
<a name="2765"><span class="lineNum">    2765 </span>                :<span class="lineCov">  156770917 :         struct tcb **const ptcp = &pid2tcb_cache[pid & PID2TCB_CACHE_MASK];</span></a>
<a name="2766"><span class="lineNum">    2766 </span>                :<span class="lineCov">  156770917 :         struct tcb *tcp = *ptcp;</span></a>
<a name="2767"><span class="lineNum">    2767 </span>                :            : </a>
<a name="2768"><span class="lineNum">    2768 </span>  [<span class="branchCov" title="Branch 0 was taken 156713773 times"> + </span><span class="branchCov" title="Branch 1 was taken 57144 times"> + </span><span class="branchCov" title="Branch 2 was taken 9202 times"> + </span><span class="branchCov" title="Branch 3 was taken 156704571 times"> + </span>]:<span class="lineCov">  156770917 :         if (tcp && tcp->pid == pid)</span></a>
<a name="2769"><span class="lineNum">    2769 </span>                :            :                 return tcp;</a>
<a name="2770"><span class="lineNum">    2770 </span>                :            : </a>
<a name="2771"><span class="lineNum">    2771 </span>        [<span class="branchCov" title="Branch 0 was taken 4938390 times"> + </span><span class="branchCov" title="Branch 1 was taken 29594 times"> + </span>]:<span class="lineCov">    4967984 :         for (unsigned int i = 0; i < tcbtabsize; ++i) {</span></a>
<a name="2772"><span class="lineNum">    2772 </span>                :<span class="lineCov">    4938390 :                 tcp = tcbtab[i];</span></a>
<a name="2773"><span class="lineNum">    2773 </span>        [<span class="branchCov" title="Branch 0 was taken 36752 times"> + </span><span class="branchCov" title="Branch 1 was taken 4901638 times"> + </span>]:<span class="lineCov">    4938390 :                 if (tcp->pid == pid)</span></a>
<a name="2774"><span class="lineNum">    2774 </span>                :<span class="lineCov">      36752 :                         return *ptcp = tcp;</span></a>
<a name="2775"><span class="lineNum">    2775 </span>                :            :         }</a>
<a name="2776"><span class="lineNum">    2776 </span>                :            : </a>
<a name="2777"><span class="lineNum">    2777 </span>                :            :         return NULL;</a>
<a name="2778"><span class="lineNum">    2778 </span>                :            : }</a>
<a name="2779"><span class="lineNum">    2779 </span>                :            : </a>
<a name="2780"><span class="lineNum">    2780 </span>                :            : static void</a>
<a name="2781"><span class="lineNum">    2781 </span>                :<span class="lineCov">      21531 : cleanup(int fatal_sig)</span></a>
<a name="2782"><span class="lineNum">    2782 </span>                :            : {</a>
<a name="2783"><span class="lineNum">    2783 </span>                :<span class="lineCov">      21531 :         unsigned int i;</span></a>
<a name="2784"><span class="lineNum">    2784 </span>                :<span class="lineCov">      21531 :         struct tcb *tcp;</span></a>
<a name="2785"><span class="lineNum">    2785 </span>                :            : </a>
<a name="2786"><span class="lineNum">    2786 </span>        [<span class="branchCov" title="Branch 0 was taken 21527 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">      21531 :         if (!fatal_sig)</span></a>
<a name="2787"><span class="lineNum">    2787 </span>                :<span class="lineCov">      21527 :                 fatal_sig = SIGTERM;</span></a>
<a name="2788"><span class="lineNum">    2788 </span>                :            : </a>
<a name="2789"><span class="lineNum">    2789 </span>        [<span class="branchCov" title="Branch 0 was taken 275821 times"> + </span><span class="branchCov" title="Branch 1 was taken 21531 times"> + </span>]:<span class="lineCov">     297352 :         for (i = 0; i < tcbtabsize; i++) {</span></a>
<a name="2790"><span class="lineNum">    2790 </span>                :<span class="lineCov">     275821 :                 tcp = tcbtab[i];</span></a>
<a name="2791"><span class="lineNum">    2791 </span>        [<span class="branchCov" title="Branch 0 was taken 275789 times"> + </span><span class="branchCov" title="Branch 1 was taken 32 times"> + </span>]:<span class="lineCov">     275821 :                 if (!tcp->pid)</span></a>
<a name="2792"><span class="lineNum">    2792 </span>                :<span class="lineCov">     275789 :                         continue;</span></a>
<a name="2793"><span class="lineNum">    2793 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 32 times"> + </span>]:<span class="lineCov">         32 :                 debug_func_msg("looking at pid %u", tcp->pid);</span></a>
<a name="2794"><span class="lineNum">    2794 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 31 times"> + </span>]:<span class="lineCov">         32 :                 if (tcp->pid == strace_child) {</span></a>
<a name="2795"><span class="lineNum">    2795 </span>                :<span class="lineCov">          1 :                         kill(tcp->pid, SIGCONT);</span></a>
<a name="2796"><span class="lineNum">    2796 </span>                :<span class="lineCov">          1 :                         kill(tcp->pid, fatal_sig);</span></a>
<a name="2797"><span class="lineNum">    2797 </span>                :            :                 }</a>
<a name="2798"><span class="lineNum">    2798 </span>                :<span class="lineCov">         32 :                 detach(tcp);</span></a>
<a name="2799"><span class="lineNum">    2799 </span>                :            :         }</a>
<a name="2800"><span class="lineNum">    2800 </span>                :<span class="lineCov">      21531 : }</span></a>
<a name="2801"><span class="lineNum">    2801 </span>                :            : </a>
<a name="2802"><span class="lineNum">    2802 </span>                :            : static void</a>
<a name="2803"><span class="lineNum">    2803 </span>                :<span class="lineCov">          4 : interrupt(int sig)</span></a>
<a name="2804"><span class="lineNum">    2804 </span>                :            : {</a>
<a name="2805"><span class="lineNum">    2805 </span>                :<span class="lineCov">          4 :         interrupted = sig;</span></a>
<a name="2806"><span class="lineNum">    2806 </span>                :<span class="lineCov">          4 : }</span></a>
<a name="2807"><span class="lineNum">    2807 </span>                :            : </a>
<a name="2808"><span class="lineNum">    2808 </span>                :            : static void</a>
<a name="2809"><span class="lineNum">    2809 </span>                :<span class="lineCov">      73171 : print_debug_info(const int pid, int status)</span></a>
<a name="2810"><span class="lineNum">    2810 </span>                :            : {</a>
<a name="2811"><span class="lineNum">    2811 </span>                :<span class="lineCov">      73171 :         const unsigned int event = (unsigned int) status >> 16;</span></a>
<a name="2812"><span class="lineNum">    2812 </span>                :<span class="lineCov">      73171 :         char buf[sizeof("WIFEXITED,exitcode=%u") + sizeof(int)*3 /*paranoia:*/ + 16];</span></a>
<a name="2813"><span class="lineNum">    2813 </span>                :<span class="lineCov">      73171 :         char evbuf[sizeof(",EVENT_VFORK_DONE (%u)") + sizeof(int)*3 /*paranoia:*/ + 16];</span></a>
<a name="2814"><span class="lineNum">    2814 </span>                :            : </a>
<a name="2815"><span class="lineNum">    2815 </span>                :<span class="lineCov">      73171 :         strcpy(buf, "???");</span></a>
<a name="2816"><span class="lineNum">    2816 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 73171 times"> + </span>]:<span class="lineCov">      73171 :         if (WIFSIGNALED(status))</span></a>
<a name="2817"><span class="lineNum">    2817 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 xsprintf(buf, "WIFSIGNALED,%ssig=%s",</span></a>
<a name="2818"><span class="lineNum">    2818 </span>                :            :                                 WCOREDUMP(status) ? "core," : "",</a>
<a name="2819"><span class="lineNum">    2819 </span>                :            :                                 sprintsigname(WTERMSIG(status)));</a>
<a name="2820"><span class="lineNum">    2820 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 73159 times"> + </span>]:<span class="lineCov">      73171 :         if (WIFEXITED(status))</span></a>
<a name="2821"><span class="lineNum">    2821 </span>                :<span class="lineCov">         12 :                 xsprintf(buf, "WIFEXITED,exitcode=%u", WEXITSTATUS(status));</span></a>
<a name="2822"><span class="lineNum">    2822 </span>        [<span class="branchCov" title="Branch 0 was taken 73159 times"> + </span><span class="branchCov" title="Branch 1 was taken 12 times"> + </span>]:<span class="lineCov">      73171 :         if (WIFSTOPPED(status))</span></a>
<a name="2823"><span class="lineNum">    2823 </span>                :<span class="lineCov">      73159 :                 xsprintf(buf, "WIFSTOPPED,sig=%s",</span></a>
<a name="2824"><span class="lineNum">    2824 </span>                :            :                          sprintsigname(WSTOPSIG(status)));</a>
<a name="2825"><span class="lineNum">    2825 </span>                :<span class="lineCov">      73171 :         evbuf[0] = '\0';</span></a>
<a name="2826"><span class="lineNum">    2826 </span>        [<span class="branchCov" title="Branch 0 was taken 37 times"> + </span><span class="branchCov" title="Branch 1 was taken 73134 times"> + </span>]:<span class="lineCov">      73171 :         if (event != 0) {</span></a>
<a name="2827"><span class="lineNum">    2827 </span>                :<span class="lineCov">         37 :                 static const char *const event_names[] = {</span></a>
<a name="2828"><span class="lineNum">    2828 </span>                :            :                         [PTRACE_EVENT_CLONE] = "CLONE",</a>
<a name="2829"><span class="lineNum">    2829 </span>                :            :                         [PTRACE_EVENT_FORK]  = "FORK",</a>
<a name="2830"><span class="lineNum">    2830 </span>                :            :                         [PTRACE_EVENT_VFORK] = "VFORK",</a>
<a name="2831"><span class="lineNum">    2831 </span>                :            :                         [PTRACE_EVENT_VFORK_DONE] = "VFORK_DONE",</a>
<a name="2832"><span class="lineNum">    2832 </span>                :            :                         [PTRACE_EVENT_EXEC]  = "EXEC",</a>
<a name="2833"><span class="lineNum">    2833 </span>                :            :                         [PTRACE_EVENT_EXIT]  = "EXIT",</a>
<a name="2834"><span class="lineNum">    2834 </span>                :            :                         [PTRACE_EVENT_SECCOMP]  = "SECCOMP",</a>
<a name="2835"><span class="lineNum">    2835 </span>                :            :                         /* [PTRACE_EVENT_STOP (=128)] would make biggish array */</a>
<a name="2836"><span class="lineNum">    2836 </span>                :            :                 };</a>
<a name="2837"><span class="lineNum">    2837 </span>                :<span class="lineCov">         37 :                 const char *e = "??";</span></a>
<a name="2838"><span class="lineNum">    2838 </span>        [<span class="branchCov" title="Branch 0 was taken 13 times"> + </span><span class="branchCov" title="Branch 1 was taken 24 times"> + </span>]:<span class="lineCov">         37 :                 if (event < ARRAY_SIZE(event_names))</span></a>
<a name="2839"><span class="lineNum">    2839 </span>                :<span class="lineCov">         13 :                         e = event_names[event];</span></a>
<a name="2840"><span class="lineNum">    2840 </span>        [<span class="branchCov" title="Branch 0 was taken 24 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         24 :                 else if (event == PTRACE_EVENT_STOP)</span></a>
<a name="2841"><span class="lineNum">    2841 </span>                :<span class="lineCov">         24 :                         e = "STOP";</span></a>
<a name="2842"><span class="lineNum">    2842 </span>                :<span class="lineCov">         37 :                 xsprintf(evbuf, ",EVENT_%s (%u)", e, event);</span></a>
<a name="2843"><span class="lineNum">    2843 </span>                :            :         }</a>
<a name="2844"><span class="lineNum">    2844 </span>                :<span class="lineCov">      73171 :         error_msg("[wait(0x%06x) = %u] %s%s", status, pid, buf, evbuf);</span></a>
<a name="2845"><span class="lineNum">    2845 </span>                :<span class="lineCov">      73171 : }</span></a>
<a name="2846"><span class="lineNum">    2846 </span>                :            : </a>
<a name="2847"><span class="lineNum">    2847 </span>                :            : static struct tcb *</a>
<a name="2848"><span class="lineNum">    2848 </span>                :<span class="lineCov">      29594 : maybe_allocate_tcb(const int pid, int status)</span></a>
<a name="2849"><span class="lineNum">    2849 </span>                :            : {</a>
<a name="2850"><span class="lineNum">    2850 </span>        [<span class="branchCov" title="Branch 0 was taken 174 times"> + </span><span class="branchCov" title="Branch 1 was taken 29420 times"> + </span>]:<span class="lineCov">      29594 :         if (!WIFSTOPPED(status)) {</span></a>
<a name="2851"><span class="lineNum">    2851 </span>  [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 172 times"> + </span><span class="branchCov" title="Branch 2 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">        174 :                 if (detach_on_execve && pid == strace_child) {</span></a>
<a name="2852"><span class="lineNum">    2852 </span>                :            :                         /* example: strace -bexecve sh -c 'exec true' */</a>
<a name="2853"><span class="lineNum">    2853 </span>                :<span class="lineCov">          2 :                         strace_child = 0;</span></a>
<a name="2854"><span class="lineNum">    2854 </span>                :<span class="lineCov">          2 :                         return NULL;</span></a>
<a name="2855"><span class="lineNum">    2855 </span>                :            :                 }</a>
<a name="2856"><span class="lineNum">    2856 </span>        [<span class="branchCov" title="Branch 0 was taken 170 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">        172 :                 if (!is_number_in_set(QUIET_EXIT, quiet_set)) {</span></a>
<a name="2857"><span class="lineNum">    2857 </span>                :            :                         /*</a>
<a name="2858"><span class="lineNum">    2858 </span>                :            :                          * This can happen if we inherited an unknown child.</a>
<a name="2859"><span class="lineNum">    2859 </span>                :            :                          * Example: (sleep 1 & exec strace true)</a>
<a name="2860"><span class="lineNum">    2860 </span>                :            :                          */</a>
<a name="2861"><span class="lineNum">    2861 </span>                :<span class="lineCov">        170 :                         error_msg("Exit of unknown pid %u ignored", pid);</span></a>
<a name="2862"><span class="lineNum">    2862 </span>                :            :                 }</a>
<a name="2863"><span class="lineNum">    2863 </span>                :<span class="lineCov">        172 :                 return NULL;</span></a>
<a name="2864"><span class="lineNum">    2864 </span>                :            :         }</a>
<a name="2865"><span class="lineNum">    2865 </span>        [<span class="branchCov" title="Branch 0 was taken 29415 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">      29420 :         if (followfork) {</span></a>
<a name="2866"><span class="lineNum">    2866 </span>                :            :                 /* We assume it's a fork/vfork/clone child */</a>
<a name="2867"><span class="lineNum">    2867 </span>                :<span class="lineCov">      29415 :                 struct tcb *tcp = alloctcb(pid);</span></a>
<a name="2868"><span class="lineNum">    2868 </span>                :<span class="lineCov">      29415 :                 after_successful_attach(tcp, post_attach_sigstop);</span></a>
<a name="2869"><span class="lineNum">    2869 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 29411 times"> + </span>]:<span class="lineCov">      29415 :                 if (!is_number_in_set(QUIET_ATTACH, quiet_set))</span></a>
<a name="2870"><span class="lineNum">    2870 </span>                :<span class="lineCov">          4 :                         error_msg("Process %d attached", pid);</span></a>
<a name="2871"><span class="lineNum">    2871 </span>                :<span class="lineCov">      29415 :                 return tcp;</span></a>
<a name="2872"><span class="lineNum">    2872 </span>                :            :         } else {</a>
<a name="2873"><span class="lineNum">    2873 </span>                :            :                 /*</a>
<a name="2874"><span class="lineNum">    2874 </span>                :            :                  * This can happen if a clone call misused CLONE_PTRACE itself.</a>
<a name="2875"><span class="lineNum">    2875 </span>                :            :                  *</a>
<a name="2876"><span class="lineNum">    2876 </span>                :            :                  * There used to be a dance around possible re-injection of</a>
<a name="2877"><span class="lineNum">    2877 </span>                :            :                  * WSTOPSIG(status), but it was later removed as the only</a>
<a name="2878"><span class="lineNum">    2878 </span>                :            :                  * observable stop here is the initial ptrace-stop.</a>
<a name="2879"><span class="lineNum">    2879 </span>                :            :                  */</a>
<a name="2880"><span class="lineNum">    2880 </span>                :<span class="lineCov">          5 :                 ptrace(PTRACE_DETACH, pid, NULL, 0L);</span></a>
<a name="2881"><span class="lineNum">    2881 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          5 :                 if (!is_number_in_set(QUIET_ATTACH, quiet_set))</span></a>
<a name="2882"><span class="lineNum">    2882 </span>                :<span class="lineCov">          2 :                         error_msg("Detached unknown pid %d", pid);</span></a>
<a name="2883"><span class="lineNum">    2883 </span>                :<span class="lineCov">          5 :                 return NULL;</span></a>
<a name="2884"><span class="lineNum">    2884 </span>                :            :         }</a>
<a name="2885"><span class="lineNum">    2885 </span>                :            : }</a>
<a name="2886"><span class="lineNum">    2886 </span>                :            : </a>
<a name="2887"><span class="lineNum">    2887 </span>                :            : /*</a>
<a name="2888"><span class="lineNum">    2888 </span>                :            :  * Under Linux, execve changes pid to thread leader's pid, and we see this</a>
<a name="2889"><span class="lineNum">    2889 </span>                :            :  * changed pid on EVENT_EXEC and later, execve sysexit.  Leader "disappears"</a>
<a name="2890"><span class="lineNum">    2890 </span>                :            :  * without exit notification.  Let user know that, drop leader's tcb, and fix</a>
<a name="2891"><span class="lineNum">    2891 </span>                :            :  * up pid in execve thread's tcb.  Effectively, execve thread's tcb replaces</a>
<a name="2892"><span class="lineNum">    2892 </span>                :            :  * leader's tcb.</a>
<a name="2893"><span class="lineNum">    2893 </span>                :            :  *</a>
<a name="2894"><span class="lineNum">    2894 </span>                :            :  * BTW, leader is 'stuck undead' (doesn't report WIFEXITED on exit syscall)</a>
<a name="2895"><span class="lineNum">    2895 </span>                :            :  * in multi-threaded programs exactly in order to handle this case.</a>
<a name="2896"><span class="lineNum">    2896 </span>                :            :  */</a>
<a name="2897"><span class="lineNum">    2897 </span>                :            : static struct tcb *</a>
<a name="2898"><span class="lineNum">    2898 </span>                :<span class="lineCov">      16310 : maybe_switch_tcbs(struct tcb *tcp, const int pid)</span></a>
<a name="2899"><span class="lineNum">    2899 </span>                :            : {</a>
<a name="2900"><span class="lineNum">    2900 </span>                :            :         /*</a>
<a name="2901"><span class="lineNum">    2901 </span>                :            :          * PTRACE_GETEVENTMSG returns old pid starting from Linux 3.0.</a>
<a name="2902"><span class="lineNum">    2902 </span>                :            :          * On 2.6 and earlier it can return garbage.</a>
<a name="2903"><span class="lineNum">    2903 </span>                :            :          */</a>
<a name="2904"><span class="lineNum">    2904 </span>        [<span class="branchCov" title="Branch 0 was taken 16310 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      16310 :         if (os_release < KERNEL_VERSION(3, 0, 0))</span></a>
<a name="2905"><span class="lineNum">    2905 </span>                :            :                 return NULL;</a>
<a name="2906"><span class="lineNum">    2906 </span>                :            : </a>
<a name="2907"><span class="lineNum">    2907 </span>                :<span class="lineCov">      16310 :         const long old_pid = tcb_wait_tab[tcp->wait_data_idx].msg;</span></a>
<a name="2908"><span class="lineNum">    2908 </span>                :            : </a>
<a name="2909"><span class="lineNum">    2909 </span>                :            :         /* Avoid truncation in pid2tcb() param passing */</a>
<a name="2910"><span class="lineNum">    2910 </span>  [<span class="branchCov" title="Branch 0 was taken 16310 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 19 times"> + </span><span class="branchCov" title="Branch 3 was taken 16291 times"> + </span>]:<span class="lineCov">      16310 :         if (old_pid <= 0 || old_pid == pid)</span></a>
<a name="2911"><span class="lineNum">    2911 </span>                :            :                 return NULL;</a>
<a name="2912"><span class="lineNum">    2912 </span>        [<span class="branchCov" title="Branch 0 was taken 19 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         19 :         if ((unsigned long) old_pid > UINT_MAX)</span></a>
<a name="2913"><span class="lineNum">    2913 </span>                :            :                 return NULL;</a>
<a name="2914"><span class="lineNum">    2914 </span>                :<span class="lineCov">         19 :         struct tcb *execve_thread = pid2tcb(old_pid);</span></a>
<a name="2915"><span class="lineNum">    2915 </span>                :            :         /* It should be !NULL, but I feel paranoid */</a>
<a name="2916"><span class="lineNum">    2916 </span>        [<span class="branchCov" title="Branch 0 was taken 19 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         19 :         if (!execve_thread)</span></a>
<a name="2917"><span class="lineNum">    2917 </span>                :            :                 return NULL;</a>
<a name="2918"><span class="lineNum">    2918 </span>                :            : </a>
<a name="2919"><span class="lineNum">    2919 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 12 times"> + </span>]:<span class="lineCov">         19 :         if (execve_thread->curcol != 0) {</span></a>
<a name="2920"><span class="lineNum">    2920 </span>                :            :                 /*</a>
<a name="2921"><span class="lineNum">    2921 </span>                :            :                  * One case we are here is -ff, try</a>
<a name="2922"><span class="lineNum">    2922 </span>                :            :                  * "strace -oLOG -ff test/threaded_execve".</a>
<a name="2923"><span class="lineNum">    2923 </span>                :            :                  * Another case is demonstrated by</a>
<a name="2924"><span class="lineNum">    2924 </span>                :            :                  * tests/maybe_switch_current_tcp.c</a>
<a name="2925"><span class="lineNum">    2925 </span>                :            :                  */</a>
<a name="2926"><span class="lineNum">    2926 </span>                :<span class="lineCov">          7 :                 fprintf(execve_thread->outf, " <pid changed to %d ...>\n", pid);</span></a>
<a name="2927"><span class="lineNum">    2927 </span>                :            :                 /*execve_thread->curcol = 0; - no need, see code below */</a>
<a name="2928"><span class="lineNum">    2928 </span>                :            :         }</a>
<a name="2929"><span class="lineNum">    2929 </span>                :            :         /* Swap output FILEs and memstream (needed for -ff) */</a>
<a name="2930"><span class="lineNum">    2930 </span>                :<span class="lineCov">         19 :         FILE *fp = execve_thread->outf;</span></a>
<a name="2931"><span class="lineNum">    2931 </span>                :<span class="lineCov">         19 :         execve_thread->outf = tcp->outf;</span></a>
<a name="2932"><span class="lineNum">    2932 </span>                :<span class="lineCov">         19 :         tcp->outf = fp;</span></a>
<a name="2933"><span class="lineNum">    2933 </span>  [<span class="branchCov" title="Branch 0 was taken 17 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 17 times"> + </span>]:<span class="lineCov">         19 :         if (execve_thread->staged_output_data || tcp->staged_output_data) {</span></a>
<a name="2934"><span class="lineNum">    2934 </span>                :<span class="lineCov">          2 :                 struct staged_output_data *staged_output_data;</span></a>
<a name="2935"><span class="lineNum">    2935 </span>                :            : </a>
<a name="2936"><span class="lineNum">    2936 </span>                :<span class="lineCov">          2 :                 staged_output_data = execve_thread->staged_output_data;</span></a>
<a name="2937"><span class="lineNum">    2937 </span>                :<span class="lineCov">          2 :                 execve_thread->staged_output_data = tcp->staged_output_data;</span></a>
<a name="2938"><span class="lineNum">    2938 </span>                :<span class="lineCov">          2 :                 tcp->staged_output_data = staged_output_data;</span></a>
<a name="2939"><span class="lineNum">    2939 </span>                :            :         }</a>
<a name="2940"><span class="lineNum">    2940 </span>                :            : </a>
<a name="2941"><span class="lineNum">    2941 </span>                :            :         /* And their column positions */</a>
<a name="2942"><span class="lineNum">    2942 </span>                :<span class="lineCov">         19 :         execve_thread->curcol = tcp->curcol;</span></a>
<a name="2943"><span class="lineNum">    2943 </span>                :<span class="lineCov">         19 :         tcp->curcol = 0;</span></a>
<a name="2944"><span class="lineNum">    2944 </span>                :            :         /* Drop leader, but close execve'd thread outfile (if -ff) */</a>
<a name="2945"><span class="lineNum">    2945 </span>                :<span class="lineCov">         19 :         droptcb(tcp);</span></a>
<a name="2946"><span class="lineNum">    2946 </span>                :            :         /* Switch to the thread, reusing leader's outfile and pid */</a>
<a name="2947"><span class="lineNum">    2947 </span>                :<span class="lineCov">         19 :         tcp = execve_thread;</span></a>
<a name="2948"><span class="lineNum">    2948 </span>                :<span class="lineCov">         19 :         tcp->pid = pid;</span></a>
<a name="2949"><span class="lineNum">    2949 </span>        [<span class="branchCov" title="Branch 0 was taken 19 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         19 :         if (cflag != CFLAG_ONLY_STATS) {</span></a>
<a name="2950"><span class="lineNum">    2950 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 7 times"> + </span>]:<span class="lineCov">         19 :                 if (!is_number_in_set(QUIET_THREAD_EXECVE, quiet_set)) {</span></a>
<a name="2951"><span class="lineNum">    2951 </span>                :<span class="lineCov">         12 :                         printleader(tcp);</span></a>
<a name="2952"><span class="lineNum">    2952 </span>                :<span class="lineCov">         12 :                         tprintf("+++ superseded by execve in pid %lu +++\n",</span></a>
<a name="2953"><span class="lineNum">    2953 </span>                :            :                                 old_pid);</a>
<a name="2954"><span class="lineNum">    2954 </span>                :<span class="lineCov">         12 :                         line_ended();</span></a>
<a name="2955"><span class="lineNum">    2955 </span>                :            :                 }</a>
<a name="2956"><span class="lineNum">    2956 </span>                :            :                 /*</a>
<a name="2957"><span class="lineNum">    2957 </span>                :            :                  * Need to reopen memstream for thread</a>
<a name="2958"><span class="lineNum">    2958 </span>                :            :                  * as we closed it in droptcb.</a>
<a name="2959"><span class="lineNum">    2959 </span>                :            :                  */</a>
<a name="2960"><span class="lineNum">    2960 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 17 times"> + </span>]:<span class="lineCov">         19 :                 if (!is_complete_set(status_set, NUMBER_OF_STATUSES))</span></a>
<a name="2961"><span class="lineNum">    2961 </span>                :<span class="lineCov">          2 :                         strace_open_memstream(tcp);</span></a>
<a name="2962"><span class="lineNum">    2962 </span>                :<span class="lineCov">         19 :                 tcp->flags |= TCB_REPRINT;</span></a>
<a name="2963"><span class="lineNum">    2963 </span>                :            :         }</a>
<a name="2964"><span class="lineNum">    2964 </span>                :            : </a>
<a name="2965"><span class="lineNum">    2965 </span>                :            :         return tcp;</a>
<a name="2966"><span class="lineNum">    2966 </span>                :            : }</a>
<a name="2967"><span class="lineNum">    2967 </span>                :            : </a>
<a name="2968"><span class="lineNum">    2968 </span>                :            : static struct tcb *</a>
<a name="2969"><span class="lineNum">    2969 </span>                :<span class="lineCov">      16310 : maybe_switch_current_tcp(void)</span></a>
<a name="2970"><span class="lineNum">    2970 </span>                :            : {</a>
<a name="2971"><span class="lineNum">    2971 </span>                :<span class="lineCov">      16310 :         struct tcb *tcp = maybe_switch_tcbs(current_tcp, current_tcp->pid);</span></a>
<a name="2972"><span class="lineNum">    2972 </span>                :            : </a>
<a name="2973"><span class="lineNum">    2973 </span>        [<span class="branchCov" title="Branch 0 was taken 19 times"> + </span><span class="branchCov" title="Branch 1 was taken 16291 times"> + </span>]:<span class="lineCov">      16310 :         if (tcp)</span></a>
<a name="2974"><span class="lineNum">    2974 </span>                :<span class="lineCov">         19 :                 set_current_tcp(tcp);</span></a>
<a name="2975"><span class="lineNum">    2975 </span>                :            : </a>
<a name="2976"><span class="lineNum">    2976 </span>                :<span class="lineCov">      16310 :         return tcp;</span></a>
<a name="2977"><span class="lineNum">    2977 </span>                :            : }</a>
<a name="2978"><span class="lineNum">    2978 </span>                :            : </a>
<a name="2979"><span class="lineNum">    2979 </span>                :            : static void</a>
<a name="2980"><span class="lineNum">    2980 </span>                :<span class="lineCov">      10070 : print_signalled(struct tcb *tcp, const int pid, int status)</span></a>
<a name="2981"><span class="lineNum">    2981 </span>                :            : {</a>
<a name="2982"><span class="lineNum">    2982 </span>        [<span class="branchCov" title="Branch 0 was taken 8 times"> + </span><span class="branchCov" title="Branch 1 was taken 10062 times"> + </span>]:<span class="lineCov">      10070 :         if (pid == strace_child) {</span></a>
<a name="2983"><span class="lineNum">    2983 </span>                :<span class="lineCov">          8 :                 exit_code = 0x100 | WTERMSIG(status);</span></a>
<a name="2984"><span class="lineNum">    2984 </span>                :<span class="lineCov">          8 :                 strace_child = 0;</span></a>
<a name="2985"><span class="lineNum">    2985 </span>                :            :         }</a>
<a name="2986"><span class="lineNum">    2986 </span>                :            : </a>
<a name="2987"><span class="lineNum">    2987 </span>        [<span class="branchCov" title="Branch 0 was taken 10070 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      10070 :         if (cflag != CFLAG_ONLY_STATS</span></a>
<a name="2988"><span class="lineNum">    2988 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 10066 times"> + </span>]:<span class="lineCov">      10070 :             && is_number_in_set(WTERMSIG(status), signal_set)) {</span></a>
<a name="2989"><span class="lineNum">    2989 </span>                :<span class="lineCov">          4 :                 printleader(tcp);</span></a>
<a name="2990"><span class="lineNum">    2990 </span>                :<span class="lineCov">          4 :                 tprintf("+++ killed by %s %s+++\n",</span></a>
<a name="2991"><span class="lineNum">    2991 </span>                :            :                         sprintsigname(WTERMSIG(status)),</a>
<a name="2992"><span class="lineNum">    2992 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">          4 :                         WCOREDUMP(status) ? "(core dumped) " : "");</span></a>
<a name="2993"><span class="lineNum">    2993 </span>                :<span class="lineCov">          4 :                 line_ended();</span></a>
<a name="2994"><span class="lineNum">    2994 </span>                :            :         }</a>
<a name="2995"><span class="lineNum">    2995 </span>                :<span class="lineCov">      10070 : }</span></a>
<a name="2996"><span class="lineNum">    2996 </span>                :            : </a>
<a name="2997"><span class="lineNum">    2997 </span>                :            : static void</a>
<a name="2998"><span class="lineNum">    2998 </span>                :<span class="lineCov">      35579 : print_exited(struct tcb *tcp, const int pid, int status)</span></a>
<a name="2999"><span class="lineNum">    2999 </span>                :            : {</a>
<a name="3000"><span class="lineNum">    3000 </span>        [<span class="branchCov" title="Branch 0 was taken 16230 times"> + </span><span class="branchCov" title="Branch 1 was taken 19349 times"> + </span>]:<span class="lineCov">      35579 :         if (pid == strace_child) {</span></a>
<a name="3001"><span class="lineNum">    3001 </span>                :<span class="lineCov">      16230 :                 exit_code = WEXITSTATUS(status);</span></a>
<a name="3002"><span class="lineNum">    3002 </span>                :<span class="lineCov">      16230 :                 strace_child = 0;</span></a>
<a name="3003"><span class="lineNum">    3003 </span>                :            :         }</a>
<a name="3004"><span class="lineNum">    3004 </span>                :            : </a>
<a name="3005"><span class="lineNum">    3005 </span>  [<span class="branchCov" title="Branch 0 was taken 35506 times"> + </span><span class="branchCov" title="Branch 1 was taken 73 times"> + </span><span class="branchCov" title="Branch 2 was taken 10368 times"> + </span><span class="branchCov" title="Branch 3 was taken 25138 times"> + </span>]:<span class="lineCov">      71085 :         if (cflag != CFLAG_ONLY_STATS &&</span></a>
<a name="3006"><span class="lineNum">    3006 </span>                :<span class="lineCov">      35506 :             !is_number_in_set(QUIET_EXIT, quiet_set)) {</span></a>
<a name="3007"><span class="lineNum">    3007 </span>                :<span class="lineCov">      10368 :                 printleader(tcp);</span></a>
<a name="3008"><span class="lineNum">    3008 </span>                :<span class="lineCov">      10368 :                 tprintf("+++ exited with %d +++\n", WEXITSTATUS(status));</span></a>
<a name="3009"><span class="lineNum">    3009 </span>                :<span class="lineCov">      10368 :                 line_ended();</span></a>
<a name="3010"><span class="lineNum">    3010 </span>                :            :         }</a>
<a name="3011"><span class="lineNum">    3011 </span>                :<span class="lineCov">      35579 : }</span></a>
<a name="3012"><span class="lineNum">    3012 </span>                :            : </a>
<a name="3013"><span class="lineNum">    3013 </span>                :            : static void</a>
<a name="3014"><span class="lineNum">    3014 </span>                :<span class="lineCov">      77820 : print_stopped(struct tcb *tcp, const siginfo_t *si, const unsigned int sig)</span></a>
<a name="3015"><span class="lineNum">    3015 </span>                :            : {</a>
<a name="3016"><span class="lineNum">    3016 </span>        [<span class="branchCov" title="Branch 0 was taken 77746 times"> + </span><span class="branchCov" title="Branch 1 was taken 74 times"> + </span>]:<span class="lineCov">      77820 :         if (cflag != CFLAG_ONLY_STATS</span></a>
<a name="3017"><span class="lineNum">    3017 </span>        [<span class="branchCov" title="Branch 0 was taken 45327 times"> + </span><span class="branchCov" title="Branch 1 was taken 32419 times"> + </span>]:<span class="lineCov">      77746 :             && !hide_log(tcp)</span></a>
<a name="3018"><span class="lineNum">    3018 </span>        [<span class="branchCov" title="Branch 0 was taken 6209 times"> + </span><span class="branchCov" title="Branch 1 was taken 39118 times"> + </span>]:<span class="lineCov">      45327 :             && is_number_in_set(sig, signal_set)) {</span></a>
<a name="3019"><span class="lineNum">    3019 </span>                :<span class="lineCov">       6209 :                 printleader(tcp);</span></a>
<a name="3020"><span class="lineNum">    3020 </span>        [<span class="branchCov" title="Branch 0 was taken 6207 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">       6209 :                 if (si) {</span></a>
<a name="3021"><span class="lineNum">    3021 </span>                :<span class="lineCov">       6207 :                         tprintf("--- %s ", sprintsigname(sig));</span></a>
<a name="3022"><span class="lineNum">    3022 </span>                :<span class="lineCov">       6207 :                         printsiginfo(tcp, si);</span></a>
<a name="3023"><span class="lineNum">    3023 </span>                :<span class="lineCov">       6207 :                         tprints(" ---\n");</span></a>
<a name="3024"><span class="lineNum">    3024 </span>                :            :                 } else</a>
<a name="3025"><span class="lineNum">    3025 </span>                :<span class="lineCov">          2 :                         tprintf("--- stopped by %s ---\n", sprintsigname(sig));</span></a>
<a name="3026"><span class="lineNum">    3026 </span>                :<span class="lineCov">       6209 :                 line_ended();</span></a>
<a name="3027"><span class="lineNum">    3027 </span>                :            : </a>
<a name="3028"><span class="lineNum">    3028 </span>                :            : #ifdef ENABLE_STACKTRACE</a>
<a name="3029"><span class="lineNum">    3029 </span>                :            :                 if (stack_trace_enabled)</a>
<a name="3030"><span class="lineNum">    3030 </span>                :            :                         unwind_tcb_print(tcp);</a>
<a name="3031"><span class="lineNum">    3031 </span>                :            : #endif</a>
<a name="3032"><span class="lineNum">    3032 </span>                :            :         }</a>
<a name="3033"><span class="lineNum">    3033 </span>                :<span class="lineCov">      77820 : }</span></a>
<a name="3034"><span class="lineNum">    3034 </span>                :            : </a>
<a name="3035"><span class="lineNum">    3035 </span>                :            : static void</a>
<a name="3036"><span class="lineNum">    3036 </span>                :<span class="lineCov">      45674 : startup_tcb(struct tcb *tcp)</span></a>
<a name="3037"><span class="lineNum">    3037 </span>                :            : {</a>
<a name="3038"><span class="lineNum">    3038 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 45662 times"> + </span>]:<span class="lineCov">      45674 :         debug_msg("pid %d has TCB_STARTUP, initializing it", tcp->pid);</span></a>
<a name="3039"><span class="lineNum">    3039 </span>                :            : </a>
<a name="3040"><span class="lineNum">    3040 </span>                :<span class="lineCov">      45674 :         tcp->flags &= ~TCB_STARTUP;</span></a>
<a name="3041"><span class="lineNum">    3041 </span>                :            : </a>
<a name="3042"><span class="lineNum">    3042 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 45674 times"> + </span>]:<span class="lineCov">      45674 :         if (!use_seize) {</span></a>
<a name="3043"><span class="lineNum">    3043 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 debug_msg("setting opts 0x%x on pid %d",</span></a>
<a name="3044"><span class="lineNum">    3044 </span>                :            :                           ptrace_setoptions, tcp->pid);</a>
<a name="3045"><span class="lineNum">    3045 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (ptrace(PTRACE_SETOPTIONS, tcp->pid, NULL, ptrace_setoptions) < 0) {</span></a>
<a name="3046"><span class="lineNum">    3046 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                         if (errno != ESRCH) {</span></a>
<a name="3047"><span class="lineNum">    3047 </span>                :            :                                 /* Should never happen, really */</a>
<a name="3048"><span class="lineNum">    3048 </span>                :<span class="lineNoCov">          0 :                                 perror_msg_and_die("PTRACE_SETOPTIONS");</span></a>
<a name="3049"><span class="lineNum">    3049 </span>                :            :                         }</a>
<a name="3050"><span class="lineNum">    3050 </span>                :            :                 }</a>
<a name="3051"><span class="lineNum">    3051 </span>                :            :         }</a>
<a name="3052"><span class="lineNum">    3052 </span>                :            : </a>
<a name="3053"><span class="lineNum">    3053 </span>  [<span class="branchCov" title="Branch 0 was taken 18 times"> + </span><span class="branchCov" title="Branch 1 was taken 45656 times"> + </span><span class="branchCov" title="Branch 2 was taken 18 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">      45674 :         if ((tcp->flags & TCB_GRABBED) && (get_scno(tcp) == 1))</span></a>
<a name="3054"><span class="lineNum">    3054 </span>                :<span class="lineCov">         18 :                 tcp->s_prev_ent = tcp->s_ent;</span></a>
<a name="3055"><span class="lineNum">    3055 </span>                :            : </a>
<a name="3056"><span class="lineNum">    3056 </span>        [<span class="branchCov" title="Branch 0 was taken 74 times"> + </span><span class="branchCov" title="Branch 1 was taken 45600 times"> + </span>]:<span class="lineCov">      45674 :         if (cflag) {</span></a>
<a name="3057"><span class="lineNum">    3057 </span>                :<span class="lineCov">         74 :                 tcp->atime = tcp->stime;</span></a>
<a name="3058"><span class="lineNum">    3058 </span>                :            :         }</a>
<a name="3059"><span class="lineNum">    3059 </span>                :<span class="lineCov">      45674 : }</span></a>
<a name="3060"><span class="lineNum">    3060 </span>                :            : </a>
<a name="3061"><span class="lineNum">    3061 </span>                :            : static void</a>
<a name="3062"><span class="lineNum">    3062 </span>                :<span class="lineCov">      45534 : print_event_exit(struct tcb *tcp)</span></a>
<a name="3063"><span class="lineNum">    3063 </span>                :            : {</a>
<a name="3064"><span class="lineNum">    3064 </span>        [<span class="branchCov" title="Branch 0 was taken 358 times"> + </span><span class="branchCov" title="Branch 1 was taken 45176 times"> + </span>]:<span class="lineCov">      45534 :         if (entering(tcp) || filtered(tcp) || hide_log(tcp)</span></a>
<a name="3065"><span class="lineNum">    3065 </span>        [<span class="branchCov" title="Branch 0 was taken 295 times"> + </span><span class="branchCov" title="Branch 1 was taken 63 times"> + </span>]:<span class="lineCov">        358 :             || cflag == CFLAG_ONLY_STATS) {</span></a>
<a name="3066"><span class="lineNum">    3066 </span>                :            :                 return;</a>
<a name="3067"><span class="lineNum">    3067 </span>                :            :         }</a>
<a name="3068"><span class="lineNum">    3068 </span>                :            : </a>
<a name="3069"><span class="lineNum">    3069 </span>  [<span class="branchCov" title="Branch 0 was taken 293 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span><span class="branchCov" title="Branch 2 was taken 36 times"> + </span><span class="branchCov" title="Branch 3 was taken 257 times"> + </span> :<span class="lineCov">        295 :         if (!output_separately && printing_tcp && printing_tcp != tcp</span></a>
<span class="lineNum">         </span>         <span class="branchCov" title="Branch 4 was taken 12 times"> + </span><span class="branchCov" title="Branch 5 was taken 24 times"> + </span>]
<a name="3070"><span class="lineNum">    3070 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">         12 :             && printing_tcp->curcol != 0) {</span></a>
<a name="3071"><span class="lineNum">    3071 </span>                :<span class="lineCov">         12 :                 set_current_tcp(printing_tcp);</span></a>
<a name="3072"><span class="lineNum">    3072 </span>                :<span class="lineCov">         12 :                 tprints(" <unfinished ...>\n");</span></a>
<a name="3073"><span class="lineNum">    3073 </span>                :<span class="lineCov">         12 :                 flush_tcp_output(printing_tcp);</span></a>
<a name="3074"><span class="lineNum">    3074 </span>                :<span class="lineCov">         12 :                 printing_tcp->curcol = 0;</span></a>
<a name="3075"><span class="lineNum">    3075 </span>                :<span class="lineCov">         12 :                 set_current_tcp(tcp);</span></a>
<a name="3076"><span class="lineNum">    3076 </span>                :            :         }</a>
<a name="3077"><span class="lineNum">    3077 </span>                :            : </a>
<a name="3078"><span class="lineNum">    3078 </span>                :<span class="lineCov">        295 :         print_syscall_resume(tcp);</span></a>
<a name="3079"><span class="lineNum">    3079 </span>                :            : </a>
<a name="3080"><span class="lineNum">    3080 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 288 times"> + </span>]:<span class="lineCov">        295 :         if (!(tcp->sys_func_rval & RVAL_DECODED)) {</span></a>
<a name="3081"><span class="lineNum">    3081 </span>                :            :                 /*</a>
<a name="3082"><span class="lineNum">    3082 </span>                :            :                  * The decoder has probably decided to print something</a>
<a name="3083"><span class="lineNum">    3083 </span>                :            :                  * on exiting syscall which is not going to happen.</a>
<a name="3084"><span class="lineNum">    3084 </span>                :            :                  */</a>
<a name="3085"><span class="lineNum">    3085 </span>                :<span class="lineCov">          7 :                 tprints(" <unfinished ...>");</span></a>
<a name="3086"><span class="lineNum">    3086 </span>                :            :         }</a>
<a name="3087"><span class="lineNum">    3087 </span>                :            : </a>
<a name="3088"><span class="lineNum">    3088 </span>                :<span class="lineCov">        295 :         printing_tcp = tcp;</span></a>
<a name="3089"><span class="lineNum">    3089 </span>                :<span class="lineCov">        295 :         tprints(") ");</span></a>
<a name="3090"><span class="lineNum">    3090 </span>                :<span class="lineCov">        295 :         tabto();</span></a>
<a name="3091"><span class="lineNum">    3091 </span>                :<span class="lineCov">        295 :         tprints("= ?\n");</span></a>
<a name="3092"><span class="lineNum">    3092 </span>        [<span class="branchCov" title="Branch 0 was taken 7 times"> + </span><span class="branchCov" title="Branch 1 was taken 288 times"> + </span>]:<span class="lineCov">        295 :         if (!is_complete_set(status_set, NUMBER_OF_STATUSES)) {</span></a>
<a name="3093"><span class="lineNum">    3093 </span>                :<span class="lineCov">          7 :                 bool publish = is_number_in_set(STATUS_UNFINISHED, status_set);</span></a>
<a name="3094"><span class="lineNum">    3094 </span>                :<span class="lineCov">          7 :                 strace_close_memstream(tcp, publish);</span></a>
<a name="3095"><span class="lineNum">    3095 </span>                :            :         }</a>
<a name="3096"><span class="lineNum">    3096 </span>                :<span class="lineCov">        295 :         line_ended();</span></a>
<a name="3097"><span class="lineNum">    3097 </span>                :            : }</a>
<a name="3098"><span class="lineNum">    3098 </span>                :            : </a>
<a name="3099"><span class="lineNum">    3099 </span>                :            : static size_t</a>
<a name="3100"><span class="lineNum">    3100 </span>                :            : trace_wait_data_size(struct tcb *tcp)</a>
<a name="3101"><span class="lineNum">    3101 </span>                :            : {</a>
<a name="3102"><span class="lineNum">    3102 </span>                :            :         return sizeof(struct tcb_wait_data);</a>
<a name="3103"><span class="lineNum">    3103 </span>                :            : }</a>
<a name="3104"><span class="lineNum">    3104 </span>                :            : </a>
<a name="3105"><span class="lineNum">    3105 </span>                :            : static struct tcb_wait_data *</a>
<a name="3106"><span class="lineNum">    3106 </span>                :<span class="lineCov">  156770719 : init_trace_wait_data(void *p)</span></a>
<a name="3107"><span class="lineNum">    3107 </span>                :            : {</a>
<a name="3108"><span class="lineNum">    3108 </span>                :<span class="lineCov">  156770719 :         struct tcb_wait_data *wd = p;</span></a>
<a name="3109"><span class="lineNum">    3109 </span>                :            : </a>
<a name="3110"><span class="lineNum">    3110 </span>                :<span class="lineCov">  156770719 :         memset(wd, 0, sizeof(*wd));</span></a>
<a name="3111"><span class="lineNum">    3111 </span>                :            : </a>
<a name="3112"><span class="lineNum">    3112 </span>                :<span class="lineCov">  156770719 :         return wd;</span></a>
<a name="3113"><span class="lineNum">    3113 </span>                :            : }</a>
<a name="3114"><span class="lineNum">    3114 </span>                :            : </a>
<a name="3115"><span class="lineNum">    3115 </span>                :            : static struct tcb_wait_data *</a>
<a name="3116"><span class="lineNum">    3116 </span>                :<span class="lineCov">        136 : copy_trace_wait_data(const struct tcb_wait_data *wd)</span></a>
<a name="3117"><span class="lineNum">    3117 </span>                :            : {</a>
<a name="3118"><span class="lineNum">    3118 </span>                :<span class="lineCov">        136 :         return xobjdup(wd);</span></a>
<a name="3119"><span class="lineNum">    3119 </span>                :            : }</a>
<a name="3120"><span class="lineNum">    3120 </span>                :            : </a>
<a name="3121"><span class="lineNum">    3121 </span>                :            : static void</a>
<a name="3122"><span class="lineNum">    3122 </span>                :<span class="lineCov">        136 : free_trace_wait_data(struct tcb_wait_data *wd)</span></a>
<a name="3123"><span class="lineNum">    3123 </span>                :            : {</a>
<a name="3124"><span class="lineNum">    3124 </span>                :<span class="lineCov">        136 :         free(wd);</span></a>
<a name="3125"><span class="lineNum">    3125 </span>                :            : }</a>
<a name="3126"><span class="lineNum">    3126 </span>                :            : </a>
<a name="3127"><span class="lineNum">    3127 </span>                :            : static void</a>
<a name="3128"><span class="lineNum">    3128 </span>                :<span class="lineCov">  156770855 : tcb_wait_tab_check_size(const size_t size)</span></a>
<a name="3129"><span class="lineNum">    3129 </span>                :            : {</a>
<a name="3130"><span class="lineNum">    3130 </span>        [<span class="branchCov" title="Branch 0 was taken 21288 times"> + </span><span class="branchCov" title="Branch 1 was taken 156770855 times"> + </span>]:<span class="lineCov">  156792143 :         while (size >= tcb_wait_tab_size) {</span></a>
<a name="3131"><span class="lineNum">    3131 </span>                :<span class="lineCov">      21288 :                 tcb_wait_tab = xgrowarray(tcb_wait_tab,</span></a>
<a name="3132"><span class="lineNum">    3132 </span>                :            :                                           &tcb_wait_tab_size,</a>
<a name="3133"><span class="lineNum">    3133 </span>                :            :                                           sizeof(tcb_wait_tab[0]));</a>
<a name="3134"><span class="lineNum">    3134 </span>                :            :         }</a>
<a name="3135"><span class="lineNum">    3135 </span>                :<span class="lineCov">  156770855 : }</span></a>
<a name="3136"><span class="lineNum">    3136 </span>                :            : </a>
<a name="3137"><span class="lineNum">    3137 </span>                :            : static const struct tcb_wait_data *</a>
<a name="3138"><span class="lineNum">    3138 </span>                :<span class="lineCov">  156787110 : next_event(void)</span></a>
<a name="3139"><span class="lineNum">    3139 </span>                :            : {</a>
<a name="3140"><span class="lineNum">    3140 </span>        [<span class="branchCov" title="Branch 0 was taken 156787106 times"> + </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">  156787110 :         if (interrupted)</span></a>
<a name="3141"><span class="lineNum">    3141 </span>                :            :                 return NULL;</a>
<a name="3142"><span class="lineNum">    3142 </span>                :            : </a>
<a name="3143"><span class="lineNum">    3143 </span>                :<span class="lineCov">  156787106 :         invalidate_umove_cache();</span></a>
<a name="3144"><span class="lineNum">    3144 </span>                :            : </a>
<a name="3145"><span class="lineNum">    3145 </span>                :<span class="lineCov">  156787106 :         struct tcb *tcp = NULL;</span></a>
<a name="3146"><span class="lineNum">    3146 </span>                :<span class="lineCov">  156787106 :         struct list_item *elem;</span></a>
<a name="3147"><span class="lineNum">    3147 </span>                :            : </a>
<a name="3148"><span class="lineNum">    3148 </span>                :<span class="lineCov">  156787106 :         static EMPTY_LIST(pending_tcps);</span></a>
<a name="3149"><span class="lineNum">    3149 </span>                :            :         /* Handle the queued tcbs before waiting for new events.  */</a>
<a name="3150"><span class="lineNum">    3150 </span>        [<span class="branchCov" title="Branch 0 was taken 23789970 times"> + </span><span class="branchCov" title="Branch 1 was taken 132997136 times"> + </span>]:<span class="lineCov">  156787106 :         if (!list_is_empty(&pending_tcps))</span></a>
<a name="3151"><span class="lineNum">    3151 </span>                :<span class="lineCov">   23789970 :                 goto next_event_get_tcp;</span></a>
<a name="3152"><span class="lineNum">    3152 </span>                :            : </a>
<a name="3153"><span class="lineNum">    3153 </span>                :<span class="lineCov">  132997136 :         static struct tcb *extra_tcp;</span></a>
<a name="3154"><span class="lineNum">    3154 </span>                :<span class="lineCov">  132997136 :         static size_t wait_extra_data_idx;</span></a>
<a name="3155"><span class="lineNum">    3155 </span>                :            :         /* Handle the extra tcb event.  */</a>
<a name="3156"><span class="lineNum">    3156 </span>        [<span class="branchCov" title="Branch 0 was taken 113 times"> + </span><span class="branchCov" title="Branch 1 was taken 132997023 times"> + </span>]:<span class="lineCov">  132997136 :         if (extra_tcp) {</span></a>
<a name="3157"><span class="lineNum">    3157 </span>                :<span class="lineCov">        113 :                 tcp = extra_tcp;</span></a>
<a name="3158"><span class="lineNum">    3158 </span>                :<span class="lineCov">        113 :                 extra_tcp = NULL;</span></a>
<a name="3159"><span class="lineNum">    3159 </span>                :<span class="lineCov">        113 :                 tcp->wait_data_idx = wait_extra_data_idx;</span></a>
<a name="3160"><span class="lineNum">    3160 </span>                :            : </a>
<a name="3161"><span class="lineNum">    3161 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 113 times"> + </span>]:<span class="lineCov">        113 :                 debug_msg("dequeued extra event for pid %u", tcp->pid);</span></a>
<a name="3162"><span class="lineNum">    3162 </span>                :<span class="lineCov">        113 :                 goto next_event_exit;</span></a>
<a name="3163"><span class="lineNum">    3163 </span>                :            :         }</a>
<a name="3164"><span class="lineNum">    3164 </span>                :            : </a>
<a name="3165"><span class="lineNum">    3165 </span>                :            :         /*</a>
<a name="3166"><span class="lineNum">    3166 </span>                :            :          * Used to exit simply when nprocs hits zero, but in this testcase:</a>
<a name="3167"><span class="lineNum">    3167 </span>                :            :          *  int main(void) { _exit(!!fork()); }</a>
<a name="3168"><span class="lineNum">    3168 </span>                :            :          * under strace -f, parent sometimes (rarely) manages</a>
<a name="3169"><span class="lineNum">    3169 </span>                :            :          * to exit before we see the first stop of the child,</a>
<a name="3170"><span class="lineNum">    3170 </span>                :            :          * and we are losing track of it:</a>
<a name="3171"><span class="lineNum">    3171 </span>                :            :          *  19923 clone(...) = 19924</a>
<a name="3172"><span class="lineNum">    3172 </span>                :            :          *  19923 exit_group(1)     = ?</a>
<a name="3173"><span class="lineNum">    3173 </span>                :            :          *  19923 +++ exited with 1 +++</a>
<a name="3174"><span class="lineNum">    3174 </span>                :            :          * Exiting only when wait() returns ECHILD works better.</a>
<a name="3175"><span class="lineNum">    3175 </span>                :            :          */</a>
<a name="3176"><span class="lineNum">    3176 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 132997023 times"> + </span>]:<span class="lineCov">  132997023 :         if (popen_pid != 0) {</span></a>
<a name="3177"><span class="lineNum">    3177 </span>                :            :                 /* However, if -o|logger is in use, we can't do that.</a>
<a name="3178"><span class="lineNum">    3178 </span>                :            :                  * Can work around that by double-forking the logger,</a>
<a name="3179"><span class="lineNum">    3179 </span>                :            :                  * but that loses the ability to wait for its completion</a>
<a name="3180"><span class="lineNum">    3180 </span>                :            :                  * on exit. Oh well...</a>
<a name="3181"><span class="lineNum">    3181 </span>                :            :                  */</a>
<a name="3182"><span class="lineNum">    3182 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 if (nprocs == 0)</span></a>
<a name="3183"><span class="lineNum">    3183 </span>                :            :                         return NULL;</a>
<a name="3184"><span class="lineNum">    3184 </span>                :            :         }</a>
<a name="3185"><span class="lineNum">    3185 </span>                :            : </a>
<a name="3186"><span class="lineNum">    3186 </span>                :<span class="lineCov">  132997023 :         const bool unblock_delay_timer = is_delay_timer_armed();</span></a>
<a name="3187"><span class="lineNum">    3187 </span>                :            : </a>
<a name="3188"><span class="lineNum">    3188 </span>                :            :         /*</a>
<a name="3189"><span class="lineNum">    3189 </span>                :            :          * The window of opportunity to handle expirations</a>
<a name="3190"><span class="lineNum">    3190 </span>                :            :          * of the delay timer opens here.</a>
<a name="3191"><span class="lineNum">    3191 </span>                :            :          *</a>
<a name="3192"><span class="lineNum">    3192 </span>                :            :          * Unblock the signal handler for the delay timer</a>
<a name="3193"><span class="lineNum">    3193 </span>                :            :          * iff the delay timer is already created.</a>
<a name="3194"><span class="lineNum">    3194 </span>                :            :          */</a>
<a name="3195"><span class="lineNum">    3195 </span>        [<span class="branchCov" title="Branch 0 was taken 401 times"> + </span><span class="branchCov" title="Branch 1 was taken 132996622 times"> + </span>]:<span class="lineCov">  132997023 :         if (unblock_delay_timer)</span></a>
<a name="3196"><span class="lineNum">    3196 </span>                :<span class="lineCov">        401 :                 sigprocmask(SIG_UNBLOCK, &timer_set, NULL);</span></a>
<a name="3197"><span class="lineNum">    3197 </span>                :            : </a>
<a name="3198"><span class="lineNum">    3198 </span>                :            :         /*</a>
<a name="3199"><span class="lineNum">    3199 </span>                :            :          * If the delay timer has expired, then its expiration</a>
<a name="3200"><span class="lineNum">    3200 </span>                :            :          * has been handled already by the signal handler.</a>
<a name="3201"><span class="lineNum">    3201 </span>                :            :          *</a>
<a name="3202"><span class="lineNum">    3202 </span>                :            :          * If the delay timer expires during wait4(),</a>
<a name="3203"><span class="lineNum">    3203 </span>                :            :          * then the system call will be interrupted and</a>
<a name="3204"><span class="lineNum">    3204 </span>                :            :          * the expiration will be handled by the signal handler.</a>
<a name="3205"><span class="lineNum">    3205 </span>                :            :          */</a>
<a name="3206"><span class="lineNum">    3206 </span>                :<span class="lineCov">  132997023 :         int status;</span></a>
<a name="3207"><span class="lineNum">    3207 </span>                :<span class="lineCov">  132997023 :         struct rusage ru;</span></a>
<a name="3208"><span class="lineNum">    3208 </span>        [<span class="branchCov" title="Branch 0 was taken 132786308 times"> + </span><span class="branchCov" title="Branch 1 was taken 210715 times"> + </span>]:<span class="lineCov">  265783331 :         int pid = wait4(-1, &status, __WALL, (cflag ? &ru : NULL));</span></a>
<a name="3209"><span class="lineNum">    3209 </span>                :<span class="lineCov">  132997023 :         int wait_errno = errno;</span></a>
<a name="3210"><span class="lineNum">    3210 </span>                :            : </a>
<a name="3211"><span class="lineNum">    3211 </span>                :            :         /*</a>
<a name="3212"><span class="lineNum">    3212 </span>                :            :          * The window of opportunity to handle expirations</a>
<a name="3213"><span class="lineNum">    3213 </span>                :            :          * of the delay timer closes here.</a>
<a name="3214"><span class="lineNum">    3214 </span>                :            :          *</a>
<a name="3215"><span class="lineNum">    3215 </span>                :            :          * Block the signal handler for the delay timer</a>
<a name="3216"><span class="lineNum">    3216 </span>                :            :          * iff it was unblocked earlier.</a>
<a name="3217"><span class="lineNum">    3217 </span>                :            :          */</a>
<a name="3218"><span class="lineNum">    3218 </span>        [<span class="branchCov" title="Branch 0 was taken 401 times"> + </span><span class="branchCov" title="Branch 1 was taken 132996622 times"> + </span>]:<span class="lineCov">  132997023 :         if (unblock_delay_timer) {</span></a>
<a name="3219"><span class="lineNum">    3219 </span>                :<span class="lineCov">        401 :                 sigprocmask(SIG_BLOCK, &timer_set, NULL);</span></a>
<a name="3220"><span class="lineNum">    3220 </span>                :            : </a>
<a name="3221"><span class="lineNum">    3221 </span>        [<span class="branchCov" title="Branch 0 was taken 401 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">        401 :                 if (restart_failed)</span></a>
<a name="3222"><span class="lineNum">    3222 </span>                :            :                         return NULL;</a>
<a name="3223"><span class="lineNum">    3223 </span>                :            :         }</a>
<a name="3224"><span class="lineNum">    3224 </span>                :            : </a>
<a name="3225"><span class="lineNum">    3225 </span>                :            :         size_t wait_tab_pos = 0;</a>
<a name="3226"><span class="lineNum">    3226 </span>                :            :         bool wait_nohang = false;</a>
<a name="3227"><span class="lineNum">    3227 </span>                :            : </a>
<a name="3228"><span class="lineNum">    3228 </span>                :            :         /*</a>
<a name="3229"><span class="lineNum">    3229 </span>                :            :          * Wait for new events until wait4() returns 0 (meaning that there's</a>
<a name="3230"><span class="lineNum">    3230 </span>                :            :          * nothing more to wait for for now), or a second event for some tcb</a>
<a name="3231"><span class="lineNum">    3231 </span>                :            :          * appears (which may happen if a tracee was SIGKILL'ed, for example).</a>
<a name="3232"><span class="lineNum">    3232 </span>                :            :          */</a>
<a name="3233"><span class="lineNum">    3233 </span>                :<span class="lineCov">  446538593 :         for (;;) {</span></a>
<a name="3234"><span class="lineNum">    3234 </span>                :<span class="lineCov">  289767808 :                 struct tcb_wait_data *wd;</span></a>
<a name="3235"><span class="lineNum">    3235 </span>                :            : </a>
<a name="3236"><span class="lineNum">    3236 </span>        [<span class="branchCov" title="Branch 0 was taken 32633 times"> + </span><span class="branchCov" title="Branch 1 was taken 289735175 times"> + </span>]:<span class="lineCov">  289767808 :                 if (pid < 0) {</span></a>
<a name="3237"><span class="lineNum">    3237 </span>        [<span class="branchCov" title="Branch 0 was taken 32501 times"> + </span><span class="branchCov" title="Branch 1 was taken 132 times"> + </span>]:<span class="lineCov">      32633 :                         if (wait_errno == EINTR)</span></a>
<a name="3238"><span class="lineNum">    3238 </span>                :            :                                 break;</a>
<a name="3239"><span class="lineNum">    3239 </span>        [<span class="branchCov" title="Branch 0 was taken 16250 times"> + </span><span class="branchCov" title="Branch 1 was taken 16251 times"> + </span>]:<span class="lineCov">      32501 :                         if (wait_nohang)</span></a>
<a name="3240"><span class="lineNum">    3240 </span>                :            :                                 break;</a>
<a name="3241"><span class="lineNum">    3241 </span>  [<span class="branchCov" title="Branch 0 was taken 16251 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 16251 times"> + </span>]:<span class="lineCov">      16251 :                         if (nprocs == 0 && wait_errno == ECHILD)</span></a>
<a name="3242"><span class="lineNum">    3242 </span>                :            :                                 return NULL;</a>
<a name="3243"><span class="lineNum">    3243 </span>                :            :                         /*</a>
<a name="3244"><span class="lineNum">    3244 </span>                :            :                          * If nprocs > 0, ECHILD is not expected,</a>
<a name="3245"><span class="lineNum">    3245 </span>                :            :                          * treat it as any other error here:</a>
<a name="3246"><span class="lineNum">    3246 </span>                :            :                          */</a>
<a name="3247"><span class="lineNum">    3247 </span>                :<span class="lineNoCov">          0 :                         errno = wait_errno;</span></a>
<a name="3248"><span class="lineNum">    3248 </span>                :<span class="lineNoCov">          0 :                         perror_msg_and_die("wait4(__WALL)");</span></a>
<a name="3249"><span class="lineNum">    3249 </span>                :            :                 }</a>
<a name="3250"><span class="lineNum">    3250 </span>                :            : </a>
<a name="3251"><span class="lineNum">    3251 </span>        [<span class="branchCov" title="Branch 0 was taken 132964277 times"> + </span><span class="branchCov" title="Branch 1 was taken 156770898 times"> + </span>]:<span class="lineCov">  289735175 :                 if (!pid)</span></a>
<a name="3252"><span class="lineNum">    3252 </span>                :            :                         break;</a>
<a name="3253"><span class="lineNum">    3253 </span>                :            : </a>
<a name="3254"><span class="lineNum">    3254 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 156770898 times"> + </span>]:<span class="lineCov">  156770898 :                 if (pid == popen_pid) {</span></a>
<a name="3255"><span class="lineNum">    3255 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                         if (!WIFSTOPPED(status))</span></a>
<a name="3256"><span class="lineNum">    3256 </span>                :<span class="lineNoCov">          0 :                                 popen_pid = 0;</span></a>
<a name="3257"><span class="lineNum">    3257 </span>                :            :                         break;</a>
<a name="3258"><span class="lineNum">    3258 </span>                :            :                 }</a>
<a name="3259"><span class="lineNum">    3259 </span>                :            : </a>
<a name="3260"><span class="lineNum">    3260 </span>        [<span class="branchCov" title="Branch 0 was taken 73171 times"> + </span><span class="branchCov" title="Branch 1 was taken 156697727 times"> + </span>]:<span class="lineCov">  156770898 :                 if (debug_flag)</span></a>
<a name="3261"><span class="lineNum">    3261 </span>                :<span class="lineCov">      73171 :                         print_debug_info(pid, status);</span></a>
<a name="3262"><span class="lineNum">    3262 </span>                :            : </a>
<a name="3263"><span class="lineNum">    3263 </span>                :            :                 /* Look up 'pid' in our table. */</a>
<a name="3264"><span class="lineNum">    3264 </span>                :<span class="lineCov">  156770898 :                 tcp = pid2tcb(pid);</span></a>
<a name="3265"><span class="lineNum">    3265 </span>                :            : </a>
<a name="3266"><span class="lineNum">    3266 </span>        [<span class="branchCov" title="Branch 0 was taken 29594 times"> + </span><span class="branchCov" title="Branch 1 was taken 156741304 times"> + </span>]:<span class="lineCov">  156770898 :                 if (!tcp) {</span></a>
<a name="3267"><span class="lineNum">    3267 </span>                :<span class="lineCov">      29594 :                         tcp = maybe_allocate_tcb(pid, status);</span></a>
<a name="3268"><span class="lineNum">    3268 </span>        [<span class="branchCov" title="Branch 0 was taken 179 times"> + </span><span class="branchCov" title="Branch 1 was taken 29415 times"> + </span>]:<span class="lineCov">      29594 :                         if (!tcp)</span></a>
<a name="3269"><span class="lineNum">    3269 </span>                :<span class="lineCov">        179 :                                 goto next_event_wait_next;</span></a>
<a name="3270"><span class="lineNum">    3270 </span>                :            :                 }</a>
<a name="3271"><span class="lineNum">    3271 </span>                :            : </a>
<a name="3272"><span class="lineNum">    3272 </span>        [<span class="branchCov" title="Branch 0 was taken 215456 times"> + </span><span class="branchCov" title="Branch 1 was taken 156555263 times"> + </span>]:<span class="lineCov">  156770719 :                 if (cflag) {</span></a>
<a name="3273"><span class="lineNum">    3273 </span>                :<span class="lineCov">     215456 :                         tcp->stime.tv_sec = ru.ru_stime.tv_sec;</span></a>
<a name="3274"><span class="lineNum">    3274 </span>                :<span class="lineCov">     215456 :                         tcp->stime.tv_nsec = ru.ru_stime.tv_usec * 1000;</span></a>
<a name="3275"><span class="lineNum">    3275 </span>                :            :                 }</a>
<a name="3276"><span class="lineNum">    3276 </span>                :            : </a>
<a name="3277"><span class="lineNum">    3277 </span>                :<span class="lineCov">  156770719 :                 tcb_wait_tab_check_size(wait_tab_pos);</span></a>
<a name="3278"><span class="lineNum">    3278 </span>                :            : </a>
<a name="3279"><span class="lineNum">    3279 </span>                :            :                 /* Initialise a new wait data structure.  */</a>
<a name="3280"><span class="lineNum">    3280 </span>                :<span class="lineCov">  156770719 :                 wd = tcb_wait_tab + wait_tab_pos;</span></a>
<a name="3281"><span class="lineNum">    3281 </span>                :<span class="lineCov">  156770719 :                 init_trace_wait_data(wd);</span></a>
<a name="3282"><span class="lineNum">    3282 </span>                :<span class="lineCov">  156770719 :                 wd->status = status;</span></a>
<a name="3283"><span class="lineNum">    3283 </span>                :            : </a>
<a name="3284"><span class="lineNum">    3284 </span>        [<span class="branchCov" title="Branch 0 was taken 10070 times"> + </span><span class="branchCov" title="Branch 1 was taken 156760649 times"> + </span>]:<span class="lineCov">  156770719 :                 if (WIFSIGNALED(status)) {</span></a>
<a name="3285"><span class="lineNum">    3285 </span>                :<span class="lineCov">      10070 :                         wd->te = TE_SIGNALLED;</span></a>
<a name="3286"><span class="lineNum">    3286 </span>        [<span class="branchCov" title="Branch 0 was taken 35579 times"> + </span><span class="branchCov" title="Branch 1 was taken 156725070 times"> + </span>]:<span class="lineCov">  156760649 :                 } else if (WIFEXITED(status)) {</span></a>
<a name="3287"><span class="lineNum">    3287 </span>                :<span class="lineCov">      35579 :                         wd->te = TE_EXITED;</span></a>
<a name="3288"><span class="lineNum">    3288 </span>                :            :                 } else {</a>
<a name="3289"><span class="lineNum">    3289 </span>                :            :                         /*</a>
<a name="3290"><span class="lineNum">    3290 </span>                :            :                          * As WCONTINUED flag has not been specified to wait4,</a>
<a name="3291"><span class="lineNum">    3291 </span>                :            :                          * it cannot be WIFCONTINUED(status), so the only case</a>
<a name="3292"><span class="lineNum">    3292 </span>                :            :                          * that remains is WIFSTOPPED(status).</a>
<a name="3293"><span class="lineNum">    3293 </span>                :            :                          */</a>
<a name="3294"><span class="lineNum">    3294 </span>                :            : </a>
<a name="3295"><span class="lineNum">    3295 </span>                :<span class="lineCov">  156725070 :                         const unsigned int sig = WSTOPSIG(status);</span></a>
<a name="3296"><span class="lineNum">    3296 </span>                :<span class="lineCov">  156725070 :                         const unsigned int event = (unsigned int) status >> 16;</span></a>
<a name="3297"><span class="lineNum">    3297 </span>                :            : </a>
<a name="3298"><span class="lineNum">    3298 </span>  [<span class="branchCov" title="Branch 0 was taken 156568207 times"> + </span><span class="branchCov" title="Branch 1 was taken 62164 times"> + </span><span class="branchCov" title="Branch 2 was taken 16310 times"> + </span><span class="branchCov" title="Branch 3 was taken 45534 times"> + </span> :<span class="lineCov">  156725070 :                         switch (event) {</span></a>
<span class="lineNum">         </span>         <span class="branchCov" title="Branch 4 was taken 3440 times"> + </span><span class="branchCov" title="Branch 5 was taken 29415 times"> + </span>]
<a name="3299"><span class="lineNum">    3299 </span>                :<span class="lineCov">  156568207 :                         case 0:</span></a>
<a name="3300"><span class="lineNum">    3300 </span>                :            :                                 /*</a>
<a name="3301"><span class="lineNum">    3301 </span>                :            :                                  * Is this post-attach SIGSTOP?</a>
<a name="3302"><span class="lineNum">    3302 </span>                :            :                                  * Interestingly, the process may stop</a>
<a name="3303"><span class="lineNum">    3303 </span>                :            :                                  * with STOPSIG equal to some other signal</a>
<a name="3304"><span class="lineNum">    3304 </span>                :            :                                  * than SIGSTOP if we happened to attach</a>
<a name="3305"><span class="lineNum">    3305 </span>                :            :                                  * just before the process takes a signal.</a>
<a name="3306"><span class="lineNum">    3306 </span>                :            :                                  */</a>
<a name="3307"><span class="lineNum">    3307 </span>        [<span class="branchCov" title="Branch 0 was taken 59 times"> + </span><span class="branchCov" title="Branch 1 was taken 156568148 times"> + </span>]:<span class="lineCov">  156568207 :                                 if (sig == SIGSTOP &&</span></a>
<a name="3308"><span class="lineNum">    3308 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 59 times"> + </span>]:<span class="lineCov">         59 :                                     (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {</span></a>
<a name="3309"><span class="lineNum">    3309 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                                         debug_func_msg("ignored SIGSTOP on "</span></a>
<a name="3310"><span class="lineNum">    3310 </span>                :            :                                                        "pid %d", tcp->pid);</a>
<a name="3311"><span class="lineNum">    3311 </span>                :<span class="lineNoCov">          0 :                                         tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;</span></a>
<a name="3312"><span class="lineNum">    3312 </span>                :<span class="lineNoCov">          0 :                                         wd->te = TE_RESTART;</span></a>
<a name="3313"><span class="lineNum">    3313 </span>        [<span class="branchCov" title="Branch 0 was taken 156506688 times"> + </span><span class="branchCov" title="Branch 1 was taken 61519 times"> + </span>]:<span class="lineCov">  156568207 :                                 } else if (sig == syscall_trap_sig) {</span></a>
<a name="3314"><span class="lineNum">    3314 </span>                :<span class="lineCov">  156506688 :                                         wd->te = TE_SYSCALL_STOP;</span></a>
<a name="3315"><span class="lineNum">    3315 </span>                :            :                                 } else {</a>
<a name="3316"><span class="lineNum">    3316 </span>                :            :                                         /*</a>
<a name="3317"><span class="lineNum">    3317 </span>                :            :                                          * True if tracee is stopped by signal</a>
<a name="3318"><span class="lineNum">    3318 </span>                :            :                                          * (as opposed to "tracee received</a>
<a name="3319"><span class="lineNum">    3319 </span>                :            :                                          * signal").</a>
<a name="3320"><span class="lineNum">    3320 </span>                :            :                                          * TODO: shouldn't we check for</a>
<a name="3321"><span class="lineNum">    3321 </span>                :            :                                          * errno == EINVAL too?</a>
<a name="3322"><span class="lineNum">    3322 </span>                :            :                                          * We can get ESRCH instead, you know...</a>
<a name="3323"><span class="lineNum">    3323 </span>                :            :                                          */</a>
<a name="3324"><span class="lineNum">    3324 </span>                :<span class="lineCov">      61519 :                                         bool stopped = ptrace(PTRACE_GETSIGINFO,</span></a>
<a name="3325"><span class="lineNum">    3325 </span>                :            :                                                 pid, 0, &wd->si) < 0;</a>
<a name="3326"><span class="lineNum">    3326 </span>                :            : </a>
<a name="3327"><span class="lineNum">    3327 </span>                :<span class="lineCov">      61519 :                                         wd->te = stopped ? TE_GROUP_STOP</span></a>
<a name="3328"><span class="lineNum">    3328 </span>        [<span class="branchCov" title="Branch 0 was taken 61519 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      61519 :                                                          : TE_SIGNAL_DELIVERY_STOP;</span></a>
<a name="3329"><span class="lineNum">    3329 </span>                :            :                                 }</a>
<a name="3330"><span class="lineNum">    3330 </span>                :            :                                 break;</a>
<a name="3331"><span class="lineNum">    3331 </span>                :<span class="lineCov">      62164 :                         case PTRACE_EVENT_STOP:</span></a>
<a name="3332"><span class="lineNum">    3332 </span>                :            :                                 /*</a>
<a name="3333"><span class="lineNum">    3333 </span>                :            :                                  * PTRACE_INTERRUPT-stop or group-stop.</a>
<a name="3334"><span class="lineNum">    3334 </span>                :            :                                  * PTRACE_INTERRUPT-stop has sig == SIGTRAP here.</a>
<a name="3335"><span class="lineNum">    3335 </span>                :            :                                  */</a>
<a name="3336"><span class="lineNum">    3336 </span>        [<span class="branchCov" title="Branch 0 was taken 16301 times"> + </span><span class="branchCov" title="Branch 1 was taken 45863 times"> + </span>]:<span class="lineCov">      62164 :                                 switch (sig) {</span></a>
<a name="3337"><span class="lineNum">    3337 </span>                :<span class="lineCov">      16301 :                                 case SIGSTOP:</span></a>
<a name="3338"><span class="lineNum">    3338 </span>                :            :                                 case SIGTSTP:</a>
<a name="3339"><span class="lineNum">    3339 </span>                :            :                                 case SIGTTIN:</a>
<a name="3340"><span class="lineNum">    3340 </span>                :            :                                 case SIGTTOU:</a>
<a name="3341"><span class="lineNum">    3341 </span>                :<span class="lineCov">      16301 :                                         wd->te = TE_GROUP_STOP;</span></a>
<a name="3342"><span class="lineNum">    3342 </span>                :<span class="lineCov">      16301 :                                         break;</span></a>
<a name="3343"><span class="lineNum">    3343 </span>                :<span class="lineCov">      45863 :                                 default:</span></a>
<a name="3344"><span class="lineNum">    3344 </span>                :<span class="lineCov">      45863 :                                         wd->te = TE_RESTART;</span></a>
<a name="3345"><span class="lineNum">    3345 </span>                :            :                                 }</a>
<a name="3346"><span class="lineNum">    3346 </span>                :            :                                 break;</a>
<a name="3347"><span class="lineNum">    3347 </span>                :<span class="lineCov">      16310 :                         case PTRACE_EVENT_EXEC:</span></a>
<a name="3348"><span class="lineNum">    3348 </span>                :            :                                         /*</a>
<a name="3349"><span class="lineNum">    3349 </span>                :            :                                          * TODO: shouldn't we check for</a>
<a name="3350"><span class="lineNum">    3350 </span>                :            :                                          * errno == EINVAL here, too?</a>
<a name="3351"><span class="lineNum">    3351 </span>                :            :                                          * We can get ESRCH instead, you know...</a>
<a name="3352"><span class="lineNum">    3352 </span>                :            :                                          */</a>
<a name="3353"><span class="lineNum">    3353 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16310 times"> + </span>]:<span class="lineCov">      16310 :                                 if (ptrace(PTRACE_GETEVENTMSG, pid, NULL,</span></a>
<a name="3354"><span class="lineNum">    3354 </span>                :            :                                     &wd->msg) < 0)</a>
<a name="3355"><span class="lineNum">    3355 </span>                :<span class="lineNoCov">          0 :                                         wd->msg = 0;</span></a>
<a name="3356"><span class="lineNum">    3356 </span>                :            : </a>
<a name="3357"><span class="lineNum">    3357 </span>                :<span class="lineCov">      16310 :                                 wd->te = TE_STOP_BEFORE_EXECVE;</span></a>
<a name="3358"><span class="lineNum">    3358 </span>                :<span class="lineCov">      16310 :                                 break;</span></a>
<a name="3359"><span class="lineNum">    3359 </span>                :<span class="lineCov">      45534 :                         case PTRACE_EVENT_EXIT:</span></a>
<a name="3360"><span class="lineNum">    3360 </span>                :<span class="lineCov">      45534 :                                 wd->te = TE_STOP_BEFORE_EXIT;</span></a>
<a name="3361"><span class="lineNum">    3361 </span>                :<span class="lineCov">      45534 :                                 break;</span></a>
<a name="3362"><span class="lineNum">    3362 </span>                :<span class="lineCov">       3440 :                         case PTRACE_EVENT_SECCOMP:</span></a>
<a name="3363"><span class="lineNum">    3363 </span>                :<span class="lineCov">       3440 :                                 wd->te = TE_SECCOMP;</span></a>
<a name="3364"><span class="lineNum">    3364 </span>                :<span class="lineCov">       3440 :                                 break;</span></a>
<a name="3365"><span class="lineNum">    3365 </span>                :<span class="lineCov">      29415 :                         default:</span></a>
<a name="3366"><span class="lineNum">    3366 </span>                :<span class="lineCov">      29415 :                                 wd->te = TE_RESTART;</span></a>
<a name="3367"><span class="lineNum">    3367 </span>                :            :                         }</a>
<a name="3368"><span class="lineNum">    3368 </span>                :            :                 }</a>
<a name="3369"><span class="lineNum">    3369 </span>                :            : </a>
<a name="3370"><span class="lineNum">    3370 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 156770719 times"> + </span>]:<span class="lineCov">  156770719 :                 if (!wd->te)</span></a>
<a name="3371"><span class="lineNum">    3371 </span>                :<span class="lineNoCov">          0 :                         error_func_msg("Tracing event hasn't been determined "</span></a>
<a name="3372"><span class="lineNum">    3372 </span>                :            :                                        "for pid %d, status %0#x", pid, status);</a>
<a name="3373"><span class="lineNum">    3373 </span>                :            : </a>
<a name="3374"><span class="lineNum">    3374 </span>        [<span class="branchCov" title="Branch 0 was taken 113 times"> + </span><span class="branchCov" title="Branch 1 was taken 156770606 times"> + </span>]:<span class="lineCov">  156770719 :                 if (!list_is_empty(&tcp->wait_list)) {</span></a>
<a name="3375"><span class="lineNum">    3375 </span>                :<span class="lineCov">        113 :                         wait_extra_data_idx = wait_tab_pos;</span></a>
<a name="3376"><span class="lineNum">    3376 </span>                :<span class="lineCov">        113 :                         extra_tcp = tcp;</span></a>
<a name="3377"><span class="lineNum">    3377 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 113 times"> + </span>]:<span class="lineCov">        113 :                         debug_func_msg("queued extra pid %d", tcp->pid);</span></a>
<a name="3378"><span class="lineNum">    3378 </span>                :            :                 } else {</a>
<a name="3379"><span class="lineNum">    3379 </span>                :<span class="lineCov">  156770606 :                         tcp->wait_data_idx = wait_tab_pos;</span></a>
<a name="3380"><span class="lineNum">    3380 </span>        [<span class="branchCov" title="Branch 0 was taken 73171 times"> + </span><span class="branchCov" title="Branch 1 was taken 156697435 times"> + </span>]:<span class="lineCov">  156770606 :                         list_append(&pending_tcps, &tcp->wait_list);</span></a>
<a name="3381"><span class="lineNum">    3381 </span>        [<span class="branchCov" title="Branch 0 was taken 73171 times"> + </span><span class="branchCov" title="Branch 1 was taken 156697435 times"> + </span>]:<span class="lineCov">  156770606 :                         debug_func_msg("queued pid %d", tcp->pid);</span></a>
<a name="3382"><span class="lineNum">    3382 </span>                :            :                 }</a>
<a name="3383"><span class="lineNum">    3383 </span>                :            : </a>
<a name="3384"><span class="lineNum">    3384 </span>                :<span class="lineCov">  156770719 :                 wait_tab_pos++;</span></a>
<a name="3385"><span class="lineNum">    3385 </span>                :            : </a>
<a name="3386"><span class="lineNum">    3386 </span>        [<span class="branchCov" title="Branch 0 was taken 113 times"> + </span><span class="branchCov" title="Branch 1 was taken 156770606 times"> + </span>]:<span class="lineCov">  156770719 :                 if (extra_tcp)</span></a>
<a name="3387"><span class="lineNum">    3387 </span>                :            :                         break;</a>
<a name="3388"><span class="lineNum">    3388 </span>                :            : </a>
<a name="3389"><span class="lineNum">    3389 </span>                :<span class="lineCov">  156770606 : next_event_wait_next:</span></a>
<a name="3390"><span class="lineNum">    3390 </span>        [<span class="branchCov" title="Branch 0 was taken 156555329 times"> + </span><span class="branchCov" title="Branch 1 was taken 215456 times"> + </span>]:<span class="lineCov">  313326114 :                 pid = wait4(-1, &status, __WALL | WNOHANG, (cflag ? &ru : NULL));</span></a>
<a name="3391"><span class="lineNum">    3391 </span>                :<span class="lineCov">  156770785 :                 wait_errno = errno;</span></a>
<a name="3392"><span class="lineNum">    3392 </span>                :<span class="lineCov">  156770785 :                 wait_nohang = true;</span></a>
<a name="3393"><span class="lineNum">    3393 </span>                :            :         }</a>
<a name="3394"><span class="lineNum">    3394 </span>                :            : </a>
<a name="3395"><span class="lineNum">    3395 </span>                :<span class="lineCov">  132980772 : next_event_get_tcp:</span></a>
<a name="3396"><span class="lineNum">    3396 </span>                :<span class="lineCov">  156770742 :         elem = list_remove_head(&pending_tcps);</span></a>
<a name="3397"><span class="lineNum">    3397 </span>                :            : </a>
<a name="3398"><span class="lineNum">    3398 </span>        [<span class="branchCov" title="Branch 0 was taken 136 times"> + </span><span class="branchCov" title="Branch 1 was taken 156770606 times"> + </span>]:<span class="lineCov">  156770742 :         if (!elem) {</span></a>
<a name="3399"><span class="lineNum">    3399 </span>                :<span class="lineCov">        136 :                 tcb_wait_tab_check_size(0);</span></a>
<a name="3400"><span class="lineNum">    3400 </span>                :<span class="lineCov">        136 :                 memset(tcb_wait_tab, 0, sizeof(*tcb_wait_tab));</span></a>
<a name="3401"><span class="lineNum">    3401 </span>                :<span class="lineCov">        136 :                 tcb_wait_tab->te = TE_NEXT;</span></a>
<a name="3402"><span class="lineNum">    3402 </span>                :            : </a>
<a name="3403"><span class="lineNum">    3403 </span>                :<span class="lineCov">        136 :                 return tcb_wait_tab;</span></a>
<a name="3404"><span class="lineNum">    3404 </span>                :            :         } else {</a>
<a name="3405"><span class="lineNum">    3405 </span>                :<span class="lineCov">  156770606 :                 tcp = list_elem(elem, struct tcb, wait_list);</span></a>
<a name="3406"><span class="lineNum">    3406 </span>        [<span class="branchCov" title="Branch 0 was taken 156697435 times"> + </span><span class="branchCov" title="Branch 1 was taken 73171 times"> + </span>]:<span class="lineCov">  156770606 :                 debug_func_msg("dequeued pid %d", tcp->pid);</span></a>
<a name="3407"><span class="lineNum">    3407 </span>                :            :         }</a>
<a name="3408"><span class="lineNum">    3408 </span>                :            : </a>
<a name="3409"><span class="lineNum">    3409 </span>                :<span class="lineCov">  156697435 : next_event_exit:</span></a>
<a name="3410"><span class="lineNum">    3410 </span>                :            :         /* Is this the very first time we see this tracee stopped? */</a>
<a name="3411"><span class="lineNum">    3411 </span>        [<span class="branchCov" title="Branch 0 was taken 45674 times"> + </span><span class="branchCov" title="Branch 1 was taken 156725045 times"> + </span>]:<span class="lineCov">  156770719 :         if (tcp->flags & TCB_STARTUP)</span></a>
<a name="3412"><span class="lineNum">    3412 </span>                :<span class="lineCov">      45674 :                 startup_tcb(tcp);</span></a>
<a name="3413"><span class="lineNum">    3413 </span>                :            : </a>
<a name="3414"><span class="lineNum">    3414 </span>                :<span class="lineCov">  156770719 :         clear_regs(tcp);</span></a>
<a name="3415"><span class="lineNum">    3415 </span>                :            : </a>
<a name="3416"><span class="lineNum">    3416 </span>                :            :         /* Set current output file */</a>
<a name="3417"><span class="lineNum">    3417 </span>                :<span class="lineCov">  156770719 :         set_current_tcp(tcp);</span></a>
<a name="3418"><span class="lineNum">    3418 </span>                :            : </a>
<a name="3419"><span class="lineNum">    3419 </span>                :<span class="lineCov">  156770719 :         return tcb_wait_tab + tcp->wait_data_idx;</span></a>
<a name="3420"><span class="lineNum">    3420 </span>                :            : }</a>
<a name="3421"><span class="lineNum">    3421 </span>                :            : </a>
<a name="3422"><span class="lineNum">    3422 </span>                :            : static int</a>
<a name="3423"><span class="lineNum">    3423 </span>                :<span class="lineCov">  156510125 : trace_syscall(struct tcb *tcp, unsigned int *sig)</span></a>
<a name="3424"><span class="lineNum">    3424 </span>                :            : {</a>
<a name="3425"><span class="lineNum">    3425 </span>        [<span class="branchCov" title="Branch 0 was taken 78269658 times"> + </span><span class="branchCov" title="Branch 1 was taken 78240467 times"> + </span>]:<span class="lineCov">  156510125 :         if (entering(tcp)) {</span></a>
<a name="3426"><span class="lineNum">    3426 </span>                :<span class="lineCov">   78269658 :                 int res = syscall_entering_decode(tcp);</span></a>
<a name="3427"><span class="lineNum">    3427 </span>     [<span class="branchCov" title="Branch 0 was taken 78269541 times"> + </span><span class="branchCov" title="Branch 1 was taken 117 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span>]:<span class="lineCov">   78269658 :                 switch (res) {</span></a>
<a name="3428"><span class="lineNum">    3428 </span>                :            :                 case 0:</a>
<a name="3429"><span class="lineNum">    3429 </span>                :            :                         return 0;</a>
<a name="3430"><span class="lineNum">    3430 </span>                :<span class="lineCov">   78269541 :                 case 1:</span></a>
<a name="3431"><span class="lineNum">    3431 </span>                :<span class="lineCov">   78269541 :                         res = syscall_entering_trace(tcp, sig);</span></a>
<a name="3432"><span class="lineNum">    3432 </span>                :            :                 }</a>
<a name="3433"><span class="lineNum">    3433 </span>                :<span class="lineCov">   78269658 :                 syscall_entering_finish(tcp, res);</span></a>
<a name="3434"><span class="lineNum">    3434 </span>                :<span class="lineCov">   78269658 :                 return res;</span></a>
<a name="3435"><span class="lineNum">    3435 </span>                :            :         } else {</a>
<a name="3436"><span class="lineNum">    3436 </span>                :<span class="lineCov">   78240467 :                 struct timespec ts = {};</span></a>
<a name="3437"><span class="lineNum">    3437 </span>                :<span class="lineCov">   78240467 :                 int res = syscall_exiting_decode(tcp, &ts);</span></a>
<a name="3438"><span class="lineNum">    3438 </span>        [<span class="branchCov" title="Branch 0 was taken 998761 times"> + </span><span class="branchCov" title="Branch 1 was taken 77241706 times"> + </span>]:<span class="lineCov">   78240467 :                 if (res != 0) {</span></a>
<a name="3439"><span class="lineNum">    3439 </span>                :<span class="lineCov">     998761 :                         res = syscall_exiting_trace(tcp, &ts, res);</span></a>
<a name="3440"><span class="lineNum">    3440 </span>                :            :                 }</a>
<a name="3441"><span class="lineNum">    3441 </span>                :<span class="lineCov">   78240467 :                 syscall_exiting_finish(tcp);</span></a>
<a name="3442"><span class="lineNum">    3442 </span>                :<span class="lineCov">   78240467 :                 return res;</span></a>
<a name="3443"><span class="lineNum">    3443 </span>                :            :         }</a>
<a name="3444"><span class="lineNum">    3444 </span>                :            : }</a>
<a name="3445"><span class="lineNum">    3445 </span>                :            : </a>
<a name="3446"><span class="lineNum">    3446 </span>                :            : /* Returns true iff the main trace loop has to continue. */</a>
<a name="3447"><span class="lineNum">    3447 </span>                :            : static bool</a>
<a name="3448"><span class="lineNum">    3448 </span>                :<span class="lineCov">  156787246 : dispatch_event(const struct tcb_wait_data *wd)</span></a>
<a name="3449"><span class="lineNum">    3449 </span>                :            : {</a>
<a name="3450"><span class="lineNum">    3450 </span>                :<span class="lineCov">  156787246 :         unsigned int restart_op;</span></a>
<a name="3451"><span class="lineNum">    3451 </span>                :<span class="lineCov">  156787246 :         unsigned int restart_sig = 0;</span></a>
<a name="3452"><span class="lineNum">    3452 </span>        [<span class="branchCov" title="Branch 0 was taken 156770991 times"> + </span><span class="branchCov" title="Branch 1 was taken 16255 times"> + </span>]:<span class="lineCov">  156787246 :         enum trace_event te = wd ? wd->te : TE_BREAK;</span></a>
<a name="3453"><span class="lineNum">    3453 </span>                :            :         /*</a>
<a name="3454"><span class="lineNum">    3454 </span>                :            :          * Copy wd->status to a non-const variable to workaround glibc bugs</a>
<a name="3455"><span class="lineNum">    3455 </span>                :            :          * around union wait fixed by glibc commit glibc-2.24~391</a>
<a name="3456"><span class="lineNum">    3456 </span>                :            :          */</a>
<a name="3457"><span class="lineNum">    3457 </span>        [<span class="branchCov" title="Branch 0 was taken 156770991 times"> + </span><span class="branchCov" title="Branch 1 was taken 16255 times"> + </span>]:<span class="lineCov">  156787246 :         int status = wd ? wd->status : 0;</span></a>
<a name="3458"><span class="lineNum">    3458 </span>                :            : </a>
<a name="3459"><span class="lineNum">    3459 </span>  [<span class="branchCov" title="Branch 0 was taken 156770993 times"> + </span><span class="branchCov" title="Branch 1 was taken 16253 times"> + </span><span class="branchCov" title="Branch 2 was taken 6932 times"> + </span><span class="branchCov" title="Branch 3 was taken 156764061 times"> + </span>]:<span class="lineCov">  156787246 :         if (current_tcp && has_seccomp_filter(current_tcp))</span></a>
<a name="3460"><span class="lineNum">    3460 </span>                :<span class="lineCov">       6932 :                 restart_op = seccomp_filter_restart_operator(current_tcp);</span></a>
<a name="3461"><span class="lineNum">    3461 </span>                :            :         else</a>
<a name="3462"><span class="lineNum">    3462 </span>                :            :                 restart_op = PTRACE_SYSCALL;</a>
<a name="3463"><span class="lineNum">    3463 </span>                :            : </a>
<a name="3464"><span class="lineNum">    3464 </span>  [<span class="branchCov" title="Branch 0 was taken 136 times"> + </span><span class="branchCov" title="Branch 1 was taken 3440 times"> + </span><span class="branchCov" title="Branch 2 was taken 156506688 times"> + </span><span class="branchCov" title="Branch 3 was taken 61519 times"> + </span> :<span class="lineCov">  156787246 :         switch (te) {</span></a>
<span class="lineNum">         </span><span class="branchCov" title="Branch 4 was taken 10070 times"> + </span><span class="branchCov" title="Branch 5 was taken 16301 times"> + </span><span class="branchCov" title="Branch 6 was taken 35579 times"> + </span><span class="branchCov" title="Branch 7 was taken 16310 times"> + </span><span class="branchCov" title="Branch 8 was taken 45534 times"> + </span> 
<span class="lineNum">         </span>         <span class="branchCov" title="Branch 9 was taken 75414 times"> + </span><span class="branchCov" title="Branch 10 was taken 16255 times"> + </span>]
<a name="3465"><span class="lineNum">    3465 </span>                :            :         case TE_BREAK:</a>
<a name="3466"><span class="lineNum">    3466 </span>                :            :                 return false;</a>
<a name="3467"><span class="lineNum">    3467 </span>                :            : </a>
<a name="3468"><span class="lineNum">    3468 </span>                :<span class="lineCov">        136 :         case TE_NEXT:</span></a>
<a name="3469"><span class="lineNum">    3469 </span>                :<span class="lineCov">        136 :                 return true;</span></a>
<a name="3470"><span class="lineNum">    3470 </span>                :            : </a>
<a name="3471"><span class="lineNum">    3471 </span>                :            :         case TE_RESTART:</a>
<a name="3472"><span class="lineNum">    3472 </span>                :            :                 break;</a>
<a name="3473"><span class="lineNum">    3473 </span>                :            : </a>
<a name="3474"><span class="lineNum">    3474 </span>                :<span class="lineCov">       3440 :         case TE_SECCOMP:</span></a>
<a name="3475"><span class="lineNum">    3475 </span>        [<span class="branchCov" title="Branch 0 was taken 3 times"> + </span><span class="branchCov" title="Branch 1 was taken 3437 times"> + </span>]:<span class="lineCov">       3440 :                 if (!has_seccomp_filter(current_tcp)) {</span></a>
<a name="3476"><span class="lineNum">    3476 </span>                :            :                         /*</a>
<a name="3477"><span class="lineNum">    3477 </span>                :            :                          * We don't know if forks/clones have a seccomp filter</a>
<a name="3478"><span class="lineNum">    3478 </span>                :            :                          * when they are created, but we can detect it when we</a>
<a name="3479"><span class="lineNum">    3479 </span>                :            :                          * have a seccomp-stop.</a>
<a name="3480"><span class="lineNum">    3480 </span>                :            :                          * In such a case, if !seccomp_before_sysentry, we have</a>
<a name="3481"><span class="lineNum">    3481 </span>                :            :                          * already processed the syscall entry, so we avoid</a>
<a name="3482"><span class="lineNum">    3482 </span>                :            :                          * processing it a second time.</a>
<a name="3483"><span class="lineNum">    3483 </span>                :            :                          */</a>
<a name="3484"><span class="lineNum">    3484 </span>                :<span class="lineCov">          3 :                         current_tcp->flags |= TCB_SECCOMP_FILTER;</span></a>
<a name="3485"><span class="lineNum">    3485 </span>                :<span class="lineCov">          3 :                         restart_op = PTRACE_SYSCALL;</span></a>
<a name="3486"><span class="lineNum">    3486 </span>                :<span class="lineCov">          3 :                         break;</span></a>
<a name="3487"><span class="lineNum">    3487 </span>                :            :                 }</a>
<a name="3488"><span class="lineNum">    3488 </span>                :            : </a>
<a name="3489"><span class="lineNum">    3489 </span>        [<span class="branchCov" title="Branch 0 was taken 3437 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">       3437 :                 if (seccomp_before_sysentry) {</span></a>
<a name="3490"><span class="lineNum">    3490 </span>                :            :                         restart_op = PTRACE_SYSCALL;</a>
<a name="3491"><span class="lineNum">    3491 </span>                :            :                         break;</a>
<a name="3492"><span class="lineNum">    3492 </span>                :            :                 }</a>
<a name="3493"><span class="lineNum">    3493 </span>                :<span class="lineCov">  156510125 :                 ATTRIBUTE_FALLTHROUGH;</span></a>
<a name="3494"><span class="lineNum">    3494 </span>                :            : </a>
<a name="3495"><span class="lineNum">    3495 </span>                :            :         case TE_SYSCALL_STOP:</a>
<a name="3496"><span class="lineNum">    3496 </span>        [<span class="branchCov" title="Branch 0 was taken 156510005 times"> + </span><span class="branchCov" title="Branch 1 was taken 120 times"> + </span>]:<span class="lineCov">  156510125 :                 if (trace_syscall(current_tcp, &restart_sig) < 0) {</span></a>
<a name="3497"><span class="lineNum">    3497 </span>                :            :                         /*</a>
<a name="3498"><span class="lineNum">    3498 </span>                :            :                          * ptrace() failed in trace_syscall().</a>
<a name="3499"><span class="lineNum">    3499 </span>                :            :                          * Likely a result of process disappearing mid-flight.</a>
<a name="3500"><span class="lineNum">    3500 </span>                :            :                          * Observed case: exit_group() or SIGKILL terminating</a>
<a name="3501"><span class="lineNum">    3501 </span>                :            :                          * all processes in thread group.</a>
<a name="3502"><span class="lineNum">    3502 </span>                :            :                          * We assume that ptrace error was caused by process death.</a>
<a name="3503"><span class="lineNum">    3503 </span>                :            :                          * We used to detach(current_tcp) here, but since we no</a>
<a name="3504"><span class="lineNum">    3504 </span>                :            :                          * longer implement "detach before death" policy/hack,</a>
<a name="3505"><span class="lineNum">    3505 </span>                :            :                          * we can let this process to report its death to us</a>
<a name="3506"><span class="lineNum">    3506 </span>                :            :                          * normally, via WIFEXITED or WIFSIGNALED wait status.</a>
<a name="3507"><span class="lineNum">    3507 </span>                :            :                          */</a>
<a name="3508"><span class="lineNum">    3508 </span>                :            :                         return true;</a>
<a name="3509"><span class="lineNum">    3509 </span>                :            :                 }</a>
<a name="3510"><span class="lineNum">    3510 </span>        [<span class="branchCov" title="Branch 0 was taken 6876 times"> + </span><span class="branchCov" title="Branch 1 was taken 156503129 times"> + </span>]:<span class="lineCov">  156510005 :                 if (has_seccomp_filter(current_tcp)) {</span></a>
<a name="3511"><span class="lineNum">    3511 </span>                :            :                         /*</a>
<a name="3512"><span class="lineNum">    3512 </span>                :            :                          * Syscall and seccomp stops can happen in different</a>
<a name="3513"><span class="lineNum">    3513 </span>                :            :                          * orders depending on kernel.  strace tests this in</a>
<a name="3514"><span class="lineNum">    3514 </span>                :            :                          * check_seccomp_order_tracer().</a>
<a name="3515"><span class="lineNum">    3515 </span>                :            :                          *</a>
<a name="3516"><span class="lineNum">    3516 </span>                :            :                          * Linux 3.5--4.7:</a>
<a name="3517"><span class="lineNum">    3517 </span>                :            :                          * (seccomp-stop before syscall-entry-stop)</a>
<a name="3518"><span class="lineNum">    3518 </span>                :            :                          *         +--> seccomp-stop ->-PTRACE_SYSCALL->-+</a>
<a name="3519"><span class="lineNum">    3519 </span>                :            :                          *         |                                     |</a>
<a name="3520"><span class="lineNum">    3520 </span>                :            :                          *     PTRACE_CONT                   syscall-entry-stop</a>
<a name="3521"><span class="lineNum">    3521 </span>                :            :                          *         |                                     |</a>
<a name="3522"><span class="lineNum">    3522 </span>                :            :                          * syscall-exit-stop <---PTRACE_SYSCALL-----<----+</a>
<a name="3523"><span class="lineNum">    3523 </span>                :            :                          *</a>
<a name="3524"><span class="lineNum">    3524 </span>                :            :                          * Linux 4.8+:</a>
<a name="3525"><span class="lineNum">    3525 </span>                :            :                          * (seccomp-stop after syscall-entry-stop)</a>
<a name="3526"><span class="lineNum">    3526 </span>                :            :                          *                 syscall-entry-stop</a>
<a name="3527"><span class="lineNum">    3527 </span>                :            :                          *</a>
<a name="3528"><span class="lineNum">    3528 </span>                :            :                          *         +---->-----PTRACE_CONT---->----+</a>
<a name="3529"><span class="lineNum">    3529 </span>                :            :                          *         |                              |</a>
<a name="3530"><span class="lineNum">    3530 </span>                :            :                          *  syscall-exit-stop               seccomp-stop</a>
<a name="3531"><span class="lineNum">    3531 </span>                :            :                          *         |                              |</a>
<a name="3532"><span class="lineNum">    3532 </span>                :            :                          *         +----<----PTRACE_SYSCALL---<---+</a>
<a name="3533"><span class="lineNum">    3533 </span>                :            :                          *</a>
<a name="3534"><span class="lineNum">    3534 </span>                :            :                          * Note in Linux 4.8+, we restart in PTRACE_CONT</a>
<a name="3535"><span class="lineNum">    3535 </span>                :            :                          * after syscall-exit to skip the syscall-entry-stop.</a>
<a name="3536"><span class="lineNum">    3536 </span>                :            :                          * The next seccomp-stop will be treated as a syscall</a>
<a name="3537"><span class="lineNum">    3537 </span>                :            :                          * entry.</a>
<a name="3538"><span class="lineNum">    3538 </span>                :            :                          *</a>
<a name="3539"><span class="lineNum">    3539 </span>                :            :                          * The line below implements this behavior.</a>
<a name="3540"><span class="lineNum">    3540 </span>                :            :                          * Note that exiting(current_tcp) actually marks</a>
<a name="3541"><span class="lineNum">    3541 </span>                :            :                          * a syscall-entry-stop because the flag was inverted</a>
<a name="3542"><span class="lineNum">    3542 </span>                :            :                          * in the above call to trace_syscall.</a>
<a name="3543"><span class="lineNum">    3543 </span>                :            :                          */</a>
<a name="3544"><span class="lineNum">    3544 </span>        [<span class="branchCov" title="Branch 0 was taken 3439 times"> + </span><span class="branchCov" title="Branch 1 was taken 3437 times"> + </span>]:<span class="lineCov">       6876 :                         restart_op = exiting(current_tcp) ? PTRACE_SYSCALL : PTRACE_CONT;</span></a>
<a name="3545"><span class="lineNum">    3545 </span>                :            :                 }</a>
<a name="3546"><span class="lineNum">    3546 </span>                :            :                 break;</a>
<a name="3547"><span class="lineNum">    3547 </span>                :            : </a>
<a name="3548"><span class="lineNum">    3548 </span>                :<span class="lineCov">      61519 :         case TE_SIGNAL_DELIVERY_STOP:</span></a>
<a name="3549"><span class="lineNum">    3549 </span>                :<span class="lineCov">      61519 :                 restart_sig = WSTOPSIG(status);</span></a>
<a name="3550"><span class="lineNum">    3550 </span>                :<span class="lineCov">      61519 :                 print_stopped(current_tcp, &wd->si, restart_sig);</span></a>
<a name="3551"><span class="lineNum">    3551 </span>                :<span class="lineCov">      61519 :                 break;</span></a>
<a name="3552"><span class="lineNum">    3552 </span>                :            : </a>
<a name="3553"><span class="lineNum">    3553 </span>                :<span class="lineCov">      10070 :         case TE_SIGNALLED:</span></a>
<a name="3554"><span class="lineNum">    3554 </span>                :<span class="lineCov">      10070 :                 print_signalled(current_tcp, current_tcp->pid, status);</span></a>
<a name="3555"><span class="lineNum">    3555 </span>                :<span class="lineCov">      10070 :                 droptcb(current_tcp);</span></a>
<a name="3556"><span class="lineNum">    3556 </span>                :<span class="lineCov">      10070 :                 return true;</span></a>
<a name="3557"><span class="lineNum">    3557 </span>                :            : </a>
<a name="3558"><span class="lineNum">    3558 </span>                :<span class="lineCov">      16301 :         case TE_GROUP_STOP:</span></a>
<a name="3559"><span class="lineNum">    3559 </span>                :<span class="lineCov">      16301 :                 restart_sig = WSTOPSIG(status);</span></a>
<a name="3560"><span class="lineNum">    3560 </span>                :<span class="lineCov">      16301 :                 print_stopped(current_tcp, NULL, restart_sig);</span></a>
<a name="3561"><span class="lineNum">    3561 </span>        [<span class="branchCov" title="Branch 0 was taken 16301 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">      16301 :                 if (use_seize) {</span></a>
<a name="3562"><span class="lineNum">    3562 </span>                :            :                         /*</a>
<a name="3563"><span class="lineNum">    3563 </span>                :            :                          * This ends ptrace-stop, but does *not* end group-stop.</a>
<a name="3564"><span class="lineNum">    3564 </span>                :            :                          * This makes stopping signals work properly on straced</a>
<a name="3565"><span class="lineNum">    3565 </span>                :            :                          * process (that is, process really stops. It used to</a>
<a name="3566"><span class="lineNum">    3566 </span>                :            :                          * continue to run).</a>
<a name="3567"><span class="lineNum">    3567 </span>                :            :                          */</a>
<a name="3568"><span class="lineNum">    3568 </span>                :<span class="lineCov">      16301 :                         restart_op = PTRACE_LISTEN;</span></a>
<a name="3569"><span class="lineNum">    3569 </span>                :<span class="lineCov">      16301 :                         restart_sig = 0;</span></a>
<a name="3570"><span class="lineNum">    3570 </span>                :            :                 }</a>
<a name="3571"><span class="lineNum">    3571 </span>                :            :                 break;</a>
<a name="3572"><span class="lineNum">    3572 </span>                :            : </a>
<a name="3573"><span class="lineNum">    3573 </span>                :<span class="lineCov">      35579 :         case TE_EXITED:</span></a>
<a name="3574"><span class="lineNum">    3574 </span>                :<span class="lineCov">      35579 :                 print_exited(current_tcp, current_tcp->pid, status);</span></a>
<a name="3575"><span class="lineNum">    3575 </span>                :<span class="lineCov">      35579 :                 droptcb(current_tcp);</span></a>
<a name="3576"><span class="lineNum">    3576 </span>                :<span class="lineCov">      35579 :                 return true;</span></a>
<a name="3577"><span class="lineNum">    3577 </span>                :            : </a>
<a name="3578"><span class="lineNum">    3578 </span>                :<span class="lineCov">      16310 :         case TE_STOP_BEFORE_EXECVE:</span></a>
<a name="3579"><span class="lineNum">    3579 </span>                :            :                 /* The syscall succeeded, clear the flag.  */</a>
<a name="3580"><span class="lineNum">    3580 </span>                :<span class="lineCov">      16310 :                 current_tcp->flags &= ~TCB_CHECK_EXEC_SYSCALL;</span></a>
<a name="3581"><span class="lineNum">    3581 </span>                :            :                 /*</a>
<a name="3582"><span class="lineNum">    3582 </span>                :            :                  * Check that we are inside syscall now (next event after</a>
<a name="3583"><span class="lineNum">    3583 </span>                :            :                  * PTRACE_EVENT_EXEC should be for syscall exiting).  If it is</a>
<a name="3584"><span class="lineNum">    3584 </span>                :            :                  * not the case, we might have a situation when we attach to a</a>
<a name="3585"><span class="lineNum">    3585 </span>                :            :                  * process and the first thing we see is a PTRACE_EVENT_EXEC</a>
<a name="3586"><span class="lineNum">    3586 </span>                :            :                  * and all the following syscall state tracking is screwed up</a>
<a name="3587"><span class="lineNum">    3587 </span>                :            :                  * otherwise.</a>
<a name="3588"><span class="lineNum">    3588 </span>                :            :                  */</a>
<a name="3589"><span class="lineNum">    3589 </span>  [<span class="branchCov" title="Branch 0 was taken 16291 times"> + </span><span class="branchCov" title="Branch 1 was taken 19 times"> + </span><span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 16291 times"> + </span>]:<span class="lineCov">      16310 :                 if (!maybe_switch_current_tcp() && entering(current_tcp)) {</span></a>
<a name="3590"><span class="lineNum">    3590 </span>                :<span class="lineNoCov">          0 :                         int ret;</span></a>
<a name="3591"><span class="lineNum">    3591 </span>                :            : </a>
<a name="3592"><span class="lineNum">    3592 </span>                :<span class="lineNoCov">          0 :                         error_msg("Stray PTRACE_EVENT_EXEC from pid %d"</span></a>
<a name="3593"><span class="lineNum">    3593 </span>                :            :                                   ", trying to recover...",</a>
<a name="3594"><span class="lineNum">    3594 </span>                :            :                                   current_tcp->pid);</a>
<a name="3595"><span class="lineNum">    3595 </span>                :            : </a>
<a name="3596"><span class="lineNum">    3596 </span>                :<span class="lineNoCov">          0 :                         current_tcp->flags |= TCB_RECOVERING;</span></a>
<a name="3597"><span class="lineNum">    3597 </span>                :<span class="lineNoCov">          0 :                         ret = trace_syscall(current_tcp, &restart_sig);</span></a>
<a name="3598"><span class="lineNum">    3598 </span>                :<span class="lineNoCov">          0 :                         current_tcp->flags &= ~TCB_RECOVERING;</span></a>
<a name="3599"><span class="lineNum">    3599 </span>                :            : </a>
<a name="3600"><span class="lineNum">    3600 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                         if (ret < 0) {</span></a>
<a name="3601"><span class="lineNum">    3601 </span>                :            :                                 /* The reason is described in TE_SYSCALL_STOP */</a>
<a name="3602"><span class="lineNum">    3602 </span>                :            :                                 return true;</a>
<a name="3603"><span class="lineNum">    3603 </span>                :            :                         }</a>
<a name="3604"><span class="lineNum">    3604 </span>                :            :                 }</a>
<a name="3605"><span class="lineNum">    3605 </span>                :            : </a>
<a name="3606"><span class="lineNum">    3606 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 16306 times"> + </span>]:<span class="lineCov">      16310 :                 if (detach_on_execve) {</span></a>
<a name="3607"><span class="lineNum">    3607 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>]:<span class="lineCov">          4 :                         if (current_tcp->flags & TCB_SKIP_DETACH_ON_FIRST_EXEC) {</span></a>
<a name="3608"><span class="lineNum">    3608 </span>                :<span class="lineCov">          2 :                                 current_tcp->flags &= ~TCB_SKIP_DETACH_ON_FIRST_EXEC;</span></a>
<a name="3609"><span class="lineNum">    3609 </span>                :            :                         } else {</a>
<a name="3610"><span class="lineNum">    3610 </span>                :<span class="lineCov">          2 :                                 detach(current_tcp); /* do "-b execve" thingy */</span></a>
<a name="3611"><span class="lineNum">    3611 </span>                :<span class="lineCov">          2 :                                 return true;</span></a>
<a name="3612"><span class="lineNum">    3612 </span>                :            :                         }</a>
<a name="3613"><span class="lineNum">    3613 </span>                :            :                 }</a>
<a name="3614"><span class="lineNum">    3614 </span>                :            :                 break;</a>
<a name="3615"><span class="lineNum">    3615 </span>                :            : </a>
<a name="3616"><span class="lineNum">    3616 </span>                :<span class="lineCov">      45534 :         case TE_STOP_BEFORE_EXIT:</span></a>
<a name="3617"><span class="lineNum">    3617 </span>                :<span class="lineCov">      45534 :                 print_event_exit(current_tcp);</span></a>
<a name="3618"><span class="lineNum">    3618 </span>                :<span class="lineCov">      45534 :                 break;</span></a>
<a name="3619"><span class="lineNum">    3619 </span>                :            :         }</a>
<a name="3620"><span class="lineNum">    3620 </span>                :            : </a>
<a name="3621"><span class="lineNum">    3621 </span>                :            :         /* We handled quick cases, we are permitted to interrupt now. */</a>
<a name="3622"><span class="lineNum">    3622 </span>        [<span class="branchCov" title="Branch 0 was taken 156725084 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">  156725084 :         if (interrupted)</span></a>
<a name="3623"><span class="lineNum">    3623 </span>                :            :                 return false;</a>
<a name="3624"><span class="lineNum">    3624 </span>                :            : </a>
<a name="3625"><span class="lineNum">    3625 </span>                :            :         /* If the process is being delayed, do not ptrace_restart just yet */</a>
<a name="3626"><span class="lineNum">    3626 </span>        [<span class="branchCov" title="Branch 0 was taken 136 times"> + </span><span class="branchCov" title="Branch 1 was taken 156724948 times"> + </span>]:<span class="lineCov">  156725084 :         if (syscall_delayed(current_tcp)) {</span></a>
<a name="3627"><span class="lineNum">    3627 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 136 times"> + </span>]:<span class="lineCov">        136 :                 if (current_tcp->delayed_wait_data)</span></a>
<a name="3628"><span class="lineNum">    3628 </span>                :<span class="lineNoCov">          0 :                         error_func_msg("pid %d has delayed wait data set"</span></a>
<a name="3629"><span class="lineNum">    3629 </span>                :            :                                        " already", current_tcp->pid);</a>
<a name="3630"><span class="lineNum">    3630 </span>                :            : </a>
<a name="3631"><span class="lineNum">    3631 </span>                :<span class="lineCov">        136 :                 current_tcp->delayed_wait_data = copy_trace_wait_data(wd);</span></a>
<a name="3632"><span class="lineNum">    3632 </span>                :            : </a>
<a name="3633"><span class="lineNum">    3633 </span>                :<span class="lineCov">        136 :                 return true;</span></a>
<a name="3634"><span class="lineNum">    3634 </span>                :            :         }</a>
<a name="3635"><span class="lineNum">    3635 </span>                :            : </a>
<a name="3636"><span class="lineNum">    3636 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 156724948 times"> + </span>]:<span class="lineCov">  156724948 :         if (ptrace_restart(restart_op, current_tcp, restart_sig) < 0) {</span></a>
<a name="3637"><span class="lineNum">    3637 </span>                :            :                 /* Note: ptrace_restart emitted error message */</a>
<a name="3638"><span class="lineNum">    3638 </span>                :<span class="lineNoCov">          0 :                 exit_code = 1;</span></a>
<a name="3639"><span class="lineNum">    3639 </span>                :<span class="lineNoCov">          0 :                 return false;</span></a>
<a name="3640"><span class="lineNum">    3640 </span>                :            :         }</a>
<a name="3641"><span class="lineNum">    3641 </span>                :            :         return true;</a>
<a name="3642"><span class="lineNum">    3642 </span>                :            : }</a>
<a name="3643"><span class="lineNum">    3643 </span>                :            : </a>
<a name="3644"><span class="lineNum">    3644 </span>                :            : static bool</a>
<a name="3645"><span class="lineNum">    3645 </span>                :<span class="lineCov">        136 : restart_delayed_tcb(struct tcb *const tcp)</span></a>
<a name="3646"><span class="lineNum">    3646 </span>                :            : {</a>
<a name="3647"><span class="lineNum">    3647 </span>                :<span class="lineCov">        136 :         struct tcb_wait_data *wd = tcp->delayed_wait_data;</span></a>
<a name="3648"><span class="lineNum">    3648 </span>                :            : </a>
<a name="3649"><span class="lineNum">    3649 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 136 times"> + </span>]:<span class="lineCov">        136 :         if (!wd) {</span></a>
<a name="3650"><span class="lineNum">    3650 </span>                :<span class="lineNoCov">          0 :                 error_func_msg("No delayed wait data found for pid %d",</span></a>
<a name="3651"><span class="lineNum">    3651 </span>                :            :                                tcp->pid);</a>
<a name="3652"><span class="lineNum">    3652 </span>                :<span class="lineNoCov">          0 :                 wd = init_trace_wait_data(alloca(trace_wait_data_size(tcp)));</span></a>
<a name="3653"><span class="lineNum">    3653 </span>                :            :         }</a>
<a name="3654"><span class="lineNum">    3654 </span>                :            : </a>
<a name="3655"><span class="lineNum">    3655 </span>                :<span class="lineCov">        136 :         wd->te = TE_RESTART;</span></a>
<a name="3656"><span class="lineNum">    3656 </span>                :            : </a>
<a name="3657"><span class="lineNum">    3657 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 136 times"> + </span>]:<span class="lineCov">        136 :         debug_func_msg("pid %d", tcp->pid);</span></a>
<a name="3658"><span class="lineNum">    3658 </span>                :            : </a>
<a name="3659"><span class="lineNum">    3659 </span>                :<span class="lineCov">        136 :         tcp->flags &= ~TCB_DELAYED;</span></a>
<a name="3660"><span class="lineNum">    3660 </span>                :            : </a>
<a name="3661"><span class="lineNum">    3661 </span>                :<span class="lineCov">        136 :         struct tcb *const prev_tcp = current_tcp;</span></a>
<a name="3662"><span class="lineNum">    3662 </span>                :<span class="lineCov">        136 :         current_tcp = tcp;</span></a>
<a name="3663"><span class="lineNum">    3663 </span>                :<span class="lineCov">        136 :         bool ret = dispatch_event(wd);</span></a>
<a name="3664"><span class="lineNum">    3664 </span>                :<span class="lineCov">        136 :         current_tcp = prev_tcp;</span></a>
<a name="3665"><span class="lineNum">    3665 </span>                :            : </a>
<a name="3666"><span class="lineNum">    3666 </span>                :<span class="lineCov">        136 :         free_trace_wait_data(tcp->delayed_wait_data);</span></a>
<a name="3667"><span class="lineNum">    3667 </span>                :<span class="lineCov">        136 :         tcp->delayed_wait_data = NULL;</span></a>
<a name="3668"><span class="lineNum">    3668 </span>                :            : </a>
<a name="3669"><span class="lineNum">    3669 </span>                :<span class="lineCov">        136 :         return ret;</span></a>
<a name="3670"><span class="lineNum">    3670 </span>                :            : }</a>
<a name="3671"><span class="lineNum">    3671 </span>                :            : </a>
<a name="3672"><span class="lineNum">    3672 </span>                :            : static bool</a>
<a name="3673"><span class="lineNum">    3673 </span>                :<span class="lineCov">        136 : restart_delayed_tcbs(void)</span></a>
<a name="3674"><span class="lineNum">    3674 </span>                :            : {</a>
<a name="3675"><span class="lineNum">    3675 </span>                :<span class="lineCov">        136 :         struct tcb *tcp_next = NULL;</span></a>
<a name="3676"><span class="lineNum">    3676 </span>                :<span class="lineCov">        136 :         struct timespec ts_now;</span></a>
<a name="3677"><span class="lineNum">    3677 </span>                :            : </a>
<a name="3678"><span class="lineNum">    3678 </span>                :<span class="lineCov">        136 :         clock_gettime(CLOCK_MONOTONIC, &ts_now);</span></a>
<a name="3679"><span class="lineNum">    3679 </span>                :            : </a>
<a name="3680"><span class="lineNum">    3680 </span>        [<span class="branchCov" title="Branch 0 was taken 2176 times"> + </span><span class="branchCov" title="Branch 1 was taken 136 times"> + </span>]:<span class="lineCov">       2312 :         for (size_t i = 0; i < tcbtabsize; i++) {</span></a>
<a name="3681"><span class="lineNum">    3681 </span>                :<span class="lineCov">       2176 :                 struct tcb *tcp = tcbtab[i];</span></a>
<a name="3682"><span class="lineNum">    3682 </span>                :            : </a>
<a name="3683"><span class="lineNum">    3683 </span>  [<span class="branchCov" title="Branch 0 was taken 612 times"> + </span><span class="branchCov" title="Branch 1 was taken 1564 times"> + </span><span class="branchCov" title="Branch 2 was taken 484 times"> + </span><span class="branchCov" title="Branch 3 was taken 128 times"> + </span>]:<span class="lineCov">       2176 :                 if (tcp->pid && syscall_delayed(tcp)) {</span></a>
<a name="3684"><span class="lineNum">    3684 </span>        [<span class="branchCov" title="Branch 0 was taken 136 times"> + </span><span class="branchCov" title="Branch 1 was taken 348 times"> + </span>]:<span class="lineCov">        484 :                         if (ts_cmp(&ts_now, &tcp->delay_expiration_time) > 0) {</span></a>
<a name="3685"><span class="lineNum">    3685 </span>        [<span class="branchCov" title="Branch 0 was taken 136 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">        136 :                                 if (!restart_delayed_tcb(tcp))</span></a>
<a name="3686"><span class="lineNum">    3686 </span>                :            :                                         return false;</a>
<a name="3687"><span class="lineNum">    3687 </span>                :            :                         } else {</a>
<a name="3688"><span class="lineNum">    3688 </span>                :            :                                 /* Check whether this tcb is the next.  */</a>
<a name="3689"><span class="lineNum">    3689 </span>  [<span class="branchCov" title="Branch 0 was taken 224 times"> + </span><span class="branchCov" title="Branch 1 was taken 124 times"> + </span><span class="branchCov" title="Branch 2 was taken 80 times"> + </span><span class="branchCov" title="Branch 3 was taken 144 times"> + </span>]:<span class="lineCov">        572 :                                 if (!tcp_next ||</span></a>
<a name="3690"><span class="lineNum">    3690 </span>                :<span class="lineCov">        224 :                                     ts_cmp(&tcp_next->delay_expiration_time,</span></a>
<a name="3691"><span class="lineNum">    3691 </span>                :            :                                            &tcp->delay_expiration_time) > 0) {</a>
<a name="3692"><span class="lineNum">    3692 </span>                :            :                                         tcp_next = tcp;</a>
<a name="3693"><span class="lineNum">    3693 </span>                :            :                                 }</a>
<a name="3694"><span class="lineNum">    3694 </span>                :            :                         }</a>
<a name="3695"><span class="lineNum">    3695 </span>                :            :                 }</a>
<a name="3696"><span class="lineNum">    3696 </span>                :            :         }</a>
<a name="3697"><span class="lineNum">    3697 </span>                :            : </a>
<a name="3698"><span class="lineNum">    3698 </span>        [<span class="branchCov" title="Branch 0 was taken 124 times"> + </span><span class="branchCov" title="Branch 1 was taken 12 times"> + </span>]:<span class="lineCov">        136 :         if (tcp_next)</span></a>
<a name="3699"><span class="lineNum">    3699 </span>                :<span class="lineCov">        124 :                 arm_delay_timer(tcp_next);</span></a>
<a name="3700"><span class="lineNum">    3700 </span>                :            : </a>
<a name="3701"><span class="lineNum">    3701 </span>                :            :         return true;</a>
<a name="3702"><span class="lineNum">    3702 </span>                :            : }</a>
<a name="3703"><span class="lineNum">    3703 </span>                :            : </a>
<a name="3704"><span class="lineNum">    3704 </span>                :            : /*</a>
<a name="3705"><span class="lineNum">    3705 </span>                :            :  * As this signal handler does a lot of work that is not suitable</a>
<a name="3706"><span class="lineNum">    3706 </span>                :            :  * for signal handlers, extra care must be taken to ensure that</a>
<a name="3707"><span class="lineNum">    3707 </span>                :            :  * it is enabled only in those places where it's safe.</a>
<a name="3708"><span class="lineNum">    3708 </span>                :            :  */</a>
<a name="3709"><span class="lineNum">    3709 </span>                :            : static void</a>
<a name="3710"><span class="lineNum">    3710 </span>                :<span class="lineCov">        136 : timer_sighandler(int sig)</span></a>
<a name="3711"><span class="lineNum">    3711 </span>                :            : {</a>
<a name="3712"><span class="lineNum">    3712 </span>                :<span class="lineCov">        136 :         delay_timer_expired();</span></a>
<a name="3713"><span class="lineNum">    3713 </span>                :            : </a>
<a name="3714"><span class="lineNum">    3714 </span>        [<span class="branchCov" title="Branch 0 was taken 136 times"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">        136 :         if (restart_failed)</span></a>
<a name="3715"><span class="lineNum">    3715 </span>                :            :                 return;</a>
<a name="3716"><span class="lineNum">    3716 </span>                :            : </a>
<a name="3717"><span class="lineNum">    3717 </span>                :<span class="lineCov">        136 :         int saved_errno = errno;</span></a>
<a name="3718"><span class="lineNum">    3718 </span>                :            : </a>
<a name="3719"><span class="lineNum">    3719 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 136 times"> + </span>]:<span class="lineCov">        136 :         if (!restart_delayed_tcbs())</span></a>
<a name="3720"><span class="lineNum">    3720 </span>                :<span class="lineNoCov">          0 :                 restart_failed = 1;</span></a>
<a name="3721"><span class="lineNum">    3721 </span>                :            : </a>
<a name="3722"><span class="lineNum">    3722 </span>                :<span class="lineCov">        136 :         errno = saved_errno;</span></a>
<a name="3723"><span class="lineNum">    3723 </span>                :            : }</a>
<a name="3724"><span class="lineNum">    3724 </span>                :            : </a>
<a name="3725"><span class="lineNum">    3725 </span>                :            : static void ATTRIBUTE_NORETURN</a>
<a name="3726"><span class="lineNum">    3726 </span>                :<span class="lineCov">      16255 : terminate(void)</span></a>
<a name="3727"><span class="lineNum">    3727 </span>                :            : {</a>
<a name="3728"><span class="lineNum">    3728 </span>                :<span class="lineCov">      16255 :         int sig = interrupted;</span></a>
<a name="3729"><span class="lineNum">    3729 </span>                :            : </a>
<a name="3730"><span class="lineNum">    3730 </span>                :<span class="lineCov">      16255 :         cleanup(sig);</span></a>
<a name="3731"><span class="lineNum">    3731 </span>        [<span class="branchCov" title="Branch 0 was taken 34 times"> + </span><span class="branchCov" title="Branch 1 was taken 16221 times"> + </span>]:<span class="lineCov">      16255 :         if (cflag)</span></a>
<a name="3732"><span class="lineNum">    3732 </span>                :<span class="lineCov">         34 :                 call_summary(shared_log);</span></a>
<a name="3733"><span class="lineNum">    3733 </span>                :<span class="lineCov">      16255 :         fflush(NULL);</span></a>
<a name="3734"><span class="lineNum">    3734 </span>        [<span class="branchCov" title="Branch 0 was taken 13826 times"> + </span><span class="branchCov" title="Branch 1 was taken 2429 times"> + </span>]:<span class="lineCov">      16255 :         if (shared_log != stderr)</span></a>
<a name="3735"><span class="lineNum">    3735 </span>                :<span class="lineCov">      13826 :                 fclose(shared_log);</span></a>
<a name="3736"><span class="lineNum">    3736 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 16255 times"> + </span>]:<span class="lineCov">      16255 :         if (popen_pid) {</span></a>
<a name="3737"><span class="lineNum">    3737 </span>  [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span><span class="branchNoExec" title="Branch 3 was not executed"> # </span>]:<span class="lineNoCov">          0 :                 while (waitpid(popen_pid, NULL, 0) < 0 && errno == EINTR)</span></a>
<a name="3738"><span class="lineNum">    3738 </span>                :            :                         ;</a>
<a name="3739"><span class="lineNum">    3739 </span>                :            :         }</a>
<a name="3740"><span class="lineNum">    3740 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 16251 times"> + </span>]:<span class="lineCov">      16255 :         if (sig) {</span></a>
<a name="3741"><span class="lineNum">    3741 </span>                :<span class="lineCov">          4 :                 exit_code = 0x100 | sig;</span></a>
<a name="3742"><span class="lineNum">    3742 </span>                :            :         }</a>
<a name="3743"><span class="lineNum">    3743 </span>        [<span class="branchCov" title="Branch 0 was taken 12 times"> + </span><span class="branchCov" title="Branch 1 was taken 16243 times"> + </span>]:<span class="lineCov">      16255 :         if (exit_code > 0xff) {</span></a>
<a name="3744"><span class="lineNum">    3744 </span>                :            :                 /* Avoid potential core file clobbering.  */</a>
<a name="3745"><span class="lineNum">    3745 </span>                :<span class="lineCov">         12 :                 struct_rlimit rlim = {0, 0};</span></a>
<a name="3746"><span class="lineNum">    3746 </span>                :<span class="lineCov">         12 :                 set_rlimit(RLIMIT_CORE, &rlim);</span></a>
<a name="3747"><span class="lineNum">    3747 </span>                :            : </a>
<a name="3748"><span class="lineNum">    3748 </span>                :            :                 /* Child was killed by a signal, mimic that.  */</a>
<a name="3749"><span class="lineNum">    3749 </span>                :<span class="lineCov">         12 :                 exit_code &= 0xff;</span></a>
<a name="3750"><span class="lineNum">    3750 </span>                :<span class="lineCov">         12 :                 signal(exit_code, SIG_DFL);</span></a>
<a name="3751"><span class="lineNum">    3751 </span>                :<span class="lineCov">         12 :                 GCOV_DUMP;</span></a>
<a name="3752"><span class="lineNum">    3752 </span>                :<span class="lineNoCov">          0 :                 raise(exit_code);</span></a>
<a name="3753"><span class="lineNum">    3753 </span>                :            : </a>
<a name="3754"><span class="lineNum">    3754 </span>                :            :                 /* Unblock the signal.  */</a>
<a name="3755"><span class="lineNum">    3755 </span>                :<span class="lineNoCov">          0 :                 sigset_t mask;</span></a>
<a name="3756"><span class="lineNum">    3756 </span>                :<span class="lineNoCov">          0 :                 sigemptyset(&mask);</span></a>
<a name="3757"><span class="lineNum">    3757 </span>                :<span class="lineNoCov">          0 :                 sigaddset(&mask, exit_code);</span></a>
<a name="3758"><span class="lineNum">    3758 </span>                :<span class="lineNoCov">          0 :                 GCOV_DUMP;</span></a>
<a name="3759"><span class="lineNum">    3759 </span>                :<span class="lineNoCov">          0 :                 sigprocmask(SIG_UNBLOCK, &mask, NULL);</span></a>
<a name="3760"><span class="lineNum">    3760 </span>                :            : </a>
<a name="3761"><span class="lineNum">    3761 </span>                :            :                 /* Paranoia - what if this signal is not fatal?</a>
<a name="3762"><span class="lineNum">    3762 </span>                :            :                    Exit with 128 + signo then.  */</a>
<a name="3763"><span class="lineNum">    3763 </span>                :<span class="lineNoCov">          0 :                 exit_code += 128;</span></a>
<a name="3764"><span class="lineNum">    3764 </span>                :            :         }</a>
<a name="3765"><span class="lineNum">    3765 </span>                :<span class="lineCov">      16243 :         exit(exit_code);</span></a>
<a name="3766"><span class="lineNum">    3766 </span>                :            : }</a>
<a name="3767"><span class="lineNum">    3767 </span>                :            : </a>
<a name="3768"><span class="lineNum">    3768 </span>                :            : int</a>
<a name="3769"><span class="lineNum">    3769 </span>                :<span class="lineCov">      22653 : main(int argc, char *argv[])</span></a>
<a name="3770"><span class="lineNum">    3770 </span>                :            : {</a>
<a name="3771"><span class="lineNum">    3771 </span>                :<span class="lineCov">      22653 :         setlocale(LC_ALL, "");</span></a>
<a name="3772"><span class="lineNum">    3772 </span>                :<span class="lineCov">      22653 :         init(argc, argv);</span></a>
<a name="3773"><span class="lineNum">    3773 </span>                :            : </a>
<a name="3774"><span class="lineNum">    3774 </span>                :<span class="lineCov">      16255 :         exit_code = !nprocs;</span></a>
<a name="3775"><span class="lineNum">    3775 </span>                :            : </a>
<a name="3776"><span class="lineNum">    3776 </span>        [<span class="branchCov" title="Branch 0 was taken 156770855 times"> + </span><span class="branchCov" title="Branch 1 was taken 16255 times"> + </span>]:<span class="lineCov">  156787110 :         while (dispatch_event(next_event()))</span></a>
<a name="3777"><span class="lineNum">    3777 </span>                :            :                 ;</a>
<a name="3778"><span class="lineNum">    3778 </span>                :<span class="lineCov">      16255 :         terminate();</span></a>
<a name="3779"><span class="lineNum">    3779 </span>                :            : }</a>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.14</a></td></tr>
  </table>
  <br>

</body>
</html>