Commit Graph

202 Commits

Author SHA1 Message Date
Lou Berger
996c93142d *: conform with COMMUNITY.md formatting rules, via 'make indent'
Signed-off-by: Lou Berger <lberger@labn.net>
2018-03-06 14:04:32 -05:00
Quentin Young
d8a8a8de00
lib: some frr_pthread fixes
* Use atomic fixed-width thread identifiers
* Add ability to change thread name at runtime

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-03-05 18:04:54 -05:00
Quentin Young
42d745387a
lib: avoid crash when cancelling invalid rw job
There are some observed instances where we end up trying to cancel a rw
job based on a file descriptor that we don't have a reference on. The
specific cancel function for rw jobs assumes it's called with a file
descriptor that is valid within pollfds and will cause a segmentation
fault by buffer overrun if this is not the case.

Instead log it and move on. Since the fd does not exist this should
patch over the buggy behavior and provide additional information to help
in finding the root cause.

Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-01-16 15:28:26 -05:00
Donald Sharp
522f7f9923 lib: Fix thread removal from a pqueue
When we remove a thread from a pqueue, use the saved
index to go to the correct spot immediately instead of
having to search the whole queue for it.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-11-29 14:53:59 -05:00
Donald Sharp
d1667f531f lib: Display unsigned instead of signed
When displaying thread cpu data, display unsigned instead
of signed data when we get really really really large
numbers of invocations.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-17 20:49:15 -04:00
Donald Sharp
acdf5e2510 *: Convert list_free usage to list_delete
list_free is occassionally being used to delete the
list and accidently not deleting all the nodes.
We keep running across this usage pattern.  Let's
remove the temptation and only allow list_delete
to handle list deletion.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-05 10:53:17 -04:00
Donald Sharp
affe9e9983 *: Convert list_delete(struct list *) to ** to allow nulling
Convert the list_delete(struct list *) function to use
struct list **.  This is to allow the list pointer to be nulled.

I keep running into uses of this list_delete function where we
forget to set the returned pointer to NULL and attempt to use
it and then experience a crash, usually after the developer
has long since left the building.

Let's make the api explicit in it setting the list pointer
to null.

Cynical Prediction:  This code will expose a attempt
to use the NULL'ed list pointer in some obscure bit
of code.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-05 10:53:13 -04:00
Renato Westphal
f5129394ec Merge pull request #1242 from donaldsharp/eigrp_tm
Eigrp tm
2017-09-27 09:20:51 -03:00
Quentin Young
33844bbe43
lib: destroy threadmaster condition variable
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-09-25 16:01:08 -04:00
Donald Sharp
1a0a92ea3b lib: Set pointer to NULL after free
list_delete does not set the list pointer to NULL
Thus when we accidently use it later we happily write
off into lala land instead of crashing imediately

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-09-25 15:41:28 -04:00
Quentin Young
4e1000a188
lib: free thread master name
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-09-08 16:39:53 -04:00
Donald Sharp
bd74dc610a lib: Hash creation cleanup
1) Some hash key functions where converting pointers
directly to a 32 bit value via downcasting.  Pointers
are 64 bit on a majority of our platforms.

2) Some hashes were being created with 256 entries,
downsize the hash creation size to more appropriate
values.

