Executable distribution methods, electronic devices, storage media, and program products
By using renaming and symbolic linking techniques, combined with architecture type determination and configuration file matching, the permission and compatibility issues of program execution under heterogeneous architectures are resolved, enabling transparent, automated scheduling and execution of cross-architecture programs.
Patent Information
- Application Number
- CN202611443574.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-17
- Publication Date
- 2026-11-17
AI Technical Summary
When running programs on a heterogeneous architecture, existing technologies suffer from issues such as high permission requirements, lack of fine-grained control, inability to flexibly inject environment variables, and susceptibility to compatibility conflicts.
By renaming the target executable file to a backup file with a predetermined suffix and creating a symbolic link pointing to the scheduler in the original path, the scheduler resolves the call path, reads the file header to determine the architecture type, matches the translator path and environment variable configuration, and constructs the execution command line and environment variable array, thus achieving transparent and automated scheduling and execution across architectures.
It achieves seamless cross-architecture program call compatibility, ensures accurate identification and execution of target programs, solves dynamic library dependency issues, avoids crashes caused by blind calls, and enables fine-grained routing and differentiated environment injection.
Smart Images

Figure CN123114558A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an executable program distribution method, electronic device, storage medium, and program product. Background Technology
[0002] In the modern operating system ecosystem, there are numerous scenarios that require running ELF executables from heterogeneous architectures. For example, when running i386 (32-bit) applications in an x86_64 architecture environment, it is necessary to correctly configure the search path for 32-bit dynamic libraries; when running x86 / x86_64 applications on non-x86 architectures (such as ARM64, LoongArch), it is necessary to use translators (such as Box86, Box64, QEMU-user) for instruction translation; and when running Windows applications using the Wine compatibility layer, the Wine process and its child processes also face the problems of dynamic library path configuration and cross-architecture translation.
[0003] The Linux kernel provides an executable file format registration mechanism (binfmt_misc) to support the automatic identification and execution of heterogeneous binary formats. However, the Linux kernel's binfmt_misc mechanism has drawbacks, including high permission requirements, lack of fine-grained control, inflexible injection of environment variables, and susceptibility to compatibility conflicts. Summary of the Invention
[0004] This application provides an executable program distribution method, electronic device, storage medium, and program product to solve the problems of high permission requirements, lack of fine-grained control, inability to flexibly inject environment variables, and easy occurrence of compatibility conflicts in programs running under heterogeneous architectures.
[0005] In a first aspect, this application provides an executable program distribution method, comprising: renaming a target executable program file to a backup file with a predetermined suffix, and creating a symbolic link pointing to a scheduler in the original path of the target executable program file; in response to the symbolic link being invoked, the scheduler resolves its own invocation path, determines the name of the invoked program based on the invocation path, and locates the backup file in the directory where the symbolic link is located, wherein the filename of the backup file includes the program name and a predetermined suffix; reading the file header of the backup file, determining the target architecture type of the backup file based on the architecture type field in the file header; matching the translator path corresponding to the target architecture type from the configuration file, and matching the environment variable configuration corresponding to the target architecture type and / or the backup file from the configuration file, based on the target architecture type; constructing an execution command line and an execution environment variable array based on the translator path and the environment variable configuration, and executing the backup file through a call interface.
[0006] The technical solution provided in this application brings at least the following beneficial effects: By renaming the original file and creating symbolic links, the hijacking and seamless replacement of the call path are achieved, ensuring the compatibility of the original program's call interface; the scheduler parses its own path and locates the backup file, ensuring that the real target program can be accurately obtained during cross-architecture execution; by reading the architecture field in the file header to determine the target architecture, the automatic identification of heterogeneous binary formats is achieved, avoiding crashes caused by blind calls; by matching the translator and environment variable configuration according to the architecture type, fine-grained routing and differentiated environment injection for programs of different architectures are achieved, solving the dynamic library dependency problem during cross-architecture runtime; finally, by constructing command lines and environment variable arrays and calling the execution interface, transparent and automated scheduling and execution of cross-architecture programs are achieved.
[0007] In one possible implementation, based on the target architecture type, the translator path corresponding to the target architecture type is matched from the configuration file. This includes: when a specified architecture translator configuration item corresponding to the target architecture type exists in the configuration file, the translator path in the specified architecture translator configuration item is used as the matching result; when a specified architecture translator configuration item corresponding to the target architecture type does not exist in the configuration file, the translator path in the general translator configuration item is used as the matching result.
[0008] In one possible implementation, matching the environment variable configuration corresponding to the target architecture type and / or the backup file from the configuration file includes: loading the main configuration file located in the first predetermined path, and sequentially loading each independent configuration file located in the configuration directory in the second predetermined path according to the file name order; when loading each independent configuration file, if the configuration item in the current independent configuration file has the same name as the loaded configuration item, then the configuration item in the current independent configuration file overwrites the loaded configuration item.
[0009] In one possible implementation, the individual configuration files located in the configuration directory of the second predetermined path are loaded sequentially according to their filenames. This includes: obtaining program filter items in the current individual configuration file, where each program filter item contains at least one target program identifier; if the absolute path of the backup file matches any target program identifier, or the filename of the backup file matches any target program identifier, then all configuration items in the current individual configuration file are loaded; wherein, the target program identifier containing a forward slash is compared with the absolute path of the backup file, and the target program identifier without a forward slash is compared with the filename of the backup file; otherwise, all configuration items in the current individual configuration file are skipped.
[0010] In one possible implementation, constructing an execution environment variable array includes: using all environment variables in the original environment variable array as an initial set; obtaining an architecture-level environment variable set corresponding to the target architecture type, and obtaining a program-specific environment variable set corresponding to the backup file; removing environment variables with the same name as any environment variable in the architecture-level environment variable set and the program-specific environment variable set from the initial set; and sequentially merging the global environment variable set, the architecture-level environment variable set, and the program-specific environment variable set into the initial set, with the variables merged later overwriting the variables with the same name merged earlier.
[0011] In one possible implementation, obtaining the set of program-specific environment variables corresponding to the backup file includes: obtaining the absolute path string of the backup file; comparing the absolute path string as a key with the key of each program-specific environment variable configuration item in the configuration file; if the comparison result is the same as any program-specific environment variable configuration item, then all environment variables in that configuration item are taken as the set of program-specific environment variables.
[0012] In one possible implementation, the target executable file is renamed to a backup file with a predetermined suffix, and a symbolic link pointing to the scheduler is created in the original path of the target executable file. This includes: moving the target executable file to a backup file; creating a temporary symbolic link pointing to the scheduler in the directory where the original path is located, the name of the temporary symbolic link being different from the filename in the original path; and renaming the temporary symbolic link to the filename in the original path.
[0013] Secondly, embodiments of this application provide an executable program distribution apparatus, comprising: The processing module is used to rename the target executable file to a backup file with a predetermined suffix, and to create a symbolic link pointing to the scheduler in the original path of the target executable file. The calling module is used to respond to the symbolic link being called. The scheduler resolves its own call path, determines the name of the program being called based on the call path, and locates the backup file in the directory where the symbolic link is located. The backup file's filename includes the program name and a predefined suffix. The determination module is used to read the file header of the backup file and determine the target architecture type of the backup file based on the architecture type field in the file header. The calling module is also used to match the translator path corresponding to the target architecture type from the configuration file, and to match the environment variable configuration corresponding to the target architecture type and / or the backup file from the configuration file. The processing module is also used to construct and execute command lines and execution environment variable arrays based on the translator path and environment variable configuration, and to execute backup files by calling the interface.
[0014] Thirdly, this application provides an electronic device, including: a processor and a memory, the processor being coupled to the memory; the memory being used to store computer instructions, which are loaded and executed by the processor to enable the computer device to implement the method described in the first aspect.
[0015] Fourthly, this application provides a computer-readable storage medium comprising: computer software instructions; which, when executed in an electronic device, cause the electronic device to implement the method described in the first aspect.
[0016] Fifthly, this application provides a computer program product comprising a computer program; when the computer program is run in an electronic device, it causes the electronic device to implement the method described in the first aspect.
[0017] The beneficial effects of the second to fifth aspects mentioned above are described in the corresponding description of the first aspect and will not be repeated here. Attached Figure Description
[0018] Figure 1 A flowchart illustrating an executable program distribution method provided in an embodiment of this application; Figure 2 A schematic diagram of the composition of an executable program distribution device provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0019] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0020] The terms "first" and "second," etc., used in the specification and drawings of this application are used to distinguish different objects or to distinguish different treatments of the same object, rather than to describe a specific order of objects.
[0021] Furthermore, the terms "comprising" and "having," and any variations thereof, used in the description of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.
[0022] It should be noted that in the embodiments of this application, the words "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0023] To facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish the same or similar items with essentially the same function and effect. Those skilled in the art can understand that the terms "first" and "second" are not intended to limit the quantity or execution order.
[0024] In the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0025] Many solutions for running executable programs on heterogeneous architectures in related technologies suffer from the following problems: (1) The binfmt_misc scheme requires root privileges, affects the whole system, cannot achieve fine control at the program level, and may conflict with existing configurations.
[0026] (2) The manual configuration scheme of LD_PRELOAD and LD_LIBRARY_PATH requires setting environment variables before each execution, which is cumbersome and easy to miss, and is not suitable for batch deployment.
[0027] (3) Directly modifying the target program binary poses security risks and cannot adapt to automatic program updates.
[0028] (4) It cannot simultaneously address the four core requirements of "cross-architecture translator selection", "dynamic library path configuration", "program-level fine-grained control" and "not affecting the global system configuration".
[0029] Based on this, this application provides an executable program distribution method to solve the problems of high permission requirements, lack of fine-grained control, inability to flexibly inject environment variables, and easy occurrence of compatibility conflicts in programs running under heterogeneous architectures.
[0030] The executable program distribution method provided in this application can be implemented using an electronic device. This electronic device can be a server, such as a server cluster consisting of multiple servers, a single server, a computer, or a processor or processing chip within a server or computer. For example, the electronic device can also be a terminal, such as a mobile phone, tablet computer, wearable device, in-vehicle device, laptop computer, or ultra-mobile personal computer. Mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), etc. It should be noted that the embodiments of this application do not limit the specific form of the electronic device.
[0031] The embodiments provided in this application will now be described in detail with reference to the accompanying drawings.
[0032] Figure 1 This is a flowchart illustrating an executable program distribution method provided in an embodiment of this application. Figure 1 As shown, the executable program distribution method provided in this application can be implemented by the aforementioned electronic device, specifically including S101~S105.
[0033] S101. Rename the target executable file to a backup file with a predetermined suffix, and create a symbolic link pointing to the scheduler in the original path of the target executable file.
[0034] By renaming the executable file, when a user or system attempts to run the original program, the dispatcher is actually loaded and executed by the operating system. This achieves transparent interception of program execution without modifying the system-level binfmt_misc configuration and avoids the global environment pollution that may result from using LD_PRELOAD.
[0035] The target executable file refers to the original ELF program that needs to be transparently distributed, such as a 32-bit i386 application named myapp; the predefined suffix refers to a special marker used to distinguish the original file from the symbolic link, such as .real mentioned in the document; the scheduler is deployed on the electronic device and is responsible for all subsequent analysis, configuration matching, and final execution; a symbolic link is a special file whose content is a path to another file or directory. It is similar to a shortcut in Windows.
[0036] In one implementation, the electronic device can perform the following operations via an automated script (such as setup_dispatcher_links), a process that is atomic to ensure safety: First, rename the target executable file myapp to myapp.real; then create a new temporary symbolic link in the original path, pointing to the scheduler (such as / usr / bin / dispatcher), and atomically rename this temporary symbolic link to myapp; finally, the target executable file path / opt / myapp / bin / myapp points to the scheduler path / usr / bin / dispatcher, while the backup file path is / opt / myapp / bin / myapp.real.
[0037] In one implementation, S101 can be achieved through S1011-S1013: S1011. Move the target executable file to a backup file.
[0038] In a file system, two files with the same name cannot exist in the same directory. Only after the actual executable program is moved (renamed) can a symbolic link pointing to the scheduler be created in the original path. At the same time, adding a predetermined suffix (such as .real) to the renaming operation not only releases the path but also leaves a clue for the scheduler to retrieve the actual program later.
[0039] Specifically, electronic devices use system calls (such as the rename or mv command) to directly rename files located in the original path (e.g., / opt / myapp / bin / myapp) to files with a predetermined suffix (e.g., / opt / myapp / bin / myapp.real).
[0040] For example, the electronic device uses an automated script (setup_dispatcher_links) to batch scan for ELF executable files in a specified directory, renames each matching file to a backup file with the .real extension, and creates a symbolic link pointing to the calling program in the original path. This process employs atomic operations (first moving the original file, then creating a temporary symbolic link, and finally atomically renaming it), ensuring that no file loss or concurrent call exceptions occur during the replacement process. A reverse operation (revert mode) is also provided, which can delete the symbolic link and restore the original .real file name, achieving fully reversible deployment.
[0041] S1012. Create a temporary symbolic link pointing to the scheduler in the directory where the original path is located. The name of the temporary symbolic link is different from the file name in the original path.
[0042] If a symbolic link is created directly in the original path, and another process happens to attempt to execute the program during the creation process, it may cause execution failure or read corrupted files. By first creating a temporary symbolic link with a different name (e.g., adding a .tmp suffix), the electronic device can safely construct a link to the scheduler without affecting the original path.
[0043] Specifically, the electronic device invokes a system call (such as symlink) to create a new link pointing to the dispatcher ( / usr / bin / dispatcher) in the directory where the original path is located ( / opt / myapp / bin / ), and gives it a temporary name that will not conflict with existing files (e.g., myapp.tmp).
[0044] S1013. Rename the temporary symbolic link to the filename of the original path.
[0045] At the operating system level, renaming files within the same directory (using the `rename` system call) is atomic. This means that when an electronic device renames `myapp.tmp` to `myapp`, the replacement is instantaneous. Other processes in the system either detect the old `myapp` (the real program) or the new `myapp` (the symbolic link), without detecting an intermediate state of "not existing" or "being created." This instantaneous completion mechanism meets the security and seamless requirements of hijacking operations.
[0046] Specifically, the electronic device invokes the `rename` system call again, renaming the newly created temporary symbolic link (` / opt / myapp / bin / myapp.tmp`) to the filename in the original path (` / opt / myapp / bin / myapp`). Since the original file was moved in the previous steps, the original path is now empty, and the renaming operation will successfully overwrite and take effect, ultimately completing the setup of the hijacking environment.
[0047] Based on the implementation of S1011-S1013 above, the electronic device first removes the original executable program to free up a conflict-free namespace for subsequent operations; then, it creates a temporary symbolic link pointing to the scheduler to avoid read failures or execution exceptions caused by other processes attempting to execute the program when the original path is directly modified; finally, it uses the operating system's underlying rename system call to rename the temporary link to the original filename. Since the renaming operation in the same directory is atomic, this replacement action is completed instantly, so that other processes in the system either see the real program before the replacement or the symbolic link after the replacement, without observing the intermediate state of missing files or files being created. Thus, while ensuring the stable operation of the system, a smooth and secure construction of the scheduler hijacking environment is achieved.
[0048] S102. In response to the symbolic link being invoked, the scheduler resolves its own call path, determines the name of the invoked program based on the call path, and locates the backup file in the directory where the symbolic link is located. The filename of the backup file includes the program name and a predetermined suffix.
[0049] Once the scheduler is invoked, it must determine which program the user actually wants to run. Therefore, the location of the original program is deduced by working backward from the way the scheduler is invoked (i.e., the path and name of the symbolic link).
[0050] The call path refers to the path used by the user when executing the command, such as / opt / myapp / bin / myapp. This path will be passed to the scheduler as the parameter argv[0]; the program name refers to the file name part of the call path, such as myapp.
[0051] In one implementation, argv[0] is first read to obtain the call path; then, the program name myapp is extracted from the call path; the program name and the predefined suffix .real are combined to construct the backup file myapp.real; the backup file is searched in the directory where the symbolic link is located ( / opt / myapp / bin / ) to obtain the complete path of the original program.
[0052] For example, the Dispatcher can serve as the core scheduling engine. When invoked, it executes the following process: First, it parses the argv[0] call path, combines the PATH environment variable and / proc / self / exe to determine the absolute path of itself being called; second, it determines the directory and program name based on its own path, and concatenates the file name.real to obtain the real program file name; then, it reads the ELF file header of the real program, and determines the target architecture type through the e_ident[EI_CLASS] field (ELFCLASS32 corresponds to i386, ELFCLASS64 corresponds to x86_64); next, it reads the configuration files (the main configuration file translator.conf and the fragmented configuration files in the conf.d directory), and matches the applicable translator and environment variables according to the target architecture and target program name; finally, it constructs the final command line and environment variable array, and executes the target program through the execve system call.
[0053] S103. Read the file header of the backup file and determine the target architecture type of the backup file based on the architecture type field in the file header.
[0054] To enable cross-architecture distribution, it is necessary to determine which CPU architecture the original program was compiled for (e.g., 32-bit i386 or 64-bit x86_64) in order to select the correct translator (e.g., Box86 or Box64).
[0055] The file header (ELF Header) refers to the structured data at the beginning of the ELF executable file, which contains key information describing the file attributes; the schema type field (e_ident[EI_CLASS]) is a specific byte in the ELF file header used to identify whether the file is 32-bit (ELFCLASS32) or 64-bit (ELFCLASS64).
[0056] In one implementation, the electronic device directly opens and reads the ELF file header of the backup file (myapp.real) and parses the value of the e_ident[EI_CLASS] field. If the value is ELFCLASS32, the target architecture is determined to be i386; if it is ELFCLASS64, it is determined to be x86_64.
[0057] S104. Based on the target architecture type, match the translator path corresponding to the target architecture type from the configuration file, and match the environment variable configuration corresponding to the target architecture type and / or the backup file from the configuration file.
[0058] Electronic devices need to determine which translator to use based on different program architectures or even different programs themselves, and inject specific environment variables (such as setting LD_LIBRARY_PATH for 32-bit programs to find the correct dynamic library).
[0059] The configuration file consists of one or more text files (such as files in the / etc / kylin-loader / translator.conf and / etc / kylin-loader / translator.conf.d / directories) used to store distribution rules; the translator path refers to the location of the cross-architecture execution engine (such as Box86, Box64, QEMU-user) in the file system; and the environment variable configuration refers to key-value pairs that need to be set before executing the target program, such as LD_LIBRARY_PATH, BOX86_LOG, etc.
[0060] In one implementation, the electronic device reads the main configuration file and all configuration files in the configuration directory, following a priority strategy: program-specific configurations (env_prog_) have the highest priority and can be set for individual programs; architecture-level configurations (env_i386, env_x86_64) have the next highest priority and apply to all programs on a specific architecture; global configurations (env) have the lowest priority and serve as the default settings. Using the files= directive, configuration files can restrict their rules to apply only to specific programs.
[0061] For example, the configuration file ( / etc / kylin-loader / translator.conf) provides global default configurations. The .conf files in the configuration directory ( / etc / kylin-loader / translator.conf.d / ) are loaded sequentially in filename order, with later-loaded configurations overriding earlier ones. The configuration file supports the following configuration items: `translator_x86_64= / translator_i386=`: Specifies the translator path for a specific architecture; `translator=`: Specifies a general fallback translator (used when no architecture-specific translator is specified); `env=`: Sets global environment variables applicable to all architectures (comma-separated KEY=VALUE pairs); `env_x86_64= / env_i386=`: Sets architecture-specific environment variables, such as setting LD_LIBRARY_PATH to point to the 32-bit library path for i386; `env_prog_<program path>=`: Sets a specific environment variable for a particular program path, enabling fine-grained control at the program level; `files=`: Limits the scope of the current configuration file, supporting absolute path matching and program name matching, and supports multi-line continuation.
[0062] S105. Construct the execution command line and execution environment variable array based on the translator path and environment variable configuration, and execute the backup file by calling the interface.
[0063] After completing the aforementioned steps, all the analysis and configuration need to be translated into actual operation.
[0064] The execution command line is a string array containing the command to be executed and all its parameters; the execution environment variable array is a string array containing all the environment variables that need to be passed to the new process; the calling interface is a system call provided by the operating system, such as execve, which is used to load and run a new program, replacing the current process.
[0065] In one implementation, the scheduler merges the matched environment variables with the original inherited environment variables, and variables with the same name are overwritten by the new configuration. If a translator (such as / usr / bin / box86) is matched, the command line is [" / usr / bin / box86"," / opt / myapp / bin / myapp.real","original parameters..."]. If no translator is matched, the original program [" / opt / myapp / bin / myapp.real","original parameters..."] is executed directly. The execve interface is called, passing in the constructed command line and the array of environment variables. The electronic device loads the translator (or directly loads the original program) and transfers control to it, thus completing the entire transparent distribution process.
[0066] For example, when constructing the final variable array, a priority strategy of "program-specific first, architecture second, global last resort" is followed. Specifically: `env_prog_configuration` has the highest priority, followed by `env_<architecture>`, and then `env` has the lowest priority. At the same time, the Dispatcher retains all environment variables from the original `environ` (excluding entries with the same name as newly added variables), ensuring that the target program can correctly inherit the configuration from the original calling environment. For environment variables with the same name, the newly added configuration will automatically overwrite the original inherited value. This design ensures the correct transmission of environment variables and the flexibility of fine-grained control.
[0067] Based on the implementation methods of S101-S105 described above, by renaming the original file and creating symbolic links, the hijacking and seamless replacement of the call path are achieved, ensuring the compatibility of the original program's call interface. The scheduler parses its own path and locates the backup file, ensuring that the real target program can be accurately obtained during cross-architecture execution. By reading the architecture field in the file header to determine the target architecture, the automatic identification of heterogeneous binary formats is achieved, avoiding crashes caused by blind calls. According to the architecture type, the translator and environment variable configuration are matched to achieve fine-grained routing and differentiated environment injection for programs of different architectures, solving the dynamic library dependency problem during cross-architecture runtime. Finally, by constructing command lines and environment variable arrays and calling the execution interface, transparent and automated scheduling and execution of cross-architecture programs are achieved.
[0068] In one implementation, the array of execution environment variables constructed in S105 can be implemented using S1051-S1054: S1051. Use all environment variables in the original environment variable array as the initial set.
[0069] Before the target program is intercepted by the scheduler, the user or parent process may have already set some necessary environment variables (such as PATH, HOME, etc.) for it. Directly inheriting these variables can ensure that the basic behavior of the target program at runtime is consistent with the user's expectations, avoiding program crashes due to missing environment variables.
[0070] In one implementation, the electronic device obtains all environment variables of the current scheduler process through system calls (such as getenv or directly reading the environ global variable) and copies them completely into memory as the "base set" for the new array of environment variables to be built.
[0071] S1052. Obtain the set of architecture-level environment variables corresponding to the target architecture type, and obtain the set of program-specific environment variables corresponding to the backup file.
[0072] For a target program to run on a heterogeneous architecture, it often requires specific library paths (such as LD_LIBRARY_PATH) or translator control parameters (such as BOX86_LOG). These parameters fall into two categories: one is a general requirement for the entire architecture, and the other is a personalized requirement for a specific program.
[0073] In one implementation, the electronic device extracts the following from the previously loaded and parsed configuration set: an architecture-level environment variable set, such as all configuration items prefixed with env_i386_; and a program-specific environment variable set, such as the specific configuration items matched by the files=myapp filter.
[0074] In another implementation, the acquisition of the program-specific environment variable set corresponding to the backup file in S1052 can be achieved through S10521-S10523: S10521. Obtain the absolute path string of the backup file.
[0075] In an operating system, the same program name (such as myapp) may exist in multiple different directories. The filename alone cannot guarantee precise configuration binding. By obtaining the absolute path of a backup file (e.g., / opt / myapp / bin / myapp.real), electronic devices provide a precise address down to the location of the currently executing task, thus avoiding configuration confusion caused by programs with the same name.
[0076] In one implementation, after locating the backup file, the electronic device obtains the absolute path string of the complete, unsigned link of the file in the root directory of the file system through a system call (such as realpath or getcwd combined with relative path resolution), and temporarily stores it in memory as a benchmark key for subsequent comparison.
[0077] S10522. Using the absolute path string as the key, compare it with the key of each program-specific environment variable configuration item in the configuration file.
[0078] Configuration files may store a large number of environment variables specific to different programs. Therefore, an efficient lookup mechanism is needed to associate the currently running program with the correct configuration rules.
[0079] In one implementation, the electronic device iterates through the program-specific environment variable configuration items in the loaded configuration file. For each configuration item, its key portion is extracted and subjected to a strict string equality comparison with the absolute path string obtained in the preceding steps.
[0080] S10523. If the comparison result with any dedicated environment variable configuration item is the same, then all environment variables in that configuration item shall be used as the program's dedicated environment variable set.
[0081] Once a match is successful, it means that the environment variables in the current configuration file are specifically tailored for the backup files in the current specific path (such as a specific dynamic library search path or debug switch). Extracting these variables allows for subsequent merging and injection.
[0082] In one implementation, when the electronic device finds that the key of a configuration item exactly matches the absolute path of a backup file, it immediately stops or continues traversing (depending on whether the configuration allows multiple matches) and resolves the value corresponding to that configuration item into one or more environment variable key-value pairs. These key-value pairs are packaged into a set, namely the "program-specific environment variable set," and are then passed to subsequent merging logic to participate in the final construction of the execution environment variable array.
[0083] Based on the implementation methods of S10521-S10523 described above, the electronic device obtains the absolute path of the backup file and compares it with the key of the configuration item. This matching mechanism ensures that even if there are multiple executable files with the same name in the system, the electronic device can accurately identify and load only the exclusive environment variables (such as specific dynamic library paths or debugging parameters) that match the current specific physical path, thereby ensuring the security and purity of the execution environment in complex heterogeneous program distribution scenarios. At the same time, this retrieval method based on absolute path has clear logic and high matching efficiency, enabling the electronic device to quickly complete the extraction of exclusive configurations with extremely low computational overhead, providing a data foundation for the subsequent construction of a pollution-free cross-architecture execution environment.
[0084] S1053. Remove environment variables with the same name as any environment variable in the architecture-level environment variable set and the program-specific environment variable set from the initial set.
[0085] If an LD_LIBRARY_PATH already exists in the original environment variables, and this variable also needs to be set in the architecture-level configuration, directly appending it without processing may lead to path concatenation errors or old values interfering with new values. "Removing" the old value before "injecting" it ensures that the new configuration has absolute control.
[0086] In one implementation, the electronic device iterates through all keys in the architecture-level and program-specific environment variable sets. For each key, it searches the initial set. If an environment variable with the same name is found, it is permanently removed from the initial set.
[0087] S1054. Merge the global environment variable set, the architecture-level environment variable set, and the program-specific environment variable set into the initial set in sequence, and the variables merged later shall overwrite the variables with the same name merged earlier.
[0088] Cross-architecture distribution requires a clear set of rules to determine which configuration source should be the dominant one when multiple configuration sources provide the same environment variable. Therefore, this "merge sequentially, with the latter overriding" mechanism can satisfy the priority logic of "program-specific > architecture-level > global default".
[0089] In one implementation, the electronic device sequentially inserts key-value pairs from three sets into an initial set: First, it merges the global environment variable set (such as configurations starting with env_); then, it merges the architecture-level environment variable set, where the new value directly overwrites the old value if a variable with the same name as the global configuration appears; further, it merges the program-specific environment variable set, where the value of the program-specific configuration again overwrites the old value if a variable with the same name as the variables in the previous two steps appears; finally, this cleaned and layered initial set becomes the execution environment variable array, which is passed to the execve system call.
[0090] Based on the implementation methods of S1051-S1054 described above, the electronic device first fully inherits the original environment variables as the initial set, ensuring the continuity of the system context during the target program's runtime and avoiding program exceptions caused by environment loss. On this basis, old variables with the same names as architecture-level and program-specific environment variables are removed from the initial set. This mechanism fundamentally eliminates conflicts or messy splicing between residual variables in the original environment and new variables required across architectures, ensuring the purity of the execution environment. At the same time, the sequential merging and name-overriding mechanism of "global -> architecture-level -> program-specific" establishes a clear configuration priority. This not only allows personalized debugging parameters or library paths for specific programs to cover general architecture configurations, but also improves the system's flexibility and robustness, ultimately ensuring that the target program can be correctly translated and executed in an expected, unpolluted, isolated environment.
[0091] In one implementation, in S104, matching the translator path corresponding to the target architecture type from the configuration file can be achieved through S1041-S1042: S1041. When a specified architecture translator configuration item corresponding to the target architecture type exists in the configuration file, the translator path in the specified architecture translator configuration item shall be used as the matching result.
[0092] Different processor architectures (such as 32-bit i386 and 64-bit x86_64) typically require different translators (such as Box86 and Box64). Electronic devices can preferentially search for and use translators specifically configured for a particular architecture.
[0093] In one implementation, after reading the configuration file, the electronic device searches for the corresponding configuration item based on the known "target architecture type" (e.g., i386) (i.e., looking for lines starting with translator_i386=). If the configuration item is found, the path after the equals sign is extracted (e.g., / usr / bin / box86). This path is then used directly as the final translator, and the matching process ends.
[0094] S1042. When there is no specified architecture translator configuration item in the configuration file that corresponds to the target architecture type, the translator path in the general translator configuration item shall be used as the matching result.
[0095] If an administrator hasn't configured a dedicated translator for a specific architecture (such as a less common one), electronic devices shouldn't report errors or fail to execute programs. In this case, using a "general" translator as an alternative ensures the program still has a chance to run.
[0096] The general translator configuration item is a key-value pair in the configuration file that is not specific to any particular architecture and serves as the default option, such as translator=.
[0097] In one implementation, when the electronic device does not find the `translator_i386=` configuration item corresponding to the target architecture (such as i386) in the configuration file, it initiates a "fallback" logic. It then searches for a generic configuration item (i.e., the line `translator=`). If found, it extracts the path following it and uses that as the final translator to be used.
[0098] Based on the implementation methods of S1041-S1042 described above, a hierarchical matching mechanism based on priority is constructed to ensure accurate adaptation to mainstream architectures while improving compatibility and robustness to unknown or special architectures. Specifically, when electronic devices prioritize finding and using the specified architecture translator configuration item that strictly corresponds to the target architecture (such as i386 or x86_64), it ensures that programs with different bit widths or instruction sets are distributed to the most suitable execution environment (e.g., 32-bit programs accurately call Box86, and 64-bit programs call Box64), thereby guaranteeing the accuracy and efficiency of cross-architecture execution and avoiding instruction set incompatibility or performance loss caused by mixed translators. When the specified configuration item for a specific architecture is missing in the configuration file, the system automatically falls back to the general translator configuration item, which provides an effective fault tolerance and degradation handling method. This not only reduces configuration maintenance costs but also ensures that programs can still be loaded and executed without directly reporting errors or interrupting when facing undefined unpopular architectures or temporary test scenarios.
[0099] Furthermore, in S104, matching the target architecture type and / or environment variable configuration corresponding to the backup file from the configuration file can be achieved through S1043-S1044: S1043. Load the main configuration file located in the first predetermined path, and load each independent configuration file located in the configuration directory in the second predetermined path in order of file name.
[0100] Packing all environment variable rules into a single large file makes maintenance difficult. Splitting them into a main configuration (global default rules) and multiple independent configurations (patch rules for specific programs or scenarios) improves system readability and maintainability. Loading them in filename order provides deterministic priority for configuration items.
[0101] The first predetermined path is a fixed directory for storing the main configuration file (Base configuration), such as / etc / kylin-loader / translator.conf, which typically contains global and general environment variable settings; the second predetermined path is a fixed path for storing the configuration directory, such as / etc / kylin-loader / translator.conf.d / , which can contain any number of independent configuration files (such as env_prog_myapp.conf, env_i386.conf).
[0102] In one implementation, the electronic device first opens and parses the main configuration file located in a first predetermined path, loading its key-value pairs (environment variable configurations) into memory. Next, the electronic device reads the configuration directory under a second predetermined path, obtaining a list of all files within it. The electronic device then opens and parses each individual configuration file sequentially, according to the filename order (e.g., alphabetically ascending a.conf, b.conf, c.conf).
[0103] Furthermore, loading the individual configuration files located in the configuration directory of the second predetermined path in order of filename in S1043 can be achieved through S10431-S14433: S10431. Obtain the program filter item in the current independent configuration file. The program filter item contains at least one target program identifier.
[0104] In real-world scenarios, the configuration directory may contain numerous independent configuration files for various programs. Loading all of them without filtering not only wastes system resources but may also lead to the incorrect injection of irrelevant environment variables. By pre-reading filter items, electronic devices can quickly determine whether a configuration file is relevant to the current task.
[0105] Among them, the program filter item refers to the specific instructions in the configuration file used to declare the scope of the file; the target program identifier is a string used to uniquely or fuzzily identify the target program. It can be an absolute path (such as / opt / myapp / bin / myapp) or simply a filename (such as myapp).
[0106] In one implementation, after opening the current independent configuration file, the electronic device first scans and extracts the program filter items (for example, parsing the line files=myapp, / usr / bin / otherapp), splits it into a list containing the target program identifier, and temporarily stores it in memory for later use.
[0107] S10432. If the absolute path of the backup file is the same as any target program identifier, or the file name of the backup file is the same as any target program identifier, then load all configuration items in the current independent configuration file.
[0108] Specifically, the target program identifier containing a forward slash is compared with the absolute path of the backup file, while the target program identifier without a forward slash is compared with the filename of the backup file.
[0109] Different administrators have different configuration habits. Sometimes they only want the configuration to apply to programs in a specific directory (using absolute paths), while other times they want it to apply regardless of the program's directory as long as it has that name (using filenames). By recognizing whether the identifier contains a forward slash ( / ), the system can intelligently select a matching strategy, balancing accuracy and universality.
[0110] The absolute path to the backup file, i.e., the complete path to the actual executable file (e.g., / opt / myapp / bin / myapp.real). The last segment of the absolute path to the backup file's filename (e.g., myapp.real).
[0111] In one implementation, the electronic device iterates through the list of target program identifiers extracted in S10431. If the current identifier contains a forward slash (e.g., / opt / myapp / bin / myapp), the electronic device performs a strict comparison with the absolute path of the current backup file (after removing the .real suffix). If the current identifier does not contain a forward slash (e.g., myapp), the electronic device only extracts the filename of the current backup file (after removing the .real suffix) for comparison. As long as either of these two matches is found, the electronic device confirms that the independent configuration file is valid and loads all its environment variable configuration items into memory.
[0112] S10433 Otherwise, skip all configuration items in the current standalone configuration file.
[0113] If the currently running program does not match a specific configuration file, it means that the environment variables in that configuration file (such as specific library paths, debug switches, etc.) are meaningless to the program or may even cause conflicts. Skipping it can prevent accidental operation.
[0114] In one implementation, when the electronic device has traversed all the target program identifiers and finds that neither the absolute path nor the filename matches, it directly closes or ignores the standalone configuration file, does not load any key-value pairs into memory, and then continues to process the next file in the configuration directory.
[0115] For example, further, the `files=` configuration item is introduced, allowing the scope of a configuration file to be limited to a specific target program. The `files=` value uses a comma-separated list of programs and supports two matching modes: items with a forward slash match the absolute path exactly, while items without a forward slash match the program's basename. The `files=` value supports multi-line continuation; lines beginning with a space or tab are considered continuations of the current `files` list, providing good readability. When a configuration file contains the `files=` item and the current target program is not in the list, the entire configuration file is skipped; when it does not contain the `files=` item, the configuration applies to all target programs. This design allows system administrators to flexibly specify different translator and environment variable combinations for different programs through independent `.conf` files in the configuration directory, without modifying the global configuration.
[0116] Based on the implementation methods of S10431-S10433 described above, before loading an independent configuration file, the electronic device first extracts the target program identifier and compares it with the current backup file. If they do not match, the file is skipped directly. This on-demand filtering mechanism effectively avoids a large number of irrelevant configuration files being loaded blindly. This not only saves system memory and parsing overhead, but also fundamentally prevents irrelevant environment variables from being incorrectly injected into the target program, ensuring the purity and security of the execution environment. At the same time, by identifying whether the target program identifier contains a forward slash, it intelligently distinguishes between absolute path matching and filename matching modes. This provides system administrators with a high degree of configuration freedom. It allows for strict absolute path restrictions for programs in a specific directory, and also allows for general matching of programs with the same name across directories based solely on the filename. This ensures fine-grained control while significantly reducing the configuration and maintenance costs in complex heterogeneous program distribution scenarios.
[0117] S1044. When loading each independent configuration file, if a configuration item in the current independent configuration file has the same name as a loaded configuration item, the configuration item in the current independent configuration file shall override the loaded configuration item.
[0118] This step enables priority control and flexible customization of configurations. The mechanism of late-loader overriding early-loader allows administrators to inject specific environment variables for specific programs or architectures, or correct errors in the global default configuration, without modifying the main configuration file, by adding new independent configuration files.
[0119] Among them, configuration items with the same name refer to environment variable settings with the same key. For example, the main configuration sets LD_LIBRARY_PATH= / usr / lib, while the independent configuration has LD_LIBRARY_PATH= / opt / myapp / lib; Override is a configuration merging strategy. When encountering a key with the same name, the old value in memory will be completely replaced by the new value.
[0120] In one implementation, when the electronic device parses the current independent configuration file, it checks whether the key name already exists in the configuration set in memory for each key-value pair it reads. If it doesn't exist, the key-value pair is added directly to the set. If it exists (i.e., a name conflict occurs), the old value in memory is directly replaced with the value from the current independent configuration file. As all independent configuration files are loaded in sequence, the final environment variable configuration retained in memory is the result with the highest priority after layers of overriding.
[0121] Based on the implementation methods of S1043-S1044 described above, by embedding the global basic rules in the main configuration file of the first predetermined path, and splitting the personalized rules for specific architectures or specific programs into independent configuration files of the second predetermined path, this physical isolation improves the maintainability of the system. This allows administrators to update configurations or add program distribution rules without modifying the core main configuration, thereby reducing the risk of misoperation. At the same time, the sequential loading and name-overriding mechanism based on filename order assigns clear priorities to configuration items (i.e., later loaded configurations have higher priorities). This not only allows system administrators to flexibly adjust the effective level of rules by controlling the file naming order (such as adding a number prefix), but also ensures that the environment variable configurations for specific programs can accurately override the global default configurations. Ultimately, while ensuring the stability of the system's basic operating environment, flexible and dynamic customization of the execution environment of complex heterogeneous programs is achieved.
[0122] The executable program distribution method provided in this application is described below with reference to embodiments in practical applications, including the following steps: Step 1: Deploy the Dispatcher link.
[0123] First, the `setup_dispatcher_links` script creates symbolic links to hijack ELF programs in a specified directory. Assuming the target program directory is ` / opt / myapp / bin / `, the script will traverse this directory, identify the ELF executable files, rename them to `.real` files, and create a symbolic link pointing to ` / usr / bin / dispatcher`. #setup_dispatcher_links / opt / myapp / bin / ; # Result: / opt / myapp / bin / myapp -> / usr / bin / dispatcher (symbolic link); # / opt / myapp / bin / myapp.real (raw ELF file) Step 2: Configuration file structure.
[0124] Set the global default translator and environment variables in the configuration file / etc / kylin-loader / translator.conf: # / etc / kylin-loader / translator.conf; translator_x86_64= / usr / bin / box64; translator_i386= / usr / bin / box86; env=BOX64_NOBANNER=1,BOX86_NOBANNER=1; env_i386=LD_LIBRARY_PATH= / opt / compat / i386 / lib: / usr / lib / i386-linux-gnu Create your own detailed configurations in the configuration directory / etc / kylin-loader / translator.conf.d / . For example, create 50-myapp.conf to set specific environment variables for a particular program: # / etc / kylin-loader / translator.conf.d / 50-myapp.conf; files=myapp; env_prog_ / opt / myapp / bin / myapp.real=BOX64_LOG=1,BOX64_TRACE_FILE= / tmp / myapp.trace.log; For example, create 60-other.conf to use a different translator for another program: # / etc / kylin-loader / translator.conf.d / 60-other.conf; files=otherapp, / opt / otherapp / bin / special; translator_x86_64= / usr / local / bin / box64-custom; Step 3: Dispatcher execution process.
[0125] The core execution logic of the Dispatcher program is as follows (described in C language pseudocode): int main(int argc, char argv[]) { / / 1. Parse the call path to locate itself and the target program. char link_abs_path = resolve_link_path(argv[0]); char cmd_name = basename(argv[0]); char target_prog = build_target_path(cmd_name, ".real"); / / 2. Obtain the true absolute path of the target program; char real_abs[PATH_MAX]; realpath(target_prog, real_abs); / / 3. Read the target program's ELF header to determine the architecture type. int ei_class = get_elf_class(real_abs); / / ELFCLASS32 ->i386, ELFCLASS64 ->x86_64; / / 4. Read the configuration file and match the translator and environment variables. read_config_from_file(CONF_PATH, ei_class, real_abs, &translator,&global_env,&arch_env,&prog_env); read_config_dir(ei_class, real_abs, &translator,&global_env,&arch_env,&prog_env); / / 5. Construct the final environ array (program-specific > architecture > global > inherit from the original) char new_environ = build_new_environ(all_envs, 3); / / 6. Constructing command-line arguments if (translator) { new_argv = {translator, real_abs, original arguments...}; } else { new_argv = {real_abs, original arguments...}; } 7. Execute the target program execve(new_argv[0], new_argv, new_environ); } Step 4: Complete workflow example.
[0126] Suppose that on an x86_64 Kylin operating system, you need to run an i386 architecture application ` / opt / myapp / bin / myapp` (32-bit), which depends on a 32-bit dynamic library located in ` / opt / compat / i386 / lib`. The complete workflow is as follows: First, execute setup_dispatcher_links to deploy the links: $ setup_dispatcher_links / opt / myapp / bin / ; Secondly, set the i386 translator and library path in the configuration file: # / etc / kylin-loader / translator.conf.d / 00-base.conf translator_i386= / usr / bin / box86env_i386=LD_LIBRARY_PATH= / opt / compat / i386 / lib: / usr / lib / i386-linux-gnu; Then, the user executes the program: $ / opt / myapp / bin / myapp arg1 arg2.
[0127] Finally, the symbolic link is resolved, and the Dispatcher is actually executed. The Dispatcher automatically completes the following: it identifies the target program myapp.real as having a 32-bit (i386) ELF type → matches translator_i386= / usr / bin / box86 from the configuration → sets LD_LIBRARY_PATH to the 32-bit library path → execve(" / usr / bin / box86",[" / usr / bin / box86"," / opt / myapp / bin / myapp.real","arg1","arg2"],new_environ) → the 32-bit program successfully runs on the x86_64 system.
[0128] This application embodiment can divide the following device into functional modules based on the above method example. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. Optionally, the module division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0129] In some embodiments, this application also provides an executable program distribution apparatus. The executable program distribution apparatus may include one or more functional modules for implementing the methods described in the above embodiments. For example, Figure 2 This is a schematic diagram illustrating the composition of an executable program distribution device 200 provided in an embodiment of this application. Figure 2 As shown, the executable program distribution device 200 includes: Processing module 210 is used to rename the target executable file to a backup file with a predetermined suffix, and to create a symbolic link pointing to the scheduler in the original path of the target executable file. Module 220 is invoked in response to a symbolic link being invoked. The scheduler resolves its own call path, determines the name of the program being invoked based on the call path, and locates the backup file in the directory where the symbolic link is located. The filename of the backup file includes the program name and a predetermined suffix. The judgment module 230 is used to read the file header of the backup file and determine the target architecture type of the backup file based on the architecture type field in the file header. Module 220 is also used to match the translator path corresponding to the target architecture type from the configuration file, and to match the environment variable configuration corresponding to the target architecture type and / or the backup file from the configuration file. The processing module 210 is also used to construct the execution command line and the execution environment variable array according to the translator path and environment variable configuration, and to execute the backup file by calling the interface.
[0130] In one implementation, the calling module 220 is further configured to, when there is a specified architecture translator configuration item in the configuration file corresponding to the target architecture type, use the translator path in the specified architecture translator configuration item as the matching result; when there is no specified architecture translator configuration item in the configuration file corresponding to the target architecture type, use the translator path in the general translator configuration item as the matching result.
[0131] In one implementation, the calling module 220 is further configured to load the main configuration file located in the first predetermined path, and load each independent configuration file located in the configuration directory in the second predetermined path in order of file name; when loading each independent configuration file, if the configuration item in the current independent configuration file has the same name as the loaded configuration item, the configuration item in the current independent configuration file shall overwrite the loaded configuration item.
[0132] In one implementation, the calling module 220 is further configured to: obtain program filter items in the current independent configuration file, wherein the program filter items contain at least one target program identifier; if the absolute path of the backup file matches any target program identifier, or the filename of the backup file matches any target program identifier, then load all configuration items in the current independent configuration file; wherein, the target program identifier containing a forward slash is compared with the absolute path of the backup file, and the target program identifier without a forward slash is compared with the filename of the backup file; otherwise, all configuration items in the current independent configuration file are skipped.
[0133] In one implementation, the processing module 210 is further configured to: use all environment variables in the original environment variable array as an initial set; obtain the architecture-level environment variable set corresponding to the target architecture type, and obtain the program-specific environment variable set corresponding to the backup file; remove environment variables with the same name as any environment variable in the architecture-level environment variable set and the program-specific environment variable set from the initial set; and merge the global environment variable set, the architecture-level environment variable set, and the program-specific environment variable set into the initial set in sequence, with the variables merged later overwriting the variables with the same name merged earlier.
[0134] In one implementation, the processing module 210 is further configured to: obtain the absolute path string of the backup file; compare the absolute path string with the key of each program-specific environment variable configuration item in the configuration file; if the comparison result with any program-specific environment variable configuration item is the same, then all environment variables in that configuration item are used as the program-specific environment variable set.
[0135] In one implementation, the processing module 210 is further configured to: move the target executable file to a backup file; create a temporary symbolic link pointing to the scheduler in the directory where the original path is located, the name of the temporary symbolic link being different from the filename of the original path; and rename the temporary symbolic link to the filename of the original path.
[0136] When the methods of the above embodiments are implemented in hardware, this embodiment of the invention provides a possible structural schematic diagram of the electronic device involved in the above embodiments. For example... Figure 3 As shown, the electronic device 300 includes: a processor 302, a communication interface 303, and a bus 304. Optionally, the electronic device 300 may also include a memory 301.
[0137] Processor 302 may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 302 may be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 302 may also be a combination that implements computing functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0138] Communication interface 303 is used to connect with other devices via a communication network. This communication network can be Ethernet, wireless access network, wireless local area network (WLAN), etc.
[0139] The memory 301 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto.
[0140] In one possible implementation, the memory 301 can exist independently of the processor 302. The memory 301 can be connected to the processor 302 via a bus 304 and is used to store instructions or program code. When the processor 302 calls and executes the instructions or program code stored in the memory 301, it can implement the method provided in the embodiments of the present invention.
[0141] In another possible implementation, the memory 301 can also be integrated with the processor 302.
[0142] Bus 304 can be an Extended Industry Standard Architecture (EISA) bus, etc. Bus 304 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 3 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.
[0143] Through the above description of the implementation methods, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the service calling device can be divided into different functional modules to complete all or part of the functions described above.
[0144] This application also provides a computer-readable storage medium. All or part of the processes in the above method embodiments can be executed by computer instructions instructing related hardware. The program can be stored in the aforementioned computer-readable storage medium, and when executed, it can include the processes of the above method embodiments. The computer-readable storage medium can be any of the foregoing embodiments or memory. The aforementioned computer-readable storage medium can also be an external storage device of the aforementioned device, such as a plug-in hard drive, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the aforementioned device. Further, the aforementioned computer-readable storage medium can include both internal storage units of the aforementioned service call device and external storage devices. The aforementioned computer-readable storage medium is used to store the aforementioned computer program and other programs and data required by the aforementioned device. The aforementioned computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
[0145] This application also provides a computer program product comprising a computer program that, when run on a computer, causes the computer to perform the methods provided in the above embodiments.
[0146] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. An executable program distribution method characterized by comprising the steps of, include: Rename the target executable file to a backup file with a predetermined suffix, and create a symbolic link pointing to the scheduler in the original path of the target executable file; In response to the symbolic link being invoked, the scheduler resolves its own invocation path, determines the name of the invoked program based on the invocation path, and locates the backup file in the directory where the symbolic link is located. The filename of the backup file includes the program name and the predetermined suffix. Read the file header of the backup file and determine the target architecture type of the backup file based on the architecture type field in the file header; Based on the target architecture type, match the translator path corresponding to the target architecture type from the configuration file, and match the environment variable configuration corresponding to the target architecture type and / or the backup file from the configuration file; The execution command line and the execution environment variable array are constructed based on the translator path and the environment variable configuration, and the backup file is executed by calling the interface.
2. The method of claim 1, wherein, The step of matching the translator path corresponding to the target architecture type from the configuration file according to the target architecture type includes: When the configuration file contains a specified architecture translator configuration item corresponding to the target architecture type, the translator path in the specified architecture translator configuration item is used as the matching result; If the configuration file does not contain a specified architecture translator configuration item corresponding to the target architecture type, the translator path in the general translator configuration item will be used as the matching result.
3. The method of claim 1, wherein, The step of matching the configuration file with the target architecture type and / or the environment variable configuration corresponding to the backup file includes: Load the main configuration file located in the first predetermined path, and load the individual configuration files located in the configuration directory in the second predetermined path in order of filename; When loading each of the aforementioned independent configuration files, if a configuration item in the current independent configuration file has the same name as a loaded configuration item, then the configuration item in the current independent configuration file will override the loaded configuration item.
4. The method of claim 3, wherein, The step of loading the individual configuration files located in the configuration directory of the second predetermined path in order of filename includes: Retrieve the program filter items in the current standalone configuration file, wherein the program filter items contain at least one target program identifier; If the absolute path of the backup file matches any of the target program identifiers, or the filename of the backup file matches any of the target program identifiers, then all configuration items in the current independent configuration file are loaded; wherein, the target program identifier containing a forward slash is compared with the absolute path of the backup file, and the target program identifier without a forward slash is compared with the filename of the backup file; Otherwise, skip all configuration items in the current standalone configuration file.
5. The method of claim 1, wherein, The construction of the execution environment variable array includes: Use all environment variables from the original environment variable array as the initial set; Obtain the set of architecture-level environment variables corresponding to the target architecture type, and obtain the set of program-specific environment variables corresponding to the backup file; Remove environment variables from the initial set that have the same name as any environment variable in either the architecture-level environment variable set or the program-specific environment variable set; The global environment variable set, the architecture-level environment variable set, and the program-specific environment variable set are sequentially merged into the initial set, with the variables merged later overwriting the variables with the same name merged earlier.
6. The method of claim 5, wherein, The step of obtaining the set of program-specific environment variables corresponding to the backup file includes: Obtain the absolute path string of the backup file; The absolute path string is used as the key and compared with the key of each program-specific environment variable configuration item in the configuration file; If the comparison result with any dedicated environment variable configuration item is the same, then all environment variables in that configuration item are taken as the set of program-specific environment variables.
7. The method of claim 1, wherein, The step of renaming the target executable file to a backup file with a predetermined suffix and creating a symbolic link pointing to the scheduler in the original path of the target executable file includes: Move the target executable file to the backup file; Create a temporary symbolic link pointing to the scheduler in the directory where the original path is located. The name of the temporary symbolic link is different from the file name in the original path. Rename the temporary symbolic link to the filename of the original path.
8. An electronic device, comprising: It includes a processor and a memory, the processor being coupled to the memory; the memory is used to store computer instructions, which are loaded and executed by the processor to enable the computer device to perform the method as described in any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer-executable instructions that, when executed on a computer, cause the computer to perform the method of any one of claims 1 to 7.
10. A computer program product, characterised in that, The computer program product includes a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1 to 7.
