mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-01-28 01:47:18 +01:00
Fix warnings found when compilling with glibc
This commit is contained in:
parent
1f9a6b0e06
commit
5b52a9c6c3
13 changed files with 43 additions and 68 deletions
|
|
@ -623,7 +623,7 @@ static int bbfdm_operate_handler(struct ubus_context *ctx, struct ubus_object *o
|
|||
struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *tb[__DM_OPERATE_MAX] = {NULL};
|
||||
char path[MAX_DM_PATH] = {0};
|
||||
char path[PATH_MAX] = {0};
|
||||
bbfdm_data_t data;
|
||||
|
||||
memset(&data, 0, sizeof(bbfdm_data_t));
|
||||
|
|
@ -958,7 +958,7 @@ static void service_list(struct blob_buf *bb)
|
|||
blobmsg_add_string(bb, NULL, "list");
|
||||
blobmsg_close_array(bb, array);
|
||||
|
||||
run_cmd(cmd, val, 32);
|
||||
run_cmd(cmd, val, sizeof(val));
|
||||
blobmsg_add_u32(bb, "expected_services_num", atoi(val));
|
||||
array = blobmsg_open_array(bb, "registered_service");
|
||||
get_list_of_registered_service(&head_registered_service, bb);
|
||||
|
|
|
|||
|
|
@ -209,34 +209,6 @@ int get_instance_mode(int instance_mode)
|
|||
return instance_mode;
|
||||
}
|
||||
|
||||
|
||||
int run_cmd(const char *cmd, char *output, size_t out_len)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE *pp;
|
||||
|
||||
if (cmd == NULL)
|
||||
return 0;
|
||||
|
||||
if (output == NULL || out_len == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
memset(output, 0, out_len);
|
||||
|
||||
pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
char line[512] = {0};
|
||||
|
||||
fgets(line, sizeof(line), pp);
|
||||
strncpyt(output, line, out_len);
|
||||
pclose(pp);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// glibc doesn't guarantee a 0 termianted string on strncpy
|
||||
// strncpy with always 0 terminated string
|
||||
void strncpyt(char *dst, const char *src, size_t n)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ int get_instance_mode(int instance_mode);
|
|||
print_warning("[%s:%d] " fmt, __func__, __LINE__, ##args)
|
||||
|
||||
int get_resolved_paths(struct dmctx *bbf_ctx, char *qpath, struct list_head *resolved_paths);
|
||||
int run_cmd(const char *cmd, char *output, size_t out_len);
|
||||
void strncpyt(char *dst, const char *src, size_t n);
|
||||
|
||||
#endif /* COMMON_H */
|
||||
|
|
|
|||
|
|
@ -336,6 +336,32 @@ int dmcmd_no_wait(char *cmd, int n, ...)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int run_cmd(const char *cmd, char *output, size_t out_len)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE *pp;
|
||||
|
||||
if (cmd == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (output == NULL || out_len == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
memset(output, 0, out_len);
|
||||
|
||||
pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
if (!(fgets(output, out_len, pp) == NULL && ferror(pp) != 0)) {
|
||||
ret = 0;
|
||||
}
|
||||
pclose(pp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void hex_to_ip(char *address, char *ret, size_t size)
|
||||
{
|
||||
unsigned int ip[4] = {0};
|
||||
|
|
|
|||
|
|
@ -229,6 +229,7 @@ bool is_strword_in_optionvalue(char *optionvalue, char *str);
|
|||
void remove_new_line(char *buf);
|
||||
int dmcmd(char *cmd, int n, ...);
|
||||
int dmcmd_no_wait(char *cmd, int n, ...);
|
||||
int run_cmd(const char *cmd, char *output, size_t out_len);
|
||||
void hex_to_ip(char *address, char *ret, size_t size);
|
||||
void add_dmmap_config_dup_list(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section);
|
||||
void free_dmmap_config_dup_list(struct list_head *dup_list);
|
||||
|
|
|
|||
|
|
@ -958,4 +958,3 @@ char *ethernet___get_ethernet_interface_name(char *device_name)
|
|||
|
||||
return dev_name;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1852,11 +1852,7 @@ static int operate_IPDiagnostics_TraceRoute(char *refparam, struct dmctx *ctx, v
|
|||
|
||||
snprintf(cmd, sizeof(cmd), "sh %s %s", TRACEROUTE_DIAGNOSTIC_PATH, input);
|
||||
|
||||
FILE *pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
fgets(output, sizeof(output) , pp);
|
||||
pclose(pp);
|
||||
} else {
|
||||
if (run_cmd(cmd, output, sizeof(output)) != 0) {
|
||||
bbfdm_set_fault_message(ctx, "TraceRoute: 'sh %s {input}' command failed to run", TRACEROUTE_DIAGNOSTIC_PATH);
|
||||
return USP_FAULT_COMMAND_FAILURE;
|
||||
}
|
||||
|
|
@ -1990,11 +1986,7 @@ static int operate_IPDiagnostics_DownloadDiagnostics(char *refparam, struct dmct
|
|||
|
||||
snprintf(cmd, sizeof(cmd), "sh %s %s", DOWNLOAD_DIAGNOSTIC_PATH, input);
|
||||
|
||||
FILE *pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
fgets(output, sizeof(output) , pp);
|
||||
pclose(pp);
|
||||
} else {
|
||||
if (run_cmd(cmd, output, sizeof(output)) != 0) {
|
||||
bbfdm_set_fault_message(ctx, "DownloadDiagnostics: 'sh %s {input}' command failed to run", DOWNLOAD_DIAGNOSTIC_PATH);
|
||||
return USP_FAULT_COMMAND_FAILURE;
|
||||
}
|
||||
|
|
@ -2136,11 +2128,7 @@ static int operate_IPDiagnostics_UploadDiagnostics(char *refparam, struct dmctx
|
|||
|
||||
snprintf(cmd, sizeof(cmd), "sh %s %s", UPLOAD_DIAGNOSTIC_PATH, input);
|
||||
|
||||
FILE *pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
fgets(output, sizeof(output) , pp);
|
||||
pclose(pp);
|
||||
} else {
|
||||
if (run_cmd(cmd, output, sizeof(output)) != 0) {
|
||||
bbfdm_set_fault_message(ctx, "UploadDiagnostics: 'sh %s {input}' command failed to run", UPLOAD_DIAGNOSTIC_PATH);
|
||||
return USP_FAULT_COMMAND_FAILURE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1193,7 +1193,9 @@ static int operate_DeviceInfoVendorLogFile_Upload(char *refparam, struct dmctx *
|
|||
vlf_file_path = DEF_VENDOR_LOG_FILE;
|
||||
char cmd[64] = {0};
|
||||
snprintf(cmd, sizeof(cmd), "logread > %s", DEF_VENDOR_LOG_FILE);
|
||||
system(cmd);
|
||||
if (system(cmd) == -1) {
|
||||
return USP_FAULT_COMMAND_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int res = bbf_upload_log(url, user, pass, vlf_file_path, upload_command, upload_path);
|
||||
|
|
|
|||
|
|
@ -117,11 +117,7 @@ int operate_Device_packetCapture(char *refparam, struct dmctx *ctx, void *data,
|
|||
|
||||
snprintf(cmd, sizeof(cmd), "sh %s %s", PACKET_CAPTURE_DIAGNOSTIC_PATH, input);
|
||||
|
||||
FILE *pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
fgets(output, sizeof(output), pp);
|
||||
pclose(pp);
|
||||
} else {
|
||||
if (run_cmd(cmd, output, sizeof(output)) != 0) {
|
||||
bbfdm_set_fault_message(ctx, "PacketCapture: 'sh %s {input}' command failed to run", PACKET_CAPTURE_DIAGNOSTIC_PATH);
|
||||
return USP_FAULT_COMMAND_FAILURE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,13 +59,8 @@ int operate_Device_SelfTest(char *refparam, struct dmctx *ctx, void *data, char
|
|||
|
||||
snprintf(cmd, sizeof(cmd), "sh %s", DIAG_BIN);
|
||||
|
||||
FILE *pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
fgets(output, sizeof(output), pp);
|
||||
pclose(pp);
|
||||
} else {
|
||||
if (run_cmd(cmd, output, sizeof(output)) != 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
// truncate the new line char from end
|
||||
remove_new_line(output);
|
||||
|
|
|
|||
|
|
@ -283,7 +283,9 @@ static void close_active_sessions(struct uci_section *s)
|
|||
continue;
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "kill -15 %s", line);
|
||||
system(cmd);
|
||||
if (system(cmd) == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(pp);
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ static void add_new_host(char **list, char *host)
|
|||
*end = '\0';
|
||||
|
||||
if (*list == NULL) {
|
||||
asprintf(list, "%s", tmp);
|
||||
dmasprintf(list, "%s", tmp);
|
||||
return;
|
||||
} else {
|
||||
prev = dmstrdup(*list);
|
||||
|
|
@ -220,7 +220,7 @@ static void add_new_host(char **list, char *host)
|
|||
*list = NULL;
|
||||
}
|
||||
|
||||
asprintf(list, "%s,%s", prev, tmp);
|
||||
dmasprintf(list, "%s,%s", prev, tmp);
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
|
|
@ -604,7 +604,6 @@ static int get_http_access_hosts(char *refparam, struct dmctx *ctx, void *data,
|
|||
|
||||
if (res) {
|
||||
*value = dmstrdup(res);
|
||||
free(res);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1075,11 +1075,7 @@ int operate_IPDiagnostics_IPLayerCapacity(char *refparam, struct dmctx *ctx, voi
|
|||
|
||||
snprintf(cmd, sizeof(cmd), "sh %s %s", IPLAYER_CAP_DIAGNOSTIC_PATH, input);
|
||||
|
||||
FILE *pp = popen(cmd, "r");
|
||||
if (pp != NULL) {
|
||||
fgets(output, sizeof(output), pp);
|
||||
pclose(pp);
|
||||
} else {
|
||||
if (run_cmd(cmd, output, sizeof(output)) != 0) {
|
||||
bbfdm_set_fault_message(ctx, "IPLayerCapacity: 'sh %s {input}' command failed to run", IPLAYER_CAP_DIAGNOSTIC_PATH);
|
||||
return USP_FAULT_COMMAND_FAILURE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue