Skip to content

Commit a7f329b

Browse files
committed
Get rid of the rtpp_genuid_singlet, convert rtpp_genuid to a
newstyle object and use it instead to avoid using static variables.
1 parent 855afac commit a7f329b

21 files changed

Lines changed: 91 additions & 158 deletions

scripts/fuzz/fuzz_rtp_parser.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "rtpp_endian.h"
1414
#include "rtpp_time.h"
1515
#include "rtpp_ssrc.h"
16-
#include "rtpp_genuid_singlet.h"
1716
#include "rtp_info.h"
1817
#include "rtp.h"
1918
#include "rtp_packet.h"
@@ -33,7 +32,6 @@ LLVMFuzzerTestOneInput(const char *data, size_t size)
3332
return (0);
3433

3534
if (log == NULL) {
36-
assert(rtpp_gen_uid_init() == 0);
3735
log = rtpp_log_ctor("rtpproxy", NULL, LF_REOPEN);
3836
assert(log != NULL);
3937
rap = rtpp_analyzer_ctor(log);

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RTPP_AUTOSRC_SOURCES_S = rtpp_netaddr.h rtpp_pearson_perfect.h rtpp_refcnt.h \
2828
rtpp_record.h rtpp_hash_table.h rtpp_weakref.h rtpp_analyzer.h \
2929
rtpp_pcnt_strm.h rtpp_ttl.h rtpp_pipe.h rtpp_ringbuf.h rtpp_sessinfo.h \
3030
rtpp_rw_lock.h rtpp_proc_servers.h rtpp_proc_wakeup.h rtpp_socket.h \
31-
rtpp_refproxy.h rtpp_command_reply.h
31+
rtpp_refproxy.h rtpp_command_reply.h rtpp_genuid.h
3232

3333
CMDSRCDIR=$(MAINSRCDIR)/commands
3434
BASE_SOURCES=main.c rtp.h rtpp_server.c \
@@ -53,7 +53,7 @@ BASE_SOURCES=main.c rtp.h rtpp_server.c \
5353
rtp_packet.c rtpp_time.c rtpp_time.h rtpp_pcnts_strm.h rtpp_runcreds.h \
5454
rtpp_sessinfo.c rtpp_weakref.c rtpp_rw_lock.c \
5555
rtpp_proc_servers.c rtpp_stream.c rtpp_proc_wakeup.c \
56-
rtpp_genuid.h rtpp_genuid.c rtpp_genuid_singlet.h rtpp_genuid_singlet.c \
56+
rtpp_genuid.c \
5757
rtpp_log_obj.c rtpp_socket.c rtpp_wi_apis.c rtpp_wi_apis.h \
5858
rtpp_ttl.c rtpp_proc_ttl.h rtpp_proc_ttl.c \
5959
rtpp_pipe.c rtpp_pcount.c rtpp_debug.h rtpp_wi_sgnl.c rtpp_wi_sgnl.h \

src/commands/rpcpv1_play.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "config.h"
3535

3636
#include "rtpp_types.h"
37+
#include "rtpp_cfg.h"
3738
#include "rtpp_log.h"
3839
#include "rtpp_log_obj.h"
3940
#include "rtpp_command.h"
@@ -93,7 +94,8 @@ rtpp_command_play_opts_free(struct play_opts *plop)
9394
}
9495

