summaryrefslogtreecommitdiff
path: root/source3/lib/messages.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-01-30 23:55:58 +0000
committerJeremy Allison <jra@samba.org>2003-01-30 23:55:58 +0000
commitbbf9f09ee5c58e348eef33448d2c38e588adb66a (patch)
tree69d4922f84219502a123dc29c52a5f96d5f048d2 /source3/lib/messages.c
parent920287bf6b6950abfac53e6430954aee7e76bd15 (diff)
downloadsamba-bbf9f09ee5c58e348eef33448d2c38e588adb66a.tar.gz
samba-bbf9f09ee5c58e348eef33448d2c38e588adb66a.tar.bz2
samba-bbf9f09ee5c58e348eef33448d2c38e588adb66a.zip
Add 3 second timeout when terminating server and sending print notify
messages. Stops build-up of large numbers of smbd's waiting to terminate on large print throughput. Jeremy. (This used to be commit 07efebb98473cb3d4adc6b2e0afef3f06dcc99b8)
Diffstat (limited to 'source3/lib/messages.c')
-rw-r--r--source3/lib/messages.c50
1 files changed, 45 insertions, 5 deletions
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 53c9e3d2bc..3603758e9f 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -160,8 +160,8 @@ static BOOL message_notify(pid_t pid)
Send a message to a particular pid.
****************************************************************************/
-BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len,
- BOOL duplicates_allowed)
+static BOOL message_send_pid_internal(pid_t pid, int msg_type, const void *buf, size_t len,
+ BOOL duplicates_allowed, unsigned int timeout)
{
TDB_DATA kbuf;
TDB_DATA dbuf;
@@ -200,7 +200,17 @@ BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len,
/* If duplicates are allowed we can just append the message and return. */
/* lock the record for the destination */
- tdb_chainlock(tdb, kbuf);
+ if (timeout) {
+ if (tdb_chainlock_with_timeout(tdb, kbuf, timeout) == -1) {
+ DEBUG(0,("message_send_pid_internal: failed to get chainlock with timeout %ul.\n", timeout));
+ return False;
+ }
+ } else {
+ if (tdb_chainlock(tdb, kbuf) == -1) {
+ DEBUG(0,("message_send_pid_internal: failed to get chainlock.\n"));
+ return False;
+ }
+ }
tdb_append(tdb, kbuf, dbuf);
tdb_chainunlock(tdb, kbuf);
@@ -210,7 +220,18 @@ BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len,
}
/* lock the record for the destination */
- tdb_chainlock(tdb, kbuf);
+ if (timeout) {
+ if (tdb_chainlock_with_timeout(tdb, kbuf, timeout) == -1) {
+ DEBUG(0,("message_send_pid_internal: failed to get chainlock with timeout %ul.\n", timeout));
+ return False;
+ }
+ } else {
+ if (tdb_chainlock(tdb, kbuf) == -1) {
+ DEBUG(0,("message_send_pid_internal: failed to get chainlock.\n"));
+ return False;
+ }
+ }
+
old_dbuf = tdb_fetch(tdb, kbuf);
if (!old_dbuf.dptr) {
@@ -236,7 +257,7 @@ BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len,
if (!memcmp(ptr, &rec, sizeof(rec))) {
if (!len || (len && !memcmp( ptr + sizeof(rec), buf, len))) {
tdb_chainunlock(tdb, kbuf);
- DEBUG(10,("message_send_pid: discarding duplicate message.\n"));
+ DEBUG(10,("message_send_pid_internal: discarding duplicate message.\n"));
SAFE_FREE(dbuf.dptr);
SAFE_FREE(old_dbuf.dptr);
return True;
@@ -259,6 +280,25 @@ BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len,
}
/****************************************************************************
+ Send a message to a particular pid - no timeout.
+****************************************************************************/
+
+BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len, BOOL duplicates_allowed)
+{
+ return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, 0);
+}
+
+/****************************************************************************
+ Send a message to a particular pid, with timeout in seconds.
+****************************************************************************/
+
+BOOL message_send_pid_with_timeout(pid_t pid, int msg_type, const void *buf, size_t len,
+ BOOL duplicates_allowed, unsigned int timeout)
+{
+ return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, timeout);
+}
+
+/****************************************************************************
Retrieve all messages for the current process.
****************************************************************************/