Skip to content

Commit

Permalink
Added -h, -? CLI options for help & -v for redsocks-version.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkk committed Nov 26, 2011
1 parent 9fce864 commit 457c5eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
19 changes: 18 additions & 1 deletion Makefile
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -64,3 +80,4 @@ clean:

distclean: clean
$(RM) tags $(DEPS)
$(RM) -r gen
12 changes: 9 additions & 3 deletions main.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand Down
6 changes: 6 additions & 0 deletions version.h
@@ -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

0 comments on commit 457c5eb

Please sign in to comment.