ipc-driver-test: Allow setting dir prefix for UD socket

Change-Id: I35282b38a1d560fb3440fe0aa9a27808d9d116cc
This commit is contained in:
Pau Espin Pedrol 2020-12-07 19:47:59 +01:00 committed by laforge
parent 1587307a99
commit 4a4e607a19
2 changed files with 24 additions and 11 deletions

View File

@ -49,6 +49,7 @@
#include "ipc_sock.h"
#define DEFAULT_SHM_NAME "/osmo-trx-ipc-driver-shm2"
#define IPC_SOCK_PATH_PREFIX "/tmp"
static void *tall_ctx;
struct ipc_sock_state *global_ipc_sock_state;
@ -63,6 +64,11 @@ void *global_dev;
static struct ipc_shm_region *decoded_region;
static struct {
int msocknum;
char *ud_prefix_dir;
} cmdline_cfg;
static const struct log_info_cat default_categories[] = {
[DMAIN] = {
.name = "DMAIN",
@ -185,8 +191,8 @@ static int ipc_tx_open_cnf(int rc, uint32_t num_chans, int32_t timingoffset)
chan_info = ipc_prim->u.open_cnf.chan_info;
for (i = 0; i < num_chans; i++) {
snprintf(chan_info->chan_ipc_sk_path, sizeof(chan_info->chan_ipc_sk_path), "%s_%d",
IPC_SOCK_PATH_PREFIX, i);
snprintf(chan_info->chan_ipc_sk_path, sizeof(chan_info->chan_ipc_sk_path),"%s/ipc_sock%d_%d",
cmdline_cfg.ud_prefix_dir, cmdline_cfg.msocknum, i);
/* FIXME: dynamc chan limit, currently 8 */
if (i < 8)
ipc_sock_init(chan_info->chan_ipc_sk_path, &global_ctrl_socks[i], ipc_chan_sock_accept, i);
@ -413,20 +419,20 @@ static void print_help(void)
{
printf("ipc-driver-test Usage:\n"
" -h --help This message\n"
" -u --unix-sk-dir DIR Existing directory where to create the Master socket\n"
" -n --sock-num NR Master socket suffix number NR\n");
}
static int msocknum = 0;
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
const struct option long_options[] = { { "help", 0, 0, 'h' },
{ "unix-sk-dir", 1, 0, 'u' },
{ "sock-num", 1, 0, 'n' },
{ 0, 0, 0, 0 } };
c = getopt_long(argc, argv, "hn:", long_options, &option_index);
c = getopt_long(argc, argv, "hu:n:", long_options, &option_index);
if (c == -1)
break;
@ -435,9 +441,13 @@ static void handle_options(int argc, char **argv)
print_help();
exit(0);
break;
case 'n':
msocknum = atoi(optarg);
case 'u':
cmdline_cfg.ud_prefix_dir = talloc_strdup(tall_ctx, optarg);
break;
case 'n':
cmdline_cfg.msocknum = atoi(optarg);
break;
default:
exit(2);
break;
@ -452,14 +462,19 @@ static void handle_options(int argc, char **argv)
int main(int argc, char **argv)
{
char ipc_msock_path[sizeof(IPC_SOCK_PATH_PREFIX) + 3];
char ipc_msock_path[128];
tall_ctx = talloc_named_const(NULL, 0, "OsmoTRX");
msgb_talloc_ctx_init(tall_ctx, 0);
osmo_init_logging2(tall_ctx, &log_infox);
log_enable_multithread();
handle_options(argc, argv);
snprintf(ipc_msock_path, sizeof(ipc_msock_path), "%s%d", IPC_SOCK_PATH_PREFIX, msocknum);
if (!cmdline_cfg.ud_prefix_dir)
cmdline_cfg.ud_prefix_dir = talloc_strdup(tall_ctx, IPC_SOCK_PATH_PREFIX);
snprintf(ipc_msock_path, sizeof(ipc_msock_path), "%s/ipc_sock%d", cmdline_cfg.ud_prefix_dir, cmdline_cfg.msocknum);
LOGP(DMAIN, LOGL_INFO, "Starting %s\n", argv[0]);
ipc_sock_init(ipc_msock_path, &global_ipc_sock_state, ipc_sock_accept, 0);

View File

@ -79,8 +79,6 @@ struct ipc_shm_region *ipc_shm_decode_region(void *tall_ctx, struct ipc_shm_raw_
//////////////////
// Master socket
//////////////////
#define IPC_SOCK_PATH_PREFIX "/tmp/ipc_sock"
#define IPC_SOCK_API_VERSION 1
/* msg_type */