[PATCH] A few unsorted patches
Volker Lendecke
Volker.Lendecke at SerNet.DE
Tue Aug 19 04:19:49 MDT 2014
Hi!
Review would be appreciated!
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From cfbc743f5aa214d6e604d6fc2ca6448d1d654383 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 18 Aug 2014 08:24:35 +0000
Subject: [PATCH 1/8] smbcontrol: Fix a typo
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/utils/smbcontrol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index 7c516c4..69d6161 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -225,7 +225,7 @@ static bool do_idmap(struct tevent_context *ev,
#if defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE)
/* Return the name of a process given it's PID. This will only work on Linux,
- * but that's probably moot since this whole stack tracing implementatino is
+ * but that's probably moot since this whole stack tracing implementation is
* Linux-specific anyway.
*/
static const char * procname(pid_t pid, char * buf, size_t bufsz)
--
1.8.1.2
From 2495ec316321343c4c9692409a64e34d5ec19754 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 19 Aug 2014 09:20:49 +0000
Subject: [PATCH 2/8] lib: Check socket length in ctdbd_connect
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 3e5e838..3ba8385 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -214,6 +214,7 @@ static int ctdbd_connect(int *pfd)
struct sockaddr_un addr = { 0, };
int fd;
socklen_t salen;
+ size_t namelen;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
@@ -223,7 +224,14 @@ static int ctdbd_connect(int *pfd)
}
addr.sun_family = AF_UNIX;
- snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", sockname);
+
+ namelen = strlcpy(addr.sun_path, sockname, sizeof(addr.sun_path));
+ if (namelen >= sizeof(addr.sun_path)) {
+ DEBUG(3, ("%s: Socket name too long: %s\n", __func__,
+ sockname));
+ close(fd);
+ return ENAMETOOLONG;
+ }
salen = sizeof(struct sockaddr_un);
--
1.8.1.2
From 79b923cfe1a75c5fedd5734819df030d117d1227 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 18 Aug 2014 11:58:05 +0000
Subject: [PATCH 3/8] messaging3: Don't print a message if there's nothing to
clean up
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages_dgm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index 2c43ec3..e2ee751 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -335,8 +335,10 @@ int messaging_dgm_cleanup(struct messaging_dgm_context *ctx, pid_t pid)
fd = open(lockfile_name, O_NONBLOCK|O_WRONLY, 0);
if (fd == -1) {
ret = errno;
- DEBUG(10, ("%s: open(%s) failed: %s\n", __func__,
- lockfile_name, strerror(ret)));
+ if (ret != ENOENT) {
+ DEBUG(10, ("%s: open(%s) failed: %s\n", __func__,
+ lockfile_name, strerror(ret)));
+ }
TALLOC_FREE(lockfile_name);
return ret;
}
--
1.8.1.2
From f3b857c4c311aa4afc56213cebc64b4f7bcd9ba6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 18 Aug 2014 11:59:00 +0000
Subject: [PATCH 4/8] smbd: Only DEBUG errors from messaging_cleanup
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/server.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index bea25cb..1a0d3c9 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -421,8 +421,11 @@ static void remove_child_pid(struct smbd_parent_context *parent,
child_id = pid_to_procid(pid);
ret = messaging_cleanup(parent->msg_ctx, pid);
- DEBUG(10, ("%s: messaging_cleanup returned %s\n",
- __func__, ret ? strerror(ret) : "ok"));
+
+ if ((ret != 0) && (ret != ENOENT)) {
+ DEBUG(10, ("%s: messaging_cleanup returned %s\n",
+ __func__, ret ? strerror(ret) : "ok"));
+ }
for (child = parent->children; child != NULL; child = child->next) {
if (child->pid == pid) {
--
1.8.1.2
From 90c2f2baab16d61916f6c67dea274676b5ac023f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Aug 2014 12:07:25 +0200
Subject: [PATCH 5/8] locking: Save 48 .text bytes (x86, -O3)
It's always hard to believe, but gcc generates tighter code with an
explicit struct initializer in many cases.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/locking/posix.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/source3/locking/posix.c b/source3/locking/posix.c
index a0966ab..a99efb9 100644
--- a/source3/locking/posix.c
+++ b/source3/locking/posix.c
@@ -349,9 +349,10 @@ struct lock_ref_count_key {
static TDB_DATA locking_ref_count_key_fsp(files_struct *fsp,
struct lock_ref_count_key *tmp)
{
- ZERO_STRUCTP(tmp);
- tmp->id = fsp->file_id;
- tmp->r = 'r';
+ *tmp = (struct lock_ref_count_key) {
+ .id = fsp->file_id,
+ .r = 'r'
+ };
return make_tdb_data((uint8_t *)tmp, sizeof(*tmp));
}
--
1.8.1.2
From 2e6974ff709d77151ddc3a4616a2b75a18ac7f27 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 18 Aug 2014 22:37:10 +0200
Subject: [PATCH 6/8] g_lock: save 32 bytes .text
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/g_lock.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 6813f06..41654c2 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -157,9 +157,8 @@ static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self,
}
locks = tmp;
- ZERO_STRUCT(locks[num_locks]);
- locks[num_locks].pid = self;
- locks[num_locks].lock_type = type;
+ locks[num_locks] = (struct g_lock_rec) {
+ .pid = self, .lock_type = type };
num_locks += 1;
modified = true;
--
1.8.1.2
From 0a91f9a09010853e562c381f0f575c70f4329da1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 2 Aug 2014 13:57:43 +0200
Subject: [PATCH 7/8] messaging_dgm: Use %ju to fill lockfile
... much nicer than PRIu64
Also, append a \n. Makes it better readable when looking at the lockfile
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages_dgm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index e2ee751..1bf1805 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -106,7 +106,7 @@ static int messaging_dgm_lockfile_create(TALLOC_CTX *tmp_ctx,
goto fail_close;
}
- unique_len = snprintf(buf, sizeof(buf), "%"PRIu64, unique);
+ unique_len = snprintf(buf, sizeof(buf), "%ju\n", (uintmax_t)unique);
/* shorten a potentially preexisting file */
--
1.8.1.2
From c33f6f6ac5d7487398576d527fbd9a02c170527a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 2 Aug 2014 13:26:44 +0200
Subject: [PATCH 8/8] messaging_dgm: Factor out messaging_dgm_lockfile_name
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages_dgm.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c
index 1bf1805..659b835 100644
--- a/source3/lib/messages_dgm.c
+++ b/source3/lib/messages_dgm.c
@@ -47,6 +47,14 @@ static void messaging_dgm_recv(struct unix_msg_ctx *ctx,
uint8_t *msg, size_t msg_len,
void *private_data);
+static char *messaging_dgm_lockfile_name(TALLOC_CTX *mem_ctx,
+ const char *cache_dir,
+ pid_t pid)
+{
+ return talloc_asprintf(mem_ctx, "%s/lck/%u", cache_dir,
+ (unsigned)pid);
+}
+
static int messaging_dgm_context_destructor(struct messaging_dgm_context *c);
static int messaging_dgm_lockfile_create(TALLOC_CTX *tmp_ctx,
@@ -69,19 +77,17 @@ static int messaging_dgm_lockfile_create(TALLOC_CTX *tmp_ctx,
}
ok = directory_create_or_exist_strict(dir, dir_owner, 0755);
+ TALLOC_FREE(dir);
if (!ok) {
ret = errno;
DEBUG(1, ("%s: Could not create lock directory: %s\n",
__func__, strerror(ret)));
- TALLOC_FREE(dir);
return ret;
}
- lockfile_name = talloc_asprintf(tmp_ctx, "%s/%u", dir,
- (unsigned)pid);
- TALLOC_FREE(dir);
+ lockfile_name = messaging_dgm_lockfile_name(tmp_ctx, cache_dir,
+ (unsigned)pid);
if (lockfile_name == NULL) {
- DEBUG(1, ("%s: talloc_asprintf failed\n", __func__));
return ENOMEM;
}
@@ -144,8 +150,8 @@ static int messaging_dgm_lockfile_remove(TALLOC_CTX *tmp_ctx,
char *lockfile_name;
int ret;
- lockfile_name = talloc_asprintf(
- tmp_ctx, "%s/lck/%u", cache_dir, (unsigned)pid);
+ lockfile_name = messaging_dgm_lockfile_name(
+ tmp_ctx, cache_dir, pid);
if (lockfile_name == NULL) {
return ENOMEM;
}
@@ -320,8 +326,8 @@ int messaging_dgm_cleanup(struct messaging_dgm_context *ctx, pid_t pid)
int fd, ret;
struct flock lck = {};
- lockfile_name = talloc_asprintf(talloc_tos(), "%s/lck/%u",
- ctx->cache_dir, (unsigned)pid);
+ lockfile_name = messaging_dgm_lockfile_name(
+ talloc_tos(), ctx->cache_dir, pid);
if (lockfile_name == NULL) {
return ENOMEM;
}
--
1.8.1.2
More information about the samba-technical
mailing list