9596
void
96-
rtpp_command_play_handle(struct rtpp_stream *rsp, struct rtpp_command *cmd)
97+
rtpp_command_play_handle(struct rtpp_stream *rsp, struct rtpp_command *cmd,
98+
const struct rtpp_cfg *cfsp)
9799
{
98100
const char *codecs;
99101
int ptime;
@@ -112,8 +114,15 @@ rtpp_command_play_handle(struct rtpp_stream *rsp, struct rtpp_command *cmd)
112114
codecs = plop->codecs->s;
113115
ptime = -1;
114116
}
115-
if (plop->count != 0 && CALL_SMETHOD(rsp, handle_play, codecs,
116-
plop->pname->s, plop->count, cmd, ptime) != 0) {
117+
const struct r_stream_h_play_args pa = {
118+
.codecs = codecs,
119+
.pname = plop->pname->s,
120+
.playcount = plop->count,
121+
.cmd = cmd,
122+
.ptime = ptime,
123+
.guid = cfsp->guid,
124+
};
125+
if (plop->count != 0 && CALL_SMETHOD(rsp, handle_play, &pa) != 0) {
117126
CALL_SMETHOD(cmd->reply, deliver_error, ECODE_PLRFAIL);
118127
goto freeplop;
119128
}

src/commands/rpcpv1_play.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ struct rtpp_log;
3333
struct play_opts;
3434
struct rtpp_command;
3535
struct rtpp_stream;
36+
struct rtpp_cfg;
3637

3738
struct play_opts *rtpp_command_play_opts_parse(struct rtpp_command *);
38-
void rtpp_command_play_handle(struct rtpp_stream *, struct rtpp_command *);
39+
void rtpp_command_play_handle(struct rtpp_stream *, struct rtpp_command *,
40+
const struct rtpp_cfg *);
3941
void rtpp_command_play_opts_free(struct play_opts *);
4042

4143
#endif

src/main.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#include "rtpp_defines.h"
8484
#include "rtpp_command.h"
8585
#include "rtpp_controlfd.h"
86-
#include "rtpp_genuid_singlet.h"
86+
#include "rtpp_genuid.h"
8787
#include "rtpp_hash_table.h"
8888
#include "commands/rpcpv1_ver.h"
8989
#include "rtpp_command_async.h"
@@ -319,7 +319,7 @@ init_config_bail(struct rtpp_cfg *cfsp, int rval, const char *msg, int memdeb)
319319
assert(cfsp->_pad == (void *)0x12345678);
320320
cfsp->_pad = (void *)((uintptr_t)cfsp->_pad ^ 0x87654321);
321321
#endif
322-
rtpp_gen_uid_free();
322+
RTPP_OBJ_DECREF(cfsp->guid);
323323
#if !defined(LIBRTPPROXY)
324324
rtpp_exit(memdeb, rval);
325325
#else
@@ -930,7 +930,7 @@ rtpp_shutdown(struct rtpp_cfg *cfsp)
930930
}
931931
free(cfsp->ctrl_socks);
932932
cfsp->ctrl_socks = NULL;
933-
rtpp_gen_uid_free();
933+
RTPP_OBJ_DECREF(cfsp->guid);
934934
#if defined(LIBRTPPROXY)
935935
RTPP_OBJ_DECREF(cfsp->glog);
936936
#endif
@@ -1025,8 +1025,9 @@ _rtpp_main(int argc, const char * const *argv)
10251025
}
10261026

