glusterfs

Форк
0
65 строк · 1.2 Кб
1
/*
2
  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3
  This file is part of GlusterFS.
4

5
  This file is licensed to you under your choice of the GNU Lesser
6
  General Public License, version 3 or any later version (LGPLv3 or
7
  later), or the GNU General Public License, version 2 (GPLv2), in all
8
  cases as published by the Free Software Foundation.
9
*/
10

11
#include <unistd.h>
12
#include <stdio.h>
13
#include "glusterfs/daemon.h"
14

15
int
16
os_daemon_return(int nochdir, int noclose)
17
{
18
    pid_t pid = -1;
19
    int ret = -1;
20
    FILE *ptr = NULL;
21

22
    ret = fork();
23
    if (ret)
24
        return ret;
25

26
    pid = setsid();
27

28
    if (pid == -1) {
29
        ret = -1;
30
        goto out;
31
    }
32

33
    if (!nochdir)
34
        ret = chdir("/");
35

36
    if (!noclose) {
37
        ptr = freopen(DEVNULLPATH, "r", stdin);
38
        if (!ptr)
39
            goto out;
40

41
        ptr = freopen(DEVNULLPATH, "w", stdout);
42
        if (!ptr)
43
            goto out;
44

45
        ptr = freopen(DEVNULLPATH, "w", stderr);
46
        if (!ptr)
47
            goto out;
48
    }
49

50
    ret = 0;
51
out:
52
    return ret;
53
}
54

55
int
56
os_daemon(int nochdir, int noclose)
57
{
58
    int ret = -1;
59

60
    ret = os_daemon_return(nochdir, noclose);
61
    if (ret <= 0)
62
        return ret;
63

64
    _exit(0);
65
}
66

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.