[SCM] Samba Shared Repository - branch v4-5-stable updated

Karolin Seeger kseeger at samba.org
Wed Oct 26 07:09:06 UTC 2016


The branch, v4-5-stable has been updated
       via  bc07150 VERSION: Disable git snapshots for the 4.5.1 release.
       via  b037821 WHATSNEW: Add release notes for Samba 4.5.1.
       via  f7ed6b2 s3: libsmb: Fix cut and paste error using the wrong structure type.
       via  152041e s3:libads: don't use MEMORY:ads_sasl_spnego_bind nor set "KRB5CCNAME"
       via  58f41cf s3:libads: don't use MEMORY:ads_sasl_gssapi_do_bind nor set "KRB5CCNAME"
       via  e6c2921 HEIMDAL:lib/krb5: destroy a memory ccache on reinit
       via  0b7656b s3-printing: fix migrate printer code (bug 8618)
       via  c5a0fc0 dbcheck: assert uSNChanged values in release-4-5-0-pre1
       via  53f94de tests: Skip a test for reveal internals for passing Windows
       via  d209450 tests: Check that USN bumps when modifying a linked attr
       via  8107066 dbcheck: Make it clearer about temporary output
       via  a439f7c tombstone-expunge: Assert than an expunge does not bump the USN
       via  bd78656 tests: Assert vanishing links doesn't bump USN
       via  43db0f1 rpmd: Skip bump of USN when vanishing forward links
       via  a67aa0a rpmd: Add a TODO regarding the additional work performed
       via  e7ef79c rpmd: Remove the seq_num check for skipping additional work
       via  72396f9 rpmd: Add the ldb error string to a debug
       via  f98f264 torture: Remove unnecessary whitespace
       via  ead7488 copyright: Add the missing notices for garbage collect tombstones
       via  c6578c3 dsdb: refactor part of garbage_collect_tombstones into new function
       via  7dbb5de kcc: Fix a -Werror,-Wformat-security error
       via  b3e2bfe gc_tombstones: Typo fix
       via  a8d2f52 dsdb: Do not check isDeleted as a possible link
       via  797fb64 lib/ldb-samba: Add test for DSDB_MATCH_FOR_EXPUNGE match rule
       via  2c8c52a dsdb: Add comments to dsdb_garbage_collect_tombstones()
       via  608b85b samba-tool: Run samba-tool domain tombstones expunge in a transaction
       via  7121855 selftest: Add test for 'samba-tool tombstones expunge'
       via  4b4d71f dsdb: Use a date comparison in the search to avoid returning all deleted objects
       via  679700a dsdb: Expose ldb error string to dsdb_garbage_collect_tombstones() callers
       via  68598e4 samba-tool: Add command-line tool to trigger tombstone expunge
       via  1902436 python: Add binding for dsdb_garbage_collect_tombstones()
       via  bdde527 dsdb: Expand garbage_collect_tombstones to expunge links also
       via  8f4f4fb dsdb: move tombstone lifetime calculation out of dsdb_garbage_collect_tombstones()
       via  6a2ed19 dsdb: Rework more KCC service-specific details out of dsdb_garbage_collect_tombstones()
       via  99d0dfb dsdb: Rework kcc_deleted() into dsdb_garbage_collect_tombstones()
       via  c71a3c6 kcc: Move kcc/kcc_deleted.c into kcc/garbage_collect_tombstones.c
       via  bd3c138 ldb-samba: Add new extended match rule DSDB_MATCH_FOR_EXPUNGE
       via  dbe2cc7 pydsdb: Raise TypeError for type errors, rather than incorrectly raising an LdbError
       via  bcaf3ca selftest: Correct name of samba4.blackbox.dbcheck.release-4-5-0-pre1
       via  92bc396 s3: cldap: cldap_multi_netlogon_send() fails with one bad IPv6 address.
       via  d465cab s3-utils: Fix loading smb.conf in smbcquotas
       via  bed424f ntquotas: support "freeing" an empty quota list
       via  a54e4e7 s3/winbindd: using default domain with user at domain.com format fails
       via  d6958d2 Add a blackbox tests for id & getent to test domain at realm type credentials
       via  fbd9451 winbind: Fix passing idmap failure from wb_sids2xids back to callers
       via  1cb9aeb idmap_ad: Fix retrieving credentials from clustered secrets.tdb
       via  b509d3a lib: Fix bug 12291
       via  cceb6e6 smbd: free talloc context if no quota records are available
       via  cbf9151 cliquota: fix param count when setting fs quota
       via  859e9c2 s3-lib: Fix %G substitution in AD member environment
       via  89e0e26 smbcquotas: fix error message listing quotas
       via  b2e42fe s3-cliquota: correctly handle no-more-entries
       via  7fd1d67 s3-sysquotas: correctly restore path when finding mount point
       via  50c559f torture/ioctl: test compression responses when unsupported
       via  100e780 smbd/ioctl: match WS2016 ReFS get compression behaviour
       via  8c9ac5b vfs_glusterfs: Fix a memory leak in connect path
       via  e05bae4 spoolss: Fix caching of printername->sharename
       via  152a6d8 kcc: Don't check schedule if None
       via  7b8d064 s4:samba_spnupdate: do not attempt to parse log level, use parsed value
       via  d6027e6 python/join: do not attempt to parse log level, use parsed value
       via  50087612 python/drs_utils: do not attempt to parse log level, use parsed value
       via  d10c377 tests/param add a test for LoadParm.log_level
       via  156136e s4:param add log_level function to retrieve log level in Python code
       via  103483a glusterfs: Avoid tevent_internal.h
       via  9562114 s3: events. Move events.c to util_event.c
       via  3f5388f s3: server: s3_tevent_context_init() -> samba_tevent_context_init()
       via  41d4a4c s3: winbind: Remove dump_event_list() calls.
       via  4fa26e0 s3: nmbd: Final changeover to stock tevent for nmbd.
       via  4842157 s3: nmbd: Change over to using tevent functions from direct poll.
       via  4cceabe s3: nmbd: Add a talloc_stackframe().
       via  42963c4 s3: nmbd: Add (currently unused) timeout and fd handlers.
       via  c290763 s3: nmbd: Now attrs array mirrors fd's array use it in preference.
       via  c9dbe89 s3: nmbd: Ensure attrs array mirrors fd's array for dns.
       via  abec724 s3: nmbd: Add fd, triggered elements to struct socket_attributes.
       via  d0bd672 s3:nmbd: fix talloc_zero_array() check in nmbd_packets.c
       via  1e288f5 s3: winbind: Ensure we store name2sid with the correct cache sequence number.
       via  208c136 s3: winbind: Trust name2sid mappings from the PAC.
       via  0e2726e s3: winbind: refresh_sequence_number is only ever called with 'false'.
       via  38ffca0 s3: auth: Use wbcAuthenticateUserEx to prime the caches.
       via  477abfb s3: winbind: Make WBC_AUTH_USER_LEVEL_PAC prime the name2sid cache.
       via  51c6659 ctdb-scripts: ctdbd_wrapper should never remove the PID file
       via  416d062 ctdb-daemon: Log when removing stale Unix domain socket
       via  14313b0 ctdb-daemon: Drop attempt to connect to Unix domain socket
       via  8866233 ctdb-daemon: Don't try to reopen TDB files
       via  2ebed56 ctdb-daemon: Bind to Unix domain socket after PID file creation
       via  81d8f89 ctdb-daemon: Use PID file abstraction
       via  a1a1fe4 ctdb-common: Add routines to manage PID file
       via  aefc593 s3-spoolss: fix winreg_printer_ver_to_qword
       via  a23ff4c nsswitch: Also set h_errnop for nss_wins functions
       via  568f9fb nsswitch: Add missing arguments to wins gethostbyname*
       via  62f4e3d s3/smbd: set FILE_ATTRIBUTE_DIRECTORY as necessary
       via  5bd28ff gencache: Bail out of stabilize if we can not get the allrecord lock
       via  68302ce ctdb-recovery-helper: Add missing initialisation of ban_credits
       via  7f0a86b lib: poll_funcs : poll_funcs_context_slot_find can select the wrong slot to replace.
       via  6411b3d lib/poll_funcs: free contexts in poll_funcs_state_destructor()
       via  a69dae2 smbd: Reset O_NONBLOCK on open files
       via  dbbf8dc ctdb-protocol: Fix marshalling for GET_DB_SEQNUM control request
       via  fff928d s3/smbd: in call_trans2qfilepathinfo call lstat when dealing with posix pathnames
       via  0558f89 ctdb-packaging: Fix systemd network dependency
       via  b0f7867 ctdb-tests: Add new public IP takeover no-op test
       via  349e65c ctdb-tests: Factor out new local daemons functions ps_ctdbd
       via  30c93b0 ctdb-ipalloc: ipalloc_set_public_ips() can't fail
       via  78ae3ec ctdb-ipalloc: Move merged IP list creation to ipalloc()
       via  0d80ca2 ctdb-ipalloc: Drop known_ips argument from merged IP list creation
       via  9ec74b3 ctdb-ipalloc: Optimise check to see if IPs can be hosted
       via  7ca6d62 ctdb-ipalloc: Whether IPs can be hosted need not depend on merged IP list
       via  2476e08 ctdb-ipalloc: Store known public IPs in IP allocation state
       via  d7c1704 ctdb-tests: CID 1125635 Dereference null return value (NULL_RETURNS)
       via  99c3c78 ctdb-tools: CID 1125617 String not null terminated (STRING_NULL)
       via  d899b1b VERSION: Bump version up to 4.5.1...
      from  916fab0 VERSION: Set version to 4.5.0...

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-5-stable


- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 VERSION                                            |   2 +-
 WHATSNEW.txt                                       | 127 ++++++
 ctdb/common/pidfile.c                              | 143 ++++++
 ctdb/common/pidfile.h                              |  51 +++
 ctdb/config/ctdb.service                           |   2 +-
 ctdb/config/ctdbd_wrapper                          |   1 -
 ctdb/protocol/protocol_control.c                   |  14 +-
 ctdb/server/ctdb_daemon.c                          |  66 ++-
 ctdb/server/ctdb_recovery_helper.c                 |   1 +
 ctdb/server/ctdb_takeover.c                        |   6 +-
 ctdb/server/ipalloc.c                              |  48 +-
 ctdb/server/ipalloc.h                              |   2 +-
 ctdb/server/ipalloc_private.h                      |   1 +
 ctdb/tests/cunit/pidfile_test_001.sh               |   8 +
 ctdb/tests/simple/19_ip_takeover_noop.sh           |  71 +++
 ctdb/tests/simple/28_zero_eventscripts.sh          |   7 +-
 ctdb/tests/simple/scripts/local_daemons.bash       |  10 +
 ctdb/tests/src/ctdb_takeover_tests.c               |   5 +-
 ctdb/tests/src/pidfile_test.c                      | 241 ++++++++++
 ctdb/tests/src/rb_test.c                           |   1 +
 ctdb/tools/ctdb.c                                  |   1 +
 ctdb/wscript                                       |   4 +-
 lib/ldb-samba/ldb_matching_rules.c                 | 133 +++++-
 lib/ldb-samba/ldb_matching_rules.h                 |   1 +
 lib/poll_funcs/poll_funcs_tevent.c                 |  17 +-
 lib/util/msghdr.c                                  |   2 +-
 libcli/cldap/cldap.c                               |   5 +
 nsswitch/wins.c                                    |  60 ++-
 python/samba/drs_utils.py                          |   2 +-
 python/samba/join.py                               |   4 +-
 python/samba/kcc/kcc_utils.py                      |  18 +-
 python/samba/netcmd/domain.py                      |  81 ++++
 python/samba/samdb.py                              |  14 +
 python/samba/tests/param.py                        |   6 +
 selftest/knownfail                                 |   1 +
 selftest/target/Samba.pm                           |   1 +
 selftest/target/Samba4.pm                          |  34 +-
 selftest/tests.py                                  |   9 +-
 source3/auth/auth_generic.c                        |  49 ++-
 source3/include/includes.h                         |   4 +-
 source3/include/{event.h => util_event.h}          |  16 +-
 source3/lib/events.c                               | 486 ---------------------
 source3/lib/gencache.c                             |   2 +-
 source3/lib/server_contexts.c                      |   2 +-
 source3/lib/substitute.c                           |  24 +-
 source3/lib/sysquotas.c                            |   5 +-
 source3/lib/util_event.c                           | 101 +++++
 source3/libads/cldap.c                             |  17 +-
 source3/libads/sasl.c                              |  11 -
 source3/libsmb/cli_smb2_fnum.c                     |   2 +-
 source3/libsmb/cliquota.c                          |  18 +-
 source3/modules/vfs_glusterfs.c                    |   4 +-
 source3/nmbd/nmbd_packets.c                        | 162 ++++---
 source3/printing/nt_printing_migrate.c             |  27 ++
 source3/rpc_client/cli_winreg_spoolss.c            |   7 +-
 source3/rpc_server/rpc_ncacn_np.c                  |   8 +-
 source3/rpc_server/spoolss/srv_spoolss_nt.c        |   4 +-
 source3/smbd/dosmode.c                             |   6 +-
 source3/smbd/ntquotas.c                            |   6 +-
 source3/smbd/open.c                                |  19 +
 source3/smbd/process.c                             |   4 +-
 source3/smbd/server.c                              |   1 -
 source3/smbd/smb2_ioctl_filesys.c                  |  29 +-
 source3/smbd/trans2.c                              |   7 +-
 source3/utils/smbcquotas.c                         |  21 +-
 source3/winbindd/idmap_ad.c                        |  11 +-
 source3/winbindd/wb_sids2xids.c                    |   2 +-
 source3/winbindd/winbindd_cache.c                  |  62 ++-
 source3/winbindd/winbindd_dual.c                   |   5 +-
 source3/winbindd/winbindd_pam.c                    |  35 +-
 source3/winbindd/winbindd_proto.h                  |   5 +
 source3/winbindd/winbindd_util.c                   |   5 +-
 source3/wscript_build                              |   2 +-
 source4/dsdb/common/util.h                         |  10 +
 source4/dsdb/kcc/garbage_collect_tombstones.c      | 344 +++++++++++++++
 .../dsdb/kcc/garbage_collect_tombstones.h          |  26 +-
 source4/dsdb/kcc/kcc_deleted.c                     | 146 -------
 source4/dsdb/kcc/kcc_periodic.c                    |  58 ++-
 source4/dsdb/kcc/kcc_service.c                     |   5 +-
 source4/dsdb/kcc/kcc_service.h                     |  13 +-
 source4/dsdb/pydsdb.c                              | 108 ++++-
 source4/dsdb/samdb/ldb_modules/repl_meta_data.c    |  34 +-
 source4/dsdb/tests/python/linked_attributes.py     |  48 +-
 source4/dsdb/wscript_build                         |  10 +-
 source4/heimdal/lib/krb5/mcache.c                  |  52 ++-
 source4/param/pyparam.c                            |   9 +
 source4/scripting/bin/samba_spnupdate              |   2 +-
 .../release-4-5-0-pre1/add-four-more-links.ldif    |  15 +
 .../release-4-5-0-pre1/add-two-more-users.ldif     |  15 +
 .../expected-deleted-links-after-expunge.ldif      |  23 +
 .../release-4-5-0-pre1/expected-expunge-output.txt |   1 +
 .../expected-links-after-dbcheck.ldif              | 217 +++++++++
 .../expected-links-after-expunge.ldif              |  22 +
 .../expected-match-rule-links.ldif                 |  47 ++
 .../expected-objects-after-expunge.ldif            |   2 +
 .../release-4-5-0-pre1/remove-one-more-link.ldif   |   5 +
 .../release-4-5-0-pre1/remove-one-more-user.ldif   |   3 +
 .../release-4-5-0-pre1/rootdse-version.final.txt   |   1 +
 .../release-4-5-0-pre1/rootdse-version.initial.txt |   1 +
 source4/selftest/tests.py                          |   7 +
 source4/setup/schema_samba4.ldif                   |   1 +
 .../torture/drs/python/linked_attributes_drs.py    |   2 +-
 source4/torture/smb2/ioctl.c                       |  76 ++++
 testprogs/blackbox/dbcheck-oldrelease.sh           |  18 +-
 testprogs/blackbox/dom_parse.sh                    |  27 ++
 testprogs/blackbox/tombstones-expunge.sh           | 206 +++++++++
 106 files changed, 2938 insertions(+), 985 deletions(-)
 create mode 100644 ctdb/common/pidfile.c
 create mode 100644 ctdb/common/pidfile.h
 create mode 100755 ctdb/tests/cunit/pidfile_test_001.sh
 create mode 100755 ctdb/tests/simple/19_ip_takeover_noop.sh
 create mode 100644 ctdb/tests/src/pidfile_test.c
 rename source3/include/{event.h => util_event.h} (64%)
 delete mode 100644 source3/lib/events.c
 create mode 100644 source3/lib/util_event.c
 create mode 100644 source4/dsdb/kcc/garbage_collect_tombstones.c
 copy lib/ldb-samba/ldb_matching_rules.h => source4/dsdb/kcc/garbage_collect_tombstones.h (59%)
 delete mode 100644 source4/dsdb/kcc/kcc_deleted.c
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/add-four-more-links.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/add-two-more-users.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-deleted-links-after-expunge.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-expunge-output.txt
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-links-after-expunge.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-match-rule-links.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-objects-after-expunge.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/remove-one-more-link.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/remove-one-more-user.ldif
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/rootdse-version.final.txt
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/rootdse-version.initial.txt
 create mode 100755 testprogs/blackbox/dom_parse.sh
 create mode 100755 testprogs/blackbox/tombstones-expunge.sh