10271027
seedrandom();
1028-
if (rtpp_gen_uid_init() != 0) {
1029-
MAIN_ERR(1, "rtpp_gen_uid_init() failed");
1028+
cfsp->guid = rtpp_genuid_ctor();
1029+
if (cfsp->guid == NULL) {
1030+
MAIN_ERR(1, "rtpp_genuid_ctor() failed");
10301031
/* NOTREACHED */
10311032
}
10321033

src/rtpp_cfg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ struct rtpp_cfg {
152152
int no_redirect;
153153

154154
struct rtpp_proc_servers *proc_servers;
155+
struct rtpp_genuid *guid;
155156
#if ENABLE_MODULE_IF
156157
struct rtpp_modman *modules_cf;
157158
#else

src/rtpp_command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ handle_command(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd)
669669
break;
670670

671671
case PLAY:
672-
rtpp_command_play_handle(spa->rtp->stream[i], cmd);
672+
rtpp_command_play_handle(spa->rtp->stream[i], cmd, cfsp);
673673
break;
674674

675675
case COPY:

src/rtpp_genuid.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,52 +32,50 @@
3232
#include <stdlib.h>
3333

3434
#include "rtpp_types.h"
35+
#include "rtpp_refcnt.h"
3536
#include "rtpp_genuid.h"
37+
#include "rtpp_genuid_fin.h"
3638
#include "rtpp_mallocs.h"
3739

3840
struct rtpp_genuid_priv {
39-
struct rtpp_genuid_obj pub;
41+
struct rtpp_genuid pub;
4042
_Atomic(uint64_t) lastuid;
4143
};
4244

43-
static void rtpp_genuid_gen(struct rtpp_genuid_obj *, uint64_t *vp);
44-
static void rtpp_genuid_dtor(struct rtpp_genuid_obj *);
45+
static uint64_t rtpp_genuid_gen(struct rtpp_genuid *);
4546

46-
struct rtpp_genuid_obj *
47+
DEFINE_SMETHODS(rtpp_genuid,
48+
.gen = &rtpp_genuid_gen,
49+
);
50+
51+
struct rtpp_genuid *
4752
rtpp_genuid_ctor(void)
4853
{
4954
struct rtpp_genuid_priv *pvt;
5055

51-
pvt = rtpp_zmalloc(sizeof(struct rtpp_genuid_priv));
56+
pvt = rtpp_rzmalloc(sizeof(struct rtpp_genuid_priv), PVT_RCOFFS(pvt));
5257
if (pvt == NULL) {
5358
goto e0;
5459
}
5560
atomic_init(&pvt->lastuid, 0);
56-
pvt->pub.dtor = &rtpp_genuid_dtor;
57-
pvt->pub.gen = &rtpp_genuid_gen;
61+
#if defined(RTPP_DEBUG)
62+
pvt->pub.smethods = GET_SMETHODS(&pvt->pub);
63+
RTPP_OBJ_DTOR_ATTACH(&pvt->pub, (rtpp_refcnt_dtor_t)&rtpp_genuid_fin,
64+
&(pvt->pub));
65+
#endif
5866
return (&pvt->pub);
5967

6068
e0:
6169
return (NULL);
6270
}
6371

64-
static void
65-
rtpp_genuid_dtor(struct rtpp_genuid_obj *pub)
66-
{
67-
struct rtpp_genuid_priv *pvt;
68-
69-
PUB2PVT(pub, pvt);
70-
71-
free(pvt);
72-
}
73-
74-
static void
75-
rtpp_genuid_gen(struct rtpp_genuid_obj *pub, uint64_t *vp)
72+
static uint64_t
73+
rtpp_genuid_gen(struct rtpp_genuid *pub)
7674
{
7775
struct rtpp_genuid_priv *pvt;
7876

7977
PUB2PVT(pub, pvt);
8078

81-
*vp = atomic_fetch_add_explicit(&(pvt->lastuid), 1,
79+
return atomic_fetch_add_explicit(&(pvt->lastuid), 1,
8280
memory_order_relaxed);
8381
}

src/rtpp_genuid.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@
2626
*
2727
*/
2828

29-
struct rtpp_genuid_obj;
29+
DECLARE_CLASS(rtpp_genuid, void);
3030

31-
DEFINE_METHOD(rtpp_genuid_obj, rtpp_genuid_gen, void, uint64_t *);
32-
DEFINE_METHOD(rtpp_genuid_obj, rtpp_genuid_dtor, void);
31+
DECLARE_METHOD(rtpp_genuid, rtpp_genuid_gen, uint64_t);
3332

34-
struct rtpp_genuid_obj {
35-
rtpp_genuid_gen_t gen;
36-
rtpp_genuid_dtor_t dtor;
33+
DECLARE_SMETHODS(rtpp_genuid)
34+
{
35+
METHOD_ENTRY(rtpp_genuid_gen, gen);
3736
};
3837

39-
struct rtpp_genuid_obj *rtpp_genuid_ctor(void);
38+
DECLARE_CLASS_PUBTYPE(rtpp_genuid, {});

src/rtpp_genuid_singlet.c

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)