3) Add hash names to hash creation so we can watch
the hash via 'show debugging hashtable'

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-09-05 14:33:01 -04:00
Quentin Young
e3c9529ee9
lib: fix thread scheduling weirdness
Restores 3.0 behavior in terms of thread scheduling & prioritization.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-31 19:00:00 -04:00
Quentin Young
eff09c66a4
lib: fix still reachable linked list in thread.c
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-08 12:54:28 -04:00
Quentin Young
bca37d172a
lib: minor style fixes
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-03 11:25:24 -04:00
Quentin Young
d764d2cc50
lib: flush ready queue before poll() again
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-02 14:29:04 -04:00
whitespace / reindent
d62a17aede *: reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17 14:04:07 +02:00
David Lamparter
2d8270596a Merge remote-tracking branch 'frr/master' into newline-redux
Lots of conflicts from CMD_WARNING_CONFIG_FAILED...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 13:07:30 +02:00
David Lamparter
625e016d14 *: remove VTYNL, part 6 of 6
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 10:20:03 +02:00
David Lamparter
6d3c2ed4ed *: remove VTYNL, part 1 of 6
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 10:20:02 +02:00
David Lamparter
181039f3d7 *: ditch vty_outln(), part 2 of 2
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 10:19:58 +02:00
David Lamparter
5c7571d43f *: ditch vty_outln(), part 1 of 2
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-13 20:29:22 +02:00
David Lamparter
151d7c3591 lib: drop off "masters" list on master_free()
Don't leave a dangling leaked reference.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-11 16:10:29 +02:00
Quentin Young
dfd19ccc3a
*: update hash_create(), hash_create_size()
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-01 19:18:37 -04:00
Quentin Young
fe232cf819 lib: printf bugfixes & improvement
* Fix bad format specifier in thread.[ch]
* Move PRINTF_ATTRIBUTE macro to zebra.h
* Use PRINTF_ATTRIBUTE on termtable printers

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-30 16:18:20 +00:00
Jafar Al-Gharaibeh
1d0ca3ebf3 Merge pull request #770 from donaldsharp/zclient
Zclient
2017-06-30 10:35:28 -05:00
Donald Sharp
85bf0f3237 lib: Fix clang warning
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-06-30 10:29:14 -04:00
Quentin Young
26eb0e4ff5 lib: fix merge error
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29 23:40:57 +00:00
Quentin Young
972a411ccc lib: more show thread cpu
Add support for naming pthreads. Also, note that we don't have any
records yet if that's the case.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29 23:40:56 +00:00
Quentin Young
62f4402239 lib: make show thread... commands mt-aware
This patch fixes up show thread commands so that they know about
and operate on all extant thread_masters, since we can now have multiple
running in any given application.

This change also eliminates a heap use after free that appears when
using a single cpu_record shared among multiple threads. Since struct
thread's have pointers to bits of memory that are freed when the global
statistics hash table is freed, later accesses are invalid. By moving
the stats hash to be unique to each thread_master this problem is
sidestepped.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29 23:37:08 +00:00
Quentin Young
e0bebc7c22 lib: mt-safe tracebacks
can't be using them statics anymore sonny

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29 23:32:15 +00:00
Quentin Young
0693f6fc75 lib: un-static trash buffer for pipe poker
data races

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29 23:32:15 +00:00
Quentin Young
96ade3ed77 *: use vty_outln
Saves 400 lines

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29 17:31:28 +00:00
Quentin Young
7feb7d7e65 lib: tighten up exit semantics for thread_fetch()
* Account for the pipe poker in poll() by explicitly returning NULL when
  we have no events, timers or file descriptors to work with
* Add a comment explaining exactly what we are doing and why

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-16 19:56:58 +00:00
Quentin Young
8797240ea4 lib: mt-safe cancel, round deux
* Update pollfds copy as well as the original
* Keep array count for copy in thread_master
* Remove last remnants of POLLHUP in .events field
* Remove unused snmpcount (lolwut)
* Improve docs
* Add missing do_thread_cancel() call in thread_cancel_event()
* Change thread_fetch() to always enter poll() to avoid starving i/o
* Remember to free up cancel_req when destroying thread_master
* Fix dereference of null pointer
* Fix dead store to timeval
* Fix missing condition for condition variable :-)

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-16 19:56:58 +00:00
Quentin Young
63ccb9cb12 lib: add mt-safe thread_cancel
This patch implements an MT-safe version of thread_cancel() in
thread_cancel_async(). Behavior as follows:

* Cancellation requests are queued into a list

* Cancellation requests made from the same pthread as the thread_master
  owner are serviced immediately (thread_cancel())

