changeset 479:cac17a050953

Finish the mq
author Louis Opter <kalessin@kalessin.fr>
date Sun, 26 Jun 2016 10:39:15 -0700
parents 904eec6daae6
children ad196be66ad1
files do_not_warn_on_unknown_packets.patch dont_use_time_t.patch fix_build_warnings.patch fix_stack_overflow_in_jsmn.patch fix_stack_underflow_in_jsonrpc.patch mkdtemp_error_handling.patch pkgbuild_fix.patch series use_systemd_user_group_keys.patch
diffstat 9 files changed, 0 insertions(+), 552 deletions(-) [+]
line wrap: on
line diff
--- a/do_not_warn_on_unknown_packets.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-# HG changeset patch
-# Parent  0609b70c96424f0d43b1a7d97171f7831b3d33a4
-Do not warn when receiving unknown LIFX packets
-
-This is confusing people, INFO is good enough.
-
-diff --git a/lifx/wire_proto.c b/lifx/wire_proto.c
---- a/lifx/wire_proto.c
-+++ b/lifx/wire_proto.c
-@@ -810,7 +810,7 @@
-         const struct lgtd_lifx_packet_info *pkt_info =
-             lgtd_lifx_wire_get_packet_info(read.hdr.packet_type);
-         if (!pkt_info) {
--            lgtd_warnx(
-+            lgtd_info(
-                 "received unknown packet %#x from %s",
-                 read.hdr.packet_type, peer_addr
-             );
--- a/dont_use_time_t.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-# HG changeset patch
-# Parent  37abecb2b0d3417349a2081a541cfbe4609f6892
-Typedef lgtd_time_mono_t to an uint64_t on all platforms
-
-time_t is 32 bits on 32 bits platforms (at least on Linux).
-
-This should fix the current armhf test failures.
-
-Not sure what's gonna be the fix in the future since struct timespec
-uses time_t.
-
-diff --git a/compat/Darwin/time_monotonic.c b/compat/Darwin/time_monotonic.c
---- a/compat/Darwin/time_monotonic.c
-+++ b/compat/Darwin/time_monotonic.c
-@@ -22,12 +22,13 @@
- #include <mach/mach_time.h>
- #include <sys/time.h>
- #include <assert.h>
-+#include <stdint.h>
- 
- #include "time_monotonic.h"
- 
- enum { MSECS_IN_NSEC = 1000000 };
- 
--time_t
-+lgtd_time_mono_t
- lgtd_time_monotonic_msecs(void)
- {
-     static mach_timebase_info_data_t timebase = { 0, 0 };
-diff --git a/compat/Darwin/time_monotonic.h b/compat/Darwin/time_monotonic.h
---- a/compat/Darwin/time_monotonic.h
-+++ b/compat/Darwin/time_monotonic.h
-@@ -17,6 +17,6 @@
- 
- #pragma once
- 
--typedef time_t lgtd_time_mono_t;
-+typedef uint64_t lgtd_time_mono_t;
- 
- lgtd_time_mono_t lgtd_time_monotonic_msecs(void);
-diff --git a/compat/generic/time_monotonic.c b/compat/generic/time_monotonic.c
---- a/compat/generic/time_monotonic.c
-+++ b/compat/generic/time_monotonic.c
-@@ -15,11 +15,12 @@
- // You should have received a copy of the GNU General Public License
- // along with lighstd.  If not, see <http://www.gnu.org/licenses/>.
- 
-+#include <stdint.h>
- #include <time.h>
- 
- #include "time_monotonic.h"
- 
--time_t
-+lgtd_time_mono_t
- lgtd_time_monotonic_msecs(void)
- {
-     struct timespec tp;
-diff --git a/compat/generic/time_monotonic.h b/compat/generic/time_monotonic.h
---- a/compat/generic/time_monotonic.h
-+++ b/compat/generic/time_monotonic.h
-@@ -17,6 +17,6 @@
- 
- #pragma once
- 
--typedef time_t lgtd_time_mono_t;
-+typedef uint64_t lgtd_time_mono_t;
- 
- lgtd_time_mono_t lgtd_time_monotonic_msecs(void);
--- a/fix_build_warnings.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-# HG changeset patch
-# Parent  1ac38c86384ead939ff131b852ab43687d930bb9
-Fix build warnings and update the changelog
-
-diff --git a/core/lightsd.c b/core/lightsd.c
---- a/core/lightsd.c
-+++ b/core/lightsd.c
-@@ -79,7 +79,7 @@
- static void
- lgtd_signal_event_callback(int signum, short events, void *ctx)
- {
--    int i = (int)ctx;
-+    intptr_t i = (intptr_t)ctx;
-     assert(i >= 0);
-     assert(i < (int)LGTD_ARRAY_SIZE(lgtd_signals));
-     assert(i < (int)LGTD_ARRAY_SIZE(lgtd_signal_evs));
-diff --git a/docs/changelog.rst b/docs/changelog.rst
---- a/docs/changelog.rst
-+++ b/docs/changelog.rst
-@@ -18,29 +18,32 @@
- and improvements, both in the code but also the documentation and examples.
- 
- Also worth noting, is the full continuous integration pipeline that has been
--setup behind the scenes. It will hopefully make it a lot easier to work on the
--project.
-+setup behind the scenes. Most of the work for this release went into it. It will
-+hopefully make it a lot easier to work on the project.
- 
- Fixes
- ~~~~~
- 
--- A couple of crash/security fixes by , one being in jsmn_
--  (JSON parser) which has been upgraded to its latest version;
--- FreeBSD build (more BSD fixes to come though, see GH-16_);
--- WIP…
-+- Discovery now works properly on computers with multiple network interfaces
-+  (closes :gh:`2`);
-+- Correctly support optional arguments in the JSON-RPC API;
-+- A couple of crash/security fixes, one being in the jsmn_ JSON parser which has
-+  been upgraded to its latest version;
-+- FreeBSD build (more BSD fixes to come though, see :gh:`16`).
- 
- .. _jsmn: https://github.com/zserge/jsmn
--.. _GH-16: https://github.com/lopter/lightsd/issues/16
- 
- Acknowledgments
- ~~~~~~~~~~~~~~~
- 
- Thanks to:
- 
--- `Xavier Deguillard`_ for his contributions, additional automated tests will be
-+- `Sylvain Laurent`_ for his original work on fixing discovery;
-+- `Xavier Deguillard`_ for his contributions; additional automated tests will be
-   setup to make crashes and security issues much harder to creep in;
- - All the people who have been trying the project and reporting issues!
- 
-+.. _Sylvain Laurent: https://github.com/Magicking/
- .. _Xavier Deguillard: https://github.com/Rip-Rip
- 
- 1.1.2 (2015-11-30)
-diff --git a/tests/lifx/broadcast/test_broadcast_write_callback_getifaddrs_fails.c b/tests/lifx/broadcast/test_broadcast_write_callback_getifaddrs_fails.c
---- a/tests/lifx/broadcast/test_broadcast_write_callback_getifaddrs_fails.c
-+++ b/tests/lifx/broadcast/test_broadcast_write_callback_getifaddrs_fails.c
-@@ -27,12 +27,6 @@
- 
- enum { MOCK_SOCKET_FD = 32 };
- static struct event *MOCK_WRITE_EV = (struct event *)0x7061726973;
--static const struct sockaddr_in LIFX_BROADCAST_ADDR = {
--    .sin_family = AF_INET,
--    .sin_addr = { INADDR_BROADCAST },
--    .sin_port = LGTD_STATIC_HTONS(LGTD_LIFX_PROTOCOL_PORT),
--    .sin_zero = { 0 }
--};
- 
- static int event_del_call_count = 0;
- 
--- a/fix_stack_overflow_in_jsmn.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,229 +0,0 @@
-# HG changeset patch
-# User Xavier Deguillard <deguilx@gmail.com>
-# Parent  69e2492f799fef0a248f7e0b2d46e050d1612644
-Fix a stack overflow in JSMN when parsing `null'
-
-Also, start updating that changelog!
-
-diff --git a/core/client.c b/core/client.c
---- a/core/client.c
-+++ b/core/client.c
-@@ -66,8 +66,6 @@
-     }
- }
- 
--#pragma GCC diagnostic push
--#pragma GCC diagnostic ignored "-Wswitch"
- static void
- lgtd_client_read_callback(struct bufferevent *bev, void *ctx)
- {
-@@ -89,7 +87,7 @@
-         jsmn_parser jsmn_ctx;
-     parse_after_realloc:
-         jsmn_init(&jsmn_ctx);
--        jsmnerr_t rv = jsmn_parse(&jsmn_ctx, buf, nbytes, tokens, ntokens);
-+        int rv = jsmn_parse(&jsmn_ctx, buf, nbytes, tokens, ntokens);
-         switch (rv) {
-         case JSMN_ERROR_NOMEM:
-         case JSMN_ERROR_INVAL:
-@@ -138,7 +136,6 @@
-         nbytes = evbuffer_get_contiguous_space(input);
-     } while (nbytes);
- }
--#pragma GCC diagnostic pop
- 
- static void
- lgtd_client_event_callback(struct bufferevent *bev, short events, void *ctx)
-diff --git a/core/jsmn.c b/core/jsmn.c
---- a/core/jsmn.c
-+++ b/core/jsmn.c
-@@ -20,8 +20,6 @@
-  * THE SOFTWARE.
-  */
- 
--#include <stdlib.h>
--
- #include "jsmn.h"
- 
- /**
-@@ -56,7 +54,7 @@
- /**
-  * Fills next available token with JSON primitive.
-  */
--static jsmnerr_t jsmn_parse_primitive(jsmn_parser *parser, const char *js,
-+static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
- 		size_t len, jsmntok_t *tokens, size_t num_tokens) {
- 	jsmntok_t *token;
- 	int start;
-@@ -103,9 +101,9 @@
- }
- 
- /**
-- * Filsl next token with JSON string.
-+ * Fills next token with JSON string.
-  */
--static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js,
-+static int jsmn_parse_string(jsmn_parser *parser, const char *js,
- 		size_t len, jsmntok_t *tokens, size_t num_tokens) {
- 	jsmntok_t *token;
- 
-@@ -172,12 +170,12 @@
- /**
-  * Parse JSON string and fill tokens.
-  */
--jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
-+int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
- 		jsmntok_t *tokens, unsigned int num_tokens) {
--	jsmnerr_t r;
-+	int r;
- 	int i;
- 	jsmntok_t *token;
--	int count = 0;
-+	int count = parser->toknext;
- 
- 	for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
- 		char c;
-@@ -262,7 +260,7 @@
- 				parser->toksuper = parser->toknext - 1;
- 				break;
- 			case ',':
--				if (tokens != NULL &&
-+				if (tokens != NULL && parser->toksuper != -1 &&
- 						tokens[parser->toksuper].type != JSMN_ARRAY &&
- 						tokens[parser->toksuper].type != JSMN_OBJECT) {
- #ifdef JSMN_PARENT_LINKS
-@@ -285,7 +283,7 @@
- 			case '5': case '6': case '7' : case '8': case '9':
- 			case 't': case 'f': case 'n' :
- 				/* And they must not be keys of the object */
--				if (tokens != NULL) {
-+				if (tokens != NULL && parser->toksuper != -1) {
- 					jsmntok_t *t = &tokens[parser->toksuper];
- 					if (t->type == JSMN_OBJECT ||
- 							(t->type == JSMN_STRING && t->size != 0)) {
-@@ -311,10 +309,12 @@
- 		}
- 	}
- 
--	for (i = parser->toknext - 1; i >= 0; i--) {
--		/* Unmatched opened object or array */
--		if (tokens[i].start != -1 && tokens[i].end == -1) {
--			return JSMN_ERROR_PART;
-+	if (tokens != NULL) {
-+		for (i = parser->toknext - 1; i >= 0; i--) {
-+			/* Unmatched opened object or array */
-+			if (tokens[i].start != -1 && tokens[i].end == -1) {
-+				return JSMN_ERROR_PART;
-+			}
- 		}
- 	}
- 
-diff --git a/core/jsmn.h b/core/jsmn.h
---- a/core/jsmn.h
-+++ b/core/jsmn.h
-@@ -37,20 +37,21 @@
-  * 	o Other primitive: number, boolean (true/false) or null
-  */
- typedef enum {
--	JSMN_PRIMITIVE = 0,
-+	JSMN_UNDEFINED = 0,
- 	JSMN_OBJECT = 1,
- 	JSMN_ARRAY = 2,
--	JSMN_STRING = 3
-+	JSMN_STRING = 3,
-+	JSMN_PRIMITIVE = 4
- } jsmntype_t;
- 
--typedef enum {
-+enum jsmnerr {
- 	/* Not enough tokens were provided */
- 	JSMN_ERROR_NOMEM = -1,
- 	/* Invalid character inside JSON string */
- 	JSMN_ERROR_INVAL = -2,
- 	/* The string is not a full JSON packet, more bytes expected */
- 	JSMN_ERROR_PART = -3
--} jsmnerr_t;
-+};
- 
- /**
-  * JSON token description.
-@@ -87,7 +88,7 @@
-  * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
-  * a single JSON object.
-  */
--jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
-+int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
- 		jsmntok_t *tokens, unsigned int num_tokens);
- 
- #ifdef __cplusplus
-diff --git a/core/pipe.c b/core/pipe.c
---- a/core/pipe.c
-+++ b/core/pipe.c
-@@ -68,8 +68,6 @@
- 
- static void lgtd_command_pipe_reset(struct lgtd_command_pipe *);
- 
--#pragma GCC diagnostic push
--#pragma GCC diagnostic ignored "-Wswitch"
- static void
- lgtd_command_pipe_read_callback(evutil_socket_t socket, short events, void *ctx)
- {
-@@ -106,7 +104,7 @@
-             ssize_t bufsz = evbuffer_get_length(pipe->read_buf);
-         parse_after_realloc:
-             jsmn_init(&jsmn_ctx);
--            jsmnerr_t rv = jsmn_parse(&jsmn_ctx, buf, bufsz, tokens, ntokens);
-+            int rv = jsmn_parse(&jsmn_ctx, buf, bufsz, tokens, ntokens);
-             switch (rv) {
-             case JSMN_ERROR_NOMEM:
-             case JSMN_ERROR_INVAL:
-@@ -153,7 +151,6 @@
- 
-     lgtd_command_pipe_reset(pipe);
- }
--#pragma GCC diagnostic pop
- 
- static bool
- _lgtd_command_pipe_open(const char *path)
-diff --git a/docs/changelog.rst b/docs/changelog.rst
---- a/docs/changelog.rst
-+++ b/docs/changelog.rst
-@@ -11,6 +11,38 @@
-   are added in a backwards-compatible manner;
- - PATCH version gets incremented for backwards-compatible bug fixes.
- 
-+1.2.0 (unreleased)
-+------------------
-+
-+This release doesn't have any new user-facing feature but packs a bunch of fixes
-+and improvements, both in the code but also the documentation and examples.
-+
-+Also worth noting, is the full continuous integration pipeline that has been
-+setup behind the scenes. It will hopefully make it a lot easier to work on the
-+project.
-+
-+Fixes
-+~~~~~
-+
-+- A couple of crash/security fixes by , one being in jsmn_
-+  (JSON parser) which has been upgraded to its latest version;
-+- FreeBSD build (more BSD fixes to come though, see GH-16_);
-+- WIP…
-+
-+.. _jsmn: https://github.com/zserge/jsmn
-+.. _GH-16: https://github.com/lopter/lightsd/issues/16
-+
-+Acknowledgments
-+~~~~~~~~~~~~~~~
-+
-+Thanks to:
-+
-+- `Xavier Deguillard`_ for his contributions, additional automated tests will be
-+  setup to make crashes and security issues much harder to creep in;
-+- All the people who have been trying the project and reporting issues!
-+
-+.. _Xavier Deguillard: https://github.com/Rip-Rip
-+
- 1.1.2 (2015-11-30)
- ------------------
- 
--- a/fix_stack_underflow_in_jsonrpc.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-# HG changeset patch
-# User Xavier Deguillard <deguilx@gmail.com>
-# Parent  a7efed63bc95fd9efac9dbb43cbdf93e1064fe9b
-Fix stack underflow in jsonrpc
-
-diff --git a/core/jsonrpc.c b/core/jsonrpc.c
---- a/core/jsonrpc.c
-+++ b/core/jsonrpc.c
-@@ -400,7 +400,7 @@
-     }
- 
-     for (int si = 0; si != schema_size; si++) {
--        if (!schema[si].optional) {
-+        if (!schema[si].optional && schema[si].value_offset != -1) {
-             const jsmntok_t *seen = LGTD_JSONRPC_GET_JSMNTOK(
-                 output, schema[si].value_offset
-             );
--- a/mkdtemp_error_handling.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-# HG changeset patch
-# Parent  37abecb2b0d3417349a2081a541cfbe4609f6892
-Improve error handling in lgtd_tests_make_temp_dir
-
-Hopefully let me solve those segfaults in the unit-tests of the pipe
-module.
-
-diff --git a/tests/core/tests_utils.c b/tests/core/tests_utils.c
---- a/tests/core/tests_utils.c
-+++ b/tests/core/tests_utils.c
-@@ -180,10 +180,13 @@
- {
-     char buf[PATH_MAX] = { 0 };
-     int n = snprintf(buf, sizeof(buf), "%s/lightsd.test.XXXXXXXX", P_tmpdir);
--    if (n >= (int)sizeof(buf)) {
--        errx(1, "cannot allocate temporary directory");
-+    if (n >= (int)sizeof(buf) || n < 0) {
-+        lgtd_errx(1, "cannot allocate temporary directory");
-     }
--    return strdup(mkdtemp(buf));
-+    if (!mkdtemp(buf)) {
-+        lgtd_err(1, "cannot create temporary directory");
-+    }
-+    return strdup(buf);
- }
- 
- void
--- a/pkgbuild_fix.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-# HG changeset patch
-# Parent  b0cc0e6c6801ce4593bc7d998d767981e07f9c35
-Fix Pacman (Arch Linux) packaging
-
-Like on Debian, hyphens in version numbers aren't supported, so use a
-tilde instead.
-
-While we are at it, fix a CMake warning when you have all the
-dependencies for the release script but are missing Sphinx to build the
-docs.
-
-diff --git a/dist/CMakeLists.txt b/dist/CMakeLists.txt
---- a/dist/CMakeLists.txt
-+++ b/dist/CMakeLists.txt
-@@ -21,9 +21,11 @@
-     pre_release
-     package_release
-     release_new_tag
--    release_docs
-     release_debuild
- )
-+IF (SPHINX_FOUND)
-+    LIST(APPEND RELEASE_COMMANDS release_docs)
-+ENDIF ()
- FOREACH (TARGET ${RELEASE_COMMANDS})
-     ADD_CUSTOM_TARGET(
-         ${TARGET}
-@@ -33,7 +35,9 @@
-     )
- ENDFOREACH ()
- 
--ADD_DEPENDENCIES(release_docs docs)
-+IF (SPHINX_FOUND)
-+    ADD_DEPENDENCIES(release_docs docs)
-+ENDIF (SPHINX_FOUND)
- 
- SET(
-     EXTRA_OUTPUT
-diff --git a/dist/pkgbuild/.SRCINFO b/dist/pkgbuild/.SRCINFO
---- a/dist/pkgbuild/.SRCINFO
-+++ b/dist/pkgbuild/.SRCINFO
-@@ -1,6 +1,6 @@
- pkgbase = lightsd
- 	pkgdesc = Daemon to control your LIFX smart bulbs via a JSON-RPC API
--	pkgver = {{ version }}
-+	pkgver = {{ version|replace("-", "~") }}
- 	pkgrel = {{ build_number }}
- 	epoch = 1
- 	url = https://www.github.com/lopter/lightsd/
-diff --git a/dist/pkgbuild/PKGBUILD b/dist/pkgbuild/PKGBUILD
---- a/dist/pkgbuild/PKGBUILD
-+++ b/dist/pkgbuild/PKGBUILD
-@@ -1,7 +1,9 @@
- # Maintainer: Louis Opter <kalessin@kalessin.fr>
- 
- pkgname=lightsd
--pkgver={{ version }}
-+pkgver={{ version|replace("-", "~") }}
-+# This will have - instead of ~ for rc versions:
-+_lightsdver={{ version }}
- pkgrel={{ build_number }}
- epoch=1
- pkgdesc="Daemon to control your LIFX smart bulbs via a JSON-RPC API"
-@@ -19,7 +21,7 @@
- install=lightsd.install
- 
- build() {
--    cd "$srcdir/$pkgname-$pkgver"
-+    cd "$srcdir/$pkgname-$_lightsdver"
- 
-     cmake .                         \
-         -DCMAKE_BUILD_TYPE=RELEASE  \
-@@ -30,14 +32,13 @@
- }
- 
- check() {
--    cd "$srcdir/$pkgname-$pkgver"
-+    cd "$srcdir/$pkgname-$_lightsdver"
- 
-     make test
- }
- 
- package() {
--    cd "$srcdir/$pkgname-$pkgver"
-+    cd "$srcdir/$pkgname-$_lightsdver"
- 
-     make DESTDIR="$pkgdir/" install
- }
--
--- a/series	Sun Jun 26 10:03:05 2016 -0700
+++ b/series	Sun Jun 26 10:39:15 2016 -0700
@@ -1,11 +1,3 @@
-mkdtemp_error_handling.patch
-dont_use_time_t.patch
-do_not_warn_on_unknown_packets.patch
-pkgbuild_fix.patch
-fix_stack_underflow_in_jsonrpc.patch
-fix_stack_overflow_in_jsmn.patch
-use_systemd_user_group_keys.patch
-fix_build_warnings.patch
 add_power_transition.patch
 open_gateway_on_any_bulb_response.patch #+future
 make_gateway_write_callbacks_low_priority.patch #+future
--- a/use_systemd_user_group_keys.patch	Sun Jun 26 10:03:05 2016 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-# HG changeset patch
-# User Xavier Deguillard <deguilx@gmail.com>
-# Parent  bc553481b7df85b46889177adb80d0428b98130c
-Use systemd's User/Group keys
-
-diff --git a/dist/lightsd.service b/dist/lightsd.service
---- a/dist/lightsd.service
-+++ b/dist/lightsd.service
-@@ -3,7 +3,10 @@
- After=network.target
- 
- [Service]
--ExecStart=/usr/bin/lightsd -t -v warning -u lightsd -s %t/lightsd/socket -c %t/lightsd/pipe
-+ExecStart=/usr/bin/lightsd -t -v warning -s %t/lightsd/socket -c %t/lightsd/pipe
-+User=lightsd
-+Group=lightsd
-+RuntimeDirectory=lightsd
- Restart=on-failure
- 
- [Install]