-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservicemaster.c
65 lines (57 loc) · 1.84 KB
/
servicemaster.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "sm_err.h"
#include "display.h"
#include "bus.h"
/**
* Displays a welcome message with basic usage and security information.
*/
static void show_welcome_message()
{
const char *welcome_text =
"Welcome to ServiceMaster!\n\n"
"This tool allows you to manage systemd units through an intuitive interface.\n\n"
"SECURITY GUIDELINE:\n"
"- Only root can manage system services\n"
"- Regular users can only manage their own user services\n\n"
"Press ENTER to continue...";
display_status_window(welcome_text, "ServiceMaster " D_VERSION);
}
/**
* Handles user input and performs various operations on systemd services.
* This function is responsible for:
* - Handling user input from the keyboard, including navigation, service operations, and mode changes
* - Updating the display based on the current state and user actions
* - Calling appropriate functions to perform service operations (start, stop, restart, etc.)
* - Reloading the service list when necessary
*/
void wait_input()
{
int rc;
sd_event *ev = NULL;
rc = sd_event_default(&ev);
if (rc < 0)
sm_err_set("Cannot fetch default event handler: %s\n", strerror(-rc));
rc = sd_event_loop(ev);
if (rc < 0)
sm_err_set("Cannot run even loop: %s\n", strerror(-rc));
sd_event_unref(ev);
return;
}
/**
* The main entry point of the application.
* This function initializes the screen, retrieves all systemd services,
* filters them, and then enters a loop to wait for user input.
* The function returns 0 on successful exit, or -1 on error.
*/
int main()
{
if (geteuid())
display_set_bus_type(USER);
else
display_set_bus_type(SYSTEM);
bus_init();
display_init();
show_welcome_message();
display_redraw(bus_currently_displayed());
wait_input();
return 0;
}