Changeset e7c26b45d2a6c8cef064cf2253d77bf8f360bef8
- Timestamp:
- 01/27/09 22:38:44
(4 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1233095924 +0000
- git-parent:
[b13e0b2a4f10bf3512ef2acdf53ae9e88b4a7ee5]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1233095924 +0000
- Message:
fix duplicates by not reusing stream names, refs #71
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2d89607 |
re7c26b4 |
|
| 16 | 16 | #include <sys/ioctl.h> |
|---|
| 17 | 17 | #include <errno.h> |
|---|
| | 18 | |
|---|
| | 19 | static noit_atomic32_t ls_counter = 0; |
|---|
| 18 | 20 | |
|---|
| 19 | 21 | struct log_entry { |
|---|
| … | … | |
| 37 | 39 | } noit_livestream_closure_t; |
|---|
| 38 | 40 | |
|---|
| | 41 | noit_livestream_closure_t * |
|---|
| | 42 | noit_livestream_closure_alloc(void) { |
|---|
| | 43 | noit_livestream_closure_t *jcl; |
|---|
| | 44 | jcl = calloc(1, sizeof(*jcl)); |
|---|
| | 45 | pthread_mutex_init(&jcl->lqueue_lock, NULL); |
|---|
| | 46 | sem_init(&jcl->lqueue_sem, 0, 0); |
|---|
| | 47 | return jcl; |
|---|
| | 48 | } |
|---|
| | 49 | |
|---|
| | 50 | void |
|---|
| | 51 | noit_livestream_closure_free(noit_livestream_closure_t *jcl) { |
|---|
| | 52 | struct log_entry *tofree; |
|---|
| | 53 | while(jcl->lqueue) { |
|---|
| | 54 | tofree = jcl->lqueue; |
|---|
| | 55 | jcl->lqueue = jcl->lqueue->next; |
|---|
| | 56 | free(tofree->buff); |
|---|
| | 57 | free(tofree); |
|---|
| | 58 | } |
|---|
| | 59 | free(jcl); |
|---|
| | 60 | } |
|---|
| | 61 | |
|---|
| 39 | 62 | static int |
|---|
| 40 | 63 | noit_livestream_logio_open(noit_log_stream_t ls) { |
|---|
| … | … | |
| 51 | 74 | struct log_entry *le; |
|---|
| 52 | 75 | if(!jcl) return 0; |
|---|
| | 76 | |
|---|
| | 77 | if(jcl->wants_shutdown) { |
|---|
| | 78 | /* This has been terminated by the client, _fail here_ */ |
|---|
| | 79 | return 0; |
|---|
| | 80 | } |
|---|
| 53 | 81 | |
|---|
| 54 | 82 | le = calloc(1, sizeof(*le)); |
|---|
| … | … | |
| 67 | 95 | static int |
|---|
| 68 | 96 | noit_livestream_logio_close(noit_log_stream_t ls) { |
|---|
| | 97 | noit_livestream_closure_t *jcl = ls->op_ctx; |
|---|
| | 98 | if(jcl) noit_livestream_closure_free(jcl); |
|---|
| 69 | 99 | ls->op_ctx = NULL; |
|---|
| 70 | 100 | return 0; |
|---|
| … | … | |
| 84 | 114 | NOIT_LIVESTREAM_DATA_FEED, |
|---|
| 85 | 115 | noit_livestream_handler); |
|---|
| 86 | | } |
|---|
| 87 | | |
|---|
| 88 | | noit_livestream_closure_t * |
|---|
| 89 | | noit_livestream_closure_alloc(void) { |
|---|
| 90 | | noit_livestream_closure_t *jcl; |
|---|
| 91 | | jcl = calloc(1, sizeof(*jcl)); |
|---|
| 92 | | pthread_mutex_init(&jcl->lqueue_lock, NULL); |
|---|
| 93 | | sem_init(&jcl->lqueue_sem, 0, 0); |
|---|
| 94 | | return jcl; |
|---|
| 95 | | } |
|---|
| 96 | | |
|---|
| 97 | | void |
|---|
| 98 | | noit_livestream_closure_free(noit_livestream_closure_t *jcl) { |
|---|
| 99 | | struct log_entry *tofree; |
|---|
| 100 | | while(jcl->lqueue) { |
|---|
| 101 | | tofree = jcl->lqueue; |
|---|
| 102 | | jcl->lqueue = jcl->lqueue->next; |
|---|
| 103 | | free(tofree->buff); |
|---|
| 104 | | free(tofree); |
|---|
| 105 | | } |
|---|
| 106 | | free(jcl); |
|---|
| 107 | 116 | } |
|---|
| 108 | 117 | |
|---|
| … | … | |
| 219 | 228 | |
|---|
| 220 | 229 | jcl->feed = malloc(32); |
|---|
| 221 | | snprintf(jcl->feed, 32, "livestream/%d", e->fd); |
|---|
| | 230 | snprintf(jcl->feed, 32, "livestream/%d", noit_atomic_inc32(&ls_counter)); |
|---|
| 222 | 231 | noit_log_stream_new(jcl->feed, "noit_livestream", jcl->feed, |
|---|
| 223 | 232 | jcl, NULL); |
|---|
| … | … | |
| 240 | 249 | } |
|---|
| 241 | 250 | |
|---|
| | 251 | noit_check_transient_remove_feed(jcl->check, jcl->feed); |
|---|
| | 252 | noit_livestream_closure_free(jcl); |
|---|
| 242 | 253 | /* Undo our dup */ |
|---|
| 243 | 254 | eventer_free(newe); |
|---|