summaryrefslogtreecommitdiffstats
path: root/src/detection/initsystem/initsystem_haiku.c
blob: 04857bca30765981f0f1892a46935c821453157e (plain) (blame)
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
#include "initsystem.h"
#include "common/strutil.h"
#include "common/haiku/version.h"
#include "common/io.h"

#include <OS.h>
#include <unistd.h>

const char* ffDetectInitSystem(FFInitSystemResult* result) {
    // Since it runs first, registrar does not know about it,
    // so we can't query be_roster for it.
    const char* path = "/boot/system/servers/launch_daemon";
    if (!ffPathExists(path, FF_PATHTYPE_FILE)) {
        return "launch_daemon is not found";
    }

    ffStrbufSetStatic(&result->exe, path);
    ffStrbufSetStatic(&result->name, "launch_daemon");
    result->pid = 0;

    team_info teamInfo;
    int32 cookie = 0;
    while (get_next_team_info(&cookie, &teamInfo) == B_OK) {
        if (ffStrEquals(teamInfo.args, path)) {
            result->pid = (uint32_t) teamInfo.team;
            break;
        }
    }

    if (instance.config.general.detectVersion) {
        ffGetFileVersion(path, &result->version);
    }

    return NULL;
}