summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-04-06 11:54:28 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-04-06 11:54:28 +0200
commitdcca0160dedf53e3683c66e04c4b8eda9d74e5c6 (patch)
tree490b13c983d93d3967bde43dbff79281e4c88b70
parent839629694a0245884f8d72d8573ca75ee33ac391 (diff)
downloadpgfuse-dcca0160dedf53e3683c66e04c4b8eda9d74e5c6.tar.gz
pgfuse-dcca0160dedf53e3683c66e04c4b8eda9d74e5c6.tar.bz2
sorted out more argument parsing trouble
-rw-r--r--Makefile2
-rw-r--r--pgfuse.c26
2 files changed, 19 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 71b58f3..169ec2f 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ CFLAGS += -DFUSE_USE_VERSION=26
# use pkg-config to detemine compiler/linker flags for libfuse
CFLAGS += `pkg-config fuse --cflags`
-LDFLAGS = `pkg-config fuse --libs`
+LDFLAGS = `pkg-config fuse --libs` -lpq
clean:
rm -f pgfuse pgfuse.o
diff --git a/pgfuse.c b/pgfuse.c
index 6cb15ce..dd87940 100644
--- a/pgfuse.c
+++ b/pgfuse.c
@@ -25,6 +25,8 @@
#include <fuse.h> /* for user-land filesystem */
#include <fuse_opt.h> /* fuse command line parser */
+#include <libpq-fe.h> /* for Postgresql database access */
+
/* --- fuse callbacks --- */
static struct fuse_operations pgfuse_oper = {
@@ -107,10 +109,13 @@ static int pgfuse_opt_proc( void* data, const char* arg, int key,
if( pgfuse.conninfo == NULL ) {
pgfuse.conninfo = strdup( arg );
return 0;
- } else {
+ } else if( pgfuse.mountpoint == NULL ) {
pgfuse.mountpoint = strdup( arg );
+ return 1;
+ } else {
+ fprintf( stderr, "%s, only two arguments allowed: Postgresql connection data and mountpoint\n", basename( outargs->argv[0] ) );
+ return -1;
}
- return 1;
case KEY_HELP:
pgfuse.print_help = 1;
@@ -164,6 +169,7 @@ static void print_usage( char* progname )
int main( int argc, char *argv[] )
{
int res;
+ PGconn *conn;
struct fuse_args args = FUSE_ARGS_INIT( argc, argv );
memset( &pgfuse, 0, sizeof( pgfuse ) );
@@ -176,18 +182,22 @@ int main( int argc, char *argv[] )
argv[1] = "-ho";
argv[2] = "mountpoint";
fuse_main( 2, argv, &pgfuse_oper, NULL);
- return EXIT_SUCCESS;
+ exit( EXIT_SUCCESS );
}
if( pgfuse.print_version ) {
fprintf( stderr, "0.0.1\n" );
- return EXIT_SUCCESS;
+ exit( EXIT_SUCCESS );
}
- return EXIT_FAILURE;
+ exit( EXIT_FAILURE );
+ }
+
+ if( pgfuse.conninfo == NULL ) {
+ fprintf( stderr, "Missing Postgresql connection data\n" );
+ fprintf( stderr, "see '%s -h' for usage\n", basename( argv[0] ) );
+ exit( EXIT_FAILURE );
}
- return EXIT_SUCCESS;
-
- res = fuse_main( argc, argv, &pgfuse_oper, NULL );
+ res = fuse_main( args.argc, args.argv, &pgfuse_oper, NULL );
exit( res );
}