commit - d431188c66e521a110f987eed2655cc9dfde9864
commit + 721e2325296b1556eb0d2224ef37b387091dff43
blob - 69df871a931e6a1f0f8a8711ca3100785961db88
blob + aa9a687625b4185962c750cd2190877096e3b043
--- ChangeLog
+++ ChangeLog
+2020-11-17 Omar Polo <op@omarpolo.com>
+
+ * gmid.c (main): add flag -p to change the port
+
2020-11-10 Omar Polo <op@omarpolo.com>
* ChangeLog: 1.3 tagged, fixed ChangeLog format
blob - 2d4ac4601f743d5d4a1e0028d7c444021a78d82c
blob + a82bd4f6ff8fb55c88165308a35dc104b9a0bec3
--- README.md
+++ README.md
\[**-d** *docs*]
\[**-k** *key.pem*]
\[**-l** *logfile*]
+\[**-p** *port*]
\[**-x** *cgi-bin*]
# DESCRIPTION
> log to the given file instead of the standard error.
+**-p** *port*
+
+> The port to bind to, by default 1965.
+
**-x** *dir*
> Enable execution of CGI scripts inside the given directory (relative
blob - f25285f2f3cd622c97faf877bf5cb4e0a4fe67db
blob + 1a8de5bbdc2bc2bbfa8625092f33ae2fa77ab1d1
--- gmid.1
+++ gmid.1
.Op Fl d Ar docs
.Op Fl k Ar key.pem
.Op Fl l Ar logfile
+.Op Fl p Ar port
.Op Fl x Ar cgi-bin
.Ek
.Sh DESCRIPTION
.Pa key.pem .
.It Fl l Ar logfile
log to the given file instead of the standard error.
+.It Fl p Ar port
+The port to bind to, by default 1965.
.It Fl x Ar dir
Enable execution of CGI scripts inside the given directory (relative
to the document root.) Cannot be provided more than once.
blob - 86a900aee4bf93b7273886bbd400b8c54015a4f0
blob + 87a4a622f653d350c159d42ba91c6265129d3fd7
--- gmid.c
+++ gmid.c
const char *dir, *cgi;
int dirfd, logfd;
+int port;
int connected_clients;
void siginfo_handler(int);
goto err;
case 0: { /* child */
- char *ex, *requri;
+ char *ex, *requri, *portno;
char addr[INET_ADDRSTRLEN];
char *argv[] = { NULL, NULL, NULL };
if (inet_ntop(c->af, &c->addr, addr, sizeof(addr)) == NULL)
goto childerr;
+ if (asprintf(&portno, "%d", port) == -1)
+ goto childerr;
+
if (asprintf(&ex, "%s%s", dir, spath+1) == -1)
goto childerr;
/* fix the env */
setenv("SERVER_SOFTWARE", "gmid", 1);
- setenv("SERVER_PORT", "1965", 1);
+ setenv("SERVER_PORT", portno, 1);
/* setenv("SERVER_NAME", "", 1); */
setenv("SCRIPT_NAME", spath, 1);
setenv("SCRIPT_EXECUTABLE", ex, 1);
{
fprintf(stderr,
"USAGE: %s [-h] [-c cert.pem] [-d docs] [-k key.pem] "
- "[-l logfile] [-x cgi-bin]\n",
+ "[-l logfile] [-p port] [-x cgi-bin]\n",
me);
}
dir = "docs/";
logfd = 2; /* stderr */
cgi = NULL;
+ port = 1965;
- while ((ch = getopt(argc, argv, "c:d:hk:l:x:")) != -1) {
+ while ((ch = getopt(argc, argv, "c:d:hk:l:p:x:")) != -1) {
switch (ch) {
case 'c':
cert = optarg;
err(1, "%s", optarg);
break;
+ case 'p': {
+ char *ep;
+ long lval;
+
+ errno = 0;
+ lval = strtol(optarg, &ep, 10);
+ if (optarg[0] == '\0' || *ep != '\0')
+ err(1, "not a number: %s", optarg);
+ if (lval < 0 || lval > UINT16_MAX)
+ err(1, "port number out of range: %s", optarg);
+ port = lval;
+ break;
+ }
+
case 'x':
cgi = optarg;
break;
if (tls_configure(ctx, conf) == -1)
errx(1, "tls_configure: %s", tls_error(ctx));
- sock = make_socket(1965, AF_INET);
+ sock = make_socket(port, AF_INET);
if ((dirfd = open(dir, O_RDONLY | O_DIRECTORY)) == -1)
err(1, "open: %s", dir);