Commit Graph
100 Commits
Author SHA1 Message Date
Valentin Bartenev 7e1d800f08 Ruby: removed unused variable from ./configure script. 2020-08-09 01:00:44 +03:00
Valentin Bartenev 0d7a6885a3 Configure: verifying the Ruby library path.
An attempt to build a Ruby module for a custom Ruby installation that has the
same major version as the system Ruby may unexpectedly cause the use of the
system Ruby library.

This closes #449 issue on GitHub.
2020-08-08 23:52:31 +03:00
Valentin Bartenev b0ff245ca8 Improved mkstemp() error reporting.
The invocation parameters should be logged as well, notably the path of the file
that is failed to be created.

Also, log level changed to ALERT as it's quite critical error.
2020-08-05 16:11:20 +03:00
Valentin Bartenev 2b53c7bbbd Fixed nxt_conn_accept_alloc() behavior in low memory conditions.
Earlier, if nxt_mp_create() failed to allocate memory while accepting a new
connection, the resulting NULL was subsequently passed to nxt_mp_destroy(),
crashing the process.

More, if nxt_mp_create() was successful but nxt_sockaddr_cache_alloc() failed,
the connection object wasn't destroyed properly, leaving the connection counter
in an inconsistent state.  Repeated, this condition lowered the connection
capacity of the process and could eventually prevent it from accepting
connections altogether.
2020-08-05 14:55:34 +03:00
Valentin Bartenev 10f90f0d48 Configuration: added checking for presence of mandatory fields. 2020-07-24 20:25:20 +03:00
Valentin Bartenev 2a71a8a9f4 Added missing ending indicator in object members validation lists.
This fixes undefined behaviour due to array over-read if an unknown parameter
is specified in an uidmap, a gidmap, or a php target object.
2020-07-24 20:25:15 +03:00
Valentin Bartenev d86e0a7aec PHP: logging in request context when possible. 2020-07-21 20:27:37 +03:00
Valentin Bartenev f46ef1b121 PHP: fixed incorrect time in interpreter error log messages.
Previously, the log message callback used a generic log function, that relied on the process time cache.
Since there were no time update calls in the application processes, all log lines were printed with the
same time, usually correlated with the process start.

Now, a non-cached logging function from libunit is used.
2020-07-21 20:27:37 +03:00
Valentin Bartenev f69d470752 Fixed non-debug log time format in libunit.
This makes log format used in libunit consistent with the daemon, where milliseconds are printed only in the
debug log level.

Currently a compile time switch is used, since there's no support for runtime changing of a log level for now.
But in the future this should be a runtime condition, similar to nxt_log_time_handler().
2020-07-21 20:27:37 +03:00
Valentin Bartenev 5fa3108e63 Version bump. 2020-06-08 16:09:07 +03:00
Valentin Bartenev 829bf07c7c Adjusted tag 1.18.0 to include 9e14c63773be. 2020-05-28 19:32:52 +03:00
Valentin Bartenev 9d8e476c4e Added tag 1.18.0 for changeset a34bc498d976 2020-05-28 18:04:47 +03:00
Valentin Bartenev ebf86b34d1 Generated Dockerfiles for Unit 1.18.0. 2020-05-28 17:34:06 +03:00
Valentin Bartenev 943865fc77 Added version 1.18.0 CHANGES. 2020-05-28 17:34:06 +03:00
Valentin Bartenev b2e6ef7beb Static: fixed potential undefined behavior in memcpy().
According to the C standard, pointer arguments passed to memcpy() calls shall
still have valid values.  NULL is considered as invalid.

Found with GCC Static Analyzer.
2020-05-20 11:18:03 +03:00
Valentin Bartenev d0de6df839 Fixed global constant declaration (appeared in 9af10e099d09).
This fixes building with GCC 10, which is default to -fno-common.
See: https://gcc.gnu.org/gcc-10/porting_to.html
2020-05-15 21:32:07 +03:00
Valentin Bartenev 79f5e531fe Router: removed two unused assignments.
This should resolve some static analyzers warnings.
2020-05-15 17:08:37 +03:00
Valentin Bartenev 376d758dd7 PHP: implemented "targets" option.
This allows to specify multiple subsequent targets inside PHP applications.
For example:

  {
      "listeners": {
          "*:80": {
              "pass": "routes"
          }
      },

      "routes": [
          {
              "match": {
                  "uri": "/info"
              },

              "action": {
                  "pass": "applications/my_app/phpinfo"
              }
          },
          {
              "match": {
                  "uri": "/hello"
              },

              "action": {
                  "pass": "applications/my_app/hello"
              }
          },
          {
              "action": {
                  "pass": "applications/my_app/rest"
              }
          }
      ],

      "applications": {
          "my_app": {
              "type": "php",
              "targets": {
                  "phpinfo": {
                      "script": "phpinfo.php",
                      "root": "/www/data/admin",
                  },

                  "hello": {
                      "script": "hello.php",
                      "root": "/www/data/test",
                  },

                  "rest": {
                      "root": "/www/data/example.com",
                      "index": "index.php"
                  },
              }
          }
      }
  }
