summaryrefslogtreecommitdiffstats
path: root/util/bbsctl.c
blob: bf66df3512349b0a5b2be3180f350e2c03086c00 (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
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
void usage(void)
{
    printf("usage:  bbsctl [start|stop|restart]\n");
    exit(0);
}

void startbbs(void)
{
    if( setuid(0) < 0 ){
    perror("setuid(0)");
    exit(1);
    }
    puts("starting mbbsd:  23"); system("/home/bbs/bin/mbbsd   23");
    puts("starting mbbsd:3000"); system("/home/bbs/bin/mbbsd 3000");
    puts("starting mbbsd:3001"); system("/home/bbs/bin/mbbsd 3001");
    puts("starting mbbsd:3002"); system("/home/bbs/bin/mbbsd 3002");
    puts("starting mbbsd:3003"); system("/home/bbs/bin/mbbsd 3003");
    puts("starting mbbsd:3004"); system("/home/bbs/bin/mbbsd 3004");
    puts("starting mbbsd:3005"); system("/home/bbs/bin/mbbsd 3005");
    puts("starting mbbsd:3006"); system("/home/bbs/bin/mbbsd 3006");
    puts("starting mbbsd:3007"); system("/home/bbs/bin/mbbsd 3007");
    puts("starting mbbsd:3008"); system("/home/bbs/bin/mbbsd 3008");
    puts("starting mbbsd:3009"); system("/home/bbs/bin/mbbsd 3009");
    puts("starting mbbsd:3010"); system("/home/bbs/bin/mbbsd 3010");
}

void stopbbs(void)
{
    char    buf[1024];
    int     pid;
    FILE    *fp = popen("/bin/ps -ax | /usr/bin/grep mbbsd | "
            "/usr/bin/grep listen", "r");
    while( fgets(buf, sizeof(buf), fp) != NULL ){
    sscanf(buf, "%d", &pid);
    printf("stopping %d\n", pid);
    kill(pid, 1);
    }
}

void restartbbs(void)
{
    stopbbs();
    startbbs();
}

int main(int argc, char **argv)
{
    if( argc == 1 )
    usage();
    if( strcmp(argv[1], "start") == 0 )
    startbbs();
    else if( strcmp(argv[1], "stop") == 0 )
    stopbbs();
    else if( strcmp(argv[1], "restart") == 0 )
    restartbbs();
    return 0;
}