LCOV - code coverage report
Current view: top level - strace - fcntl.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 59 109 54.1 %
Date: 2017-07-31 03:46:08 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 74 31.1 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
       3                 :            :  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
       4                 :            :  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
       5                 :            :  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
       6                 :            :  * Copyright (c) 1999-2017 The strace developers.
       7                 :            :  * All rights reserved.
       8                 :            :  *
       9                 :            :  * Redistribution and use in source and binary forms, with or without
      10                 :            :  * modification, are permitted provided that the following conditions
      11                 :            :  * are met:
      12                 :            :  * 1. Redistributions of source code must retain the above copyright
      13                 :            :  *    notice, this list of conditions and the following disclaimer.
      14                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      15                 :            :  *    notice, this list of conditions and the following disclaimer in the
      16                 :            :  *    documentation and/or other materials provided with the distribution.
      17                 :            :  * 3. The name of the author may not be used to endorse or promote products
      18                 :            :  *    derived from this software without specific prior written permission.
      19                 :            :  *
      20                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      21                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      22                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      23                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      24                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      25                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      26                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      27                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      29                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30                 :            :  */
      31                 :            : 
      32                 :            : #include "defs.h"
      33                 :            : #include "flock.h"
      34                 :            : 
      35                 :            : #include "xlat/f_owner_types.h"
      36                 :            : #include "xlat/f_seals.h"
      37                 :            : #include "xlat/fcntlcmds.h"
      38                 :            : #include "xlat/fcntl64cmds.h"
      39                 :            : #include "xlat/fdflags.h"
      40                 :            : #include "xlat/lockfcmds.h"
      41                 :            : #include "xlat/notifyflags.h"
      42                 :            : 
      43                 :            : static void
      44                 :         22 : print_struct_flock64(const struct_kernel_flock64 *fl, const int getlk)
      45                 :            : {
      46                 :         22 :         tprints("{l_type=");
      47                 :         22 :         printxval(lockfcmds, (unsigned short) fl->l_type, "F_???");
      48                 :         22 :         tprints(", l_whence=");
      49                 :         22 :         printxval(whence_codes, (unsigned short) fl->l_whence, "SEEK_???");
      50                 :         22 :         tprintf(", l_start=%" PRId64 ", l_len=%" PRId64,
      51                 :         22 :                 (int64_t) fl->l_start, (int64_t) fl->l_len);
      52         [ +  + ]:         22 :         if (getlk)
      53                 :          4 :                 tprintf(", l_pid=%lu", (unsigned long) fl->l_pid);
      54                 :         22 :         tprints("}");
      55                 :         22 : }
      56                 :            : 
      57                 :            : static void
      58                 :          7 : printflock64(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
      59                 :            : {
      60                 :            :         struct_kernel_flock64 fl;
      61                 :            : 
      62         [ +  - ]:          7 :         if (fetch_struct_flock64(tcp, addr, &fl))
      63                 :          7 :                 print_struct_flock64(&fl, getlk);
      64                 :          7 : }
      65                 :            : 
      66                 :            : static void
      67                 :         15 : printflock(struct tcb *const tcp, const kernel_ulong_t addr, const int getlk)
      68                 :            : {
      69                 :            :         struct_kernel_flock64 fl;
      70                 :            : 
      71         [ +  - ]:         15 :         if (fetch_struct_flock(tcp, addr, &fl))
      72                 :         15 :                 print_struct_flock64(&fl, getlk);
      73                 :         15 : }
      74                 :            : 
      75                 :            : static void
      76                 :          0 : print_f_owner_ex(struct tcb *const tcp, const kernel_ulong_t addr)
      77                 :            : {
      78                 :            :         struct { int type, pid; } owner;
      79                 :            : 
      80         [ #  # ]:          0 :         if (umove_or_printaddr(tcp, addr, &owner))
      81                 :          0 :                 return;
      82                 :            : 
      83                 :          0 :         tprints("{type=");
      84                 :          0 :         printxval(f_owner_types, owner.type, "F_OWNER_???");
      85                 :          0 :         tprintf(", pid=%d}", owner.pid);
      86                 :            : }
      87                 :            : 
      88                 :            : static int
      89                 :         26 : print_fcntl(struct tcb *tcp)
      90                 :            : {
      91                 :         26 :         const unsigned int cmd = tcp->u_arg[1];
      92                 :            : 
      93   [ -  -  -  -  :         26 :         switch (cmd) {
          +  +  -  -  -  
          -  -  -  -  +  
          -  -  -  -  -  
                   +  - ]
      94                 :            :         case F_SETFD:
      95                 :          0 :                 tprints(", ");
      96                 :          0 :                 printflags(fdflags, tcp->u_arg[2], "FD_???");
      97                 :            :                 break;
      98                 :            :         case F_SETOWN:
      99                 :            :         case F_SETPIPE_SZ:
     100                 :          0 :                 tprintf(", %" PRI_kld, tcp->u_arg[2]);
     101                 :          0 :                 break;
     102                 :            :         case F_DUPFD:
     103                 :            :         case F_DUPFD_CLOEXEC:
     104                 :          0 :                 tprintf(", %" PRI_kld, tcp->u_arg[2]);
     105                 :          0 :                 return RVAL_DECODED | RVAL_FD;
     106                 :            :         case F_SETFL:
     107                 :          0 :                 tprints(", ");
     108                 :          0 :                 tprint_open_modes(tcp->u_arg[2]);
     109                 :          0 :                 break;
     110                 :            :         case F_SETLK:
     111                 :            :         case F_SETLKW:
     112                 :         12 :                 tprints(", ");
     113                 :         12 :                 printflock(tcp, tcp->u_arg[2], 0);
     114                 :         12 :                 break;
     115                 :            :         case F_OFD_SETLK:
     116                 :            :         case F_OFD_SETLKW:
     117                 :          2 :                 tprints(", ");
     118                 :          2 :                 printflock64(tcp, tcp->u_arg[2], 0);
     119                 :          2 :                 break;
     120                 :            :         case F_SETOWN_EX:
     121                 :          0 :                 tprints(", ");
     122                 :          0 :                 print_f_owner_ex(tcp, tcp->u_arg[2]);
     123                 :          0 :                 break;
     124                 :            :         case F_NOTIFY:
     125                 :          0 :                 tprints(", ");
     126                 :          0 :                 printflags64(notifyflags, tcp->u_arg[2], "DN_???");
     127                 :            :                 break;
     128                 :            :         case F_SETLEASE:
     129                 :          0 :                 tprints(", ");
     130                 :          0 :                 printxval64(lockfcmds, tcp->u_arg[2], "F_???");
     131                 :            :                 break;
     132                 :            :         case F_ADD_SEALS:
     133                 :          0 :                 tprints(", ");
     134                 :          0 :                 printflags64(f_seals, tcp->u_arg[2], "F_SEAL_???");
     135                 :            :                 break;
     136                 :            :         case F_SETSIG:
     137                 :          0 :                 tprints(", ");
     138                 :          0 :                 tprints(signame(tcp->u_arg[2]));
     139                 :          0 :                 break;
     140                 :            :         case F_GETOWN:
     141                 :            :         case F_GETPIPE_SZ:
     142                 :            :                 break;
     143                 :            :         case F_GETFD:
     144 [ #  # ][ #  # ]:          0 :                 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
                 [ #  # ]
     145                 :            :                         return 0;
     146                 :          0 :                 tcp->auxstr = sprintflags("flags ", fdflags,
     147                 :            :                                           (kernel_ulong_t) tcp->u_rval);
     148                 :          0 :                 return RVAL_HEX | RVAL_STR;
     149                 :            :         case F_GETFL:
     150 [ #  # ][ #  # ]:          0 :                 if (entering(tcp) || syserror(tcp))
     151                 :            :                         return 0;
     152                 :          0 :                 tcp->auxstr = sprint_open_modes(tcp->u_rval);
     153                 :          0 :                 return RVAL_HEX | RVAL_STR;
     154                 :            :         case F_GETLK:
     155         [ +  + ]:          6 :                 if (entering(tcp))
     156                 :            :                         return 0;
     157                 :          3 :                 tprints(", ");
     158                 :          3 :                 printflock(tcp, tcp->u_arg[2], 1);
     159                 :          3 :                 break;
     160                 :            :         case F_OFD_GETLK:
     161         [ #  # ]:          0 :                 if (entering(tcp))
     162                 :            :                         return 0;
     163                 :          0 :                 tprints(", ");
     164                 :          0 :                 printflock64(tcp, tcp->u_arg[2], 1);
     165                 :          0 :                 break;
     166                 :            :         case F_GETOWN_EX:
     167         [ #  # ]:          0 :                 if (entering(tcp))
     168                 :            :                         return 0;
     169                 :          0 :                 tprints(", ");
     170                 :          0 :                 print_f_owner_ex(tcp, tcp->u_arg[2]);
     171                 :          0 :                 break;
     172                 :            :         case F_GETLEASE:
     173 [ #  # ][ #  # ]:          0 :                 if (entering(tcp) || syserror(tcp))
     174                 :            :                         return 0;
     175                 :          0 :                 tcp->auxstr = xlookup(lockfcmds, (kernel_ulong_t) tcp->u_rval);
     176                 :          0 :                 return RVAL_HEX | RVAL_STR;
     177                 :            :         case F_GET_SEALS:
     178 [ #  # ][ #  # ]:          0 :                 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
                 [ #  # ]
     179                 :            :                         return 0;
     180                 :          0 :                 tcp->auxstr = sprintflags("seals ", f_seals,
     181                 :            :                                           (kernel_ulong_t) tcp->u_rval);
     182                 :          0 :                 return RVAL_HEX | RVAL_STR;
     183                 :            :         case F_GETSIG:
     184 [ #  # ][ #  # ]:          0 :                 if (entering(tcp) || syserror(tcp) || tcp->u_rval == 0)
                 [ #  # ]
     185                 :            :                         return 0;
     186                 :          0 :                 tcp->auxstr = signame(tcp->u_rval);
     187                 :          0 :                 return RVAL_STR;
     188                 :            :         default:
     189                 :          6 :                 tprintf(", %#" PRI_klx, tcp->u_arg[2]);
     190                 :          6 :                 break;
     191                 :            :         }
     192                 :            :         return RVAL_DECODED;
     193                 :            : }
     194                 :            : 
     195                 :         18 : SYS_FUNC(fcntl)
     196                 :            : {
     197         [ +  + ]:         18 :         if (entering(tcp)) {
     198                 :         16 :                 printfd(tcp, tcp->u_arg[0]);
     199                 :         16 :                 tprints(", ");
     200                 :         16 :                 const unsigned int cmd = tcp->u_arg[1];
     201                 :         16 :                 const char *str = xlookup(fcntlcmds, cmd);
     202         [ +  + ]:         16 :                 if (str) {
     203                 :         10 :                         tprints(str);
     204                 :            :                 } else {
     205                 :            :                         /*
     206                 :            :                          * fcntl syscall does not recognize these
     207                 :            :                          * constants, but we would like to show them
     208                 :            :                          * for better debugging experience.
     209                 :            :                          */
     210                 :            :                         printxval(fcntl64cmds, cmd, "F_???");
     211                 :            :                 }
     212                 :            :         }
     213                 :         18 :         return print_fcntl(tcp);
     214                 :            : }
     215                 :            : 
     216                 :         14 : SYS_FUNC(fcntl64)
     217                 :            : {
     218                 :         14 :         const unsigned int cmd = tcp->u_arg[1];
     219         [ +  + ]:         14 :         if (entering(tcp)) {
     220                 :         12 :                 printfd(tcp, tcp->u_arg[0]);
     221                 :         12 :                 tprints(", ");
     222                 :         12 :                 const char *str = xlookup(fcntl64cmds, cmd);
     223         [ +  + ]:         12 :                 if (str) {
     224                 :          5 :                         tprints(str);
     225                 :            :                 } else {
     226                 :            :                         printxval(fcntlcmds, cmd, "F_???");
     227                 :            :                 }
     228                 :            :         }
     229      [ +  +  + ]:         14 :         switch (cmd) {
     230                 :            :                 case F_SETLK64:
     231                 :            :                 case F_SETLKW64:
     232                 :          4 :                         tprints(", ");
     233                 :          4 :                         printflock64(tcp, tcp->u_arg[2], 0);
     234                 :          4 :                         return RVAL_DECODED;
     235                 :            :                 case F_GETLK64:
     236         [ +  + ]:          2 :                         if (exiting(tcp)) {
     237                 :          1 :                                 tprints(", ");
     238                 :          1 :                                 printflock64(tcp, tcp->u_arg[2], 1);
     239                 :            :                         }
     240                 :            :                         return 0;
     241                 :            :         }
     242                 :          8 :         return print_fcntl(tcp);
     243                 :            : }

Generated by: LCOV version 1.11