-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
38 lines (33 loc) · 976 Bytes
/
main.c
File metadata and controls
38 lines (33 loc) · 976 Bytes
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
#include "utils.h"
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]){
int opt;
bool is_saved_flag = false;
while ((opt = getopt(argc, argv, "s")) != -1) {
switch (opt) {
case 's':
is_saved_flag = true;
break;
default:
fprintf(stderr, "Usage: %s [-s] <service_name>\n", argv[0]);
return 1;
}
}
if (optind >= argc){
fprintf(stderr, "Error: No service name provided.\n");
return 1;
}
char *service_name = argv[optind];
if (read_and_save_service_log(service_name, is_saved_flag)) {
if (is_saved_flag) {
printf("Successfully saved logs for '%s' to '%s.log'\n", service_name, service_name);
}
return 0;
} else {
fprintf(stderr, "Failed to retrieve logs for service: %s\n", service_name);
return 1;
}
}