mirror of
https://github.com/linux-msm/qrtr.git
synced 2025-12-24 14:06:30 +01:00
Unify logging into one function
This prepares us to add log-to-syslog functionality by passing all logging through one place. Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
This commit is contained in:
committed by
Bjorn Andersson
parent
516011d79f
commit
f64c25c8af
4
Makefile
4
Makefile
@@ -17,12 +17,14 @@ endif
|
||||
SFLAGS := -I$(shell $(CC) -print-file-name=include) -Wno-non-pointer-null
|
||||
|
||||
$(proj)-cfg-srcs := \
|
||||
lib/logging.c \
|
||||
src/addr.c \
|
||||
src/cfg.c \
|
||||
|
||||
$(proj)-cfg-cflags := -Ilib
|
||||
|
||||
$(proj)-ns-srcs := \
|
||||
lib/logging.c \
|
||||
src/addr.c \
|
||||
src/ns.c \
|
||||
src/map.c \
|
||||
@@ -33,12 +35,14 @@ $(proj)-ns-srcs := \
|
||||
$(proj)-ns-cflags := -Ilib
|
||||
|
||||
$(proj)-lookup-srcs := \
|
||||
lib/logging.c \
|
||||
src/lookup.c \
|
||||
src/util.c \
|
||||
|
||||
$(proj)-lookup-cflags := -Ilib
|
||||
|
||||
lib$(proj).so-srcs := \
|
||||
lib/logging.c \
|
||||
lib/qrtr.c \
|
||||
lib/qmi.c
|
||||
|
||||
|
||||
49
lib/logging.c
Normal file
49
lib/logging.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#define QLOG_BUF_SIZE 512
|
||||
|
||||
static const char default_tag[] = "libqrtr";
|
||||
static const char *current_tag = default_tag;
|
||||
|
||||
void qlog_setup(const char *tag)
|
||||
{
|
||||
current_tag = tag;
|
||||
}
|
||||
|
||||
static const char *get_priority_string(int priority)
|
||||
{
|
||||
switch (priority) {
|
||||
case LOG_EMERG:
|
||||
return "EMERG";
|
||||
case LOG_ALERT:
|
||||
return "ALERT";
|
||||
case LOG_CRIT:
|
||||
return "CRIT";
|
||||
case LOG_ERR:
|
||||
return "ERROR";
|
||||
case LOG_WARNING:
|
||||
return "WARNING";
|
||||
case LOG_NOTICE:
|
||||
return "NOTICE";
|
||||
case LOG_INFO:
|
||||
return "INFO";
|
||||
case LOG_DEBUG:
|
||||
return "DEBUG";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void qlog(int priority, const char *format, ...)
|
||||
{
|
||||
char buf[QLOG_BUF_SIZE];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, QLOG_BUF_SIZE, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
fprintf(stderr, "%s %s: %s\n",
|
||||
get_priority_string(priority), current_tag, buf);
|
||||
}
|
||||
32
lib/logging.h
Normal file
32
lib/logging.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _QRTR_LOGGING_H_
|
||||
#define _QRTR_LOGGING_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define __PRINTF__(fmt, args) __attribute__((format(__printf__, fmt, args)))
|
||||
#else
|
||||
#define __PRINTF__(fmt, args)
|
||||
#endif
|
||||
|
||||
void qlog_setup(const char *tag);
|
||||
|
||||
void qlog(int priority, const char *format, ...) __PRINTF__(2, 3);
|
||||
|
||||
#define LOGW(fmt, ...) qlog(LOG_WARNING, fmt, ##__VA_ARGS__)
|
||||
#define PLOGW(fmt, ...) \
|
||||
qlog(LOG_WARNING, fmt ": %s", ##__VA_ARGS__, strerror(errno))
|
||||
|
||||
#define LOGE(fmt, ...) qlog(LOG_ERR, fmt, ##__VA_ARGS__)
|
||||
#define PLOGE(fmt, ...) qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno))
|
||||
#define LOGE_AND_EXIT(fmt, ...) do { \
|
||||
qlog(LOG_ERR, fmt, ##__VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while(0)
|
||||
#define PLOGE_AND_EXIT(fmt, ...) do { \
|
||||
qlog(LOG_ERR, fmt ": %s", ##__VA_ARGS__, strerror(errno)); \
|
||||
exit(1); \
|
||||
} while(0)
|
||||
|
||||
#endif
|
||||
53
lib/qmi.c
53
lib/qmi.c
@@ -34,6 +34,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "libqrtr.h"
|
||||
#include "logging.h"
|
||||
|
||||
/**
|
||||
* qmi_header - wireformat header of QMI messages
|
||||
@@ -245,7 +246,7 @@ static int qmi_encode_struct_elem(struct qmi_elem_info *ei_array,
|
||||
rc = qmi_encode(temp_ei->ei_array, buf_dst, buf_src,
|
||||
out_buf_len - encoded_bytes, enc_level);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "%s: STRUCT Encode failure\n", __func__);
|
||||
LOGW("%s: STRUCT Encode failure\n", __func__);
|
||||
return rc;
|
||||
}
|
||||
buf_dst = buf_dst + rc;
|
||||
@@ -286,22 +287,22 @@ static int qmi_encode_string_elem(struct qmi_elem_info *ei_array,
|
||||
string_len_sz = temp_ei->elem_len <= 256 ?
|
||||
sizeof(uint8_t) : sizeof(uint16_t);
|
||||
if (string_len > temp_ei->elem_len) {
|
||||
fprintf(stderr, "%s: String to be encoded is longer - %d > %d\n",
|
||||
__func__, string_len, temp_ei->elem_len);
|
||||
LOGW("%s: String to be encoded is longer - %d > %d\n",
|
||||
__func__, string_len, temp_ei->elem_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (enc_level == 1) {
|
||||
if (string_len + TLV_LEN_SIZE + TLV_TYPE_SIZE >
|
||||
out_buf_len) {
|
||||
fprintf(stderr, "%s: Output len %d > Out Buf len %d\n",
|
||||
__func__, string_len, out_buf_len);
|
||||
LOGW("%s: Output len %d > Out Buf len %d\n",
|
||||
__func__, string_len, out_buf_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
} else {
|
||||
if (string_len + string_len_sz > out_buf_len) {
|
||||
fprintf(stderr, "%s: Output len %d > Out Buf len %d\n",
|
||||
__func__, string_len, out_buf_len);
|
||||
LOGW("%s: Output len %d > Out Buf len %d\n",
|
||||
__func__, string_len, out_buf_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
rc = qmi_encode_basic_elem(buf_dst, &string_len,
|
||||
@@ -362,7 +363,7 @@ static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf,
|
||||
data_len_value = temp_ei->elem_len;
|
||||
} else if (data_len_value <= 0 ||
|
||||
temp_ei->elem_len < data_len_value) {
|
||||
fprintf(stderr, "%s: Invalid data length\n", __func__);
|
||||
LOGW("%s: Invalid data length\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -383,7 +384,7 @@ static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf,
|
||||
/* Check to avoid out of range buffer access */
|
||||
if ((data_len_sz + encoded_bytes + TLV_LEN_SIZE +
|
||||
TLV_TYPE_SIZE) > out_buf_len) {
|
||||
fprintf(stderr, "%s: Too Small Buffer @DATA_LEN\n",
|
||||
LOGW("%s: Too Small Buffer @DATA_LEN\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -408,8 +409,8 @@ static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf,
|
||||
if (((data_len_value * temp_ei->elem_size) +
|
||||
encoded_bytes + TLV_LEN_SIZE + TLV_TYPE_SIZE) >
|
||||
out_buf_len) {
|
||||
fprintf(stderr, "%s: Too Small Buffer @data_type:%d\n",
|
||||
__func__, temp_ei->data_type);
|
||||
LOGW("%s: Too Small Buffer @data_type:%d\n",
|
||||
__func__, temp_ei->data_type);
|
||||
return -EINVAL;
|
||||
}
|
||||
rc = qmi_encode_basic_elem(buf_dst, buf_src,
|
||||
@@ -443,7 +444,7 @@ static int qmi_encode(struct qmi_elem_info *ei_array, void *out_buf,
|
||||
encode_tlv, rc);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: Unrecognized data type\n", __func__);
|
||||
LOGW("%s: Unrecognized data type\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -527,9 +528,9 @@ static int qmi_decode_struct_elem(struct qmi_elem_info *ei_array,
|
||||
|
||||
if ((dec_level <= 2 && decoded_bytes != tlv_len) ||
|
||||
(dec_level > 2 && (i < elem_len || decoded_bytes > tlv_len))) {
|
||||
fprintf(stderr, "%s: Fault in decoding: dl(%d), db(%d), tl(%d), i(%d), el(%d)\n",
|
||||
__func__, dec_level, decoded_bytes, tlv_len,
|
||||
i, elem_len);
|
||||
LOGW("%s: Fault in decoding: dl(%d), db(%d), tl(%d), i(%d), el(%d)\n",
|
||||
__func__, dec_level, decoded_bytes, tlv_len,
|
||||
i, elem_len);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
@@ -574,12 +575,12 @@ static int qmi_decode_string_elem(struct qmi_elem_info *ei_array,
|
||||
}
|
||||
|
||||
if (string_len > temp_ei->elem_len) {
|
||||
fprintf(stderr, "%s: String len %d > Max Len %d\n",
|
||||
__func__, string_len, temp_ei->elem_len);
|
||||
LOGW("%s: String len %d > Max Len %d\n",
|
||||
__func__, string_len, temp_ei->elem_len);
|
||||
return -EINVAL;
|
||||
} else if (string_len > tlv_len) {
|
||||
fprintf(stderr, "%s: String len %d > Input Buffer Len %d\n",
|
||||
__func__, string_len, tlv_len);
|
||||
LOGW("%s: String len %d > Input Buffer Len %d\n",
|
||||
__func__, string_len, tlv_len);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
@@ -656,7 +657,7 @@ static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
|
||||
decoded_bytes += (TLV_TYPE_SIZE + TLV_LEN_SIZE);
|
||||
temp_ei = find_ei(ei_array, tlv_type);
|
||||
if (!temp_ei && tlv_type < OPTIONAL_TLV_TYPE_START) {
|
||||
fprintf(stderr, "%s: Inval element info\n", __func__);
|
||||
LOGW("%s: Inval element info\n", __func__);
|
||||
return -EINVAL;
|
||||
} else if (!temp_ei) {
|
||||
UPDATE_DECODE_VARIABLES(buf_src,
|
||||
@@ -695,8 +696,8 @@ static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
|
||||
} else if (temp_ei->array_type == STATIC_ARRAY) {
|
||||
data_len_value = temp_ei->elem_len;
|
||||
} else if (data_len_value > temp_ei->elem_len) {
|
||||
fprintf(stderr, "%s: Data len %d > max spec %d\n",
|
||||
__func__, data_len_value, temp_ei->elem_len);
|
||||
LOGW("%s: Data len %d > max spec %d\n",
|
||||
__func__, data_len_value, temp_ei->elem_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -731,7 +732,7 @@ static int qmi_decode(struct qmi_elem_info *ei_array, void *out_c_struct,
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s: Unrecognized data type\n", __func__);
|
||||
LOGW("%s: Unrecognized data type\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
temp_ei = temp_ei + 1;
|
||||
@@ -763,8 +764,8 @@ ssize_t qmi_encode_message(struct qrtr_packet *pkt, int type, int msg_id,
|
||||
if (!c_struct) {
|
||||
ret = qmi_calc_min_msg_len(ei, 1);
|
||||
if (ret) {
|
||||
fprintf(stderr, "%s: Calc. len %d != 0, but NULL c_struct\n",
|
||||
__func__, ret);
|
||||
LOGW("%s: Calc. len %d != 0, but NULL c_struct\n",
|
||||
__func__, ret);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -796,7 +797,7 @@ int qmi_decode_header(struct qrtr_packet *pkt, unsigned int *msg_id)
|
||||
struct qmi_header *qmi = pkt->data;
|
||||
|
||||
if (qmi->msg_len != pkt->data_len - sizeof(*qmi)) {
|
||||
fprintf(stderr, "[RMTFS] Invalid length of incoming qmi request\n");
|
||||
LOGW("[RMTFS] Invalid length of incoming qmi request\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
19
lib/qrtr.c
19
lib/qrtr.c
@@ -10,12 +10,9 @@
|
||||
#include <poll.h>
|
||||
|
||||
#include "libqrtr.h"
|
||||
#include "logging.h"
|
||||
#include "ns.h"
|
||||
|
||||
#define LOGW(fmt, ...) do { fprintf(stderr, "W|qrtr: " fmt "\n", ##__VA_ARGS__); } while (0)
|
||||
#define LOGE(fmt, ...) do { fprintf(stderr, "E|qrtr: " fmt "\n", ##__VA_ARGS__); } while (0)
|
||||
#define LOGE_errno(fmt, ...) do { fprintf(stderr, "E|qrtr: " fmt ": %s\n", ##__VA_ARGS__, strerror(errno)); } while (0)
|
||||
|
||||
static int qrtr_getname(int sock, struct sockaddr_qrtr *sq)
|
||||
{
|
||||
socklen_t sl = sizeof(*sq);
|
||||
@@ -23,7 +20,7 @@ static int qrtr_getname(int sock, struct sockaddr_qrtr *sq)
|
||||
|
||||
rc = getsockname(sock, (void *)sq, &sl);
|
||||
if (rc) {
|
||||
LOGE_errno("getsockname()");
|
||||
PLOGE("getsockname()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -41,7 +38,7 @@ int qrtr_open(int rport)
|
||||
|
||||
sock = socket(AF_QIPCRTR, SOCK_DGRAM, 0);
|
||||
if (sock < 0) {
|
||||
LOGE_errno("socket(AF_QIPCRTR)");
|
||||
PLOGE("socket(AF_QIPCRTR)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -50,7 +47,7 @@ int qrtr_open(int rport)
|
||||
|
||||
rc = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
if (rc) {
|
||||
LOGE_errno("setsockopt(SO_RCVTIMEO)");
|
||||
PLOGE("setsockopt(SO_RCVTIMEO)");
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -63,7 +60,7 @@ int qrtr_open(int rport)
|
||||
|
||||
rc = bind(sock, (void *)&sq, sizeof(sq));
|
||||
if (rc < 0) {
|
||||
LOGE_errno("bind(%d)", rport);
|
||||
PLOGE("bind(%d)", rport);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@@ -90,7 +87,7 @@ int qrtr_sendto(int sock, uint32_t node, uint32_t port, const void *data, unsign
|
||||
|
||||
rc = sendto(sock, data, sz, 0, (void *)&sq, sizeof(sq));
|
||||
if (rc < 0) {
|
||||
LOGE_errno("sendto()");
|
||||
PLOGE("sendto()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -196,7 +193,7 @@ int qrtr_recv(int sock, void *buf, unsigned int bsz)
|
||||
|
||||
rc = recv(sock, buf, bsz, 0);
|
||||
if (rc < 0)
|
||||
LOGE_errno("recv()");
|
||||
PLOGE("recv()");
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -209,7 +206,7 @@ int qrtr_recvfrom(int sock, void *buf, unsigned int bsz, uint32_t *node, uint32_
|
||||
sl = sizeof(sq);
|
||||
rc = recvfrom(sock, buf, bsz, 0, (void *)&sq, &sl);
|
||||
if (rc < 0) {
|
||||
LOGE_errno("recvfrom()");
|
||||
PLOGE("recvfrom()");
|
||||
return rc;
|
||||
}
|
||||
if (node)
|
||||
|
||||
13
src/addr.c
13
src/addr.c
@@ -10,6 +10,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libqrtr.h"
|
||||
#include "logging.h"
|
||||
|
||||
void qrtr_set_address(uint32_t addr)
|
||||
{
|
||||
@@ -31,11 +32,11 @@ void qrtr_set_address(uint32_t addr)
|
||||
/* Trigger loading of the qrtr kernel module */
|
||||
sock = socket(AF_QIPCRTR, SOCK_DGRAM, 0);
|
||||
if (sock < 0)
|
||||
err(1, "failed to create AF_QIPCRTR socket");
|
||||
PLOGE_AND_EXIT("failed to create AF_QIPCRTR socket");
|
||||
|
||||
ret = getsockname(sock, (void*)&sq, &sl);
|
||||
if (ret < 0)
|
||||
err(1, "getsockname()");
|
||||
PLOGE_AND_EXIT("getsockname()");
|
||||
close(sock);
|
||||
|
||||
/* Skip configuring the address, if it's same as current */
|
||||
@@ -44,7 +45,7 @@ void qrtr_set_address(uint32_t addr)
|
||||
|
||||
sock = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
|
||||
if (sock < 0)
|
||||
err(1, "failed to create netlink socket");
|
||||
PLOGE_AND_EXIT("failed to create netlink socket");
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.nh.nlmsg_len = NLMSG_SPACE(sizeof(struct ifaddrmsg));
|
||||
@@ -61,15 +62,15 @@ void qrtr_set_address(uint32_t addr)
|
||||
|
||||
ret = send(sock, &req, req.nh.nlmsg_len, 0);
|
||||
if (ret < 0)
|
||||
err(1, "failed to send netlink request");
|
||||
PLOGE_AND_EXIT("failed to send netlink request");
|
||||
|
||||
ret = recv(sock, &resp, sizeof(resp), 0);
|
||||
if (ret < 0)
|
||||
err(1, "failed to receive netlink response");
|
||||
PLOGE_AND_EXIT("failed to receive netlink response");
|
||||
|
||||
if (resp.nh.nlmsg_type == NLMSG_ERROR && resp.err.error != 0) {
|
||||
errno = -resp.err.error;
|
||||
err(1, "failed to configure node id");
|
||||
PLOGE_AND_EXIT("failed to configure node id");
|
||||
}
|
||||
|
||||
close(sock);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "addr.h"
|
||||
#include "libqrtr.h"
|
||||
#include "logging.h"
|
||||
|
||||
static void usage(const char *progname)
|
||||
{
|
||||
@@ -28,6 +29,8 @@ int main(int argc, char **argv)
|
||||
char *ep;
|
||||
const char *progname = basename(argv[0]);
|
||||
|
||||
qlog_setup(progname);
|
||||
|
||||
if (argc != 2)
|
||||
usage(progname);
|
||||
|
||||
|
||||
21
src/lookup.c
21
src/lookup.c
@@ -11,6 +11,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libqrtr.h"
|
||||
#include "logging.h"
|
||||
#include "ns.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -106,6 +107,8 @@ int main(int argc, char **argv)
|
||||
int rc;
|
||||
const char *progname = basename(argv[0]);
|
||||
|
||||
qlog_setup(progname);
|
||||
|
||||
rc = 0;
|
||||
memset(&pkt, 0, sizeof(pkt));
|
||||
|
||||
@@ -117,16 +120,18 @@ int main(int argc, char **argv)
|
||||
case 2: pkt.server.service = read_num_le(argv[1], &rc);
|
||||
case 1: break;
|
||||
}
|
||||
if (rc)
|
||||
errx(1, "Usage: %s [<service> [<instance> [<filter>]]]", progname);
|
||||
if (rc) {
|
||||
fprintf(stderr, "Usage: %s [<service> [<instance> [<filter>]]]\n", progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sock = socket(AF_QIPCRTR, SOCK_DGRAM, 0);
|
||||
if (sock < 0)
|
||||
err(1, "sock(AF_QIPCRTR)");
|
||||
PLOGE_AND_EXIT("sock(AF_QIPCRTR)");
|
||||
|
||||
rc = getsockname(sock, (void *)&sq, &sl);
|
||||
if (rc || sq.sq_family != AF_QIPCRTR || sl != sizeof(sq))
|
||||
err(1, "getsockname()");
|
||||
PLOGE_AND_EXIT("getsockname()");
|
||||
|
||||
sq.sq_port = QRTR_PORT_CTRL;
|
||||
|
||||
@@ -137,11 +142,11 @@ int main(int argc, char **argv)
|
||||
|
||||
rc = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
if (rc)
|
||||
err(1, "setsockopt(SO_RCVTIMEO)");
|
||||
PLOGE_AND_EXIT("setsockopt(SO_RCVTIMEO)");
|
||||
|
||||
rc = sendto(sock, &pkt, sizeof(pkt), 0, (void *)&sq, sizeof(sq));
|
||||
if (rc < 0)
|
||||
err(1, "sendto()");
|
||||
PLOGE_AND_EXIT("sendto()");
|
||||
|
||||
printf(" Service Version Instance Node Port\n");
|
||||
|
||||
@@ -151,7 +156,7 @@ int main(int argc, char **argv)
|
||||
unsigned int i;
|
||||
|
||||
if (len < sizeof(pkt) || type != QRTR_TYPE_NEW_SERVER) {
|
||||
warn("invalid/short packet");
|
||||
PLOGW("invalid/short packet");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -184,7 +189,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (len < 0)
|
||||
err(1, "recv()");
|
||||
PLOGE_AND_EXIT("recv()");
|
||||
|
||||
close(sock);
|
||||
|
||||
|
||||
17
src/ns.c
17
src/ns.c
@@ -23,6 +23,7 @@
|
||||
#include "waiter.h"
|
||||
|
||||
#include "libqrtr.h"
|
||||
#include "logging.h"
|
||||
|
||||
static const char *ctrl_pkt_strings[] = {
|
||||
[QRTR_TYPE_HELLO] = "hello",
|
||||
@@ -103,7 +104,7 @@ static struct node *node_get(unsigned int node_id)
|
||||
|
||||
rc = map_create(&node->services);
|
||||
if (rc)
|
||||
errx(1, "unable to create map");
|
||||
LOGE_AND_EXIT("unable to create map");
|
||||
|
||||
rc = map_put(&nodes, hash_u32(node_id), &node->mi);
|
||||
if (rc) {
|
||||
@@ -704,6 +705,8 @@ int main(int argc, char **argv)
|
||||
int rc;
|
||||
const char *progname = basename(argv[0]);
|
||||
|
||||
qlog_setup(progname);
|
||||
|
||||
while ((opt = getopt(argc, argv, "f")) != -1) {
|
||||
switch (opt) {
|
||||
case 'f':
|
||||
@@ -728,27 +731,27 @@ int main(int argc, char **argv)
|
||||
|
||||
w = waiter_create();
|
||||
if (w == NULL)
|
||||
errx(1, "unable to create waiter");
|
||||
LOGE_AND_EXIT("unable to create waiter");
|
||||
|
||||
list_init(&ctx.lookups);
|
||||
|
||||
rc = map_create(&nodes);
|
||||
if (rc)
|
||||
errx(1, "unable to create node map");
|
||||
LOGE_AND_EXIT("unable to create node map");
|
||||
|
||||
ctx.sock = socket(AF_QIPCRTR, SOCK_DGRAM, 0);
|
||||
if (ctx.sock < 0)
|
||||
err(1, "unable to create control socket");
|
||||
PLOGE_AND_EXIT("unable to create control socket");
|
||||
|
||||
rc = getsockname(ctx.sock, (void*)&sq, &sl);
|
||||
if (rc < 0)
|
||||
err(1, "getsockname()");
|
||||
PLOGE_AND_EXIT("getsockname()");
|
||||
sq.sq_port = QRTR_PORT_CTRL;
|
||||
ctx.local_node = sq.sq_node;
|
||||
|
||||
rc = bind(ctx.sock, (void *)&sq, sizeof(sq));
|
||||
if (rc < 0)
|
||||
err(1, "bind control socket");
|
||||
PLOGE_AND_EXIT("bind control socket");
|
||||
|
||||
ctx.bcast_sq.sq_family = AF_QIPCRTR;
|
||||
ctx.bcast_sq.sq_node = QRTR_NODE_BCAST;
|
||||
@@ -756,7 +759,7 @@ int main(int argc, char **argv)
|
||||
|
||||
rc = say_hello(&ctx);
|
||||
if (rc)
|
||||
err(1, "unable to say hello");
|
||||
PLOGE_AND_EXIT("unable to say hello");
|
||||
|
||||
/* If we're going to background, fork and exit parent */
|
||||
if (!foreground && fork() != 0) {
|
||||
|
||||
Reference in New Issue
Block a user