2020-05-14 13:15:01 +03:00
Valentin Bartenev 0174c971b5 Configuration: URI encoding in the "pass" option.
This is useful to escape "/" in path fragments.  For example, in order
to reference the application named "foo/bar":

  {
      "pass": "applications/foo%2Fbar"
  }
2020-05-14 13:15:00 +03:00
Valentin Bartenev f291f24938 Version bump. 2020-05-12 11:15:03 +03:00
Valentin Bartenev 9877087756 Added tag 1.17.0 for changeset 4b13438632bc 2020-04-16 18:21:09 +03:00
Valentin Bartenev 4d62989f5c Generated Dockerfiles for Unit 1.17.0. 2020-04-16 17:49:09 +03:00
Valentin Bartenev e377820b6c Added version 1.17.0 CHANGES. 2020-04-16 17:49:09 +03:00
Valentin Bartenev c7f5c1c664 Controller: improved handling of unix domain control socket.
One of the ways to detect Unit's startup and subsequent readiness to accept
commands relies on waiting for the control socket file to be created.
Earlier, it was unreliable due to a race condition between the client's
connect() and the daemon's listen() calls after the socket's bind() call.

Now, unix domain listening sockets are created with a nxt_listen_socket_create()
call as follows:

   s = socket();
   unlink("path/to/socket.tmp")
   bind(s, "path/to/socket.tmp");
   listen(s);
   rename("path/to/socket.tmp", "path/to/socket");

This eliminates a time-lapse when the socket file is already created but nobody
is listening on it yet, which therefore prevents the condition described above.

Also, it allows reliably detecting whether the socket is being used or simply
wasn't cleaned after the daemon stopped abruptly.  A successful connection to
the socket file means the daemon has been started; otherwise, the file can be
overwritten.
2020-04-08 15:15:24 +03:00
Valentin Bartenev a6d9efcee1 Controller: fixed cleaning up of control socket file in some cases.
Previously, the unix domain control socket file might have been left
in the file system after a failed nxt_listen_socket_create() call.
2020-04-08 15:15:24 +03:00
Valentin Bartenev 555d595f38 Removed unused code related to testing of address binding. 2020-04-08 15:15:24 +03:00
Valentin Bartenev 27c1e26856 Controller: eliminated extra control socket's sockaddr copying. 2020-04-08 15:15:24 +03:00
Valentin Bartenev be943c9fd4 Fixed build with Clang 10, broken by 32578e837322.
This silences the -Wimplicit-int-float-conversion warning.
2020-04-01 18:33:48 +03:00
Valentin Bartenev 68c6b67ffc Configuration: support for rational numbers. 2020-03-30 19:37:58 +03:00
Valentin Bartenev c63b498f94 Implemented "location" option for "return" action.
This allows to specify redirects:

  {
      "action": {
          "return": 301,
          "location": "https://www.example.com/"
      }
  }
