Method and apparatus for processing restart instruction of network device
By introducing a global variable into the network device kernel to uniformly determine the configuration data saving status, generating a prompt and confirming before saving or restarting, the problem of configuration loss during network device restart is solved, reducing memory consumption and development difficulty.
Patent Information
- Application Number
- CN202211327033.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-26
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2042-10-26
AI Technical Summary
In existing technologies, when a network device restarts, the configuration is lost because it is not saved in memory, which affects the stable operation of the device. Furthermore, the command registration process increases memory consumption and development difficulty.
Add global variables g_write_file_flag, g_cli_pid, and g_cfg_change to the system kernel of the network device. Use these variables to uniformly determine whether the configuration data should be saved, generate a prompt message and display it on the command line. After the user confirms, the configuration is saved or the device is restarted.
It reduces the workload of developers, avoids misjudgments due to configuration loss, reduces memory consumption, and improves device stability.
Smart Images

Figure CN115904509B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the field of computer information processing, and in particular, to a reboot instruction processing method and device of a network device, an electronic device, and a computer readable medium. BACKGROUND
[0002] An administrator can usually maintain a network device through a web or a command line. The web refers to that the administrator can access a web server of the network device using a browser, log in to the device, and then operate the device on the browser to issue a configuration to the device. The command line is an interactive terminal interface, and the administrator can access the device through a console, telnet, ssh, or the like, and input a command at a prompt to maintain the device.
[0003] There are a large number of configurations in a network device. In order to improve the efficiency of configuring the device, batch processing of the configurations through the command line is usually performed. In order to avoid frequent operations on files and reduce the efficiency of configuring the device, some data that needs to be saved in a configuration file is saved in a memory. The data saved in the memory is easy to lose, and the data saved in the memory will be lost when the device is restarted. Therefore, after the configurations are performed through the command line, a configuration personnel needs to manually execute a write file command to save the data in the memory to the configuration file. If the configuration personnel forgets to execute the write file command after the configurations are performed through the command line, the configurations saved in the memory will be lost when the device is restarted, which causes a major network problem of the device. Therefore, a method capable of solving the loss of configurations is very important for stable operation of the network device.
[0004] The above information disclosed in the background section is only intended to enhance the understanding of the background of the present application, and thus it can include information that does not constitute the prior art that is known to those of ordinary skill in the art. SUMMARY
[0005] Therefore, the present application provides a reboot instruction processing method and device of a network device, an electronic device, and a computer readable medium, which can reduce the workload of a developer developing a command, avoid misjudgment due to incorrect registration of the command, and reduce consumption of a memory of the device by the command.
[0006] Other characteristics and advantages of the present application will become apparent from the following detailed description, or will be learned by practice of the present application.
[0007] According to an aspect of the present application, a method for processing a restart instruction of a network device is provided. The method comprises: after the network device obtains a restart instruction from a user, calling a first global variable; when the first global variable is a valid value, generating prompt information that configuration data is not saved; displaying the prompt information in a command line of the user; restarting the network device according to an operation of the user; or storing the unsaved configuration data before restarting the network device according to the operation of the user.
[0008] In an exemplary embodiment of the present application, the method further comprises: adding a first global variable for displaying whether there is unsaved configuration data in a system kernel of the network device; adding a second global variable for saving a command process number in the system kernel of the network device; and adding a third global variable for recording whether a command process operates on a configuration file in the system kernel of the network device.
[0009] In an exemplary embodiment of the present application, the method further comprises: the network device receiving a write operation command of a system file from a user; calling an entry function in a kernel mode based on the write operation command; and the entry function assigning values to the second global variable and / or the third global variable according to the write operation command.
[0010] In an exemplary embodiment of the present application, the entry function assigning values to the second global variable and / or the third global variable according to the write operation command comprises: the entry function obtaining the write operation command; judging whether a process number of a current call is equal to the second global variable; and when the process number of the current call is equal to the second global variable and a current operation is located in a non-configuration partition, assigning a first preset value to the third global variable.
[0011] In an exemplary embodiment of the present application, the entry function assigning values to the second global variable and / or the third global variable according to the write operation command further comprises: when the process number of the current call is equal to the second global variable and the current operation is located in a configuration partition, not changing the assignment of the third global variable.
[0012] In an exemplary embodiment of the present application, the process number of the current call being equal to the second global variable and the current operation being located in the non-configuration partition comprises: the process number of the current call being equal to the second global variable; and a file path of a current operation file not being a preset path.
[0013] In an example embodiment of the present application, further comprising: determining whether the user command is a configuration command when the command line service process of the network device receives the user command; assigning the third global variable to a second preset value when the user command is a configuration command; and executing the user command.
[0014] In an example embodiment of the present application, further comprising: obtaining a value of a third global variable after executing the user command; and assigning the first global variable to a valid value when the third global variable is the second preset value.
[0015] In an example embodiment of the present application, further comprising: assigning the first global variable to an invalid value after the network device executes a write document command.
[0016] According to an aspect of the present application, a network device restart instruction processing apparatus is provided, which comprises: an instruction module configured to obtain a first global variable after the network device obtains a restart instruction from a user; an information module configured to generate prompt information that configuration data is not saved when the first global variable is a valid value; a display module configured to display the prompt information in a command line of the user; and a restart module configured to restart the network device according to an operation of the user, or store the unsaved configuration data and then restart the network device according to the operation of the user.
[0017] According to an aspect of the present application, an electronic device is provided, which comprises: one or more processors; a storage device configured to store one or more programs; and when the one or more programs are executed by the one or more processors, the one or more processors implement the method as described above.
[0018] According to an aspect of the present application, a computer readable medium is provided, which stores a computer program, and the program is executed by a processor to implement the method as described above.
[0019] According to the network device restart instruction processing method, apparatus, electronic device and computer readable medium of the present application, after the network device obtains a restart instruction from a user, a first global variable is obtained; when the first global variable is a valid value, prompt information that configuration data is not saved is generated; the prompt information is displayed in a command line of the user; the network device is restarted according to an operation of the user, or the network device is restarted after the unsaved configuration data is stored according to the operation of the user, which can reduce the workload of a developer developing a command, avoid misjudgment due to incorrect registration of the command, and reduce the consumption of device memory by the command.
[0020] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application, as claimed. BRIEF DESCRIPTION OF DRAWINGS
[0021] The above and other objects, features and advantages of the present application will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings in which:
[0022] Figure 1 is a system block diagram of a method and apparatus for processing a restart instruction of a network device according to an example embodiment.
[0023] Figure 2 is a flowchart of a method for processing a restart instruction of a network device according to an example embodiment.
[0024] Figure 3 is a flowchart of a method for processing a restart instruction of a network device according to another example embodiment.
[0025] Figure 4 is a flowchart of a method for processing a restart instruction of a network device according to another example embodiment.
[0026] Figure 5 is a flowchart of a method for processing a restart instruction of a network device according to another example embodiment.
[0027] Figure 6 is a block diagram of an apparatus for processing a restart instruction of a network device according to an example embodiment.
[0028] Figure 7 is a block diagram of an electronic device according to an example embodiment.
[0029] Figure 8 is a block diagram of a computer readable medium according to an example embodiment. DETAILED DESCRIPTION
[0030] Example embodiments now will be described more fully hereinafter with reference to the accompanying drawings. Example embodiments may, however, be implemented in many different forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of example embodiments to those skilled in the art. Like reference numerals refer to like elements throughout the figures and specification.
[0031] Moreover, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the application. One skilled in the relevant art will recognize, however, that the application can be practiced without one or more of the specific details, or with other methods, components, materials, and so forth. In other instances, well-known structures, devices, implementations, or operations are not shown or described in detail to avoid obscuring aspects of the application.
[0032] The block diagrams in the drawings show only the functionality and the relation between the functional entities, and not necessarily the physical arrangement of the entities. That is, the functional entities can be implemented in software, or in hardware, or in a combination of software and hardware, or in different network and / or processor devices and / or microcontroller devices.
[0033] The flow diagrams shown in the drawings are merely examples of possible flow diagrams, and not necessarily all of the content and operations / steps, and not necessarily executed in the order described. For example, some operations / steps can be broken down, and some operations / steps can be combined or partially combined, so the actual execution order can be changed according to the actual situation.
[0034] It should be understood that although the terms first, second, third, etc. can be used herein to describe various components, these components should not be limited by these terms. These terms are used only to distinguish one component from another. Thus, a first component discussed below could be termed a second component without departing from the teachings of the present disclosure. As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0035] Those skilled in the art can understand that the modules or flows in the drawings are only schematic diagrams of example embodiments, and are not necessarily required to implement the present application, and therefore cannot be used to limit the protection scope of the present application.
[0036] The technical abbreviations involved in the present application are explained as follows:
[0037] System call: The main function of the operating system is to manage hardware resources and provide a good environment for application developers to make the application more compatible. In order to achieve this purpose, the kernel provides a series of multi-kernel functions with predetermined functions, which are presented to the user through a set of interfaces called system calls. System calls pass the application's request to the kernel, call the corresponding kernel function to complete the required processing, and return the processing result to the application.
[0038] Write file command: This command will write all memory configurations of the device into the configuration file.
[0039] Command line: a service program running on a device that provides functions such as parsing commands and executing commands.
[0040] The present applicant finds that in the prior art, when registering a command line, view information, module information, command prototype, command execution function, command help function, and other information of the command are added to the structure array of cmd_element. A mem_flag flag is added in the structure to indicate whether the data of the command is saved in memory. When mem_flag is equal to 1, it indicates that the configuration is saved in memory. When mem_flag is equal to 0, it indicates that the configuration is not saved in memory. A global variable g_mem_flag is added in the kernel to indicate whether the configuration has changed. When g_mem_flag is equal to 1, it indicates that the configuration has changed. When g_mem_flag is equal to 0, it indicates that the configuration has not changed. When the configuration is performed through the command line, the command line framework parses the input command, finds the matching command by traversing the registered command structure, and obtains the command line structure of the command. The mem_flag flag in the command structure is checked. If mem_flag is equal to 1, g_mem_flag is assigned a value of 1. After the write file command is executed, g_mem_flag is assigned a value of 0.
[0041] After the command line executes the restart device command, it is checked whether g_mem_flag is not 0. If it is equal to 0, the device is directly restarted. If it is not equal to 0, it indicates that the configuration has changed. The command line prints a prompt for the next operation, and the prompt information is “System configuration has been modified. Save? (Y / N) [N]:”. If the user inputs N, the device will cancel saving the configuration data in memory and directly restart the device. After the device is restarted, all data in the memory will be lost. If Y is input, the device executes the wirte file command to save the memory configuration to the configuration file and then executes the restart process.
[0042] In the prior art, the mem_flag is added in the command structure when registering the command, which increases the memory space occupied by each command;
[0043] In the prior art, each configuration needs to be set separately whether to save in memory when registering. The developer needs to consider assigning the correct value to mem_flag when registering the command, which brings a huge workload to the developer;
[0044] If the mem_flag of some commands is set incorrectly in the prior art, for example, the field is not set for a new command, the field is not set for an old command, or the new command is set incorrectly, the configuration of the command will still be lost after restart, that is, there is still a risk of configuration loss.
[0045] In view of the technical defects in the prior art, the present application provides a restart instruction processing method of a network device, which can uniformly determine whether all configuration commands are saved in memory without increasing memory consumption and command development difficulty.
[0046] The content of the present application will be described in detail below with the help of specific embodiments.
[0047] Figure 1 is a system block diagram of a restart instruction processing method and device of a network device according to an exemplary embodiment.
[0048] As shown in Figure 1 , the system architecture 10 can include terminal devices 101, 102, 103, a network 104, and a network device 105. The network 104 is used to provide a communication link medium between the terminal devices 101, 102, 103 and the network device 105. The network 104 can include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0049] A user can use the terminal devices 101, 102, 103 to interact with the network device 105 through the network 104 to receive or send configuration instructions, etc. The terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smartphones, tablet computers, laptop computers, and desktop computers, etc.
[0050] After the network device 105 obtains a restart instruction, for example, by the terminal devices 101, 102, 103, the network device 105 can call a first global variable; when the first global variable is a valid value, for example, the network device 105 can generate a prompt information that the configuration data is not saved; the network device 105 can display the prompt information in the command line of the user; the network device 105 can restart according to the operation of the user; or the network device 105 can store the unsaved configuration data before restarting.
[0051] The network device 105 can also increase a first global variable for displaying whether there is unsaved configuration data; the network device 105 can also increase a second global variable for saving the command process number; the network device 105 can also increase a third global variable for recording whether the command process operates on the configuration file.
[0052] The network device 105 can also receive a write operation command of a terminal device 101, 102, 103 on a system file, for example; the network device 105 can also invoke an entry function in the kernel mode to process based on the write operation command, for example; the network device 105 can also assign values to the second global variable and / or the third global variable according to the write operation command, for example.
[0053] The command line service process of the network device 105 can also receive a user command, for example; determine whether the user command is a configuration command; assign the third global variable as a second preset value when the user command is a configuration command; and execute the user command.
[0054] The network device 105 can also obtain the value of the third global variable after executing the user command; and assign the first global variable as a valid value when the third global variable is the second preset value.
[0055] The network device 105 can also assign the first global variable as an invalid value after executing the write document command.
[0056] The network device 105 can be a server of an entity, and can also be composed of multiple servers, for example; it should be noted that the network device restart instruction processing method provided in the embodiments of the present application can be executed by the network device 105, and accordingly, the network device restart instruction processing apparatus can be arranged in the network device 105. The operation terminal for inputting the configuration command provided for the user is generally located in the terminal device 101, 102, 103.
[0057] In one embodiment, a first global variable for displaying whether there is unsaved configuration data can be added in the system kernel of the network device; a second global variable for saving the command process number can be added in the system kernel of the network device; and a third global variable for recording whether the command process operates on the configuration file can be added in the system kernel of the network device.
[0058] In an actual application, a global variable g_write_file_flag (first global variable) can be added in the kernel to save whether the current device has memory configuration, 1 indicating that there is memory configuration, and 0 indicating that there is no memory configuration; the initial value of g_write_file_flag is 0.
[0059] A global variable g_cli_pid (second global variable) can also be added in the kernel to save the command line process number; the command line service program process number is saved in the kernel global variable g_cli_pid through a system call each time the command line service program is started.
[0060] A global variable g_cfg_change (third global variable) can also be added to the kernel to save a flag indicating whether the command line program performs a write operation on the configuration file.
[0061] Figure 2 Fig. 1 is a flowchart illustrating a method for processing a restart instruction of a network device according to an exemplary embodiment. The method 20 for processing a restart instruction of a network device comprises at least steps S202 to S208.
[0062] As shown in S202, after the network device obtains the restart instruction from a user, a first global variable is invoked. The first global variable is g_write_file_flag. Figure 2
[0063] In S204, when the first global variable is a valid value, a prompt message is generated to indicate that the configuration data is not saved. g_write_file_flag is used to save whether there is memory configuration in the current device, 1 indicating that there is memory configuration and 0 indicating that there is no memory configuration. When g_write_file_flag is a valid value, i.e., 1, it means that there is unsaved configuration data in the current device, and thus the prompt message is generated.
[0064] In one embodiment, the method further comprises: after the network device executes a write document command, the first global variable is assigned an invalid value. Each time the write file command is executed, g_write_file_flag is re-assigned 0.
[0065] In S206, the prompt message is displayed in a command line of the user. The next step of operation can be printed in the command line, and the prompt message can be "System configuration has been modified. Save? (Y / N) [N]:".
[0066] In S208, the network device is restarted according to the operation of the user.
[0067] In S210, the network device is restarted after the unsaved configuration data is stored according to the operation of the user.
[0068] If the user inputs N, the device will cancel saving the configuration data in the memory and directly restart the device, and the data in the memory will be lost after the device is restarted. If the user inputs Y, the device executes the write file command to save the memory configuration to the configuration file and then executes the restart process.
[0069] According to the network equipment restart instruction processing method of the application, after the network equipment obtains the restart instruction from the user, the first global variable is called; when the first global variable is a valid value, prompt information that configuration data is not saved is generated; the prompt information is displayed in the command line of the user; the network equipment is restarted according to the operation of the user; or the unsaved configuration data is stored before the network equipment is restarted, which can reduce the workload of the developer, avoid misjudgment due to incorrect registration of the command, and reduce the consumption of the command to the device memory.
[0070] It should be clearly understood that the application describes how to form and use specific examples, but the principles of the application are not limited to any details of these examples. On the contrary, based on the teachings of the disclosure of the application, these principles can be applied to many other embodiments.
[0071] Figure 3 A flowchart of a network equipment restart instruction processing method according to another exemplary embodiment is shown. Figure 3 The flowchart 30 shown is for Figure 2 The detailed description of S102 in the flowchart shown.
[0072] As shown in Figure 3 In S302, the entry function receives the write operation command.
[0073] In S304, whether the current process number of the call is equal to the second global variable.
[0074] In S306, whether the file path of the current operation starts with the configuration partition path.
[0075] In S308, the third global variable is assigned a first preset value, which can be 1.
[0076] In S310, the file write operation is performed.
[0077] In one embodiment, the network equipment also includes: receiving a write operation command of a system file from a user; calling a kernel-level entry function based on the write operation command to process; the entry function assigns values to the second global variable and / or the third global variable according to the write operation command.
[0078] The entry function assigns values to the second global variable and / or the third global variable based on the write operation command, including: the entry function obtaining the write operation command; determining whether the currently invoked process ID is equal to the second global variable; and assigning the third global variable a first preset value when the currently invoked process ID is equal to the second global variable and the current operation is located in a non-configuration partition. When the currently invoked process ID is equal to the second global variable and the current operation is located in a configuration partition, the value of the third global variable is not changed.
[0079] Specifically, when the process ID of the currently invoked process is equal to the second global variable, and the file path of the currently operated file is not a preset path, the third global variable is assigned the first preset value.
[0080] In a Linux system, all user-space programs performing file write operations ultimately need to execute the kernel-mode `sys_write` function via a system call. In other words, `sys_write` is the entry point for write operations in the operating system. Command-line service programs that modify device configuration files also require write operations to the configuration files.
[0081] Add the following process to the kernel write operation entry function `sys_write`: Check if the process ID of the current system call is equal to `g_cli_pid`. If they are not equal, do not assign a value to the global variable `g_cfg_change`. If they are equal, it indicates that the current write operation is a command-line service program call. Then, further check if the file path of the current write operation is a configuration partition. Typically, Linux systems require external storage to be mounted to a directory for access, such as ` / cfg / `. Therefore, if the file path starts with ` / cfg / `, it means the file is a configuration partition file and will not be lost after a reboot. If the file path does not start with ` / cfg / `, it means the file is not a configuration partition file and will be lost after a reboot. If the current write operation's file path is a configuration partition path, assign the global variable `g_cfg_change` to 1 (the first preset value); otherwise, do not assign a value to the global variable `g_cfg_change`.
[0082] Figure 4 This is a flowchart illustrating a method for processing restart commands for a network device according to another exemplary embodiment. Figure 4 The process shown in step 40 is... Figure 2 The process shown is described in detail for S102 "".
[0083] like Figure 4 As shown, in S402, when the command line service process of the network device receives a user command, it determines whether the user command is a configuration command.
[0084] In S404, when the user command is a configuration command, the third global variable is assigned a second preset value.
[0085] In S406, the user command is executed.
[0086] In S408, after the user command is executed, the value of the third global variable is obtained.
[0087] In S410, when the third global variable is the second preset value, the first global variable is assigned a valid value.
[0088] After the command line service program receives a command, it is determined whether the current executable command is a configuration command (usually, a configuration command is registered in a configuration view, and the command starts with a non-show key). If it is a configuration command, a system call is invoked to assign g_cfg_change to 0 (a second preset value), and then the function flow corresponding to the command is executed. After the command is executed successfully, the g_cfg_change state is obtained through a system call. If the g_cfg_change value is 1 (a first preset value), it is indicated that the current configuration command has invoked the system call to execute the sys_write function to save the configuration to the configuration file. If the g_cfg_change value is 0 (the second preset value), it is indicated that the current configuration command does not save the configuration to the configuration file, that is, only saves the configuration to the memory. At this time, the kernel global variable g_write_file_flag is assigned to 1 through a system call, indicating that the save configuration operation needs to be performed through the write file command.
[0089] Figure 5 FIG. 40 is a flowchart of a method for processing a restart instruction of a network device according to another example embodiment. Figure 4 The flowchart 40 is described in detail with reference to Figure 2 the flowchart.
[0090] As shown in Figure 5 S502, a user inputs a command.
[0091] In S504, it is determined whether the command is a configuration command.
[0092] In S506, the command is executed.
[0093] In S508, a third global variable is set to a second preset value, and the command is executed. The second preset value may be, for example, 0.
[0094] In S510, it is determined whether the command is executed successfully.
[0095] In S512, it is determined whether the third global variable is the second preset value.
[0096] In S514, the first global variable is assigned a value of valid.
[0097] The network device restart instruction processing method of the present application adds a global variable g_cli_pid in the kernel to save the command line process number, and judges whether the current process number is the command line service program in the kernel write operation entry function.
[0098] The network device restart instruction processing method of the present application judges whether the current write operation file is a configuration file under the configuration partition according to whether the file currently operated is started with the configuration partition mounting directory path in the kernel write operation entry function.
[0099] The network device restart instruction processing method of the present application judges whether the current configuration command saves the configuration into the configuration file according to whether g_cfg_change changes before and after the command execution after the command line program judges that the current command is a configuration command.
[0100] The network device restart instruction processing method of the present application provides a method for the command line framework to uniformly judge whether all configuration commands save the configuration into the memory. This scheme does not need to modify the command registration process, thus reducing the workload of the developers to develop the commands and avoiding misjudgment due to not correctly registering the commands. No new field is added during the command registration, thus reducing the consumption of the device memory by the commands.
[0101] Those skilled in the art can understand that all or part of the steps of the above embodiments are implemented as a computer program executed by a CPU. When the computer program is executed by the CPU, the above functions defined by the above method provided by the present application are executed. The program can be stored in a computer readable storage medium, which can be a read-only memory, a disk or an optical disk, etc.
[0102] In addition, it should be noted that the above figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present application, and are not for limiting purposes. It is easy to understand that the processes shown in the above figures do not indicate or limit the time sequence of the processes. In addition, it is also easy to understand that the processes can be executed synchronously or asynchronously, for example, in multiple modules.
[0103] The following is a device embodiment of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
[0104] Figure 6 is a block diagram of a network device restart instruction processing device according to an exemplary embodiment. As shown in Figure 6As shown, the network device restart instruction processing apparatus 60 comprises an instruction module 602, an information module 604, a display module 606 and a restart module 608. The network device restart instruction processing apparatus 60 can further comprise an increase module 610, an operation module 612 and a command module 614.
[0105] The instruction module 602 is configured to call a first global variable after the network device obtains a restart instruction from a user;
[0106] The information module 604 is configured to generate prompt information that configuration data is not saved when the first global variable is a valid value.
[0107] The display module 606 is configured to display the prompt information in a command line of the user.
[0108] The restart module 608 is configured to restart the network device according to an operation of the user, or store the unsaved configuration data before restarting the network device according to the operation of the user.
[0109] The increase module 610 is configured to add a first global variable for displaying whether there is unsaved configuration data in a system kernel of the network device, add a second global variable for saving a command process number in the system kernel of the network device, and add a third global variable for recording whether a command process operates a configuration file in the system kernel of the network device.
[0110] The operation module 612 is configured to receive a write operation command of a system file of the network device, call an entry function in a kernel mode to process based on the write operation command, and assign values to the second global variable and / or the third global variable according to the write operation command.
[0111] The command module 614 is configured to judge whether a user command is a configuration command when the command line service process of the network device receives the user command, assign the third global variable to a second preset value when the user command is the configuration command, and execute the user command. After executing the user command, a value of the third global variable is obtained, and the first global variable is assigned to a valid value when the third global variable is the second preset value.
[0112] The restart instruction processing device of the network device according to the application can reduce the workload of the developer of the command, avoid misjudgment due to incorrect registration of the command, and reduce the consumption of the memory of the device.
[0113] Figure 7 is a block diagram of an electronic device according to an exemplary embodiment.
[0114] The electronic device 700 according to this embodiment of the application will be described below with reference to Figure 7 . Figure 7 The electronic device 700 shown is merely an example and should not impose any limitation on the function and scope of use of the embodiments of the application.
[0115] As shown in Figure 7 , the electronic device 700 is in the form of a general computing device. The components of the electronic device 700 can include, but are not limited to, at least one processing unit 710, at least one storage unit 720, a bus 730 connecting different system components (including the storage unit 720 and the processing unit 710), a display unit 740, and the like.
[0116] The storage unit stores program codes that can be executed by the processing unit 710, so that the processing unit 710 performs the steps described in this specification according to various exemplary embodiments of the application. For example, the processing unit 710 can perform the steps as shown in Figure 2 , Figure 3 , Figure 4 , Figure 5 .
[0117] The storage unit 720 can include a readable medium in the form of a volatile storage unit, such as a random access memory (RAM) 7201 and / or a cache memory unit 7202, and can further include a read-only memory (ROM) 7203.
[0118] The storage unit 720 can also include program / utilities 7204 with a set of (at least one) program modules 7205, such as an operating system, one or more application programs, other program modules, and program data, each of which or some combination of which can include the implementation of a network environment.
[0119] Bus 730 can be one of several types of bus structures including a memory bus, memory controller, a peripheral bus, graphics bus, processing bus, or a local bus using any of a variety of bus architectures.
[0120] Electronic device 700 can also communicate with one or more external devices 700' such as a keyboard or pointing device, a Bluetooth device, or a
[0121] Those skilled in the art will readily recognize that the example embodiments described herein can be implemented in software, hardware, or a combination of software and hardware. In an example embodiment, the example embodiments can be implemented in software as an application running on one or more computers, servers, or other electronic devices. In an example embodiment, the example embodiments can be implemented as a computer program product, which can include one or more computer program elements descended in a computer readable medium for execution by, or to control the operation of, one or more electronic devices. Figure 8 As shown, the technical solutions according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, U disk, mobile hard disk, etc.) or network, and includes several instructions to make a computing device (which can be a personal computer, server, or network device, etc.) execute the above-mentioned method according to the embodiments of the present application.
[0122] The software product can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0123] Overall, the present disclosure provides a method for processing reboot instructions of a network device, which can uniformly determine whether all configuration commands are saved in memory without increasing memory consumption and command development difficulty. Specifically, a global variable g_cli_pid is added in the kernel to save the process number of the command line. Each time the command line service program is started, the process number of the command line service program is saved in the kernel global variable g_cli_pid through a system call. A global variable g_write_file_flag is added in the kernel to save whether the current device has memory configuration. 1 represents that there is memory configuration, and 0 represents that there is no memory configuration. The initial value of g_write_file_flag is 0. A global variable g_cfg_change is added in the kernel to save a flag indicating whether the command line program performs write operation on the configuration file. All user-mode programs of the linux system perform write operation on the file, and finally need to perform write operation on the file through the kernel-mode sys_write function by a system call, that is, the sys_write function is the entry function of the write operation of the operating system. The command line service program needs to perform write operation on the configuration file to modify the device configuration file. The following process is added in the kernel write operation entry function sys_write: it is judged whether the process number of the current system call is equal to g_cli_pid. If not, the global variable g_cfg_change is not assigned. If yes, it is judged whether the file path of the current write operation is the configuration partition. The external storage of the linux system needs to be mounted to a directory to be accessed, for example, mounted to the / cfg / directory. Therefore, it can be judged that if the file path starts with / cfg / , the file is the configuration partition file and will not be lost after reboot. If the file path does not start with / cfg / , the file is not the configuration partition file and will be lost after reboot. If it is judged that the file path of the current write operation is the configuration partition path, the global variable g_cfg_change is assigned to 1. Otherwise, the global variable g_cfg_change is not assigned.After the command line service program receives the command, it is determined whether the current executable command is a configuration command (generally, the configuration command is registered in the configuration view, and the command starts with a non-show key). If it is a configuration command, a system call is invoked to assign g_cfg_change to 0, and then the function flow corresponding to the command is executed. After the command is executed successfully, the g_cfg_change state is obtained through a system call. If the g_cfg_change value is 1, it indicates that the current configuration command has invoked the system call to execute the sys_write function to save the configuration to the configuration file. If the g_cfg_change value is 0, it indicates that the current configuration command does not save the configuration to the configuration file, that is, only saves the configuration to the memory. At this time, the kernel global variable g_write_file_flag is assigned to 1 through a system call, indicating that the save configuration operation needs to be performed through the write file command. After the command line executes the restart device command, it is checked whether g_write_file_flag is not 0. If it is equal to 0, the device is directly restarted. If it is not equal to 0, it indicates that the configuration has been changed, and a prompt for the next operation is printed on the command line. The prompt information is "System configuration has been modified. Save? (Y / N) [N]:". If the user inputs N, the device will cancel the saving of the configuration data in the memory and directly restart the device. After the device is restarted, the data in the memory will be completely lost. If Y is input, the device executes the write file command to save the memory configuration to the configuration file and then executes the restart process. Each execution of the write file command will reassign g_write_file_flag to 0. The method of the present disclosure uniformly judges whether all configuration commands save the configuration to the memory. The method does not need to modify the command registration process, thereby reducing the workload of the developers developing the commands, avoiding misjudgment due to the failure to correctly register the commands, and reducing the consumption of the device memory by the commands because no new field is added during the command registration.
[0124] The computer readable storage medium can include a data signal transported within a baseband or propagated as a carrier wave by a transmitting device, and can take any suitable form including but not limited to wireless, wireline, optical, cable, RF, etc., or any suitable combination of the foregoing. A computer readable storage medium can further be any medium that can be used to store or transfer data or instructions for use by, or in connection with, an instruction execution system, apparatus, or device. The instructions stored on the computer readable storage medium can be in any suitable form, including but not limited to compiled or interpreted object code.
[0125] The program code can be executed by one or more programmable processors, digital signal processors, ASICs, FPGAs, or microprocessors or microcontrollers under the control of operating software. The memory can be volatile memory or non-volatile memory. The volatile memory can be used for, but not limited to, caching, and the non-volatile memory can be used for, but not limited to, storage. The memory can be used for storing data or instructions, and / or any combination thereof.
[0126] The computer readable medium described above carries one or more programs, when the one or more programs are executed by the device, the computer readable medium causes the computer readable medium to realize the following functions: after the network device obtains the restart instruction from the user, the first global variable is called; when the first global variable is a valid value, prompt information that configuration data is not saved is generated; the prompt information is displayed in the command line of the user; the network device is restarted according to the operation of the user; or the unsaved configuration data is stored before the network device is restarted according to the operation of the user.
[0127] Those skilled in the art can understand that the above modules can be distributed in the device according to the description of the embodiment, and can also be changed in one or more devices different from the embodiment. The modules of the above embodiment can be combined into one module, or can be further split into a plurality of sub-modules.
[0128] Through the description of the above embodiment, those skilled in the art can easily understand that the example embodiment described herein can be realized by software, or realized by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a U disk, a mobile hard disk, etc.) or a network, and includes a plurality of instructions to make a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) execute the method according to the embodiment of the application.
[0129] The example embodiments of the present application are specifically shown and described above. It should be understood that the present application is not limited to the detailed structure, arrangement or implementation method described herein; on the contrary, the present application is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the appended claims.
Claims
1. A method for processing restart commands of a network device, characterized in that, include: In the system kernel of the network device, a first global variable is added to indicate whether there is unsaved configuration data, a second global variable is added to store the command process ID, and a third global variable is added to record whether the command process operates on the configuration file; After receiving the restart command from the user, the network device retrieves the first global variable; When the first global variable is a valid value, generate a message indicating that the configuration data has not been saved; The prompt message is displayed in the user's command line; Restart the network device according to the user's operation; or After storing the unsaved configuration data according to the user's operation, the network device is restarted. The network device receives user commands to write system files; The write operation command is used to call the kernel-mode entry function for processing; The entry function assigns values to the second global variable and / or the third global variable according to the write operation command, including: the entry function obtains the write operation command; determines whether the currently called process ID is equal to the second global variable; and when the currently called process ID is equal to the second global variable and the current operation is located in a non-configuration partition, assigns the third global variable a first preset value.
2. The method as described in claim 1, characterized in that, The entry function assigns values to the second global variable and / or the third global variable according to the write operation command, and further includes: When the process ID of the currently calling process is equal to the second global variable and the current operation is located in the configuration partition, the value of the third global variable is not changed.
3. The method as described in claim 1, characterized in that, The process ID of the current call is equal to the second global variable, and the current operation is located in a non-configuration partition, including: The process ID of the currently calling process is equal to the second global variable; and The file path of the currently operated file is not the default path.
4. The method as described in claim 1, characterized in that, Also includes: When the command-line service process of the network device receives a user command, it determines whether the user command is a configuration command. When the user command is a configuration command, the third global variable is assigned a second preset value; Execute the user command.
5. The method as described in claim 4, characterized in that, Also includes: After executing the user command, obtain the value of the third global variable; When the third global variable is the second preset value, the first global variable is assigned a valid value.
6. The method as described in claim 1, characterized in that, Also includes: After the network device executes the write document command, the first global variable is assigned an invalid value.
Citation Information
Patent Citations
Prompting method and device
CN109976798A