0
0
mirror of https://github.com/darkk/redsocks.git synced 2025-08-25 19:25:30 +00:00

Added -h, -? CLI options for help & -v for redsocks-version.

This commit is contained in:
Leonid Evdokimov 2011-11-27 03:30:43 +04:00
parent 9fce864ae0
commit 457c5eb79a
3 changed files with 33 additions and 4 deletions

View File

@ -1,4 +1,4 @@
OBJS := parser.o main.o redsocks.o log.o http-connect.o socks4.o socks5.o http-relay.o base.o base64.o md5.o http-auth.o utils.o redudp.o dnstc.o
OBJS := parser.o main.o redsocks.o log.o http-connect.o socks4.o socks5.o http-relay.o base.o base64.o md5.o http-auth.o utils.o redudp.o dnstc.o gen/version.o
SRCS := $(OBJS:.o=.c)
CONF := config.h
DEPS := .depend
@ -29,6 +29,22 @@ $(CONF):
;; \
esac
# Dependency on .git is useful to rebuild `version.c' after commit
# FIXME: non-git builds should be supported.
gen/version.c: *.c *.h gen/.build .git
rm -f $@.tmp
echo '/* this file is auto-generated during build */' > $@.tmp
echo '#include "../version.h"' > $@.tmp
echo 'const char* redsocks_version = "redsocks.git/"' >> $@.tmp
echo '"'`git describe --tags`'"' >> $@.tmp
[ `git status --porcelain | grep -v -c '^??'` != 0 ] && { echo '"-unclean"' >> $@.tmp; } || true
echo ';' >> $@.tmp
mv -f $@.tmp $@
gen/.build:
mkdir -p gen
touch $@
base.c: $(CONF)
$(DEPS): $(SRCS)
@ -64,3 +80,4 @@ clean:
distclean: clean
$(RM) tags $(DEPS)
$(RM) -r gen

12
main.c
View File

@ -25,6 +25,7 @@
#include "log.h"
#include "main.h"
#include "utils.h"
#include "version.h"
extern app_subsys redsocks_subsys;
extern app_subsys base_subsys;
@ -66,7 +67,7 @@ int main(int argc, char **argv)
int i;
red_srand();
while ((opt = getopt(argc, argv, "tc:p:")) != -1) {
while ((opt = getopt(argc, argv, "h?vtc:p:")) != -1) {
switch (opt) {
case 't':
conftest = true;
@ -77,13 +78,18 @@ int main(int argc, char **argv)
case 'p':
pidfile = optarg;
break;
case 'v':
puts(redsocks_version);
return EXIT_SUCCESS;
default:
printf(
"Usage: %s [-t] [-c config] [-p pidfile]\n"
"Usage: %s [-?hvt] [-c config] [-p pidfile]\n"
" -h, -? this message\n"
" -v print version\n"
" -t test config syntax\n"
" -p write pid to pidfile\n",
argv[0]);
return EXIT_FAILURE;
return (opt == '?' || opt == 'h') ? EXIT_SUCCESS : EXIT_FAILURE;
}
}

6
version.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef VERSION_H_SUN_NOV_27_03_22_30_2011
#define VERSION_H_SUN_NOV_27_03_22_30_2011
extern const char* redsocks_version;
#endif // VERSION_H_SUN_NOV_27_03_22_30_2011