Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#933 closed defect (wontfix)

include with wildcard but non-existent parent is not detected by nginx -t

Reported by: welwood08@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.9.x
Keywords: Cc:
uname -a: Linux devil 2.6.26-1-686-bigmem #1 SMP Fri Mar 13 18:52:29 UTC 2009 i686 GNU/Linux
nginx -V: nginx version: nginx/1.9.12
built by gcc 5.3.0 (GCC)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/usr --conf-path=/home/nginx/conf/nginx.conf --pid-path=/home/nginx/nginx.pid --lock-path=/home/nginx/nginx.lock --error-log-path=/home/nginx/logs/error.log --http-log-path=/home/nginx/logs/access.log --http-client-body-temp-path=/tmp/client_body --http-proxy-temp-path=/tmp/proxy --http-fastcgi-temp-path=/tmp/fastcgi --http-uwsgi-temp-path=/tmp/uwsgi --http-scgi-temp-path=/tmp/scgi --with-cc-opt='-gdwarf-2 -gstrict-dwarf -I/home/me/gcc/5.3.0/lib/gcc/i686-pc-linux-gnu/5.3.0/include -I/home/me/gcc/5.3.0/lib/gcc/i686-pc-linux-gnu/5.3.0/include-fixed -I/home/me/openssl/include' --with-ld-opt='-L/home/me/gcc/5.3.0/lib -L/home/me/openssl/lib' --with-pcre=/home/me/src/pcre/pcre-8.38 --with-zlib=/home/me/src/zlib/zlib-1.2.8 --with-pcre-jit --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module

Description

Include wildcard with non-existent parent directory:

  • nginx.conf
    include nonexistant/*;
    
  • nginx -t
    nginx: the configuration file /home/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /home/nginx/conf/nginx.conf test is successful
    

Include non-existent file:

  • nginx.conf
    include nonexistant;
    
  • nginx -t
    nginx: [emerg] open() "/home/nginx/conf/nonexistant" failed (2: No such file or directory) in /home/nginx/conf/nginx.conf:1
    nginx: configuration file /home/nginx/conf/nginx.conf test failed
    

I encountered this problem because a wildcard include directive contained a typo. One of the files that failed to be included was for SSL, so I also hit #178 and was investigating in the wrong place. Both should have been caught by the configtest feature.

Change History (3)

comment:1 by Maxim Dounin, 9 years ago

Resolution: wontfix
Status: newclosed

Wildcard includes intentionally don't fail if no files were found, this is done to allow wildcard includes of possibly empty set of files. E.g., this allows to include all files from a directory, even if there are no files in the directory in question. Or all files from a directory if the directory exists and contains any files.

in reply to:  1 comment:2 by welwood08@…, 8 years ago

Replying to mdounin:

Wildcard includes intentionally don't fail if no files were found, this is done to allow wildcard includes of possibly empty set of files. E.g., this allows to include all files from a directory, even if there are no files in the directory in question. Or all files from a directory if the directory exists and contains any files.

I happened to be revisiting this today and after reading both the report and response again I believe my original report was misinterpreted - perhaps I was unclear.

For the case where no files are found in a wildcard include, I have no objection with it being silently successful as you suggest was intended behaviour.

However, when the parent directory of the wildcard include does not exist it seems to me that should be considered an error in the same way that a non-wildcard file that doesn't exist is also considered an error.

The examples you give even suggest you have only considered the case of an existing parent directory, "files from a directory" and "if the directory exists" clearly make no sense when the directory does not exist.

Consider:

include file;
  • If file exists: no problem.
  • If file does not exist: error.

Now consider:

include parent/*;
  • If parent exists: no problem (even if it contains no files).
  • If parent does not exist: error.

The last point is where the current behaviour of nginx -t (silently succeeding with no error) is inconsistent between files and directories and I believe is where my original point was not conveyed clearly. Hopefully I can at least confirm that I've been understood now even if the final decision is unchanged - thank you for your time.

comment:3 by Maxim Dounin, 8 years ago

You've been understood. Including all files from a directory if the directory exists (and doing nothing if there is no such directory) is believed to be a valid use case for wildcard includes.

From the code point of view a non-existing directory and an existing directory without files are basically identical, as nginx just uses glob() to expand the mask given.

Note: See TracTickets for help on using tickets.