* Cancellation requests made from a separate pthread are queued and the
  call blocks on a condition variable until the owning pthread services
  the request, at which point the condition variable is signaled and
  execution continues (thread_cancel_async())

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-16 19:56:58 +00:00
Quentin Young
a587d00bac *: remove THREAD_BACKGROUND
it's just an alias for a millisecond timer used in exactly nine places
and serves only to complicate

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-08 01:53:50 +00:00
David Lamparter
fa135ba008 Merge pull request #648 from qlyoung/fix-pollfd-stack-overflow
lib: use heap for pollfds
2017-06-06 17:25:06 +02:00
Quentin Young
82fc5591f4 lib: allow infinite sleep in poll()
If fd_poll() is called with no file descriptors, an incorrect check in
the function prelude causes it to return instantly; for a thread that
wishes to poll but has no file descriptors, this results in busy
waiting. Desired behavior is to block.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-06 14:23:42 +00:00
Quentin Young
95db01eb22 lib: use heap for pollfds
a bunch of pollfds can cause a stack overflow when using a stack
allocated buffer...silly me...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-31 23:21:40 +00:00
Quentin Young
8c88ac94fa lib: make writing end of pipe nonblocking
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-31 17:30:53 +00:00
Quentin Young
a772d6eae6 lib: missed AWAKEN in r/w thread scheduler
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-30 10:27:10 -04:00
Quentin Young
3bf2673b30 lib: allow pthreads to poke poll()
When scheduling a task onto a thread master owned by another pthread, we
need to lock the thread master's mutex. However, if the pthread which
owns that thread master is in poll(), we could be stuck waiting for a
very long time. To solve this, we copy all data poll() needs and unlock
during poll(). To break the target pthread out of poll(), thread_master
has gained a pipe whose reading end is passed into poll(). After an event
that requires immediate action by the target pthread, a byte is written
into the pipe in order to wake it up.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
[DL: split off from select() removal]
2017-05-30 10:27:10 -04:00
Quentin Young
75bcb3558d lib: remove select()
poll() is present on every supported platform and does not have an upper
limit on file descriptors.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
[DL: split off from AWAKEN() change]
2017-05-30 10:27:10 -04:00
Quentin Young
48cdf1a9d6 lib: enforce thread_cancel() MT-unsafe invariant
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-19 19:10:21 +00:00
Lou Berger
745ad980fe Merge pull request #538 from qlyoung/fix-stack-access-2
lib: return thread * from thread_add*
2017-05-17 07:34:30 -04:00
David Lamparter
34f99549ab Merge pull request #549 from qlyoung/fix-poll-eof
lib: correctly handle EOF when using poll()
2017-05-17 11:25:30 +02:00
Quentin Young
6ccdc60d96 lib: correctly handle EOF when using poll()
Descriptor owner should handle EOF, not thread.c

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-16 18:29:51 +00:00
Quentin Young
56a94b3668 lib: return thread pointer from thread_add*
Allow some more flexibility in case callers wish to manage their own
thread pointers and don't require or don't want the thread to keep a
back reference to its holding pointer.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-16 15:59:51 +00:00
David Lamparter
896014f4bc *: make consistent & update GPLv2 file headers
The FSF's address changed, and we had a mixture of comment styles for
the GPL file header.  (The style with * at the beginning won out with
580 to 141 in existing files.)

Note: I've intentionally left intact other "variations" of the copyright
header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15 16:37:41 +02:00
Quentin Young
368d025eca lib: fix access to stack value
Passing stack value to thread_add_* causes thread->ref to become an
invalid pointer when the value goes out of scope

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-15 06:29:54 +00:00
Quentin Young
32d86f8b7a lib: safely check & set thread pointers
When scheduling a thread, the scheduling function returns a pointer to
the struct thread that was placed on one of the scheduling queues in the
associated thread master. This pointer is used to check whether or not
the thread is scheduled, and is passed to thread_cancel() should the
daemon need to cancel that particular task.

The thread_fetch() function is called to retrieve the next thread to
execute. However, when it returns, the aforementioned pointer is not
updated. As a result, in order for the above use cases to work, every
thread handler function must set the associated pointer to NULL. This is
bug prone, and moreover, not thread safe.

This patch changes the thread scheduling functions to return void. If
the caller needs a reference to the scheduled thread, it must pass in a
pointer to store the pointer to the thread struct in. Subsequent calls
to thread_cancel(), thread_cancel_event() or thread_fetch() will result
in that pointer being nulled before return. These operations occur
within the thread_master critical sections.