2020-03-21 01:39:00 +03:00
Valentin Bartenev 35d6f84426 Added nxt_is_complex_uri_encoded()/nxt_encode_complex_uri(). 2020-03-27 17:22:52 +03:00
Valentin Bartenev d4b4cb0438 Updated URI escaping table for better conformity with RFC 3986.
Now '>', '<', '"', '^', '\', '}', '|', '{', and '`' are also escaped.
2020-03-27 17:22:52 +03:00
Valentin Bartenev 8d727774e3 Implemented "return" action.
The "return" action can be used to immediately generate a simple HTTP response
with an arbitrary status:

  {
      "action": {
          "return": 404
      }
  }

This is especially useful for denying access to specific resources.
2020-03-27 17:22:52 +03:00
Valentin Bartenev 5f9c4754cb Initialization of the action object made more consistent. 2020-03-27 17:22:52 +03:00
Valentin Bartenev fd8e524b82 Configuration: fixed comments parsing.
Unclosed multi-line comments and "/" at the end of JSON shouldn't be allowed.
2020-03-25 19:14:15 +03:00
Valentin Bartenev b7f0e09de0 Version bump. 2020-03-16 13:27:10 +03:00
Valentin Bartenev b3c8a7b33a Added tag 1.16.0 for changeset 8bab088952dd 2020-03-12 18:35:33 +03:00
Valentin Bartenev 8f397c8ae5 Generated Dockerfiles for Unit 1.16.0. 2020-03-12 18:13:08 +03:00
Valentin Bartenev f6d53f69b8 Added version 1.16.0 CHANGES. 2020-03-12 18:13:07 +03:00
Valentin Bartenev 810b8dbb67 Tests: unitd stderr output redirected to unit.log.
A part of the debug log was printed to stderr before the log file was opened.
Now, this output is redirected to the same log file.
2020-03-06 20:08:38 +03:00
Valentin Bartenev 3617d4ed03 Tests: simplified unitd process running.
There are no reasons to wrap the Unit daemon in a separate Python process.
2020-03-06 20:08:29 +03:00
Valentin Bartenev afa2f86ecf PHP: added ZTS indication to ./configure output. 2020-03-04 15:24:27 +03:00
Valentin Bartenev 75cb2a947d PHP: rearranged feature checks in ./configure.
Now it prints version even if PHP was built without embed SAPI.
2020-03-04 15:24:27 +03:00
Valentin Bartenev a98de7f705 Added a "fallback" option to be used with the "share" action.
It allows proceeding to another action if a file isn't available.

An example:

    {
        "share": "/data/www/",

        "fallback": {
            "pass": "applications/php"
        }
    }

In the example above, an attempt is made first to serve a request with
a file from the "/data/www/" directory.  If there's no such file, the
request is passed to the "php" application.

Fallback actions may be nested:

    {
        "share": "/data/www/",

        "fallback": {
            "share": "/data/cache/",

            "fallback": {
                "proxy": "http://127.0.0.1:9000"
            }
        }
    }
2020-03-03 20:37:47 +03:00
Valentin Bartenev a60f856ce2 Improved validation of the "action" object.
Now it enforces the mutual exclusivity of "pass", "proxy", and "share" options.
2020-03-03 20:37:47 +03:00
Valentin Bartenev d198a105eb Configuration: removing UTF-8 BOM from the input JSON.
Some editors can add it to JSON files.
2020-02-20 17:58:24 +03:00
Valentin Bartenev 044b3afcda Configuration: stripping comments from the input JSON.
This allows to have JavaScript-like comments in the uploading JSON.
2020-02-20 17:58:24 +03:00
Valentin Bartenev 7a0383189c Version bump. 2020-02-19 19:13:51 +03:00
Valentin Bartenev 6e19090736 Added tag 1.15.0 for changeset 801ac82f80fb 2020-02-06 18:20:37 +03:00
Valentin Bartenev e6bb4c5493 Generated Dockerfiles for Unit 1.15.0. 2020-02-06 17:33:44 +03:00
Valentin Bartenev 672602d1ee Added version 1.15.0 CHANGES. 2020-02-06 17:33:44 +03:00
Valentin Bartenev f860c20a96 PHP: added check for the ".php" extension.
A check for the ".php" extension is added to prevent execution of files
with arbitrary extensions in cases where "index" and "script" options
aren't used.
2020-01-28 19:18:26 +03:00
Valentin Bartenev 4bad2cf1e9 Version bump. 2020-01-27 16:52:53 +03:00
Valentin Bartenev d2eac78c57 Updated copyright notice. 2020-01-27 16:52:45 +03:00
Valentin Bartenev 55f8e31ed7 Added tag 1.14.0 for changeset 6e28966ed1f2 2019-12-26 17:04:37 +03:00
Valentin Bartenev be8589d925 Generated Dockerfiles for Unit 1.14.0. 2019-12-26 17:03:21 +03:00
Valentin Bartenev 9403233328 Added version 1.14.0 CHANGES. 2019-12-26 17:03:21 +03:00
Valentin Bartenev 9224e94a8d Removed unused variables from "docs/Makefile".
They actually have been broken since 00d8049418cf,
where NXT_VERSION was removed from nxt_main.h.

Also, shebang is added.
2019-12-24 17:03:47 +03:00
Valentin Bartenev 51af6ac0a1 Python: pre-creation of objects for string constants.
This is an optimization to avoid creating them at runtime on each request.
2019-12-23 21:14:14 +03:00
Valentin Bartenev 0a27f137de Added tag 1.13.0 for changeset 3313bf222e6e 2019-11-14 19:25:20 +03:00
Valentin Bartenev 2241847efb Generated Dockerfiles for Unit 1.13.0. 2019-11-14 19:24:14 +03:00
Valentin Bartenev 182107c10e Added version 1.13.0 CHANGES. 2019-11-14 19:23:38 +03:00
Valentin Bartenev c2976fb337 Python: avoiding buffering of exception backtraces.
A quote from the Python 3 documentation:

 | When interactive, stdout and stderr streams are line-buffered.
 | Otherwise, they are block-buffered like regular text files.

As a result, if an exception occurred and PyErr_Print() was called, its output
could be buffered but not printed to the log for a while (ultimately, until
the interpreter finalization).  If the application process crashed shortly,
the backtrace was completely lost.

Buffering can be disabled by redefining the sys.stderr stream object.
However, interference with standard environment objects was deemed undesirable.
Instead, sys.stderr.flush() is called every time after printing exceptions.
A potential advantage here is that lines from backtraces won't be mixed
with other lines in the log.
2019-11-14 17:48:48 +03:00
Valentin Bartenev 4e41d90006 Python: removed wrong PyErr_Print() call.
PyCallable_Check() doesn't produce errors.

The needless call was introduced in fdd6ed28e3b9.
2019-11-14 17:48:48 +03:00
Valentin Bartenev b3db7a30c0 Python: optimized response object close() calling.
PyObject_HasAttrString() is just a wrapper over PyObject_GetAttrString(),
while PyObject_CallMethod() calls it as the first step.  As a result,
PyObject_GetAttrString() was called twice if close() was present.

To get rid of PyObject_HasAttrString() while keeping the same behaviour,
the PyObject_CallMethod() call has been decomposed into separate calls of
PyObject_GetAttrString() and PyObject_CallFunction().
2019-11-14 17:48:48 +03:00
Valentin Bartenev 75c2c23bb6 Python: fixed an object leak when response close() is called.
On success, PyObject_CallMethod() returns a new reference to
the result of the call, which previously got lost.

Also, error logging on failure was added.

The issue was introduced by b0148ec28c4d.
2019-11-14 17:48:48 +03:00
Valentin Bartenev c667bb446d Python: refactored nxt_python_request_handler(). 2019-11-14 17:48:48 +03:00
Valentin Bartenev cd6cb02be0 Python: fixed potential object leak in case of allocation error. 2019-11-14 17:48:48 +03:00
Valentin Bartenev e9429324c2 Python: improved error handling if response object isn't iterable.
According to the documentation, PyObject_GetIter():

 | Raises TypeError and returns NULL if the object cannot be iterated.

Previously, this exception wasn't printed or cleared and remained unhandled.
2019-11-14 17:48:48 +03:00
Valentin Bartenev e189d0a96c Python: fixed handling of errors on response object iteration.
According to the documentation, PyIter_Next():

 | If there are no remaining values, returns NULL with no exception set.
 | If an error occurs while retrieving the item, returns NULL and passes
 | along the exception.

Previously, this exception wasn't properly handled and the response was
finalized as successful.

This issue was introduced in b0148ec28c4d.

A check for PyErr_Occurred() located in the code below might print this
traceback or occasionally catch an exception from one of the two response
close() calls.

Albeit that exceptions from the close() calls also need to be catched,
it's clear that this particular check wasn't supposed to do so.  This is
another issue and it will be fixed later.
2019-11-14 17:48:48 +03:00
Valentin Bartenev 69ff7ce731 Python: releasing GIL while waiting for a request.
It unblocks other threads that can be forked by the application
to work in background.

This closes #336 issue on GitHub.
2019-11-13 16:45:37 +03:00
Valentin Bartenev cc82547782 Respecting AR environment variable to configure ar binary. 2019-11-07 19:53:25 +03:00
Valentin Bartenev 75453479f3 Configuration: added check for mandatory options of "action". 2019-10-09 15:26:59 +03:00
Valentin Bartenev 1b4c96f265 Version bump. 2019-10-07 18:38:41 +03:00
Valentin Bartenev 59db9a3887 Added tag 1.12.0 for changeset b391df5f0102 2019-10-03 17:34:58 +03:00
Valentin Bartenev 946cbd1f10 Generated Dockerfiles for Unit 1.12.0. 2019-10-03 17:08:32 +03:00
Valentin Bartenev b1cb78ef8e Added version 1.12.0 CHANGES. 2019-10-03 16:30:31 +03:00
Valentin Bartenev 73f096f796 Added response status code to error page body.
Also the error page markup is now valid according to HTML5 specification.
All optional tags were omitted.
2019-10-02 20:04:52 +03:00
Valentin Bartenev f8ff71b917 HTTP: corrected allocation size for tail chunk. 2019-09-30 19:11:17 +03:00
Valentin Bartenev f7d3db314d HTTP parser: removed unused "exten" field.
This field was intended for MIME type lookup by file extension when serving
static files, but this use case is too narrow; only a fraction of requests
targets static content, and the URI presumably isn't rewritten.  Moreover,
current implementation uses the entire filename for MIME type lookup if the
file has no extension.

Instead of extracting filenames and extensions when parsing requests, it's
easier to obtain them right before serving static content; this behavior is
already implemented.  Thus, we can drop excessive logic from parser.
2019-09-30 19:11:17 +03:00
Valentin Bartenev 2dbda125db HTTP parser: normalization of paths ending with "." or "..".
Earlier, the paths were normalized only if there was a "/" at the end, which
is wrong according to section 5.2.4 of RFC 3986 and hypothetically may allow
to the directory above the document root.
2019-09-30 19:11:17 +03:00
Valentin Bartenev f2c0f2899a Refactored nxt_process_create() for more explicit pipe closing. 2019-09-26 16:03:02 +03:00
Valentin Bartenev 9c06bfdf2c Fixed descriptors leak on process creation.
The leak has been introduced in 325b315e48c4.
This closes #322 issue in GitHub.
2019-09-26 16:03:01 +03:00
Valentin Bartenev 514f34144a Static: returning 404 for Unix domain sockets.
It's now similar to how attempts to access other non-regular files are handled.
2019-09-24 15:33:42 +03:00
Valentin Bartenev 5c50329f8e Fixed segfault if an inappropriate file system object is requested.
Found by Coverity (CID 349483).
2019-09-20 14:31:19 +03:00
Valentin Bartenev 8853dece44 Version bump. 2019-09-20 14:29:11 +03:00
Valentin Bartenev db777d1e7f Added tag 1.11.0 for changeset 3b1601ac0f2f 2019-09-19 17:38:16 +03:00
Valentin Bartenev 7d53cc7029 Generated Dockerfiles for Unit 1.11.0. 2019-09-19 17:36:09 +03:00
Valentin Bartenev 2281d9f02c Added version 1.11.0 CHANGES. 2019-09-19 17:28:55 +03:00
Valentin Bartenev 08a8d1510d Basic support for serving static files. 2019-09-19 02:47:09 +03:00
Valentin Bartenev ca01845d89 Configuration: added ability to modify object members with slashes.
Example:

  PUT/POST/DELETE /config/listeners/unix:%2Fpath%2Fto%2Fsocket

This follows a49ee872e83d.
2019-09-18 16:03:28 +03:00
Valentin Bartenev 6352c21a58 HTTP parser: fixed parsing of target after literal space character.
In theory, all space characters in request target must be encoded; however,
some clients may violate the specification.  For the sake of interoperability,
Unit supports unencoded space characters.

Previously, if there was a space character before the extension or arguments
parts, those parts weren't recognized.  Also, quoted symbols and complex
target weren't detected after a space character.
2019-09-17 18:40:21 +03:00
Valentin Bartenev 3b77e402a9 HTTP parser: removed unused "plus_in_target" flag. 2019-09-16 20:17:42 +03:00
Valentin Bartenev 56f4085b9d HTTP parser: removed unused "offset" field.
Thanks to 洪志道 (Hong Zhi Dao).
2019-09-16 20:17:42 +03:00
Valentin Bartenev 2fb7a1bfb9 HTTP parser: removed unused "exten_start" and "args_start" fields. 2019-09-16 20:17:42 +03:00
Valentin Bartenev 64be8717bd Configuration: added ability to access object members with slashes.
Now URI encoding can be used to escape "/" in the request path:

  GET /config/listeners/unix:%2Fpath%2Fto%2Fsocket/
2019-09-16 20:17:42 +03:00
Valentin Bartenev 1298824130 Version bump. 2019-08-26 18:06:03 +03:00
Valentin Bartenev bc57d1d076 Added tag 1.10.0 for changeset cdbba3c3e376 2019-08-22 18:56:22 +03:00
Valentin Bartenev 19f59b221d Generated Dockerfiles for Unit 1.10.0. 2019-08-22 18:43:25 +03:00
Valentin Bartenev 700987c355 Fixed rebuilding of Dockerfiles. 2019-08-22 18:43:21 +03:00