Method, device, electronic device and readable storage medium for modifying root directory
Patent Information
- Application Number
- CN202110243035.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-04
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2041-03-04
Smart Images

Figure CN112965760B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of electronic information processing, and specifically relates to a method, apparatus, electronic device, and readable non-transitory storage medium for modifying a root directory. Background Technology
[0002] Root is the super administrator user account in a Linux system. This account has the highest privileges in the entire system and can easily delete or modify system components. Changing the root directory (full name: change root, abbreviation: chroot) means changing the location of the root directory referenced by programs when they execute. Changing the root directory can improve system security and restrict what users can do.
[0003] There are two existing methods for modifying the root directory: the first is through the chroot system call provided by the operating system kernel, which is currently the most commonly used method; the second is proot, which allows the root user to run programs using an alternate root directory, and is especially useful when chroot cannot be used due to a lack of root privileges. When modifying the root directory through proot, the parent process forks the open, getcwd, and other file path-related system calls of the child process using the ptrace function, changing the file path parameter passed to the system call from the guest virtual path to the host real path, and changing the file path result returned by the system call from the host real path to the guest virtual path.
[0004] The drawbacks of the chroot system call implementation method are: the chroot system call requires root privileges, which has limitations in certain use cases, and the chroot system call cannot build a chroot environment that mixes host and guest.
[0005] The drawback of using proot to implement chroot is that while proot can create a mixed host and guest chroot environment, and it does require root privileges to do so, it uses ptrace to modify paths. All process system calls within the chroot environment need to be handled by the parent process, resulting in extremely low performance for this method.
[0006] In summary, the existing technology lacks a technical solution that can construct a modified root directory environment that combines main files and guest files, and that provides a superior performance for this modified root directory environment.
[0007] Application content
[0008] To solve at least one of the technical problems existing in the prior art, this application is implemented as follows:
[0009] In a first aspect, embodiments of this application provide a method for modifying a root directory, comprising: starting a first process to read environment configuration information required to modify the root directory; creating a shared file through the first process and writing the environment configuration information into the shared file; replicating a child process through the first process and setting environment variables in the child process; calling a first function through the child process to execute the child process to be executed; replacing the file path parameter passed to the function call from the guest path to the main path, and replacing the file path parameter of the function call return result from the main path to the guest path.
[0010] In addition, the technical solution provided in the first aspect of this application may also have the following additional technical features:
[0011] In any of the above technical solutions, replacing the file path parameter passed to the function call from the guest path to the primary path, and replacing the file path parameter returned by the function call from the primary path to the guest path, specifically includes: loading a dynamic library through the linker, causing the dynamic library to call a second function to obtain environment configuration information through environment variables, and saving functions related to the file path. These functions related to the file path include: a third function whose input parameter includes the file path and a fourth function whose return result includes the file path; when the child process needs to call the third function, it calls the fifth function in the dynamic library corresponding to the third function to replace the file path parameter passed to the function call from the guest path to the primary path; when the child process needs to call the fourth function, it calls the sixth function in the dynamic library corresponding to the fourth function to replace the file path parameter returned by the function call from the primary path to the guest path.
[0012] In any of the above technical solutions, the environment configuration information includes first environment configuration information and second environment configuration information. The process involves replicating a child process through the first process and setting environment variables in the child process. Specifically, this includes: replicating a child process through the first process; setting a first environment variable in the child process so that the linker can load the dynamic library in advance and replace functions related to the file path; and setting a second environment variable in the child process to pass and save the file path of the environment configuration information.
[0013] In any of the above technical solutions, the second function includes an init function configured with construction attributes. The linker loads the dynamic library, causing the dynamic library to call the second function to obtain environment configuration information through environment variables and save functions related to the file path. Specifically, the linker loads the dynamic library by reading the first environment variable, causes the dynamic library to call the init function to obtain environment configuration information through the second environment variable, and saves functions related to the file path through the dlsym function.
[0014] In any of the above technical solutions, the steps of replacing the file path parameter passed to the function call from the guest path to the main path and replacing the file path parameter of the function call return result from the main path to the guest path are performed at least twice.
[0015] In any of the above technical solutions, when performing the steps of replacing the file path parameter passed to the function call from the guest path to the main path, and replacing the file path parameter of the function call return result from the main path to the guest path, the method further includes: detecting the file path and restricting the file path to the path specified by the modified root directory.
[0016] In any of the above technical solutions, creating a shared file through a first process and writing environment configuration information into the shared file specifically includes: creating a shared file through a first process and using the mmap function to write environment configuration information into the shared file.
[0017] Secondly, embodiments of this application provide an apparatus for modifying a root directory, comprising: a reading module, configured to start a first process to read environment configuration information required to modify the root directory; a creation module, configured to create a shared file through the first process and write the environment configuration information into the shared file; a replication module, configured to replicate a child process through the first process and set environment variables in the child process; an execution module, configured to call a first function through the child process to execute the child process to be executed; and a replacement module, configured to replace the file path parameter passed to the function call from the guest path to the main path, and replace the file path parameter of the function call return result from the main path to the guest path.
[0018] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method as described in the first aspect.
[0019] Fourthly, embodiments of this application provide a readable non-transitory storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method as described in the first aspect.
[0020] The method, apparatus, electronic device, and readable non-transitory storage medium for modifying the root directory provided in this application enable the construction of a root directory modification environment that combines main files and guest files, and the performance of this root directory modification environment is superior. Attached Figure Description
[0021] Figure 1 This is one of the flowcharts of the method for modifying the root directory according to an embodiment of this application;
[0022] Figure 2 This is the second flowchart of the method for modifying the root directory according to an embodiment of this application;
[0023] Figure 3 This is the third step in the flowchart of the method for modifying the root directory according to an embodiment of this application;
[0024] Figure 4 This is a schematic block diagram of the electronic device according to an embodiment of this application.
[0025] Figure label:
[0026] Device for modifying the root directory: 100, reading module: 110, creation module: 120, copying module: 130, execution module: 140, replacement module: 150, loop module: 160, detection module: 170, electronic device: 200, processor: 210, memory: 220. Detailed Implementation
[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0028] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0029] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. The following, in conjunction with the accompanying drawings, provides a detailed description of the method for modifying the root directory, the apparatus for modifying the root directory, the electronic device, and the readable non-transitory storage medium provided by the embodiments of this application through specific embodiments and application scenarios.
[0030] Figure 1 This is one of the flowcharts illustrating the steps of a method for modifying the root directory according to an embodiment of this application. For example... Figure 1 As shown in the embodiment of this application, a method for modifying the root directory is provided, including:
[0031] Step S102: Start the first process to read the environment configuration information required to modify the root directory;
[0032] Step S104: Create a shared file through the first process and write the environment configuration information into the shared file;
[0033] Step S106: The child process is replicated by the first process, and environment variables are set in the child process;
[0034] Step S108: The first function is called through the child process to execute the child process to be executed;
[0035] Step S110: Replace the file path parameter passed to the function call with the main path, and replace the file path parameter returned by the function call with the guest path.
[0036] This embodiment constructs a binary executable program for the chroot environment using the sroot command. The first process in step S102 is the sroot process. By starting the sroot process, the environment configuration information of the root directory (i.e., chroot) is read and modified. This environment configuration information specifically includes the chroot root directory, the mapping relationship between the host file and the guest file, etc.
[0037] Then, step S104 creates a shared file through the first process and writes the environment configuration information using the mmap function. In other words, in some embodiments of this application, creating a shared file through the first process and writing the environment configuration information into the shared file specifically includes: creating a shared file through the first process and writing the environment configuration information into the shared file using the mmap function.
[0038] In step S106, the first process forks the child process and sets environment variables in the child process. Figure 2 This is the second flowchart of the method for modifying the root directory according to an embodiment of this application. Figure 2 As shown, in some embodiments of this application, the environment configuration information in step S106 includes first environment configuration information and second environment configuration information. Step S106, which involves replicating a child process through a first process and setting environment variables in the child process, specifically includes:
[0039] Step S1062: The child process is replicated by the first process;
[0040] Step S1064: Set the first environment variable in the child process so that the linker can load the dynamic library in advance and replace the functions related to the file path.
[0041] Step S1066: Set a second environment variable in the child process to pass and save the file path of the environment configuration information.
[0042] Specifically, the first environment variable is LD_LIBRARY_PATH / LD_PRELOAD, and the second is SROOT_CONFIG_FILE. LD_LIBRARY_PATH / LD_PRELOAD are Linux system environment variables. The LD_LIBRARY_PATH environment variable is mainly used to specify paths other than the default paths when searching for shared libraries (dynamic link libraries). The LD_PRELOAD environment variable can affect the runtime linking of a program and allows defining dynamic link libraries that are loaded preferentially before the program runs. This function is mainly used to selectively load the same functions from different dynamic link libraries. Through this environment variable, other dynamic link libraries can be loaded between the main program and its dynamic link libraries, even overriding normal function libraries. In this embodiment, the LD_LIBRARY_PATH / LD_PRELOAD environment variables are configured to configure the linker to preload the libsroot-libc.so dynamic library, replacing functions related to file paths such as libc open or getcwd. In this embodiment, the SROOT_CONFIG_FILE (non-existent) environment variable is configured to pass the file path that stores the chroot environment configuration information.
[0043] In step S108, the first function is the exec function. The child process calls the exec function to execute the child process program that is actually to be executed, such as bash or other binary programs that can be executed separately.
[0044] By step S110, the file path parameter passed to the function call can be replaced from the guest path to the main path, and the file path parameter returned by the function call can be replaced from the main path to the guest path. Figure 3 This is the third step in the flowchart of the method for modifying the root directory according to an embodiment of this application. Figure 3 As shown, in some embodiments of this application, step S110 replaces the file path parameter passed to the function call from the guest path to the primary path, and replaces the file path parameter of the function call return result from the primary path to the guest path, specifically including:
[0045] Step S1102: Load the dynamic library through the linker, so that the dynamic library calls the second function to obtain environment configuration information through environment variables and save the functions related to the file path. The functions related to the file path include: a third function whose input parameter contains the file path and a fourth function whose return result contains the file path.
[0046] Step S1104: When the child process needs to call the third function, it calls the fifth function in the dynamic library corresponding to the third function to replace the file path parameter passed to the function call with the main path instead of the guest path.
[0047] In step S1106, when the child process needs to call the fourth function, it calls the sixth function in the dynamic library corresponding to the fourth function to replace the file path parameter of the function call return result with the guest path.
[0048] Specifically, step S110 implements the above path replacement in the following way.
[0049] In step S1102, the dynamic library is the libsroot-libc.so dynamic library. The second function includes the init function configured with construction attributes. The third function includes functions such as open / fopen that take a file path as an input parameter. The fourth function includes functions such as getcwd that return a file path as a return result.
[0050] The linker loads the dynamic library, causing it to call a second function to obtain environment configuration information through environment variables and save functions related to file paths. Specifically, the linker loads the dynamic library by reading the first environment variable, causing the dynamic library to call the `init` function to obtain environment configuration information through the second environment variable, and saves functions related to file paths through the `dlsym` function. In other words, after the child process executes the new executable program through the `exec` function, it is handed over to the linker for execution. The linker loads the `libsroot-libc.so` dynamic library by reading the `LD_LIBRARY_PATH` / `LD_PRELOAD` environment variables. When the `libsroot-libc.so` dynamic library is loaded by the linker, the `init` function, configured with the constructor attribute, is executed. The `init` function obtains the chroot environment configuration by reading the file using the value of the environment variable `SROOT_CONFIG_FILE`, and also saves the symbol addresses of functions such as `open` / `getcwd` in `libc` in a table using the `dlsym` function.
[0051] In step S1104, when the child process needs to call the third function, it calls the fifth function corresponding to the third function in the dynamic library. The specific method for replacing the file path parameter passed to the function call from the guest path to the host path is as follows: During subsequent execution, when the child process calls functions such as `open` / `fopen` that take a file path as an argument, it will call the corresponding `open` / `fopen` functions in the `libsroot-libc.so` dynamic library. It first replaces the passed file path parameter from the guest path to the host path, and then calls the corresponding `open` / `fopen` functions using the previously saved function address from `libc.so`.
[0052] In step S1106, when the child process needs to call the fourth function, it calls the sixth function corresponding to the fourth function in the dynamic library. The specific method for replacing the file path parameter in the function call return result from the host path to the guest path is as follows: When functions such as getcwd that return results containing file paths are called, the corresponding getcwd functions in the libsroot-libc.so dynamic library are also called. First, it calls the corresponding getcwd function using the previously saved function address of libc.so, and then modifies the file path parameter in the return result from the host path to the guest path.
[0053] In some embodiments of this application, the steps of replacing the file path parameter passed to the function call from the guest path to the host path and replacing the file path parameter returned by the function call from the host path to the guest path are performed at least twice. In other words, in this embodiment, the subsequent bash process replication steps are repeated, i.e., steps S1102 to S1106 are executed repeatedly. Through the above steps, a chroot environment with a mix of host and guest can be achieved.
[0054] In some embodiments of this application, when performing the steps of replacing the file path parameter passed to the function call from the guest path to the home path, and replacing the file path parameter of the function call return result from the home path to the guest path, the method further includes: detecting the file path and restricting the file path to the path specified by the modified root directory. The above steps can strictly limit the path to the path specified by chroot, preventing breaches of the chroot environment.
[0055] It should also be noted that the method for modifying the root directory provided in this application's embodiments performs path conversion on related parameters and results by replacing functions such as open and getcwd in libc. Furthermore, in this application's embodiments, the chroot environment configuration is shared across processes. Through mmap shared memory, complex chroot environment configurations can be achieved, supporting the construction of complex host and guest hybrid environments.
[0056] In summary, the method for modifying the root directory provided in this application achieves the mapping from the guest path to the host path by replacing and hacking the `open` and `getcwd` functions in libc. The parent process in the host system passes the chroot environment configuration (e.g., file mapping table) to all processes in the chroot guest environment through inter-process communication (e.g., using environment variables or shared memory). By replacing and hacking functions in libc, this application can achieve file mapping between the guest and host environments, so root privileges are not required during its construction. Furthermore, since the replacements all occur in the current process and there are no cross-process calls, the performance of this application's method of building a chroot environment using a mixture of host and guest files is essentially unaffected compared to environments built using chroot system calls.
[0057] Figure 4 This is a schematic block diagram illustrating the composition of an electronic device according to an embodiment of this application. Figure 4 As shown in the illustration, this application provides an apparatus 100 for modifying the root directory, including: a reading module 110, a creation module 120, a replication module 130, an execution module 140, and a replacement module 150. The reading module 110 is used to start a first process to read the environment configuration information required to modify the root directory. The creation module 120 is used to create a shared file through the first process and write the environment configuration information into the shared file. The replication module 130 is used to replicate a child process through the first process and set environment variables in the child process. The execution module 140 is used to call a first function through the child process to execute the child process to be executed. The replacement module 150 is used to replace the file path parameter passed to the function call from the guest path to the main path, and replace the file path parameter of the function call return result from the main path to the guest path.
[0058] In some embodiments of this application, the replacement module 150 is specifically used to: load a dynamic library through the linker, causing the dynamic library to call a second function to obtain environment configuration information through environment variables, and save functions related to file paths, wherein the functions related to file paths include: a third function whose input parameters include file paths and a fourth function whose return result includes file paths; when the child process needs to call the third function, it calls a fifth function in the dynamic library corresponding to the third function to replace the file path parameter passed to the function call with the main path; when the child process needs to call the fourth function, it calls a sixth function in the dynamic library corresponding to the fourth function to replace the file path parameter returned by the function call with the guest path.
[0059] In some embodiments of this application, the environment configuration information includes first environment configuration information and second environment configuration information. The replication module 130 is specifically used to: replicate the child process through the first process; set the first environment variable in the child process so that the linker can load the dynamic library in advance and replace the functions related to the file path; and set the second environment variable in the child process to pass and save the file path of the environment configuration information.
[0060] In some embodiments of this application, the second function includes an init function configured with construction attributes. The linker loads the dynamic library, causes the dynamic library to call the second function, obtains environment configuration information through environment variables, and saves functions related to the file path. Specifically, the linker loads the dynamic library by reading the first environment variable, causes the dynamic library to call the init function, obtains environment configuration information through the second environment variable, and saves functions related to the file path through the dlsym function.
[0061] In some embodiments of this application, the apparatus 100 for modifying the root directory further includes a loop module 160, which is used to perform the steps of replacing the file path parameter passed to the function call from the guest path to the main path and replacing the file path parameter returned by the function call from the main path to the guest path at least twice.
[0062] In some embodiments of this application, the device 100 for modifying the root directory further includes a detection module 170, which is used to detect file paths and restrict the file paths to the paths specified by the modified root directory.
[0063] In some embodiments of this application, the creation module 120 is specifically used to: create a shared file through a first process, and use the mmap function to write environment configuration information into the shared file.
[0064] It should be noted that the method for modifying the root directory provided in this application embodiment can be executed by an apparatus for modifying the root directory, or by a control module within that apparatus for executing the method for loading the method for modifying the root directory. This application embodiment uses the execution of the method for loading the method for modifying the root directory by an apparatus for modifying the root directory as an example to illustrate the method for modifying the root directory provided in this application embodiment.
[0065] The device for modifying the root directory in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.
[0066] The device for modifying the root directory in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0067] The apparatus for modifying the root directory provided in this application embodiment can implement the various processes implemented by the apparatus for modifying the root directory in the method embodiment of this application embodiment. To avoid repetition, it will not be described again here.
[0068] Figure 4 This is a schematic block diagram illustrating the composition of an electronic device according to an embodiment of this application. Figure 4 As shown, this application provides an electronic device 200, including a processor 210, a memory 220, and a program or instructions stored in the memory 220 and executable on the processor 210. When executed by the processor, the program or instructions implement the steps of the method for modifying the root directory as described in any embodiment of this application. It should be noted that the electronic device in this application includes the aforementioned mobile electronic device and non-mobile electronic device.
[0069] Those skilled in the art will understand that the electronic device 200 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 210 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0070] The processor is the processor in the electronic device described in the above embodiments. The readable non-transitory storage medium includes computer-readable non-transitory storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0071] This application provides a readable non-transitory storage medium on which a program or instructions are stored. When the program or instructions are executed by a processor, they implement the steps of a method for modifying a root directory as described in any embodiment of this application.
[0072] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0073] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods of the various embodiments of this application.
[0074] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A method for modifying the root directory, characterized in that, include: The first process is started to read the environment configuration information required to modify the root directory; wherein, the environment configuration information includes the mapping relationship between the main file and the guest file; A shared file is created through the first process, and the environment configuration information is written into the shared file; The first process replicates the child process and sets environment variables in the child process; the environment variables are used to pass the file path of the shared file that stores the environment configuration information. The child process calls a first function to execute the child process to be executed; the first function is the exec function. During the execution of the child process to be executed in the child process, the environment configuration information in the shared file is read according to the environment variables; Based on the environment configuration information, the file path parameter passed to the function call is replaced with the primary path from the guest path, and the file path parameter returned by the function call is replaced with the guest path from the primary path.
2. The method for modifying the root directory according to claim 1, characterized in that, The step of replacing the file path parameter passed to the function call from the guest path to the primary path, and replacing the file path parameter of the function call return result from the primary path to the guest path, specifically includes: The linker loads the dynamic library, causing the dynamic library to call the second function to obtain the environment configuration information through the environment variables and save the functions related to the file path. The second function is an init function configured with construction attributes. The functions related to the file path include: a third function whose input parameters include the file path and a fourth function whose return result includes the file path. When the subprocess needs to call the third function, it calls the fifth function in the dynamic library corresponding to the third function to replace the file path parameter passed to the function call with the main path instead of the guest path; the fifth function is a function in the dynamic library used to replace the third function. When the subprocess needs to call the fourth function, it calls the sixth function in the dynamic library corresponding to the fourth function to replace the file path parameter of the function call return result with the guest path; the sixth function is a function in the dynamic library used to replace the fourth function.
3. The method for modifying the root directory according to claim 2, characterized in that, The environment configuration information includes first environment configuration information and second environment configuration information. The step of replicating a child process through a first process and setting environment variables in the child process specifically includes: The child process is replicated through the first process; The first environment variable is set in the child process so that the linker can load the dynamic library in advance and replace the functions related to the file path; The subprocess sets the second environment variable to pass and store the shared file path of the environment configuration information.
4. The method for modifying the root directory according to claim 3, characterized in that, The second function includes an `init` function configured with construction attributes. The linker loads the dynamic library, causing the dynamic library to call the second function to obtain the environment configuration information through the environment variables and save functions related to the file path. Specifically, this includes: The linker loads the dynamic library by reading the first environment variable, causes the dynamic library to call the init function to obtain the environment configuration information through the second environment variable, and saves the functions related to the file path through the dlsym function.
5. The method for modifying the root directory according to any one of claims 1 to 4, characterized in that, The steps of replacing the file path parameter passed to the function call from the guest path to the home path and replacing the file path parameter returned by the function call from the home path to the guest path are performed at least twice.
6. The method for modifying the root directory according to any one of claims 1 to 4, characterized in that, When performing the steps of replacing the file path parameter passed to the function call from the guest path to the primary path, and replacing the file path parameter of the function call return result from the primary path to the guest path, the method further includes: The file path is detected and restricted to the path specified in the modified root directory.
7. The method for modifying the root directory according to any one of claims 1 to 4, characterized in that, The step of creating a shared file through a first process and writing the environment configuration information into the shared file specifically includes: The first process creates a shared file and uses the mmap function to write the environment configuration information into the file.
8. An apparatus for modifying the root directory, characterized in that, include: A reading module is used to start a first process to read the environment configuration information required to modify the root directory; wherein, the environment configuration information includes the mapping relationship between the main file and the guest file; A creation module is provided, which is used to create a shared file through the first process and write the environment configuration information into the shared file; A replication module is used to replicate a child process through the first process and set environment variables in the child process; the environment variables are used to pass the file path of the shared file that stores the environment configuration information. An execution module is configured to call a first function through the subprocess to execute a subprocess to be executed within the subprocess; the first function is the exec function; during the execution of the subprocess to be executed within the subprocess, the environment configuration information in the shared file is read according to the environment variables; The replacement module is used to replace the file path parameter passed to the function call from the guest path to the main path based on the environment configuration information, and to replace the file path parameter returned by the function call from the main path to the guest path.
9. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein when the program or instructions are executed by the processor, they implement the steps of the method for modifying the root directory as described in any one of claims 1 to 7.
10. A readable non-transitory storage medium, characterized in that, The storage medium stores a program or instructions that, when executed by a processor, implement the steps of the method for modifying the root directory as described in any one of claims 1 to 7.
Citation Information
Patent Citations
File storage path obtaining method and device
CN109977075A
Construction method of multi-container root file system
CN111367854A