Overall this should avoid bugs introduced by thread handler funcs
forgetting to null the associated pointer, double-scheduling caused by
overwriting pointers to currently scheduled threads without performing a
nullity check, and the introduction of true kernel threads causing race
conditions within the userspace threading world.

Also removes the return value for thread_execute since it always returns
null...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-09 20:44:22 +00:00
Quentin Young
ffa2c8986d *: remove THREAD_ON macros, add nullity check
The way thread.c is written, a caller who wishes to be able to cancel a
thread or avoid scheduling it twice must keep a reference to the thread.
Typically this is done with a long lived pointer whose value is checked
for null in order to know if the thread is currently scheduled.  The
check-and-schedule idiom is so common that several wrapper macros in
thread.h existed solely to provide it.

This patch removes those macros and adds a new parameter to all
thread_add_* functions which is a pointer to the struct thread * to
store the result of a scheduling call. If the value passed is non-null,
the thread will only be scheduled if the value is null. This helps with
consistency.

A Coccinelle spatch has been used to transform code of the form:

  if (t == NULL)
    t = thread_add_* (...)

to the form

  thread_add_* (..., &t)

The THREAD_ON macros have also been transformed to the underlying
thread.c calls.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-09 20:44:19 +00:00
Donald Sharp
6281320446 Merge remote-tracking branch 'origin/stable/3.0' 2017-05-08 16:51:21 -04:00
Quentin Young
6a5fb771a9 lib: abort if fd >= FD_SETSIZE and using select
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-07 04:42:07 +00:00
Donald Sharp
704ef00bb5 lib: Rename HAVE_POLL to prevent conflicting #defines
Rename HAVE_POLL to HAVE_POLL_CALL, when compiling with
snmp and poll enabled this was causing issues.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-05-04 10:32:41 -04:00
Quentin Young
705f21797e lib: allow nonblocking thread_fetch()
This change adds three fields to thread_master and associated code to
use them. The fields are:

 * long selectpoll_timeout

This is a millisecond value that, if nonzero, will override the
internally calculated timeout for select()/poll(). -1 indicates
nonblocking while a positive value indicates the desired timeout in
milliseconds.

 * bool spin

This indicates whether a call to thread_fetch() should result in a loop
until work is available. By default this is set to true, in order to
keep the default behavior. In this case a return value of NULL indicates
that a fatal signal was received in select() or poll(). If it is set to
false, thread_fetch() will return immediately. NULL is then an
acceptable return value if there is no work to be done.

 * bool handle_signals

This indicates whether or not the pthread that owns the thread master
is responsible for handling signals (since this is an MT-unsafe
operation, it is best to have just the root thread do it). It is set to
true by default. Non-root pthreads should set this to false.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-04-30 23:06:14 +00:00
Quentin Young
2c70efaed1 lib: additional thread.c MT-safety work
Fixes a few insufficient critical sections. Adds back locking for
thread_cancel(), since while thread_cancel() is only safe to call from
the pthread which owns the thread master due to races involving
thread_fetch() modifying thread master's ready queue, we still need
mutual exclusion here for all of the other public thread.c functions to
maintain their MT-safety.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-04-28 22:43:37 +00:00
Quentin Young
1189d95fca lib: make thread.c pthread-safe
This change introduces synchronization mechanisms to thread.c in order
to allow safe concurrent use.

Thread.c should now be threadstafe with respect to:
* struct thread
* struct thread_master

Calls into thread.c for operations upon data of this type should not
require external synchronization.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-04-28 22:43:36 +00:00
David Lamparter
4c0a782d47 lib: remove unused add_snmp_pollfds()
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-03-24 12:46:26 +01:00
David Lamparter
4525281af1 *: get rid of zlog(*, LOG_LEVEL, ...)
Result of running the following Coccinelle patch + fixups:
<<EOF
/* long-forms: zlog(NULL, <level>, ...)
 *    =>       zlog_level(...)
 */

@@
expression list args;
@@
- zlog(NULL, LOG_DEBUG, args)
+ zlog_debug(args)

