[BusyBox] Single-threaded Syslogd
Mark Whitley
markw at lineo.com
Mon Mar 12 19:53:20 UTC 2001
On Wed, Mar 07, 2001 at 01:51:34PM -0500, Gennady Feldman wrote:
>
> Here is my first somewhat working version of the patch which
> changes syslogd not to fork itself when serving requests. It seems to work
> on my test system. I would like other people to bang on it somewhat. I
> didn't include any of my other changes yet, so don't commit this to cvs. I
> am preparing a bigger patch which will address my TODO list. I still have
> a few small things to fix up. Most of the stuff seems to be compiling
> cleanly and working for me.
Gennady, I've tested your patch. Explanation / details follow:
I wrote a program to test concurrent access to syslogd with multiple threads.
Here it is:
---begin-test-program---------
/*
* tst-syslogd.c - tests concurrent threads calling syslog
*/
#include <stdio.h>
#include <pthread.h>
#include <syslog.h>
#include <unistd.h>
void *log_func(void *arg)
{
int i;
int thrid = (int)arg;
openlog(NULL, LOG_PERROR | LOG_PID, LOG_USER);
for (i = 0; i < 10; i++) {
syslog(LOG_DEBUG, "thread %i iter %i\n", thrid, i);
sleep(thrid); /* this mixes things up a bit */
}
closelog();
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thr1, thr2, thr3;
int id1 = 1;
int id2 = 2;
int id3 = 3;
pthread_create(&thr1, NULL, log_func, (void *)id1);
pthread_create(&thr2, NULL, log_func, (void *)id2);
pthread_create(&thr3, NULL, log_func, (void *)id3);
pthread_join(thr1, NULL);
pthread_join(thr2, NULL);
pthread_join(thr3, NULL);
return 0;
}
---end-test-program---------
Here are the results of the test program BEFORE applying your patch (this one
uses fork):
Mar 12 12:44:29 shiva klogd started: BusyBox v0.50pre (2001.03.12-19:44+0000)
Mar 12 12:44:29 shiva syslogd started: BusyBox v0.50pre (2001.03.12-19:44+0000)
Mar 12 12:44:42 shiva user.debug a.out[2389]: thread 1 iter 0
Mar 12 12:44:42 shiva user.debug a.out[2391]: thread 2 iter 0
Mar 12 12:44:42 shiva user.debug a.out[2392]: thread 3 iter 0
Mar 12 12:44:43 shiva user.debug a.out[2389]: thread 1 iter 1
Mar 12 12:44:44 shiva user.debug a.out[2391]: thread 2 iter 1
Mar 12 12:44:44 shiva user.debug a.out[2389]: thread 1 iter 2
Mar 12 12:44:45 shiva user.debug a.out[2389]: thread 1 iter 3
Mar 12 12:44:45 shiva user.debug a.out[2392]: thread 3 iter 1
Mar 12 12:44:46 shiva user.debug a.out[2391]: thread 2 iter 2
Mar 12 12:44:46 shiva user.debug a.out[2389]: thread 1 iter 4
Mar 12 12:44:47 shiva user.debug a.out[2389]: thread 1 iter 5
Mar 12 12:44:48 shiva user.debug a.out[2391]: thread 2 iter 3
Mar 12 12:44:48 shiva user.debug a.out[2392]: thread 3 iter 2
Mar 12 12:44:48 shiva user.debug a.out[2389]: thread 1 iter 6
Mar 12 12:44:49 shiva user.debug a.out[2389]: thread 1 iter 7
Mar 12 12:44:50 shiva user.debug a.out[2391]: thread 2 iter 4
Mar 12 12:44:50 shiva user.debug a.out[2389]: thread 1 iter 8
Mar 12 12:44:51 shiva user.debug a.out[2392]: thread 3 iter 3
Mar 12 12:44:51 shiva user.debug a.out[2389]: thread 1 iter 9
Mar 12 12:44:52 shiva user.debug a.out[2391]: thread 2 iter 5
Mar 12 12:44:54 shiva user.debug a.out[2391]: thread 2 iter 6
Mar 12 12:44:54 shiva user.debug a.out[2392]: thread 3 iter 4
Mar 12 12:44:56 shiva user.debug a.out[2391]: thread 2 iter 7
Mar 12 12:44:57 shiva user.debug a.out[2392]: thread 3 iter 5
Mar 12 12:44:58 shiva user.debug a.out[2391]: thread 2 iter 8
Mar 12 12:45:00 shiva user.debug a.out[2392]: thread 3 iter 6
Mar 12 12:45:00 shiva user.debug a.out[2391]: thread 2 iter 9
Mar 12 12:45:03 shiva user.debug a.out[2392]: thread 3 iter 7
Mar 12 12:45:06 shiva user.debug a.out[2392]: thread 3 iter 8
Mar 12 12:45:09 shiva user.debug a.out[2392]: thread 3 iter 9
Here are the results of the test program AFTER applying your patch
(single-threaded):
Mar 12 12:46:57 shiva klogd started: BusyBox v0.50pre (2001.03.12-19:46+0000)
Mar 12 12:46:57 shiva syslogd started: BusyBox v0.50pre (2001.03.12-19:46+0000)
Mar 12 12:47:01 shiva user.debug a.out[2433]: thread 1 iter 0
Mar 12 12:47:01 shiva user.debug a.out[2434]: thread 2 iter 0
Mar 12 12:47:01 shiva user.debug a.out[2435]: thread 3 iter 0
Mar 12 12:47:02 shiva user.debug a.out[2433]: thread 1 iter 1
Mar 12 12:47:03 shiva user.debug a.out[2433]: thread 1 iter 2
Mar 12 12:47:03 shiva user.debug a.out[2434]: thread 2 iter 1
Mar 12 12:47:04 shiva user.debug a.out[2435]: thread 3 iter 1
Mar 12 12:47:04 shiva user.debug a.out[2433]: thread 1 iter 3
Mar 12 12:47:05 shiva user.debug a.out[2434]: thread 2 iter 2
Mar 12 12:47:05 shiva user.debug a.out[2433]: thread 1 iter 4
Mar 12 12:47:06 shiva user.debug a.out[2433]: thread 1 iter 5
Mar 12 12:47:07 shiva user.debug a.out[2435]: thread 3 iter 2
Mar 12 12:47:07 shiva user.debug a.out[2434]: thread 2 iter 3
Mar 12 12:47:07 shiva user.debug a.out[2433]: thread 1 iter 6
Mar 12 12:47:08 shiva user.debug a.out[2433]: thread 1 iter 7
Mar 12 12:47:09 shiva user.debug a.out[2434]: thread 2 iter 4
Mar 12 12:47:09 shiva user.debug a.out[2433]: thread 1 iter 8
Mar 12 12:47:10 shiva user.debug a.out[2435]: thread 3 iter 3
Mar 12 12:47:10 shiva user.debug a.out[2433]: thread 1 iter 9
Mar 12 12:47:11 shiva user.debug a.out[2434]: thread 2 iter 5
Mar 12 12:47:13 shiva user.debug a.out[2435]: thread 3 iter 4
Mar 12 12:47:13 shiva user.debug a.out[2434]: thread 2 iter 6
Mar 12 12:47:15 shiva user.debug a.out[2434]: thread 2 iter 7
Mar 12 12:47:16 shiva user.debug a.out[2435]: thread 3 iter 5
Mar 12 12:47:17 shiva user.debug a.out[2434]: thread 2 iter 8
Mar 12 12:47:19 shiva user.debug a.out[2435]: thread 3 iter 6
Mar 12 12:47:19 shiva user.debug a.out[2434]: thread 2 iter 9
Mar 12 12:47:22 shiva user.debug a.out[2435]: thread 3 iter 7
Mar 12 12:47:25 shiva user.debug a.out[2435]: thread 3 iter 8
Mar 12 12:47:28 shiva user.debug a.out[2435]: thread 3 iter 9
Bottom line: Looks like it works fine. (And Erik likes getting rid of calls to
fork(), which is a plus.) Committed to CVS.
Mark Whitley
markw at lineo.com
More information about the busybox
mailing list