~ubuntu-branches/debian/sid/rlinetd/sid

« back to all changes in this revision

Viewing changes to src/db.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2010-03-20 18:03:45 UTC
  • mfrom: (2.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320180345-x1srfbe2tg00ezsf
Tags: 0.7-1
* New upstream version.
* Recommend rsyslog instead of sysklogd (closes: #526922).
* update-inetd:
  + add support for enabling, disabling and removing entries;
  + use ucf for managing generated files;
  + ignore ucf files in rlinetd.conf;
  + make appropriate changes in  postinst and postrm scripts.
* Set debhelper compat level to 7
* Standards-Version: 3.8.4 (no changes). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <ctype.h>
 
2
#include <fcntl.h>
 
3
#include <netinet/in.h>
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
#include <string.h>
 
7
#include <sys/stat.h>
 
8
#include <sys/types.h>
 
9
#include <sysexits.h>
 
10
#include "config.h"
 
11
 
 
12
#ifdef HAVE_CAPABILITIES
 
13
#include <sys/capability.h>
 
14
#endif
 
15
 
 
16
#include "db.h"
 
17
#include "rlinetd.h"
 
18
#include "strings.h"
 
19
#include "error.h"
 
20
 
 
21
struct argvtab *argvs = NULL;
 
22
int numargvs = 0;
 
23
 
 
24
struct rlimit *rlimits = NULL;
 
25
int numrlimits = 0;
 
26
 
 
27
struct logtab *logtabs = NULL;
 
28
int numlogtabs = 0;
 
29
 
 
30
char **strings = NULL;
 
31
int numstrings = 0;
 
32
 
 
33
struct buftab *bufs = NULL;
 
34
int numbufs = 0;
 
35
 
 
36
struct oplist *oplists = NULL;
 
37
int numoplists = 0;
 
38
 
 
39
struct pidtab pidtabs[8] = {
 
40
        { 0, NULL, NULL, NULL, 0, NULL },
 
41
        { 0, NULL, NULL, NULL, 0, NULL },
 
42
        { 0, NULL, NULL, NULL, 0, NULL },
 
43
        { 0, NULL, NULL, NULL, 0, NULL },
 
44
        { 0, NULL, NULL, NULL, 0, NULL },
 
45
        { 0, NULL, NULL, NULL, 0, NULL },
 
46
        { 0, NULL, NULL, NULL, 0, NULL },
 
47
        { 0, NULL, NULL, NULL, 0, NULL }
 
48
};
 
49
 
 
50
struct semaphore *sems = NULL;
 
51
int numsems = 0;
 
52
 
 
53
#ifdef HAVE_CAPABILITIES
 
54
cap_t *caps;
 
55
int numcaps;
 
56
#endif
 
57
 
 
58
fd_set *fdsets = NULL;
 
59
int numfdsets = 0;
 
60
 
 
61
void pidtab_init() {
 
62
        memset(pidtabs, 0, 8 * sizeof(struct pidtab));
 
63
}
 
64
 
 
65
static struct pidtab *pidtab_new() {
 
66
        struct pidtab *p;
 
67
        
 
68
        p = (struct pidtab *)malloc(sizeof(struct pidtab));
 
69
        if (!p)
 
70
                rl_fatal(EX_SOFTWARE, _("ABORT - Can't allocate memory"));
 
71
        memset(p, 0, sizeof(struct pidtab));
 
72
        return p;
 
73
}
 
74
 
 
75
void pidtab_add(pid_t pid, int onexit, struct rl_instance *inst) {
 
76
        struct pidtab *p = pidtab_new();
 
77
        p->pid = pid;
 
78
        p->inst = inst;
 
79
        p->onexit = onexit;
 
80
        p->prev = pidtabs + (pid & 0x7);
 
81
        p->next = p->prev->next;
 
82
        p->prev->next = p;
 
83
        if(p->next)
 
84
                p->next->prev = p;
 
85
}
 
86
 
 
87
#ifdef BYTECODE_DEBUG
 
88
#define CHECK(tab,print) \
 
89
  fprintf(stderr, #tab " get %d, %d\n", i, num##tab); \
 
90
        if (i < 0 || i >= num##tab) { fprintf(stderr, #tab ", %d >= %d\n",  i, num##tab); return 0; } \
 
91
        else if (print)    fprintf(stderr, #tab "[%d] = %s\n", i, tab[i]); \
 
92
        fflush(stderr);
 
93
#else
 
94
#define CHECK(tab,print)
 
95
#endif
 
96
 
 
97
struct pidtab *pidtab_get(pid_t pid) {
 
98
        struct pidtab *p;
 
99
 
 
100
        p = pidtabs[pid & 0x7].next;
 
101
        if(!p)
 
102
                return NULL;
 
103
        do {
 
104
                if(p->pid == pid) {
 
105
                        return p;
 
106
                }
 
107
        } while((p = p->next));
 
108
        return NULL;
 
109
}
 
110
 
 
111
struct logtab *logtab_get(int i) {
 
112
        CHECK(logtabs, 0)
 
113
        return logtabs + i;
 
114
}
 
115
 
 
116
struct rlimit *rlimittab_get(int i) {
 
117
        CHECK(rlimits, 0)
 
118
        return rlimits + i;
 
119
}
 
120
 
 
121
struct argvtab *argvtab_get(int i) {
 
122
        CHECK(argvs, 0)
 
123
        return argvs + i;
 
124
}
 
125
 
 
126
#ifdef HAVE_CAPABILITIES
 
127
 
 
128
cap_t captab_get(int i) {
 
129
        return caps[i];
 
130
}
 
131
 
 
132
#endif /* HAVE_CAPABILITIES */
 
133
 
 
134
 
 
135
char *stringtab_get(int i) {
 
136
        CHECK(strings, 1)
 
137
        return strings[i];
 
138
}
 
139
 
 
140
struct buftab *buftab_get(int i) {
 
141
        CHECK(bufs, 1)
 
142
        return bufs + i;
 
143
}
 
144
 
 
145
rl_opcode_t *oplisttab_get(int i) {
 
146
        CHECK(oplists, 0)
 
147
        return oplists[i].ops_list;
 
148
}
 
149
 
 
150
struct semaphore *semaphore_get(int i) {
 
151
        CHECK(sems, 0)
 
152
        return sems + i;
 
153
}
 
154
 
 
155
fd_set *fdsettab_get(int i) {
 
156
        CHECK(fdsets, 0)
 
157
        return fdsets + i;
 
158
}
 
159
 
 
160
/* vim: set ts=2: */