@@
expression list args;
@@
- zlog(NULL, LOG_NOTICE, args)
+ zlog_notice(args)

@@
expression list args;
@@
- zlog(NULL, LOG_INFO, args)
+ zlog_info(args)

@@
expression list args;
@@
- zlog(NULL, LOG_WARNING, args)
+ zlog_warn(args)

@@
expression list args;
@@
- zlog(NULL, LOG_ERR, args)
+ zlog_err(args)

/* long-forms: zlog(base->log, <level>, ...)
 *    =>       zlog_level(...)
 */

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_DEBUG, args)
+ zlog_debug(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_NOTICE, args)
+ zlog_notice(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_INFO, args)
+ zlog_info(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_WARNING, args)
+ zlog_warn(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_ERR, args)
+ zlog_err(args)

EOF

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-03-08 00:15:39 +01:00
Donald Sharp
7df2e1c379 Merge remote-tracking branch 'origin/stable/2.0' 2017-02-07 13:20:12 -05:00
Donald Sharp
f0d975f752 lib: Fixup CR comment
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-02-07 04:54:40 -05:00
Donald Sharp
f96872f001 lib: Don't use malloc!
thread.c was using malloc.  This was found by the
assert added to memory.c.

Fixes issues #170

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-02-06 12:52:28 -05:00
Donald Sharp
907ca8e4d5 lib: Inadvertent assignment in ? operator
In the case where we are using select as
the operator *and* we call
funcname_thread_add_read_write *and* the
fd is already set, we would overwrite
the read/write direction to always be READ.

Clearly this was a bad idea.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-02-01 19:47:39 -05:00
David Lamparter
e0e2a99068 lib: cope with negative timeout in thread.c
Since time is no longer cached, if we schedule something with zero
timeout, it will automatically be negative by the time we reach the
event loop.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:59:15 +01:00
David Lamparter
4b185cb399 lib: time: clean out thread.c
Remove quagga_get_relative(), replace with monotime().

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:55:33 +01:00
David Lamparter
816c2194ca ospfd: simplify SPF time consumption calculations
monotime_since() does exactly the same thing.
... and timeval_elapsed is now private to lib/thread.c

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:26:33 +01:00
David Lamparter
cf672a8654 *: use monotime()
This is largely a bulk-replace made with coccinelle.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:26:32 +01:00
David Lamparter
d9d5c3e8bf lib: time: remove local time helpers
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:26:32 +01:00
David Lamparter
3dad49ca94 lib: time: remove recent_time
This isn't even used anywhere.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:26:32 +01:00
David Lamparter
6ced0e7f10 lib: time: remove recent_relative_time()
Replace with monotime() [which is not cached].

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:26:32 +01:00
Donald Sharp
f7c62e11d6 lib: Fix 'show thread cpu' to display active threads
Fix the display of 'show thread cpu' to keep track
of the number of active threads and to display that
information.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>

lib: Fix thread_execute_crash
2017-01-17 18:43:28 -05:00
Donald Sharp
b3f5645df3 lib: Slight Optimization of thread handling.
This commit does these things:

1) Make thread_add_unuse own the setting of THREAD_UNUSED.
2) Move thread->hist finding to to thread_get.
   We are storing the thread->hist even when the thread
   is on the unused.  This means that we check to see
   if the funcname or func have changed and we get new
   history.  Else we've probably just retrieved the last
   unused which has the same func/funcanme.  This is
   a common practice to do THREAD_OFF/THREAD_ON in
   quick succession.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com.
2017-01-17 18:40:33 -05:00
David Lamparter
0b84f29490 *: make DEFUN installations file-local
This moves all install_element calls into the file where the DEFUNs are
located.  This fixes several small related bugs:

- ospf6d wasn't installing a "no interface FOO" command
- zebra had a useless copy of "interface FOO"
- pimd's copy of "interface FOO" was not setting qobj_index, which means
  "description LINE" commands would fail with an error