Changeset truncated at 500 lines:

diff --git a/VERSION b/VERSION
index 91beb78..5a2d7c1 100644
--- a/VERSION
+++ b/VERSION
@@ -25,7 +25,7 @@
 ########################################################
 SAMBA_VERSION_MAJOR=4
 SAMBA_VERSION_MINOR=5
-SAMBA_VERSION_RELEASE=0
+SAMBA_VERSION_RELEASE=1
 
 ########################################################
 # If a official release has a serious bug              #
diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index b198a56..f26834a 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -1,4 +1,131 @@
                    =============================
+                   Release Notes for Samba 4.5.1
+                          October 26, 2016
+                   =============================
+
+
+This is the latest stable release of the Samba 4.5 release series.
+
+Major enhancements in Samba 4.5.1 include:
+
+o  Let winbindd discard expired kerberos tickets when built against
+   (internal) heimdal (BUG #12369).
+o  REGRESSION: smbd segfaults on startup, tevent context being freed
+   (BUG #12283).
+
+
+Changes since 4.5.0:
+--------------------
+
+o  Jeremy Allison <jra at samba.org>
+   * BUG 11259: smbd contacts a domain controller for each session.
+   * BUG 12272: Fix messaging subsystem crash.
+   * BUG 12283: REGRESSION: smbd segfaults on startup, tevent context being
+     freed.
+   * BUG 12381: s3: cldap: cldap_multi_netlogon_send() fails with one bad IPv6
+     address.
+   * BUG 12383: s3: libsmb: Fix cut and paste error using the wrong structure
+     type.
+
+o  Christian Ambach <ambi at samba.org>
+   * BUG 9945: Setting specific logger levels in smb.conf makes 'samba-tool drs
+     showrepl' crash.
+
+o  Andrew Bartlett <abartlet at samba.org>
+   * BUG 12382: Tombstone expunge does not remove old links.
+
+o  Björn Baumbach <bb at sernet.de>
+   * BUG 8618: s3-printing: Fix migrate printer code.
+
+o  Ralph Boehme <slow at samba.org>
+   * BUG 12256: s3/smbd: In call_trans2qfilepathinfo call lstat when dealing
+     with posix pathnames.
+   * BUG 12261: s3/smbd: Set FILE_ATTRIBUTE_DIRECTORY as necessary.
+
+o  Günther Deschner <gd at samba.org>
+   * BUG 12285: "DriverVersion" registry backend parsing incorrect in spoolss.
+
+o  David Disseldorp <ddiss at samba.org>
+   * BUG 12144: smbd/ioctl: Match WS2016 ReFS get compression behaviour.
+
+o  Amitay Isaacs <amitay at gmail.com>
+   * BUG 12259: ctdb-protocol: Fix marshalling for GET_DB_SEQNUM control
+     request.
+   * BUG 12275: ctdb-recovery-helper: Add missing initialisation of ban_credits.
+   * BUG 12287: CTDB PID file handling is too weak.
+
+o  Volker Lendecke <vl at samba.org>
+   * BUG 12045: gencache: Bail out of stabilize if we can not get the allrecord
+     lock.
+   * BUG 12268: smbd: Reset O_NONBLOCK on open files.
+   * BUG 12283: glusterfs: Avoid tevent_internal.h.
+   * BUG 12291: source3/lib/msghdr.c, line 208: syntax error before or at: ;.
+   * BUG 12374: spoolss: Fix caching of printername->sharename.
+
+o  Stefan Metzmacher <metze at samba.org>
+   * BUG 12283: REGRESSION: smbd segfaults on startup, tevent context being
+     freed.
+   * BUG 12369: Let winbindd discard expired kerberos tickets when built against
+     (internal) heimdal.
+
+o  Noel Power <noel.power at suse.com>
+   * BUG 12298: s3/winbindd: Fix using default domain with user at domain.com
+     format.
+
+o  Christof Schmitt <cs at samba.org>
+   * BUG 12295: winbind: Fix passing idmap failure from wb_sids2xids back to
+     callers.
+
+o  Andreas Schneider <asn at samba.org>
+   * BUG 12269: nss_wins has incorrect function definitions for gethostbyname*.
+   * BUG 12276: s3-lib: Fix %G substitution in AD member environment.
+   * BUG 12364: s3-utils: Fix loading smb.conf in smbcquotas.
+
+o  Garming Sam <garming at catalyst.net.nz>
+   * BUG 12286: kcc: Don't check schedule if None.
+   * BUG 12382: Tombstone expunge does not remove old links.
+
+o  Anoop C S <anoopcs at redhat.com>
+   * BUG 12377: vfs_glusterfs: Fix a memory leak in connect path.
+
+o  Martin Schwenke <martin at meltin.net>
+   * BUG 12254: CTDB IP takeover does not complete if there are no public
+     addresses configured.
+   * BUG 12255: ctdb-packaging: Fix systemd network dependency.
+   * BUG 12287: CTDB PID file handling is too weak.
+
+o  Uri Simchoni <uri at samba.org>
+   * BUG 12270: smbcquotas: Fix error message listing quotas.
+   * BUG 12273: s3-sysquotas: Correctly restore path when finding mount point.
+   * BUG 12288: cliquota: Fix param count when setting fs quota.
+   * BUG 12289: smbd: Free talloc context if no quota records are available.
+   * BUG 12307: ntquotas: Support "freeing" an empty quota list.
+
+
+#######################################
+Reporting bugs & Development Discussion
+#######################################
+
+Please discuss this release on the samba-technical mailing list or by
+joining the #samba-technical IRC channel on irc.freenode.net.
+
+If you do report problems then please try to send high quality
+feedback. If you don't provide vital information to help us track down
+the problem then you will probably be ignored.  All bug reports should
+be filed under the Samba 4.1 and newer product in the project's Bugzilla
+database (https://bugzilla.samba.org/).
+
+
+======================================================================
+== Our Code, Our Bugs, Our Responsibility.
+== The Samba Team
+======================================================================
+
+
+Release notes for older releases follow:
+----------------------------------------
+
+                   =============================
                    Release Notes for Samba 4.5.0
                            September 7, 2016
                    =============================
diff --git a/ctdb/common/pidfile.c b/ctdb/common/pidfile.c
new file mode 100644
index 0000000..b3f29e3
--- /dev/null
+++ b/ctdb/common/pidfile.c
@@ -0,0 +1,143 @@
+/*
+   Create and remove pidfile
+
+   Copyright (C) Amitay Isaacs  2016
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/filesys.h"
+
+#include <talloc.h>
+
+#include "common/pidfile.h"
+
+struct pidfile_context {
+	const char *pidfile;
+	int fd;
+	pid_t pid;
+};
+
+static int pidfile_context_destructor(struct pidfile_context *pid_ctx);
+
+int pidfile_create(TALLOC_CTX *mem_ctx, const char *pidfile,
+		   struct pidfile_context **result)
+{
+	struct pidfile_context *pid_ctx;
+	struct flock lck;
+	char tmp[64];
+	int fd, ret = 0;
+	int len;
+	ssize_t nwritten;
+
+	pid_ctx = talloc_zero(mem_ctx, struct pidfile_context);
+	if (pid_ctx == NULL) {
+		return ENOMEM;
+	}
+
+	pid_ctx->pidfile = talloc_strdup(pid_ctx, pidfile);
+	if (pid_ctx->pidfile == NULL) {
+		ret = ENOMEM;
+		goto fail;
+	}
+
+	pid_ctx->pid = getpid();
+
+	fd = open(pidfile, O_CREAT|O_WRONLY|O_NONBLOCK, 0644);
+	if (fd == -1) {
+		ret = errno;
+		goto fail;
+	}
+
+	pid_ctx->fd = fd;
+
+	lck = (struct flock) {
+		.l_type = F_WRLCK,
+		.l_whence = SEEK_SET,
+	};
+
+	do {
+		ret = fcntl(fd, F_SETLK, &lck);
+	} while ((ret == -1) && (errno == EINTR));
+
+	if (ret != 0) {
+		ret = errno;
+		goto fail;
+	}
+
+	do {
+		ret = ftruncate(fd, 0);
+	} while ((ret == -1) && (errno == EINTR));
+
+	if (ret == -1) {
+		ret = EIO;
+		goto fail_unlink;
+	}
+
+	len = snprintf(tmp, sizeof(tmp), "%u\n", pid_ctx->pid);
+	if (len < 0) {
+		ret = EIO;
+		goto fail_unlink;
+	}
+
+	do {
+		nwritten = write(fd, tmp, len);
+	} while ((nwritten == -1) && (errno == EINTR));
+
+	if ((nwritten == -1) || (nwritten != len)) {
+		ret = EIO;
+		goto fail_unlink;
+	}
+
+	talloc_set_destructor(pid_ctx, pidfile_context_destructor);
+
+	*result = pid_ctx;
+	return 0;
+
+fail_unlink:
+	unlink(pidfile);
+	close(fd);
+
+fail:
+	talloc_free(pid_ctx);
+	return ret;
+}
+
+static int pidfile_context_destructor(struct pidfile_context *pid_ctx)
+{
+	struct flock lck;
+	int ret;
+
+	if (getpid() != pid_ctx->pid) {
+		return 0;
+	}
+
+	lck = (struct flock) {
+		.l_type = F_UNLCK,
+		.l_whence = SEEK_SET,
+	};
+
+	(void) unlink(pid_ctx->pidfile);
+
+	do {
+		ret = fcntl(pid_ctx->fd, F_SETLK, &lck);
+	} while ((ret == -1) && (errno == EINTR));
+
+	do {
+		ret = close(pid_ctx->fd);
+	} while ((ret == -1) && (errno == EINTR));
+
+	return 0;
+}
diff --git a/ctdb/common/pidfile.h b/ctdb/common/pidfile.h
new file mode 100644
index 0000000..1450134
--- /dev/null
+++ b/ctdb/common/pidfile.h
@@ -0,0 +1,51 @@
+/*
+   Create and remove pidfile
+
+   Copyright (C) Amitay Isaacs  2016
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __CTDB_PIDFILE_H__
+#define __CTDB_PIDFILE_H__
+
+#include <talloc.h>
+
+/**
+ * @file pidfile.h
+ *
+ * @brief Routines to manage PID file
+ */
+
+/**
+ * @brief Abstract struct to store pidfile details
+ */
+struct pidfile_context;
+
+/**
+ * @brief Create a PID file
+ *
+ * This creates a PID file, locks it, and writes PID.
+ *
+ * @param[in] mem_ctx Talloc memory context
+ * @param[in] pidfile Path of PID file
+ * @param[out] result Pidfile context
+ * @return 0 on success, errno on failure
+ *
+ * Freeing the pidfile_context, will delete the pidfile.
+ */
+int pidfile_create(TALLOC_CTX *mem_ctx, const char *pidfile,
+		   struct pidfile_context **result);
+
+#endif /* __CTDB_PIDFILE_H__ */
diff --git a/ctdb/config/ctdb.service b/ctdb/config/ctdb.service
index ea37c30..63cdfa9 100644
--- a/ctdb/config/ctdb.service
+++ b/ctdb/config/ctdb.service
@@ -1,6 +1,6 @@
 [Unit]
 Description=CTDB
-After=network.target
+After=network-online.target time-sync.target
 
 [Service]
 Type=forking
diff --git a/ctdb/config/ctdbd_wrapper b/ctdb/config/ctdbd_wrapper
index cdf0304..bfc91f7 100755
--- a/ctdb/config/ctdbd_wrapper
+++ b/ctdb/config/ctdbd_wrapper
@@ -185,7 +185,6 @@ kill_ctdbd ()
 
     if [ -n "$_session" ] ; then
 	pkill -9 -s "$_session" 2>/dev/null
-	rm -f "$pidfile"
     fi
 }
 
diff --git a/ctdb/protocol/protocol_control.c b/ctdb/protocol/protocol_control.c
index d5237ec..a909fc6 100644
--- a/ctdb/protocol/protocol_control.c
+++ b/ctdb/protocol/protocol_control.c
@@ -49,7 +49,6 @@ struct ctdb_reply_control_wire {
 static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
 {
 	size_t len = 0;
-	uint64_t u64;
 
 	if (cd == NULL) {
 		return 0;
@@ -335,8 +334,7 @@ static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
 		break;
 
 	case CTDB_CONTROL_GET_DB_SEQNUM:
-		u64 = cd->data.db_id;
-		len = ctdb_uint64_len(u64);
+		len = ctdb_uint64_len((uint64_t)cd->data.db_id);
 		break;
 
 	case CTDB_CONTROL_DB_SET_HEALTHY:
@@ -452,8 +450,6 @@ static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
 				       uint8_t *buf)
 {
-	uint64_t u64;
-
 	switch (cd->opcode) {
 	case CTDB_CONTROL_PROCESS_EXISTS:
 		ctdb_pid_push(cd->data.pid, buf);
@@ -635,8 +631,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
 		break;
 
 	case CTDB_CONTROL_GET_DB_SEQNUM:
-		u64 = cd->data.db_id;
-		ctdb_uint64_push(u64, buf);
+		ctdb_uint32_push(cd->data.db_id, buf);
 		break;
 
 	case CTDB_CONTROL_DB_SET_HEALTHY:
@@ -735,7 +730,6 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
 				      struct ctdb_req_control_data *cd)
 {
 	int ret = 0;
-	uint64_t u64 = 0;
 
 	cd->opcode = opcode;
 
@@ -964,8 +958,8 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
 		break;
 
 	case CTDB_CONTROL_GET_DB_SEQNUM:
-		ret = ctdb_uint64_pull(buf, buflen, mem_ctx, &u64);
-		cd->data.db_id = (uint32_t)u64;
+		ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
+				       &cd->data.db_id);
 		break;
 
 	case CTDB_CONTROL_DB_SET_HEALTHY:
diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index 47e49df..8cd5bba 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -44,6 +44,7 @@
 #include "common/system.h"
 #include "common/common.h"
 #include "common/logging.h"
+#include "common/pidfile.h"
 
 struct ctdb_client_pid_list {
 	struct ctdb_client_pid_list *next, *prev;
@@ -53,6 +54,7 @@ struct ctdb_client_pid_list {
 };
 
 const char *ctdbd_pidfile = NULL;
+static struct pidfile_context *ctdbd_pidfile_ctx = NULL;
 
 static void daemon_incoming_packet(void *, struct ctdb_req_header *);
 
@@ -1005,17 +1007,16 @@ static int ux_socket_bind(struct ctdb_context *ctdb)
 	addr.sun_family = AF_UNIX;
 	strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path)-1);
 
-	/* First check if an old ctdbd might be running */
-	if (connect(ctdb->daemon.sd,
-		    (struct sockaddr *)&addr, sizeof(addr)) == 0) {
-		DEBUG(DEBUG_CRIT,
-		      ("Something is already listening on ctdb socket '%s'\n",
-		       ctdb->daemon.name));
-		goto failed;
-	}
-
 	/* Remove any old socket */
-	unlink(ctdb->daemon.name);
+	ret = unlink(ctdb->daemon.name);
+	if (ret == 0) {
+		DEBUG(DEBUG_WARNING,
+		      ("Removed stale socket %s\n", ctdb->daemon.name));
+	} else if (errno != ENOENT) {
+		DEBUG(DEBUG_ERR,
+		      ("Failed to remove stale socket %s\n", ctdb->daemon.name));
+		return -1;
+	}
 
 	set_close_on_exec(ctdb->daemon.sd);
 
@@ -1149,32 +1150,21 @@ static void ctdb_tevent_trace(enum tevent_trace_point tp,
 
 static void ctdb_remove_pidfile(void)
 {
-	/* Only the main ctdbd's PID matches the SID */
-	if (ctdbd_pidfile != NULL && getsid(0) == getpid()) {
-		if (unlink(ctdbd_pidfile) == 0) {
-			DEBUG(DEBUG_NOTICE, ("Removed PID file %s\n",
-					     ctdbd_pidfile));
-		} else {
-			DEBUG(DEBUG_WARNING, ("Failed to Remove PID file %s\n",
-					      ctdbd_pidfile));
-		}
-	}


-- 
Samba Shared Repository



More information about the samba-cvs mailing list