summaryrefslogtreecommitdiff
path: root/src/non_critical/_tools.c
blob: 4b6159dd83539b5d5f08ef8226ec0bfb7cc47a68 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <string.h>

int check_root() {
    if(getuid() == 0) {
        return 1;
    }
    return 0;
}

int check_pid(int pid) {
    if(getpid() == pid) {
        return 1;
    }
    return 0;
}


char* get_os_name() {
    FILE* file = fopen("/etc/os-release", "r");
    if (file == NULL) {
        perror("fopen");
        return NULL;
    }

    char line[256];
    while (fgets(line, sizeof(line), file)) {
        char* name = strstr(line, "NAME=");
        if (name != NULL) {
            name += 5; // skip "NAME="
            char* end = strchr(name, '\n');
            if (end != NULL) {
                *end = '\0';
            }
            return name;
        }
    }

    fclose(file);
    return NULL;
}

char* get_desktop_server() {
    if(getenv("XDG_SESSION_TYPE") != NULL) { 
        return getenv("XDG_SESSION_TYPE");
    } else {
        return NULL; 
    }
}