blob: d3846b6de8b46b628568d9e7b6b163421ccc78f2 (
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright (c) 1994, 1995. Netscape Communications Corporation. All
* rights reserved.
*
* Use of this software is governed by the terms of the license agreement for
* the Netscape Communications or Netscape Comemrce Server between the
* parties.
*/
/* ------------------------------------------------------------------------ */
/*
* daemon.h: Things related to the accepting connections
*
* Rob McCool
*/
#ifndef DAEMON_H
#define DAEMON_H
#ifdef XP_WIN32
#include <nt/ntdaemon.h>
#else
#include "net.h"
#include "session.h"
#include <pwd.h> /* struct passwd */
/* ------------------------------- Defines -------------------------------- */
#define child_exit exit
/* Codes for child_status */
#define CHILD_EMPTY_SLOT 0xfe
#define CHILD_AWAIT_CONNECT 0xff
#define CHILD_PROCESSING 0x00
#define CHILD_READING 0x01
#define CHILD_WRITING 0x02
#define CHILD_RESOLVING 0x03
typedef struct {
char *ipstr;
int port;
struct passwd *pw;
char *chr;
char *pidfn;
void (*rcback)(int);
#if defined(DAEMON_UNIX_POOL) || defined(DAEMON_UNIX_MOBRULE)
int maxprocs, minprocs, proclife;
#endif
#ifdef NET_SSL
char *secure_keyfn;
char *secure_certfn;
char *secure_dongle;
int secure_auth;
int secure_session_timeout;
int security;
#endif
} daemon_s;
/* ------------------------------ Prototypes ------------------------------ */
#ifdef MCC_PROXY
/* A unique serial number assigned to each child. */
extern int child_serial;
#endif
/*
* daemon_run accepts whether or not it should detach from its parent process,
* and a daemon structure as its arguments. The daemon structure contains
* a port number, a root directory to chroot to (can be NULL), a filename to
* log the daemon pid to (can be NULL). daemon_run never returns.
*
* child_callback is a function which will be called every time a new
* connection is recieved. Session is a new session ID.
*
* rcback is a function which is a restart function: When SIGHUP is received,
* this function will be called. You may give SIG_DFL if you don't want to
* support restarting. The rcback will be passed SIGHUP.
*
* pw is the passwd entry to run the daemon as. If the effective user id is
* root, daemon_run will try to set its uid and gid to the user pointed
* to by this structure. You may pass NULL.
*/
void daemon_run(int det, void (*child_callback)(Session *), daemon_s *d);
/*
* fork is a wrapper for the system's fork function. This closes the listen
* socket for the mob. This also makes sure that a threaded daemon only gets
* the calling thread and not all of them.
*/
pid_t child_fork(void);
/*
* Set status to the given code for statistics reporting
*/
#ifdef DAEMON_STATS
void child_status(int code);
#else
#define child_status(code) (void)(code)
#endif
#endif
#endif
|