]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Further fixes to improper usage of scheduler 97/1597/2
authorSteve Davies <steve@one47.co.uk>
Wed, 11 Nov 2015 10:16:22 +0000 (10:16 +0000)
committerSteve Davies <steve@one47.co.uk>
Wed, 11 Nov 2015 10:21:28 +0000 (10:21 +0000)
When ASTERISK-25449 was closed, a number of scheduler issues mentioned in
the comments were missed. These have since beed raised in ASTERISK-25476
and elsewhere.

This patch attempts to collect all of the scheduler issues discovered so
far and address them sensibly.

ASTERISK-25476 #close

Change-Id: I87a77d581e2e0d91d33b4b2fbff80f64a566d05b

channels/chan_iax2.c
channels/chan_sip.c
res/res_rtp_asterisk.c

index f6708c67de1db9666d8c238a7059d40fec3e8dfc..34c447310a1b1a05d2cd665b93eeed85ae905251 100644 (file)
@@ -7068,7 +7068,7 @@ static char *handle_cli_iax2_unregister(struct ast_cli_entry *e, int cmd, struct
 
        p = find_peer(a->argv[2], 1);
        if (p) {
-               if (p->expire > 0) {
+               if (p->expire > -1) {
                        struct iax2_peer *peer;
 
                        peer = ao2_find(peers, a->argv[2], OBJ_KEY);
@@ -7101,7 +7101,7 @@ static char *complete_iax2_unregister(const char *line, const char *word, int po
                struct ao2_iterator i = ao2_iterator_init(peers, 0);
                while ((p = ao2_iterator_next(&i))) {
                        if (!strncasecmp(p->name, word, wordlen) && 
-                               ++which > state && p->expire > 0) {
+                               ++which > state && p->expire > -1) {
                                res = ast_strdup(p->name);
                                peer_unref(p);
                                break;
index 39d9f00a41f6916bc76b0dc32711cc6805a9bc78..d0e8212da894059763f336718dc04081c2375f81 100644 (file)
@@ -20580,7 +20580,7 @@ static char *sip_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
                return CLI_SHOWUSAGE;
        
        if ((peer = sip_find_peer(a->argv[2], NULL, load_realtime, FINDPEERS, TRUE, 0))) {
-               if (peer->expire > 0) {
+               if (peer->expire > -1) {
                        AST_SCHED_DEL_UNREF(sched, peer->expire,
                                sip_unref_peer(peer, "remove register expire ref"));
                        expire_register(sip_ref_peer(peer, "ref for expire_register"));
@@ -21164,7 +21164,7 @@ static char *complete_sip_registered_peer(const char *word, int state, int flags
        while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) {
               if (!strncasecmp(word, peer->name, wordlen) &&
                   (!flags2 || ast_test_flag(&peer->flags[1], flags2)) &&
-                  ++which > state && peer->expire > 0)
+                  ++which > state && peer->expire > -1)
                       result = ast_strdup(peer->name);
               if (result) {
                       sip_unref_peer(peer, "toss iterator peer ptr before break");
@@ -30647,13 +30647,11 @@ static struct ast_variable *add_var(const char *buf, struct ast_variable *list)
 /*! \brief Set peer defaults before configuring specific configurations */
 static void set_peer_defaults(struct sip_peer *peer)
 {
-       if (peer->expire == 0) {
+       if (peer->expire < 0) {
                /* Don't reset expire or port time during reload
                   if we have an active registration
                */
-               peer->expire = -1;
-               peer->pokeexpire = -1;
-               peer->keepalivesend = -1;
+               peer_sched_cleanup(peer);
                set_socket_transport(&peer->socket, SIP_TRANSPORT_UDP);
        }
        peer->type = SIP_TYPE_PEER;
@@ -30739,6 +30737,10 @@ static struct sip_peer *temp_peer(const char *name)
        }
 
        ast_atomic_fetchadd_int(&apeerobjs, 1);
+       peer->expire = -1;
+       peer->pokeexpire = -1;
+       peer->keepalivesend = -1;
+
        set_peer_defaults(peer);
 
        ast_copy_string(peer->name, name, sizeof(peer->name));
@@ -30858,6 +30860,10 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
                        ast_debug(3, "-REALTIME- peer built. Name: %s. Peer objects: %d\n", name, rpeerobjs);
                } else
                        ast_atomic_fetchadd_int(&speerobjs, 1);
+
+               peer->expire = -1;
+               peer->pokeexpire = -1;
+               peer->keepalivesend = -1;
        }
 
        /* Note that our peer HAS had its reference count increased */
index dfbc3e92458bb82017b729386b8ff2c330be44a8..f9cfa7d8a1e45ef19256947b654f535db54adb21 100644 (file)
@@ -4635,7 +4635,7 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
                        return;
                } else {
                        if (rtp->rtcp) {
-                               if (rtp->rtcp->schedid > 0) {
+                               if (rtp->rtcp->schedid > -1) {
                                        if (!ast_sched_del(rtp->sched, rtp->rtcp->schedid)) {
                                                /* Successfully cancelled scheduler entry. */
                                                ao2_ref(instance, -1);
@@ -4863,7 +4863,7 @@ static void ast_rtp_stop(struct ast_rtp_instance *instance)
        }
 #endif
 
-       if (rtp->rtcp && rtp->rtcp->schedid > 0) {
+       if (rtp->rtcp && rtp->rtcp->schedid > -1) {
                if (!ast_sched_del(rtp->sched, rtp->rtcp->schedid)) {
                        /* successfully cancelled scheduler entry. */
                        ao2_ref(instance, -1);