7 * Uncomment this #define if you are a Citadel developer tracking
8 * down memory leaks in the server. Do NOT do this on a production
9 * system because it definitely incurs a lot of additional overhead.
10 #define DEBUG_MEMORY_LEAKS
19 #if SIZEOF_SIZE_T == SIZEOF_INT
20 #define SIZE_T_FMT "%d"
22 #define SIZE_T_FMT "%ld"
26 /* Logging levels - correspond to syslog(3) */
28 /* When about to exit the server for an unrecoverable error */
29 CTDL_EMERG, /* system is unusable */
30 /* Manual intervention is required to avoid an abnormal exit */
31 CTDL_ALERT, /* action must be taken immediately */
32 /* The server can continue to run with degraded functionality */
33 CTDL_CRIT, /* critical conditions */
34 /* An error occurs but the server continues to run normally */
35 CTDL_ERR, /* error conditions */
36 /* An abnormal condition was detected; server will continue normally */
37 CTDL_WARNING, /* warning conditions */
38 /* Normal messages (login/out, activity, etc.) */
39 CTDL_NOTICE, /* normal but significant condition */
40 /* Unimportant progress messages, etc. */
41 CTDL_INFO, /* informational */
42 /* Debugging messages */
43 CTDL_DEBUG /* debug-level messages */
47 void lprintf (enum LogLevel loglevel, const char *format, ...) __attribute__((__format__(__printf__,2,3)));
48 void cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
50 void lprintf (enum LogLevel loglevel, const char *format, ...);
51 void cprintf (const char *format, ...);
54 void vlprintf (enum LogLevel loglevel, const char *format, va_list arg_ptr);
56 extern pthread_key_t MyConKey; /* TSD key for MyContext() */
58 extern int enable_syslog;
60 void init_sysdep (void);
61 void begin_critical_section (int which_one);
62 void end_critical_section (int which_one);
63 int ig_tcp_server (char *ip_addr, int port_number, int queue_len,char **errormessage);
64 int ig_uds_server(char *sockpath, int queue_len, char **errormessage);
65 struct CitContext *MyContext (void);
66 struct CitContext *CreateNewContext (void);
67 void InitMyContext (struct CitContext *con);
68 void buffer_output(void);
69 void unbuffer_output(void);
70 void flush_output(void);
71 void client_write (char *buf, int nbytes);
72 int client_read_to (char *buf, int bytes, int timeout);
73 int client_read (char *buf, int bytes);
74 int client_getln (char *buf, int maxbytes);
75 void sysdep_master_cleanup (void);
76 void kill_session (int session_to_kill);
77 void *sd_context_loop (struct CitContext *con);
78 void start_daemon (int do_close_stdio);
79 void cmd_nset (char *cmdbuf);
80 int convert_login (char *NameToConvert);
81 void *worker_thread (void *arg);
82 void become_session(struct CitContext *which_con);
83 void InitializeMasterCC(void);
84 void init_master_fdset(void);
85 void create_worker(void);
86 void InitialiseSemaphores(void);
89 extern int num_sessions;
90 extern volatile int exit_signal;
91 extern volatile int shutdown_and_halt;
92 extern volatile int running_as_daemon;
93 extern volatile int restart_server;
98 extern struct worker_node {
100 struct worker_node *next;
108 #define CTDLTHREAD_BIGSTACK 0x0001
109 #define CTDLTHREAD_WORKER 0x0002
111 void ctdl_internal_thread_gc (void);
112 void ctdl_thread_internal_init(void);
113 struct CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thread_func) (void *arg), void *args);
115 enum CtdlThreadState {
119 CTDL_THREAD_CANCELLED,
121 CTDL_THREAD_STOPPING,
122 CTDL_THREAD_STOP_REQ, /* Do NOT put any running states before this state */
123 CTDL_THREAD_SLEEPING,
125 CTDL_THREAD_LAST_STATE
128 extern struct CtdlThreadNode {
129 pthread_t tid; /* id as returned by pthread_create() */
130 pid_t pid; /* pid, as best the OS will let us determine */
131 struct CitConext *Context; /* The session context that this thread mught be working on or NULL if none */
132 long number; /* A unigue number for this thread (not implimented yet) */
133 int wakefd_recv; /* An fd that this thread can sleep on (not implimented yet) */
134 int wakefd_send; /* An fd that this thread can send out on (Not implimented yet) */
135 char *name; /* A name for this thread */
136 void *(*thread_func) (void *arg); /* The actual function that does this threads work */
137 void *user_args; /* Arguments passed to this threads work function */
138 long flags; /* Flags that describe this thread */
139 enum CtdlThreadState state; /* Flag to show state of this thread */
140 pthread_mutex_t ThreadMutex; /* A mutex to sync this thread to others if this thread allows (also used for sleeping) */
141 pthread_cond_t ThreadCond; /* A condition variable to sync this thread with others (also used for sleeping) */
142 pthread_attr_t attr; /* Attributes of this thread */
143 struct CtdlThreadNode *prev; /* Previous thread in the thread table */
144 struct CtdlThreadNode *next; /* Next thread in the thread table */
147 extern int SyslogFacility(char *name);
148 extern int syslog_facility;
150 #ifdef DEBUG_MEMORY_LEAKS
151 #define malloc(x) tracked_malloc(x, __FILE__, __LINE__)
152 #define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__)
154 #define strdup(x) tracked_strdup(x, __FILE__, __LINE__)
155 #define free(x) tracked_free(x)
156 void *tracked_malloc(size_t size, char *file, int line);
157 void *tracked_realloc(void *ptr, size_t size, char *file, int line);
158 void tracked_free(void *ptr);
159 char *tracked_strdup(const char *s, char *file, int line);
160 void dump_heap(void);
163 void create_maintenance_threads(void);
165 #endif /* SYSDEP_DECLS_H */