summaryrefslogtreecommitdiffstats
path: root/tests/bugs/cli/bug-1169302.c
blob: 7c6b5fbf856002839164dbcad89d7d366abd68cc (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <errno.h>
#include <stdio.h>
#include <signal.h>

#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>

int keep_running = 1;

void
stop_running(int sig)
{
    if (sig == SIGTERM)
        keep_running = 0;
}

int
main(int argc, char *argv[])
{
    glfs_t *fs = NULL;
    int ret = 0;
    glfs_fd_t *fd = NULL;
    char *filename = NULL;
    char *logfile = NULL;
    char *host = NULL;

    if (argc != 5) {
        return -1;
    }

    host = argv[2];
    logfile = argv[3];
    filename = argv[4];

    /* setup signal handler for exiting */
    signal(SIGTERM, stop_running);

    fs = glfs_new(argv[1]);
    if (!fs) {
        return -1;
    }

    ret = glfs_set_volfile_server(fs, "tcp", host, 24007);
    if (ret < 0) {
        return -1;
    }

    ret = glfs_set_logging(fs, logfile, 7);
    if (ret < 0) {
        return -1;
    }

    ret = glfs_init(fs);
    if (ret < 0) {
        return -1;
    }

    fd = glfs_creat(fs, filename, O_RDWR, 0644);
    if (!fd) {
        return -1;
    }

    /* sleep until SIGTERM has been received */
    while (keep_running) {
        sleep(1);
    }

    ret = glfs_close(fd);
    if (ret < 0) {
        return -1;
    }

    ret = glfs_fini(fs);
    if (ret < 0) {
        return -1;
    }

    return 0;
}