chiark / gitweb /
Bump version to 7.0.1~iwj0
[chiark-utils.git] / cprogs / prefork.h
1 /* common stuff for cgi-fcgi-interp and prefork-interp */
2 /*
3  * Copyright 2016-2022 Ian Jackson and contributors to chiark-utils
4  * SPDX-License-Identifier: GPL-3.0-or-later
5  * There is NO WARRANTY.
6  */
7
8 #ifndef PREFORK_H
9 #define PREFORK_H
10
11 #include "common.h"
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <stdbool.h>
18 #include <assert.h>
19 #include <limits.h>
20
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <sys/utsname.h>
24 #include <sys/socket.h>
25 #include <sys/un.h>
26 #include <sys/file.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <pwd.h>
30 #include <time.h>
31 #include <signal.h>
32 #include <sys/wait.h>
33 #include <syslog.h>
34         
35 #include <nettle/sha.h>
36
37 #include "myopt.h"
38
39 #define MINHEXHASH 33
40
41 extern const char *interp, *ident, *script, *socket_path, *lock_path;
42 extern bool logging;
43 extern struct sha256_ctx identsc;
44 extern const char *run_base;
45
46 extern const char our_name[];
47
48 bool find_run_base_var_run(void);
49 void find_socket_path(void);
50
51 int acquire_lock(void);
52 int flock_file(const char *lock_path);
53
54 extern const struct cmdinfo cmdinfos[];
55 #define PREFORK_CMDINFOS \
56   { "help",   0, .call=of_help                                         }, \
57   { 0, 'g',   1,                    .sassignto= &ident                 }, \
58   { 0, 'G',   1, .call= off_ident_addstring                            }, \
59   { 0, 'E',   1, .call= off_ident_addenv                               },
60
61 void process_opts(const char *const **argv_io);
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, -1,    { });
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,  -1)
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_addinit(void);
91 bool stabs_same_inode(struct stat *a, struct stat *b);
92 void ident_addstring(char key, const char *string);
93
94 void off_ident_addstring(const struct cmdinfo *ci, const char *name);
95 void off_ident_addenv(const struct cmdinfo *ci, const char *name);
96
97 void ident_add_key_byte(char key);
98
99 #define IDENT_ADD_OBJ(key, obj) do{                             \
100     ident_add_key_byte(key);                                    \
101     sha256_update(&identsc, sizeof((obj)), (void*)&obj);        \
102   }while(0)
103
104 #endif /*PREFORK_H*/