source: rtems/cpukit/libmisc/shell/main_lsof.c @ 56f22600

4.115
Last change on this file since 56f22600 was d2d09eac, checked in by Andreas Heinig <andreas.heinig@…>, on 05/15/13 at 13:14:28

shell: Fix NULL pointer access

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <stdio.h>
20
21#include <rtems/libio_.h>
22#include <rtems/shell.h>
23#include <rtems/shellconfig.h>
24
25static void lsof(void)
26{
27  rtems_chain_control *mt_chain = &rtems_filesystem_mount_table;
28  rtems_chain_node *mt_node = NULL;
29
30  for (
31    mt_node = rtems_chain_first( mt_chain );
32    !rtems_chain_is_tail( mt_chain, mt_node );
33    mt_node = rtems_chain_next( mt_node )
34  ) {
35    rtems_filesystem_mount_table_entry_t *mt_entry =
36      (rtems_filesystem_mount_table_entry_t *) mt_node;
37    rtems_chain_control *mt_entry_chain = &mt_entry->location_chain;
38    rtems_chain_node *mt_entry_node = NULL;
39
40    fprintf(
41      stdout,
42      "%c %c %s %s -> %s root 0x%08x -> 0x%08x\n",
43      mt_entry->mounted ? 'M' : 'U',
44      mt_entry->writeable ? 'W' : 'R',
45      mt_entry->type,
46      mt_entry->target,
47      mt_entry->dev == NULL ? "none" : mt_entry->dev,
48      mt_entry->mt_fs_root,
49      mt_entry->mt_fs_root->location.node_access
50    );
51
52    for (
53      mt_entry_node = rtems_chain_first( mt_entry_chain );
54      !rtems_chain_is_tail( mt_entry_chain, mt_entry_node );
55      mt_entry_node = rtems_chain_next( mt_entry_node )
56    ) {
57      const rtems_filesystem_location_info_t *loc =
58        (rtems_filesystem_location_info_t *) mt_entry_node;
59
60      fprintf(
61        stdout,
62        "\t0x%08x -> 0x%08x\n",
63        loc,
64        loc->node_access
65      );
66    }
67  }
68}
69
70static int rtems_shell_main_lsof(int argc, char **argv)
71{
72  lsof();
73
74  return 0;
75}
76
77rtems_shell_cmd_t rtems_shell_LSOF_Command = {
78  .name = "lsof",
79  .usage = "lsof",
80  .topic = "files",
81  .command = rtems_shell_main_lsof
82};
Note: See TracBrowser for help on using the repository browser.