2 * "Interpreter" that you can put in #! like this
3 * #!/usr/bin/cgi-fcgi-perl [<options>]
5 * The result is a program which looks, when executed via the #!
6 * line, like a CGI program. But the perl script inside will
7 * be executed via /usr/bin/perl in fcgi.
12 * Use <ident> rather than hex(sha256(<script>))
13 * as the basename of the leafname of the fcgi rendezvous
14 * socket. If <ident> contains only hex digit characters it
15 * ought to be no more than 32 characters.
18 * Start <numservers> instances of the program. This
19 * determines the maximum concurrency. (Note that unlike
20 * speedy, the specified number of servers is started
21 * right away.) The default is 4.
23 * cgi-fcgi-perl automatically expires old sockets, including
24 * ones where the named perl script is out of date.
28 * Uses one of two directories
29 * /var/run/user/<UID>/cgi-fcgi-perl/
30 * ~/.cgi-fcgi-perl/<node>/
31 * and inside there uses these paths
35 * If -M<ident> is not specified then an initial substricg of the
36 * lowercase hex of the sha256 of the <script> (ie, our argv[1]) is
37 * used. The substring is chosen so that the whole path is 10 bytes
38 * shorter than sizeof(sun_path). But always at least 33 characters.
41 * - see if /var/run/user exists
42 * if so, lstat /var/run/user/<UID> and check that
43 * we own it and it's X700; if not, fail
44 * if it's ok then <base> is /var/run/user/<UID>
45 * otherwise, look for and maybe create ~/.cgi-fcgi-perl
46 * (where ~ is HOME or from getpwuid)
47 * and then <base> is ~/.cgi-fcgi-perl/<node>
48 * - calculate pathname (checking <ident> length is OK)
49 * - check for and maybe create <base>
50 * - stat and lstat the <script>
51 * - stat the socket and check its timestamp
52 * if it is too hold, rename it to g<inum> (where
53 * <inum> is in decimal)
54 * and run garbage collection
55 * - run cgi-fcgi -connect SOCKET SCRIPT
65 static const char *ident;
66 static int numservers;
68 static void diee(const char *m) {
69 fprintf(stderr,"cgi-fcgi-: error: %s failed: %s\n", m, strerror(errno));
73 static void fusagemessage(FILE *f) {
74 fprintf(f, "usage: #!/usr/bin/cgi-fcgi-perl [<options>]\n");
77 void usagemessage(void) { fusagemessage(stderr); }
79 static void of_help(const struct cmdinfo *ci, const char *val) {
80 fusagemessage(stdout);
81 if (ferror(stdout)) diee("write usage message to stdout");
85 static const struct cmdinfo cmdinfos[]= {
86 { "help", 0, .call= of_help },
87 { 0, 'g', 1, .sassignto= &ident },
88 { 0, 'M', 1, .iassignto= &numservers },
92 int main(int argc, const char *const *argv) {
93 myopt(&argv, cmdinfos);