source: rtems/cpukit/libcsupport/src/chroot.c @ 7666afc

4.115
Last change on this file since 7666afc was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  chroot() -  Change Root Directory
3 *  Author: fernando.ruiz@ctv.es
4 *
5 *  COPYRIGHT (c) 1989-2008.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  Modifications to support reference counting in the file system are
9 *  Copyright (c) 2012 embedded brains GmbH.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17  #include "config.h"
18#endif
19
20#include <unistd.h>
21
22#include <rtems/libio_.h>
23
24int chroot( const char *path )
25{
26  int rv = 0;
27  rtems_status_code sc = RTEMS_SUCCESSFUL;
28  rtems_filesystem_eval_path_context_t ctx;
29  int eval_flags = RTEMS_FS_PERMS_EXEC
30    | RTEMS_FS_FOLLOW_LINK;
31  rtems_filesystem_location_info_t loc;
32  rtems_filesystem_global_location_t *new_current_loc;
33
34  /*
35   * We use the global environment for path evaluation.  This makes it possible
36   * to escape from a chroot environment referencing an unmounted file system.
37   */
38  rtems_filesystem_eval_path_start_with_root_and_current(
39    &ctx,
40    path,
41    eval_flags,
42    &rtems_global_user_env.root_directory,
43    &rtems_global_user_env.current_directory
44  );
45
46  rtems_filesystem_eval_path_extract_currentloc( &ctx, &loc );
47  new_current_loc = rtems_filesystem_location_transform_to_global( &loc );
48  if ( !rtems_filesystem_global_location_is_null( new_current_loc ) ) {
49    rtems_filesystem_global_location_t *new_root_loc =
50      rtems_filesystem_global_location_obtain( &new_current_loc );
51    rtems_filesystem_node_types_t type =
52      (*new_root_loc->location.ops->node_type_h)( &new_root_loc->location );
53
54    if ( type == RTEMS_FILESYSTEM_DIRECTORY ) {
55      sc = rtems_libio_set_private_env();
56      if (sc == RTEMS_SUCCESSFUL) {
57        rtems_filesystem_global_location_assign(
58          &rtems_filesystem_root,
59          new_root_loc
60        );
61        rtems_filesystem_global_location_assign(
62          &rtems_filesystem_current,
63          new_current_loc
64        );
65      } else {
66        if (sc != RTEMS_UNSATISFIED) {
67          errno = ENOMEM;
68        }
69        rv = -1;
70      }
71    } else {
72      rtems_filesystem_location_error( &new_root_loc->location, ENOTDIR );
73      rv = -1;
74    }
75
76    if ( rv != 0 ) {
77      rtems_filesystem_global_location_release( new_root_loc );
78    }
79  } else {
80    rv = -1;
81  }
82
83  rtems_filesystem_eval_path_cleanup( &ctx );
84
85  if ( rv != 0 ) {
86    rtems_filesystem_global_location_release( new_current_loc );
87  }
88
89  return rv;
90}
Note: See TracBrowser for help on using the repository browser.