chiark / gitweb /
Break much of cgi-fcgi-interp.c out into prefork.[ch]
[chiark-utils.git] / cprogs / prefork.h
1 /* common stuff for cgi-fcgi-interp and prefork-interp */
2
3 #ifndef PREFORK_H
4 #define PREFORK_H
5
6 #include "common.h"
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <stdbool.h>
13 #include <assert.h>
14 #include <limits.h>
15
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <sys/utsname.h>
19 #include <sys/socket.h>
20 #include <sys/un.h>
21 #include <sys/file.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <pwd.h>
25 #include <time.h>
26 #include <signal.h>
27 #include <sys/wait.h>
28 #include <syslog.h>
29         
30 #include <nettle/sha.h>
31
32 #include "myopt.h"
33 #include "timespeccmp.h"
34
35 #define MINHEXHASH 33
36 #define STAGE2_VAR "CHIARKUTILS_CGIFCGIINTERP_STAGE2"
37
38 extern const char *interp, *ident;
39 extern int numservers, debugmode;
40 extern int check_interval;
41
42 extern struct sha256_ctx identsc;
43
44 extern uid_t us;
45 extern const char *run_base, *script, *socket_path;
46 extern const char *run_base_mkdir_p;
47 extern bool logging;
48
49 bool find_run_base_var_run(void);
50 void find_socket_path(void);
51
52 bool stab_isnewer(const struct stat *a, const struct stat *b);
53 void stab_mtimenow(struct stat *out);
54 bool check_garbage_vs(const struct stat *started);
55 bool check_garbage(void);
56 void tidy_garbage(void);
57
58 extern const struct cmdinfo cmdinfos[];
59
60 // returns script pathname
61 const char *process_opts(int argc, const char *const *argv);
62
63 void vmsgcore(int estatus, int errnoval, const char *fmt, va_list al);
64
65 #define DEF_MSG(func, attrs, estatus, errnoval, after)  \
66   static void func(const char *fmt, ...)                \
67     __attribute__((unused, format(printf,1,2))) attrs;  \
68   static void func(const char *fmt, ...) {              \
69     va_list al;                                         \
70     va_start(al,fmt);                                   \
71     vmsgcore(estatus,errnoval,fmt,al);                  \
72     after                                               \
73   }
74
75 DEF_MSG(warninge, /*empty*/, 0, errno, { });
76 DEF_MSG(warning , /*empty*/, 0, 0,     { });
77
78 #define DEF_DIE(func, errnoval) \
79   DEF_MSG(func, __attribute__((noreturn)), 127, errnoval, { abort(); })
80
81 DEF_DIE(diee, errno)
82 DEF_DIE(die,  0)
83
84 #define MAX_OPTS 5
85
86 void fusagemessage(FILE *f);
87 void usagemessage(void);
88 void of_help(const struct cmdinfo *ci, const char *val);
89 void of_iassign(const struct cmdinfo *ci, const char *val);
90 void ident_addstring(const struct cmdinfo *ci, const char *string);
91 void off_ident_addenv(const struct cmdinfo *ci, const char *name);
92
93 #endif /*PREFORK_H*/