The next commit will do the actual act of making "foo_cmd" static.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-12-01 17:25:56 +01:00
David Lamparter
82992fed8c Merge branch 'vtysh-grammar'
Conflicts:
	isisd/isisd.c
	lib/Makefile.am
	lib/thread.c

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-28 17:56:29 +01:00
David Lamparter
24f5e2fc62 build: massively remove needless checks
Since we have autoconf results from a wide swath of target platforms, we
can go remove checks that have the same result on all systems.

This also removes several "fallback" implementations of functions that,
at some point in the history, weren't available on all target platforms.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-11-15 14:23:17 +09:00
Quentin Young
e52702f29d Merge branch 'cmaster-next' into vtysh-grammar
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>

Conflicts:
	bgpd/bgp_route.c
	bgpd/bgp_routemap.c
	bgpd/bgp_vty.c
	isisd/isis_redist.c
	isisd/isis_routemap.c
	isisd/isis_vty.c
	isisd/isisd.c
	lib/command.c
	lib/distribute.c
	lib/if.c
	lib/keychain.c
	lib/routemap.c
	lib/routemap.h
	ospf6d/ospf6_asbr.c
	ospf6d/ospf6_interface.c
	ospf6d/ospf6_neighbor.c
	ospf6d/ospf6_top.c
	ospf6d/ospf6_zebra.c
	ospf6d/ospf6d.c
	ospfd/ospf_routemap.c
	ospfd/ospf_vty.c
	ripd/rip_routemap.c
	ripngd/ripng_routemap.c
	vtysh/extract.pl.in
	vtysh/vtysh.c
	zebra/interface.c
	zebra/irdp_interface.c
	zebra/rt_netlink.c
	zebra/rtadv.c
	zebra/test_main.c
	zebra/zebra_routemap.c
	zebra/zebra_vty.c
2016-10-17 23:36:21 +00:00
Daniel Walton
abddf07563 all: scrubbed some argc CHECK MEs
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
2016-09-29 19:51:56 +00:00
Daniel Walton
67656e9b65 all: added CHECK ME for DEFUNs that look at argc
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
2016-09-29 17:48:57 +00:00
Donald Sharp
0cf74a8392 lib: Allow more space in thread.c output
When displaying thread time for long running/busy
protocols, the space allocated may not be sufficient.

Allow the runtime to take a bit more space.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-09-26 14:06:23 -04:00
Daniel Walton
c349116d7c lib: add 'int idx_foo' argv index variables
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
2016-09-23 20:17:29 +00:00
Quentin Young
1bf1b05af9 lib: argv update for thread.c
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2016-09-22 20:32:34 +00:00
Daniel Walton
5c307a08f2 Revert "lib: Get thread.c to compile"
This reverts commit 9c5f6b578e.
2016-09-22 18:23:29 +00:00
Donald Sharp
9c5f6b578e lib: Get thread.c to compile
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-09-20 21:23:53 -04:00
David Lamparter
4a1ab8e405 *: split & distribute memtypes and stop (re|ab)using lib/ MTYPEs
This is a rather large mechanical commit that splits up the memory types
defined in lib/memtypes.c and distributes them into *_memory.[ch] files
in the individual daemons.

The zebra change is slightly annoying because there is no nice place to
put the #include "zebra_memory.h" statement.

bgpd, ospf6d, isisd and some tests were reusing MTYPEs defined in the
library for its own use.  This is bad practice and would break when the
memtype are made static.

Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
[CF: rebased for cmaster-next]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2016-09-19 16:31:04 -04:00
Donald Sharp
49d41a26c6 isisd, lib, vtysh: Allow extract.pl to fully work
The regular expression for finding DEFUN/ALIAS in
extract.pl looks for "DEFUN (" or "ALIAS (" if
the *.c file does not have this then it will just
silently ignore the cli.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-09-17 07:25:35 -04:00
David Lamparter
56e2c5e847 lib: AgentX: use threads instead of eventloop hack
AgentX fd/timeout handling is rather hackishly monkeyed into thread.c.
Replace with code that uses plain thread_* functions.

NB: Net-SNMP's API rivals Quagga's in terms of age and absence of
documentation.  netsnmp_check_outstanding_agent_requests() in particular
seems to be unused and is therefore untested.

