A coexistence method and system for the same dbus service in a host and a container
By running the proxy process in the container, intercepting and modifying the service name in the DBUS message, the coexistence of the same DBUS service in the domestic operating system and the same DBUS service in the container, solve the problem of DBUS service conflict, improve the compatibility and operation of the application and operation of the application and operation of the operation. stability.
Patent Information
- Application Number
- CN202411676284.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-11-22
AI Technical Summary
In domestic operating systems, applications installed in the host and container will rely on different versions of the same dbus service, resulting in conflicts in the dbus service, which will affect the compatibility and operation stability of the application.
By running a proxy process in the container, the communication between the application in the proxy container and the DBUS bus of the host, intercept and modify the service name in the DBUS message to realize the forwarding of the DBUS message between the container and the host, so that the same makes the same DBUS service is stored in the host and container of the CCP.
Effectively solved the problem of DBUS service conflict, realized the coexistence of the same name on the container and the host of the domestic operating system, and improved the compatibility and operating stability of the application.
Smart Images

Figure CN119201359B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of application containerized operation in an operating system, and in particular to a coexistence method and system for the same dbus service in a host machine and a container. Background Art
[0002] As the popularity of domestic operating systems increases year by year, there are more and more applications under domestic systems, and the compatibility issues between different versions of the same application are becoming more and more complicated. Developers usually use container technology to solve the compatibility issues between different versions of applications by installing applications into containers, so that different versions of the same application can be installed on the operating system. On domestic operating systems, dbus is an important means for communication between applications. In the process of dealing with application compatibility issues, the applications installed in the host and the container will rely on different versions of the same dbus service. Due to the limitations of the dbus bus, the same dbus service can only be owned by one process. At this time, the root cause of the problem becomes a conflict between container and host services, so solving the conflict problem of dbus services with the same name has become one of the main difficulties in application compatibility.
[0003] At present, when domestic operating systems use container technology for application compatibility, when different applications that provide the same dbus service need to be installed in the host and container, or different versions of the same application that provides the dbus service need to be installed, the container or the host will fail to run at runtime because of the same dbus service name, that is, dbus service conflict.
[0004] The Chinese patent application with application number CN202110366560.9 discloses a method and system for optimizing the performance of MPI applications in a container environment. The container-based MPI job is mainly started in a high-performance computing environment. While making full use of the convenience of container technology, it improves the performance of MPI inter-process messaging in high-performance scenarios and reduces performance loss. Although this solution optimizes and upgrades inter-process communication under containers and improves the performance and efficiency of inter-process communication, it is only applicable to high-performance computing scenarios.
[0005] The Korean patent with announcement number KR101810762B1 proposes a method for analyzing container security logs in a cloud environment. The main method is: install a fluentd agent process for collecting logs in each container, then transmit the log data of each container to at least one fluentd collector installed in each container, and finally distribute the log data to the container used for monitoring to complete the log analysis. This solution runs an agent program in a container to complete different functions and requirements, but the agent process needs to work properly under the cooperation of multiple agent processes. Summary of the invention
[0006] The technical problem to be solved by the present invention is as follows: In view of the above-mentioned problems in the prior art, a method and system for the coexistence of the same dbus service in a host machine and a container are provided, which intercepts and forwards the dbus messages of the application in the container to achieve the coexistence of the same dbus service and solve the dbus conflict problem.
[0007] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0008] A method for coexistence of the same dbus service in a host and a container, comprising:
[0009] The proxy process running in the container proxies the communication between the application in the container and the dbus bus in the host machine, and the dbus service name in the message sent from the application in the container to the dbus bus in the host machine is modified through the proxy process so that the dbus service of the application in the container and the dbus service of the same application in the host machine can communicate through the dbus bus at the same time. The destination in the message sent from the dbus bus in the host machine to the application in the container is modified through the proxy process according to the correspondence between the application and the dbus connection so that the application in the container can normally receive the message of the dbus bus.
[0010] Furthermore, when the communication between the application in the container and the dbus bus in the host is performed by the proxy process running in the container, the process proxy processes the dbus service declaration message sent by the application in the container to the dbus bus in the host, including:
[0011] S101, obtaining the dbus service name in the message body of the dbus service declaration message;
[0012] S102, calling the function interface of the dbus bus to determine whether the dbus service name in the message body has been occupied, if it has been occupied, jump to step S104, otherwise jump to step S103;
[0013] S103, call the function interface of the dbus bus to obtain the list of activatable dbus services, and determine whether the dbus service name in the message body is in the list of activatable dbus services. If it is not in the list of activatable dbus services, directly forward the message body of the dbus service declaration message to the dbus bus, end and exit; otherwise, jump to step S104.
[0014] S104, modify the message body of the dbus service declaration message, add a suffix to the dbus service name in the message body to obtain a new dbus service name, the suffix is the container name when the container is created, and then insert the dbus service name and the new dbus service name as a key-value pair into the service name mapping table, and finally forward the modified message body of the dbus service declaration message to the dbus bus.
[0015] Furthermore, when the communication between the application in the container and the dbus bus in the host is performed by the proxy process running in the container, the process proxy processes the dbus method call message sent by the application in the container to the dbus bus in the host, including:
[0016] The proxy process queries the internally maintained service name mapping table and connection mapping table to query the new dbus service name and destination of the dbus method call message, and then modifies the message body of the dbus method call message, modifies the dbus service name to the new dbus service name obtained by the query, modifies the destination to the destination obtained by the query, and forwards the modified message body to the dbus bus.
[0017] Furthermore, when the communication between the application in the container and the dbus bus in the host is performed by the proxy process running in the container, the process proxy processes the dbus connection disconnection message sent by the application in the container to the dbus bus in the host, including:
[0018] The proxy process queries the internally maintained service name mapping table and connection mapping table to query the new dbus service name and destination of the disconnect dbus connection message, and then modifies the message body of the disconnect dbus connection message, modifies the dbus service name therein to the new dbus service name obtained by the query, modifies the destination to the destination obtained by the query, forwards the modified message body to the dbus bus, and finally deletes the new dbus service name and destination of the disconnect dbus connection message from the service name mapping table and the connection mapping table.
[0019] Furthermore, when the communication between the application in the container and the dbus bus in the host machine is performed by the proxy process running in the container, the process proxy forwards the dbus message sent by the dbus bus in the host machine to the application in the container, including:
[0020] The proxy process queries the internally maintained connection mapping table to query the application corresponding to the destination of the message forwarding dbus message, and then modifies the destination in the message body of the message forwarding dbus message according to the queried application, so that the modified message body can be forwarded to the correct application in the container.
[0021] Furthermore, the proxy process runs as a daemon process in the container, and starts running when the container is created, and exits running when the container is destroyed, so that the life cycle of the proxy process is consistent with the life cycle of the container.
[0022] Furthermore, the proxy process monitors the connection request of the application in the container by monitoring a Unix domain socket. After monitoring the connection request, the proxy process applies for a real connection from the dbus bus and records the application and the connection destination in a connection mapping table maintained internally.
[0023] The present invention also proposes a coexistence system of the same dbus service in a host machine and a container, comprising a microprocessor and a memory connected to each other, wherein the microprocessor is programmed or configured to execute any one of the coexistence methods of the same dbus service in a host machine and a container.
[0024] The present invention also proposes a computer-readable storage medium, in which a computer program or instruction is stored. The computer program or instruction is programmed or configured to execute any one of the coexistence methods of the same dbus service in the host machine and the container through a processor.
[0025] The present invention also proposes a computer program product, comprising a computer program or instructions, wherein the computer program or instructions are programmed or configured to execute, through a processor, any one of the coexistence methods of the same dbus service in a host machine and a container.
[0026] Compared with the prior art, the present invention has the following advantages:
[0027] The present invention uses a proxy process running in a container to proxy the communication between an application in the container and a dbus bus in a host machine, intercepts all dbus requests and reply messages in the container, and responds according to the type of the message: if a request for registering a service by an application in the container is monitored, it is determined whether to add a suffix to the name by judging whether there is a service with the same name, and a service name mapping table is maintained internally; if a dbus method call request of an application in the container is monitored or a dbus message sent from the bus to the container is received, the dbus message body is modified through a list maintained internally by the proxy process, thereby realizing the forwarding of dbus messages between the container and the host machine, so that the coexistence of dbus services with the same name can be achieved on the container and the host machine in the domestic operating system. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 The figure is a flow chart of a method according to an embodiment of the present invention.
[0029] Figure 2 FIG. 4 is a program architecture diagram of an embodiment of the present invention. DETAILED DESCRIPTION
[0030] Before introducing the specific embodiments of the present invention, related concepts or terms are first explained.
[0031] dbus: is a low-latency, low-overhead, and highly available inter-process communication mechanism;
[0032] dbus bus: It is the running entity of dbus for inter-process communication and is responsible for forwarding messages. There are usually two dbus buses in a system, one is the system bus and the other is the session bus.
[0033] Container: is a lightweight virtualization technology that allows applications and their dependencies to be packaged together to form an independent and portable operating environment.
[0034] Embodiment 1
[0035] This embodiment proposes a coexistence method of the same dbus service in the host and the container, such as Figure 1 As shown, including:
[0036] A dbus proxy background daemon process is run in the container, which is called a proxy process in this embodiment, such as Figure 2 As shown, the communication between the application in the container and the dbus bus in the host is proxied by the proxy process running in the container. The dbus requests and replies of all applications in the container will first be intercepted by the dbus proxy process, and the proxy process will forward the messages. In this process, the dbus service name in the message sent by the application in the container to the dbus bus in the host is modified by the proxy process so that the dbus service of the application in the container and the dbus service of the same application in the host can communicate through the dbus bus at the same time. The destination in the message sent by the dbus bus in the host to the application in the container is modified by the proxy process according to the corresponding relationship between the application and the dbus connection so that the application in the container can normally receive the message of the dbus bus.
[0037] The proxy process in this embodiment runs as a daemon process in the container, and starts running when the container is created and exits running when the container is destroyed, so that the life cycle of the proxy process is consistent with the life cycle of the container.
[0038] like Figure 1As shown, when the proxy process running in the container proxies the communication between the application in the container and the dbus bus in the host machine, the proxy process listens to the dbus connection request of the application in the container. The proxy process listens to the connection request of the application in the container by listening to a Unix domain socket. After listening to the connection request, the proxy process applies for a real connection from the dbus bus and records the application and the connection destination in a connection mapping table maintained internally.
[0039] Specifically, when building a container in the Kylin operating system, modify the configuration file of the container so that the proxy process runs as a daemon process of the container, and its life cycle is consistent with that of the container. After the proxy process runs, it will listen to the address specified by the environment variable DBUS_SESSION_BUS_ADDRESS in the container. When an application wants to create a dbus connection, the proxy process will read the relevant connection request from the address, and then apply for a real dbus connection on the system's dbus bus. Finally, this real dbus connection and the application's connection request are placed in a mapping table, which is called a "connection mapping table" in this embodiment.
[0040] like Figure 1 As shown in the figure, when the proxy process running in the container is used to proxy the communication between the application in the container and the dbus bus in the host machine, the proxy process cyclically monitors various dbus messages sent by the application in the container, including dbus service declaration messages, dbus method call messages, etc., where:
[0041] If a dbus service declaration message is monitored, the process agent obtains a list of all service names on the dbus bus. If a dbus service with the same name exists on the bus, the message body of the dbus request is modified, a suffix is added to the service name field, and then the message is forwarded to the system bus and recorded in the mapping table inside the agent process. Specifically, the agent process processes the dbus service declaration message sent by the application in the container to the dbus bus in the host machine by:
[0042] S101, obtaining the dbus service name in the message body of the dbus service declaration message, where the service name is the service name to be declared by the application;
[0043] S102, calling the function interface of the dbus bus to determine whether the dbus service name in the message body has been occupied, if it has been occupied, jump to step S104, otherwise jump to step S103. In this embodiment, the proxy service will call the interface dbus_bus_name_has_ower provided by the dbus bus to determine whether the service name is occupied by an already running service;
[0044] S103, calling the function interface of the dbus bus to obtain the activatable dbus service list, judging whether the dbus service name in the message body is in the activatable dbus service list, if not in the activatable dbus service list, directly forwarding the message body of the dbus service declaration message to the dbus bus, ending and exiting;
[0045] If step S102 obtains the result that the service name is not occupied, the list of activatable services is further obtained by calling the ListAvtivatableNames dbus method provided by the dbus bus to determine whether the service name is in the list. If the service name is not in the list, it means that the service name has no conflict and can be directly declared, and the agent forwards the message to the dbus bus; if the service name is in the list, it means that the service name has a conflict and cannot be directly declared, and jumps to step S104;
[0046] As an optional implementation, if step S102 obtains the result that the service name is not occupied, not only the list of activated dbus service names should be obtained, but also the list of inactivated dbus service names should be obtained. If the service name is in the list of activated dbus service names, it means that the service name has a conflict and cannot be directly declared. If the service name is in the list of inactivated dbus service names, it means that the service name has no conflict and can be directly declared.
[0047] S104, modify the message body of the dbus service declaration message, add a suffix to the dbus service name in the message body to obtain a new dbus service name, where the suffix is the container name when the container is created, and then insert the dbus service name and the new dbus service name as a key-value pair into the service name mapping table, that is, the service name mapping table records the service name before and after the modification of the dbus service declaration applied in the container, and finally forward the message body of the modified dbus service declaration message to the dbus bus;
[0048] If step S102 or step S103 obtains the result that the service name is already occupied, the message body of the dbus message is modified, a suffix is added to the service name field, the suffix name is the container name when the container is created, and then the name of the service name before and after the suffix is added is inserted into the service name mapping table as a key-value pair, and finally the dbus message is forwarded to the dbus bus.
[0049] If a dbus method call message is intercepted, the proxy process determines where the message is sent through the internally maintained service name mapping table, then modifies the destination field of the dbus message, and finally sends the message to the system bus for further forwarding. Specifically, the process proxy processes the dbus method call message sent by the application in the container to the dbus bus in the host machine by:
[0050] The proxy process queries the internally maintained service name mapping table and connection mapping table to query the new dbus service name and destination of the dbus method call message, and then modifies the message body of the dbus method call message, modifies the dbus service name to the new dbus service name obtained by the query, modifies the destination to the destination obtained by the query, and forwards the modified message body to the dbus bus.
[0051] If a dbus disconnection message is monitored, the proxy process deletes the dbus service to be disconnected from the service name mapping table and releases related resources. Specifically, the process proxy processes the dbus disconnection message sent by the application in the container to the dbus bus in the host machine including:
[0052] The proxy process obtains the dbus service name to be disconnected from the disconnect dbus connection message, queries the internally maintained service name mapping table for the dbus service name, obtains the new dbus service name of the disconnect dbus connection message, and queries the connection mapping table for the application that sent the message to obtain the corresponding destination, and then modifies the message body of the disconnect dbus connection message, modifies the dbus service name therein to the new dbus service name obtained by the query, modifies the destination to the destination obtained by the query, forwards the modified message body to the dbus bus, and finally deletes the new dbus service name and destination of the disconnect dbus connection message from the service name mapping table and the connection mapping table, and releases related resources, such as releasing the memory and resources allocated for this dbus service.
[0053] If the proxy process receives a message forwarding dbus message sent by the bus to the container, it forwards it to the application in the system. Specifically, the process proxy forwards the dbus message sent by the dbus bus in the host machine to the application in the container, including:
[0054] The proxy process queries the internally maintained connection mapping table to query the application corresponding to the destination of the message forwarding dbus message, and then modifies the destination in the message body of the message forwarding dbus message according to the queried application, so that the modified message body can be forwarded to the correct application in the container.
[0055] As an optional implementation, the process agent can also obtain the dbus service name in the message when forwarding the dbus message sent by the dbus bus in the host machine to the application in the container, query the internally maintained service name mapping table for the dbus service name, and obtain its original dbus service name. Then, when modifying the message body of the message forwarding dbus message, the new dbus service name therein is modified to the original dbus service name obtained by the query, so as to avoid the situation where the application cannot correctly parse the received message when the dbus service name of the message forwarding dbus message is the modified dbus service name.
[0056] Embodiment 2
[0057] This embodiment proposes a coexistence system of the same dbus service in a host machine and a container, including a microprocessor and a memory connected to each other, and the microprocessor is programmed or configured to execute the coexistence method of the same dbus service in a host machine and a container described in Embodiment 1.
[0058] This embodiment provides a computer-readable storage medium, in which a computer program or instruction is stored. The computer program or instruction is programmed or configured to execute the coexistence method of the same dbus service in the host machine and the container described in Embodiment 1 through a processor.
[0059] This embodiment also proposes a computer program product, including a computer program or instructions, which are programmed or configured to execute the coexistence method of the same dbus service in the host machine and the container described in Embodiment 1 through a processor.
[0060] In summary, the present invention discloses a coexistence method and system of the same dbus service in a host machine and a container. By using a proxy process running in a container, different dbus requests are monitored and intercepted between the container application and the dbus bus of the host machine, and messages are forwarded after processing. If a dbus service with the same name is found on the bus during the processing, the message body of the dbus request is modified, a suffix is added to the service name field, and then the message is forwarded to the system bus and recorded in a mapping table inside the proxy process, thereby achieving the coexistence of the same dbus service and solving the dbus conflict problem. The method has the following advantages:
[0061] The present invention fills the gap in the solution to the conflict between dbus services on the container and the host machine under the domestic operating system;
[0062] The dbus proxy method in the container based on the domestic operating system of the present invention can be applied to all domestic desktop operating systems developed based on Linux, and does not depend on the use on the Galaxy Kylin operating system mentioned in the specific implementation method;
[0063] The dbus proxy method in a container based on a domestic operating system of the present invention is a solution implemented inside the container and will not have any impact on the host machine.
[0064] Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the process Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0065] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.
Claims
1. A method for coexistence of the same dbus service in a host and a container, characterized in that: include: The proxy process running in the container is used to proxy the communication between the application in the container and the dbus bus in the host machine, and the dbus service name in the message sent by the application in the container to the dbus bus in the host machine is modified by the proxy process so that the dbus service of the application in the container and the dbus service of the same application in the host machine can communicate through the dbus bus at the same time, and the destination in the message sent by the dbus bus in the host machine to the application in the container is modified by the proxy process according to the corresponding relationship between the application in the container and the dbus connection in the host machine so that the application in the container can normally receive the message of the dbus bus; When the communication between the application in the container and the dbus bus in the host is performed by the proxy process running in the container, the process proxy processes the dbus service declaration message sent by the application in the container to the dbus bus in the host, including: S101, obtaining the dbus service name in the message body of the dbus service declaration message; S102, calling the function interface of the dbus bus to determine whether the dbus service name in the message body has been occupied, if it has been occupied, jump to step S104, otherwise jump to step S103; S103, calling the function interface of the dbus bus to obtain the activatable dbus service list, and judging whether the dbus service name in the message body is in the activatable dbus service list, if not in the activatable dbus service list, directly forwarding the message body of the dbus service declaration message to the dbus bus, ending and exiting; otherwise, jumping to step S104; S104, modify the message body of the dbus service declaration message, add a suffix to the dbus service name in the message body to obtain a new dbus service name, the suffix is the container name when the container is created, and then insert the dbus service name and the new dbus service name as a key-value pair into the service name mapping table, and finally forward the modified message body of the dbus service declaration message to the dbus bus.
2. The method for coexistence of the same dbus service in a host and a container according to claim 1, characterized in that: When the communication between the application in the container and the dbus bus in the host is performed by the proxy process running in the container, the process proxy processes the dbus method call message sent by the application in the container to the dbus bus in the host, including: The proxy process queries the internally maintained service name mapping table and connection mapping table to query the new dbus service name and destination of the dbus method call message, and then modifies the message body of the dbus method call message, modifies the dbus service name to the new dbus service name obtained by the query, modifies the destination to the destination obtained by the query, and forwards the modified message body to the dbus bus.
3. The method for coexistence of the same dbus service in a host and a container according to claim 1, characterized in that: When the communication between the application in the container and the dbus bus in the host is performed by the proxy process running in the container, the process proxy processes the dbus connection disconnection message sent by the application in the container to the dbus bus in the host, including: The proxy process queries the internally maintained service name mapping table and connection mapping table to query the new dbus service name and destination of the disconnect dbus connection message, and then modifies the message body of the disconnect dbus connection message, modifies the dbus service name therein to the new dbus service name obtained by the query, modifies the destination to the destination obtained by the query, forwards the modified message body to the dbus bus, and finally deletes the new dbus service name and destination of the disconnect dbus connection message from the service name mapping table and the connection mapping table.
4. The method for coexistence of the same dbus service in a host and a container according to claim 1, characterized in that: When the communication between the application in the container and the dbus bus in the host is performed by the proxy process running in the container, the process proxy forwards the dbus message sent by the dbus bus in the host to the application in the container, including: The proxy process queries the internally maintained connection mapping table to query the application corresponding to the destination of the message forwarding dbus message, and then modifies the destination in the message body of the message forwarding dbus message according to the queried application, so that the modified message body can be forwarded to the correct application in the container.
5. The method for coexistence of the same dbus service in a host and a container according to claim 1, characterized in that: The proxy process runs as a daemon process in the container, starts running when the container is created, and exits running when the container is destroyed so that the life cycle of the proxy process is consistent with the life cycle of the container.
6. The method for coexistence of the same dbus service in a host and a container according to claim 1, characterized in that: The proxy process monitors the connection request of the application in the container by monitoring a Unix domain socket. After monitoring the connection request, the proxy process will apply for a real connection from the dbus bus and record the application and the connection destination in a connection mapping table maintained internally.
7. A coexistence system of the same dbus service in a host and a container, comprising a microprocessor and a memory connected to each other, characterized in that: The microprocessor is programmed or configured to execute the coexistence method of the same dbus service in the host and the container as described in any one of claims 1 to 6.
8. A computer-readable storage medium having a computer program or instruction stored therein, characterized in that: The computer program or instruction is programmed or configured to execute the coexistence method of the same dbus service in the host machine and the container described in any one of claims 1 to 6 through a processor.
9. A computer program product comprising a computer program or instructions, characterized in that The computer program or instruction is programmed or configured to execute the coexistence method of the same dbus service in the host machine and the container described in any one of claims 1 to 6 through a processor.
Citation Information
Patent Citations
MPI application performance optimization method and system in container environment
CN113076176A
Docker container security log analysis method and system based on hadoop distributed file system in cloud environment
KR101810762B1
Command execution method and device
CN112650557A
Application software cross-version compatible operation method, system and device and storage medium
CN114780950A