The branch, master has been updated via f1c49d7 messaging: Fix creating the dgm lockfile via 3e705ad lib/tsocket: fix non-blockging connect() error handling via 41fe3cf README.Coding: Update section about debug macros via b041a58 Remove function name from callers of DBG_* via 1d3df7e debug: Prefix messages from DBG_* with function name from 38d547b dcerpc.idl: accept invalid dcerpc_bind_nak pdus
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit f1c49d7656b29b2e77e9373ccb863f07e19e5299 Author: Volker Lendecke <v...@samba.org> Date: Wed Oct 21 15:15:51 2015 +0200 messaging: Fix creating the dgm lockfile There might be situations where the lock directory moves to a location where a previous installation left the datagram sockets (Yes, I just came across this). We can't really deal with it except by just removing the socket without properly checking. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> Autobuild-User(master): Jeremy Allison <j...@samba.org> Autobuild-Date(master): Thu Oct 22 02:14:29 CEST 2015 on sn-devel-104 commit 3e705adcab8404ee6e5f71a38e98eeaca29a5b61 Author: Ralph Boehme <s...@samba.org> Date: Wed Oct 21 16:08:00 2015 +0200 lib/tsocket: fix non-blockging connect() error handling Non-blockging connect() either returns immediate success, or -1 with errno EINPROGESS as indication that the connection is pending. All other errnos indicate immediate failure. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 41fe3cfcb5fa2441da9180e57255a3b7fa23da12 Author: Christof Schmitt <c...@samba.org> Date: Wed Oct 21 11:12:22 2015 -0700 README.Coding: Update section about debug macros Signed-off-by: Christof Schmitt <c...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit b041a589ae680de38f4e9c8c4979c3972a4e7b07 Author: Christof Schmitt <c...@samba.org> Date: Wed Oct 21 11:07:57 2015 -0700 Remove function name from callers of DBG_* It is now added automatically. Signed-off-by: Christof Schmitt <c...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 1d3df7e18def05c4552f4647b3644f7b7952fc66 Author: Christof Schmitt <c...@samba.org> Date: Wed Oct 21 11:07:35 2015 -0700 debug: Prefix messages from DBG_* with function name Signed-off-by: Christof Schmitt <c...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> ----------------------------------------------------------------------- Summary of changes: README.Coding | 24 +++++++++++++++--------- lib/tsocket/tsocket_bsd.c | 13 +++++-------- lib/util/charset/util_str.c | 4 ++-- lib/util/debug.h | 18 +++++++++++++----- source3/lib/ctdbd_conn.c | 2 +- source3/lib/dbwrap/dbwrap_ctdb.c | 2 +- source3/lib/dbwrap/dbwrap_watch.c | 11 +++++------ source3/lib/messages_dgm.c | 20 ++++++++++++++++++++ source3/lib/messages_dgm_ref.c | 11 +++++------ source3/lib/util.c | 4 ++-- 10 files changed, 69 insertions(+), 40 deletions(-) Changeset truncated at 500 lines: diff --git a/README.Coding b/README.Coding index 9073b77..29bad1b 100644 --- a/README.Coding +++ b/README.Coding @@ -417,15 +417,21 @@ The only exception is the test code that depends repeated use of calls like CHECK_STATUS, CHECK_VAL and others. -Function names in DEBUG statements ----------------------------------- +DEBUG statements +---------------- -Many DEBUG statements contain the name of the function they appear in. This is -not a good idea, as this is prone to bitrot. Function names change, code -moves, but the DEBUG statements are not adapted. Use %s and __func__ for this: +Use these following macros instead of DEBUG: -Bad Example: - DEBUG(0, ("strstr_m: src malloc fail\n")); +DBG_ERR log level 0 error conditions +DBG_WARNING log level 1 warning conditions +DBG_NOTICE log level 3 normal, but significant, condition +DBG_INFO log level 5 informational message +DBG_DEBUG log level 10 debug-level message -Good Example: - DEBUG(0, ("%s: src malloc fail\n", __func__)); +Example usage: + +DBG_ERR("Memory allocation failed\n"); +DBG_DEBUG("Received %d bytes\n", count); + +The messages from these macros are automatically prefixed with the +function name. diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 8203755..ac0617d 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -2114,8 +2114,6 @@ static struct tevent_req *tstream_bsd_connect_send(TALLOC_CTX *mem_ctx, talloc_get_type_abort(remote->private_data, struct tsocket_address_bsd); int ret; - int err; - bool retry; bool do_bind = false; bool do_reuseaddr = false; bool do_ipv6only = false; @@ -2256,12 +2254,11 @@ static struct tevent_req *tstream_bsd_connect_send(TALLOC_CTX *mem_ctx, } ret = connect(state->fd, &rbsda->u.sa, rbsda->sa_socklen); - err = tsocket_bsd_error_from_errno(ret, errno, &retry); - if (retry) { - /* retry later */ - goto async; - } - if (tevent_req_error(req, err)) { + if (ret == -1) { + if (errno == EINPROGRESS) { + goto async; + } + tevent_req_error(req, errno); goto post; } diff --git a/lib/util/charset/util_str.c b/lib/util/charset/util_str.c index c1b81f1..ef8a82a 100644 --- a/lib/util/charset/util_str.c +++ b/lib/util/charset/util_str.c @@ -545,13 +545,13 @@ char *strstr_m(const char *src, const char *findstr) frame = talloc_stackframe(); if (!push_ucs2_talloc(frame, &src_w, src, &converted_size)) { - DBG_WARNING("strstr_m: src malloc fail\n"); + DBG_WARNING("src malloc fail\n"); TALLOC_FREE(frame); return NULL; } if (!push_ucs2_talloc(frame, &find_w, findstr, &converted_size)) { - DBG_WARNING("strstr_m: find malloc fail\n"); + DBG_WARNING("find malloc fail\n"); TALLOC_FREE(frame); return NULL; } diff --git a/lib/util/debug.h b/lib/util/debug.h index e399379..2a0a05c 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -204,6 +204,14 @@ extern int *DEBUGLEVEL_CLASS; #define DEBUGSEP(level)\ DEBUG((level),("===============================================================\n")) +/* Prefix messages with the function name */ +#define DBG_PREFIX(level, body ) \ + (void)( ((level) <= MAX_DEBUG_LEVEL) && \ + unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \ + && (dbghdrclass(level, DBGC_CLASS, __location__, __func__ )) \ + && (dbgtext("%s: ", __func__)) \ + && (dbgtext body) ) + /* * Debug levels matching RFC 3164 */ @@ -213,11 +221,11 @@ extern int *DEBUGLEVEL_CLASS; #define DBGLVL_INFO 5 /* informational message */ #define DBGLVL_DEBUG 10 /* debug-level message */ -#define DBG_ERR(...) DEBUG(DBGLVL_ERR, (__VA_ARGS__)) -#define DBG_WARNING(...) DEBUG(DBGLVL_WARNING, (__VA_ARGS__)) -#define DBG_NOTICE(...) DEBUG(DBGLVL_NOTICE, (__VA_ARGS__)) -#define DBG_INFO(...) DEBUG(DBGLVL_INFO, (__VA_ARGS__)) -#define DBG_DEBUG(...) DEBUG(DBGLVL_DEBUG, (__VA_ARGS__)) +#define DBG_ERR(...) DBG_PREFIX(DBGLVL_ERR, (__VA_ARGS__)) +#define DBG_WARNING(...) DBG_PREFIX(DBGLVL_WARNING, (__VA_ARGS__)) +#define DBG_NOTICE(...) DBG_PREFIX(DBGLVL_NOTICE, (__VA_ARGS__)) +#define DBG_INFO(...) DBG_PREFIX(DBGLVL_INFO, (__VA_ARGS__)) +#define DBG_DEBUG(...) DBG_PREFIX(DBGLVL_DEBUG, (__VA_ARGS__)) /* The following definitions come from lib/debug.c */ diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index c7c6356..9187ee7 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -431,7 +431,7 @@ static int ctdbd_init_connection(TALLOC_CTX *mem_ctx, conn->sockname = talloc_strdup(conn, sockname); if (conn->sockname == NULL) { - DBG_ERR("%s: talloc failed\n", __func__); + DBG_ERR("talloc failed\n"); ret = ENOMEM; goto fail; } diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c index 9066beb..457f427 100644 --- a/source3/lib/dbwrap/dbwrap_ctdb.c +++ b/source3/lib/dbwrap/dbwrap_ctdb.c @@ -1664,7 +1664,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx, fd = tdb_fd(db_ctdb->wtdb->tdb); ret = fchmod(fd, mode); if (ret == -1) { - DBG_WARNING("%s: fchmod failed: %s\n", __func__, + DBG_WARNING("fchmod failed: %s\n", strerror(errno)); TALLOC_FREE(result); return NULL; diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c index 426fe77..09e67fb 100644 --- a/source3/lib/dbwrap/dbwrap_watch.c +++ b/source3/lib/dbwrap/dbwrap_watch.c @@ -295,8 +295,7 @@ static void dbwrap_watch_record_stored_fn(TDB_DATA key, TDB_DATA data, size_t i, num_ids; if ((data.dsize % sizeof(struct server_id)) != 0) { - DBG_WARNING("%s: Invalid data size: %zu\n", __func__, - data.dsize); + DBG_WARNING("Invalid data size: %zu\n", data.dsize); return; } num_ids = data.dsize / sizeof(struct server_id); @@ -312,8 +311,8 @@ static void dbwrap_watch_record_stored_fn(TDB_DATA key, TDB_DATA data, key.dptr, key.dsize); if (!NT_STATUS_IS_OK(status)) { struct server_id_buf tmp; - DBG_WARNING("%s: messaging_send to %s failed: %s\n", - __func__, server_id_str_buf(dst, &tmp), + DBG_WARNING("messaging_send to %s failed: %s\n", + server_id_str_buf(dst, &tmp), nt_errstr(status)); } } @@ -346,8 +345,8 @@ static void dbwrap_watch_record_stored(struct db_context *db, return; } if (!NT_STATUS_IS_OK(status)) { - DBG_WARNING("%s: dbwrap_parse_record failed: %s\n", - __func__, nt_errstr(status)); + DBG_WARNING("dbwrap_parse_record failed: %s\n", + nt_errstr(status)); } } diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index 006e917..a802882 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -88,6 +88,26 @@ static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx, lockfile_fd = open(lockfile_name.buf, O_NONBLOCK|O_CREAT|O_RDWR, 0644); + + if ((lockfile_fd == -1) && + ((errno == ENXIO) /* Linux */ || + (errno == ENODEV) /* Linux kernel bug */ || + (errno == EOPNOTSUPP) /* FreeBSD */)) { + /* + * Huh -- a socket? This might be a stale socket from + * an upgrade of Samba. Just unlink and retry, nobody + * else is supposed to be here at this time. + * + * Yes, this is racy, but I don't see a way to deal + * with this properly. + */ + unlink(lockfile_name.buf); + + lockfile_fd = open(lockfile_name.buf, + O_NONBLOCK|O_CREAT|O_WRONLY, + 0644); + } + if (lockfile_fd == -1) { ret = errno; DEBUG(1, ("%s: open failed: %s\n", __func__, strerror(errno))); diff --git a/source3/lib/messages_dgm_ref.c b/source3/lib/messages_dgm_ref.c index e3b2d88..3ea8b9d 100644 --- a/source3/lib/messages_dgm_ref.c +++ b/source3/lib/messages_dgm_ref.c @@ -73,8 +73,7 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev, ret = messaging_dgm_init(ev, unique, socket_dir, lockfile_dir, msg_dgm_ref_recv, NULL); - DBG_DEBUG("%s: messaging_dgm_init returned %s\n", __func__, - strerror(ret)); + DBG_DEBUG("messaging_dgm_init returned %s\n", strerror(ret)); if (ret != 0) { DEBUG(10, ("messaging_dgm_init failed: %s\n", strerror(ret))); @@ -86,8 +85,8 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev, } else { int ret; ret = messaging_dgm_get_unique(getpid(), unique); - DBG_DEBUG("%s: messaging_dgm_get_unique returned %s\n", - __func__, strerror(ret)); + DBG_DEBUG("messaging_dgm_get_unique returned %s\n", + strerror(ret)); if (ret != 0) { TALLOC_FREE(result); *err = ret; @@ -103,7 +102,7 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev, } } - DBG_DEBUG("%s: unique = %"PRIu64"\n", __func__, *unique); + DBG_DEBUG("unique = %"PRIu64"\n", *unique); refs = tmp_refs; @@ -140,7 +139,7 @@ static int msg_dgm_ref_destructor(struct msg_dgm_ref *r) TALLOC_FREE(r->tevent_handle); - DBG_DEBUG("%s: refs=%p\n", __func__, refs); + DBG_DEBUG("refs=%p\n", refs); if (refs == NULL) { messaging_dgm_destroy(); diff --git a/source3/lib/util.c b/source3/lib/util.c index 7c24f8a..3a8bc67 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1967,8 +1967,8 @@ struct server_id pid_to_procid(pid_t pid) ret = messaging_dgm_get_unique(pid, &unique); if (ret != 0) { - DBG_WARNING("%s: messaging_dgm_get_unique failed: %s\n", - __func__, strerror(ret)); + DBG_WARNING("messaging_dgm_get_unique failed: %s\n", + strerror(ret)); } return (struct server_id) { -- Samba Shared Repository