File: profile.c

package info (click to toggle)
mongrel2 1.12.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 6,020 kB
  • sloc: ansic: 39,099; python: 2,833; sql: 1,555; javascript: 1,202; sh: 467; makefile: 360; asm: 189; yacc: 145; php: 73; awk: 28; sed: 5
file content (49 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download | duplicates (5)
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
#include "procer.h"
#include <dbg.h>

bstring Profile_read_setting(bstring path, const char *file)
{
    bstring target = bformat("%s/%s", bdata(path), file);
    bstring data = NULL;
    FILE *test_file = NULL;

    test_file = fopen(bdata(target), "r"); 
    check(test_file, "Failed to open %s file that's required.", 
            bdata(target));

    data = bgets((bNgetc)fgetc, test_file, '\n');
    if(data) btrimws(data);


error:
    // fallthrough on purpose
    if(test_file) fclose(test_file);
    bdestroy(target);
    return data;
};


int Profile_check_setting(bstring path, const char *file)
{
    bstring target = bformat("%s/%s", bdata(path), file);
    int rc = access(bdatae(target, ""), R_OK);
    bdestroy(target);

    return rc == 0;
}


Profile *Profile_load(bstring profile_dir)
{
    Profile *prof = calloc(sizeof(Profile), 1);
    check_mem(prof);

    prof->command = bformat("%s/run", bdata(profile_dir));
    prof->pid_file = Profile_read_setting(profile_dir, "pid_file");
    prof->restart = Profile_check_setting(profile_dir, "restart");

    return prof;

error:
    return NULL;
}