-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.c
More file actions
27 lines (22 loc) · 760 Bytes
/
Copy pathparser.c
File metadata and controls
27 lines (22 loc) · 760 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
#include <stdio.h>
#include <string.h>
#include "main.h"
void parse_service(const char *path, service_t *svc) {
FILE *f = fopen(path, "r");
if (!f) return;
char line[MAX_LINE];
while (fgets(line, sizeof(line), f)) {
if (strncmp(line, "ExecStart=", 10) == 0)
strcpy(svc->exec, line + 10);
else if (strncmp(line, "After=", 6) == 0)
strcpy(svc->after, line + 6);
else if (strncmp(line, "User=", 5) == 0)
strcpy(svc->user, line + 5);
else if (strncmp(line, "Restart=always", 14) == 0)
svc->restart = 1;
}
svc->exec[strcspn(svc->exec, "\n")] = 0;
svc->after[strcspn(svc->after, "\n")] = 0;
svc->user[strcspn(svc->user, "\n")] = 0;
fclose(f);
}