The most useful documentation on this is actually the blog post Vincent
Bernat wrote when he originally integrated this into lldpd and Quagga:
https://vincent.bernat.im/en/blog/2012-snmp-event-loop.html

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-07-28 07:27:47 -04:00
David Lamparter
d03c4cbd9a lib: add thread_add_timer_tv (struct timeval)
Another zoo extension, this adds a timer scheduling function that takes
a struct timeval argument (which is actually what the wrappers boil down
to, yet it's not exposed...)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-07-28 07:27:47 -04:00
David Lamparter
16f5949d44 lib: remove a whole bunch of unused time stuff
QUAGGA_CLK_REALTIME and QUAGGA_CLK_REALTIME_STABILISED aren't used
anywhere in the code.  Remove.  The enum is kept to avoid having to
change the calls everywhere.

Same applies to the workaround code for systems that don't have a
monotonic clock.  None of the systems Quagga works on fall into that
category;  Linux, BSD and Solaris all do clock_gettime, for OSX we have
mach_absolute_time() - that covers everything.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-07-28 07:27:47 -04:00
David Lamparter
a05d8b7ae4 ospfd: monotonic clock for lsa_refresher_started
ospf->lsa_refresher_started is only used in relative timing to itself;
replace with monotonic clock which is appropriate for this.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-07-28 07:27:47 -04:00
David Lamparter
d11f748b30 *: fixup snmp support
- HAVE_POLL is overloaded by net-snmp
- missing includes
- ospf6_snmp converted to vrf_iflist()

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-07-24 03:47:03 -04:00
Donald Sharp
1bba4c938b lib: Fix some poll semantics
Two Fixes:

1) When a fd has both read and write as a .events.
(POLLHUP | POLLIN | POLLOUT) and a
thread_cancel_read_write call is executed
from a protocol, the code was blindly removing
the fd from consideration at all.

2) POLLNVAL was being evaluated before POLLIN|POLLOUT
were being evaluated.  While I didn't see a case
of POLLNVAL being included with other .revent flags
I decided to move the POLLNVAL and POLLHUP handling
to the same section of code.

Additionally the function thread_cancel_read_write
was poorly named and let me to poorly implement
the poll version of it.  I've renamed the function
thread_cancel_read_or_write in an attempt to
make this problem moot in the future.

Ticket: CM-11027
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
(cherry picked from commit f6da66a913)
2016-06-10 11:18:58 -04:00
Donald Sharp
69f30024c1 lib, bgpd: Fixup some more compile errors due to warnings
Original cherry-pick done on a fedora box with a completely
different compiler.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-06-04 20:45:43 -04:00
David Lamparter
d1265948c3 lib: include thread information in backtraces
now that we know what thread we're currently executing, let's add that
information to SEGV / assert backtraces.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
(cherry picked from commit 615f9f18fc025757a255f936748fc1e86e922783)
2016-05-29 20:11:42 -04:00
David Lamparter
9c7753e41a lib: unstupidify thread debug information
the library's thread scheduling functions keep track of the thread
function's name, so far so good.  However, copying the compiler-provided
constant into a buffer inside the thread structure is plain useless.
Also, strip_funcname() was trying to support something that never
happens.

Instead, let's use some bytes here to track where threads are scheduled
from.  Another commit will print that information on crashes.

Ripping out useless stuff:  -64 bytes in the thread structure
Re-add as const ptr:         +8 bytes
Extra debug info:           +12 bytes

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
(cherry picked from commit 3493b7731b750cbc62f00be94b624a08ccccf0b2)
2016-05-29 20:08:52 -04:00
Donald Sharp
f48f65d225 lib: Clean up some small static analysis warnings
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
2016-05-19 10:42:17 -04:00
Christian Franke
6ac446878f lib: add function to get precise remaining time of timer thread
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-03-29 20:26:26 -04:00
Donald Sharp
c026ca1c01 lib: Really fix handling of poll
This fix is just the actual point fix of the poll event handling.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-03-28 08:07:08 -04:00
Donald Sharp
aa037235c1 Revert "lib: Fix handling of poll"
This reverts commit cc7165b62a.

This commit was causing crashes.
2016-03-28 08:04:48 -04:00