Re: [PATCH] MEDIUM: init: allow directory as argument of -f

2016-05-07 Thread Maxime de Roucy
Hello,

I just realize I include a typo when editing my commit message to
respect the 75 char limit :

>   $ ./haproxy -C rootdir -f root2 -f superdir2 \
>      -f root -f superdir1 -f root1

is in fact :

>   $ ./haproxy -C rootdir -f root2 -f superdir2 \
>      -f root3 -f superdir1 -f root1

Should I re-send my patch or is it OK ?
-- 
Regards
Maxime de Roucy

signature.asc
Description: This is a digitally signed message part


[PATCH] MEDIUM: init: allow directory as argument of -f

2016-05-07 Thread Maxime de Roucy
If -f argument is a directory add all the files (and only files) it
containes to the config files list.
These files are added in lexical order (man alphasort).
The -f order is still respected:

$ tree rootdir
rootdir
├── root1
├── root2
├── root3
├── superdir1
│   ├── aaa1
│   ├── aaa2
│   ├── aaa3
│   ├── bbb1 -> aaa1
│   └── wrong
│   └── wrongfile
└── superdir2
├── ccc1
└── wronglink -> .

$ ./haproxy -C rootdir -f root2 -f superdir2 \
   -f root -f superdir1 -f root1
root2
superdir2/ccc1
root3
superdir1/aaa1
superdir1/aaa2
superdir1/aaa3
superdir1/bbb1
root1

This can be useful on systemd where you can't change the haproxy
commande line options on service reload.
---
 doc/haproxy.1 |  8 +++--
 doc/management.txt| 23 ++--
 include/common/defaults.h |  7 
 src/haproxy.c | 89 +++
 4 files changed, 108 insertions(+), 19 deletions(-)

diff --git a/doc/haproxy.1 b/doc/haproxy.1
index a836d5d..6017efa 100644
--- a/doc/haproxy.1
+++ b/doc/haproxy.1
@@ -6,7 +6,7 @@ HAProxy \- fast and reliable http reverse proxy and load 
balancer
 
 .SH SYNOPSIS
 
-haproxy \-f  [\-L\ ] [\-n\ maxconn] [\-N\ maxconn] 
[\-C\ ] [\-v|\-vv] [\-d] [\-D] [\-q] [\-V] [\-c] [\-p\ ] [\-dk] 
[\-ds] [\-de] [\-dp] [\-db] [\-dM[]] [\-m\ ] [{\-sf|\-st}\ 
pidlist...]
+haproxy \-f  [\-L\ ] [\-n\ maxconn] [\-N\ 
maxconn] [\-C\ ] [\-v|\-vv] [\-d] [\-D] [\-q] [\-V] [\-c] [\-p\ ] 
[\-dk] [\-ds] [\-de] [\-dp] [\-db] [\-dM[]] [\-m\ ] [{\-sf|\-st}\ 
pidlist...]
 
 .SH DESCRIPTION
 
@@ -33,8 +33,10 @@ instances without risking the system's stability.
 .SH OPTIONS
 
 .TP
-\fB\-f \fP
-Specify configuration file path.
+\fB\-f \fP
+Specify configuration file or directory path. If the argument is a directory
+the files (and only files) it containes are added in lexical order (man
+alphasort).
 
 .TP
 \fB\-L \fP
diff --git a/doc/management.txt b/doc/management.txt
index e0469aa..3e51d49 100644
--- a/doc/management.txt
+++ b/doc/management.txt
@@ -134,16 +134,19 @@ list of options is :
 one of "global", "defaults", "peers", "listen", "frontend", "backend", and
 so on. A file cannot contain just a server list for example.
 
-  -f  : adds  to the list of configuration files to be
-loaded. Configuration files are loaded and processed in their declaration
-order. This option may be specified multiple times to load multiple files.
-See also "--". The difference between "--" and "-f" is that one "-f" must
-be placed before each file name, while a single "--" is needed before all
-file names. Both options can be used together, the command line ordering
-still applies. When more than one file is specified, each file must start
-on a section boundary, so the first keyword of each file must be one of
-"global", "defaults", "peers", "listen", "frontend", "backend", and so
-on. A file cannot contain just a server list for example.
+  -f  : adds  to the list of configuration files to be
+loaded. If  is a directory, all the files (and only files) it
+containes are added in lexical order (man alphasort) to the list of
+configuration files to be loaded. Configuration files are loaded and
+processed in their declaration order. This option may be specified multiple
+times to load multiple files. See also "--". The difference between "--"
+and "-f" is that one "-f" must be placed before each file name, while a
+single "--" is needed before all file names. Both options can be used
+together, the command line ordering still applies. When more than one file
+is specified, each file must start on a section boundary, so the first
+keyword of each file must be one of "global", "defaults", "peers",
+"listen", "frontend", "backend", and so on. A file cannot contain just a
+server list for example.
 
   -C  : changes to directory  before loading configuration
 files. This is useful when using relative paths. Warning when using
diff --git a/include/common/defaults.h b/include/common/defaults.h
index 1c971d9..fefa30f 100644
--- a/include/common/defaults.h
+++ b/include/common/defaults.h
@@ -66,6 +66,13 @@
 #define MAX_SYSLOG_LEN  1024
 #endif
 
+/* maximum "directoryname/filename" string size when CLI
+ * -f argument is a directory (named "directoryname" here)
+ */
+#ifndef MAX_CLI_DIRFILE_NAME
+#define MAX_CLI_DIRFILE_NAME   1024
+#endif
+
 // maximum line size when parsing config
 #ifndef LINESIZE
 #define LINESIZE   2048
diff --git a/src/haproxy.c b/src/haproxy.c
index 0c223e5..69b1e8a 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -33,10 +33,12 @@
 #include 
 #include 
 #include 
+#include 
 #include