Added getting port from environment variable

This commit is contained in:
Dm1tr1y147 2020-07-28 12:14:28 +05:00
parent b62443ecf1
commit fadbc96146
2 changed files with 11 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# bin/detect <build-dir>
if [[ -f $1/Makefile || -f $1/configure ]]; then
if [[ -f $1/Makefile ]]; then
echo "C" && exit 0
else
echo "no" && exit 1

View File

@ -67,14 +67,20 @@ int main(int argc, char *argv[])
struct sockaddr_storage cli_addr;
char s[INET6_ADDRSTRLEN];
if (argc != 2)
char *port;
if (argc == 2)
port = argv[1];
else
port = getenv("PORT");
if (port == NULL)
{
err_msg("Usage: <Server Port>\n");
perror("Port must be specified either as an argument or environment variable \"PORT\"");
exit(1);
}
char *port = argv[1];
int listenfd = get_listener_socket(port);
int listenfd = get_listener_socket(port);
if (listenfd < 0)
{
err_msg("!fatal! couldn't create listening socket");