mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Added number of expected micro-services
This commit is contained in:
parent
bdce9e9f05
commit
2eac512589
3 changed files with 47 additions and 13 deletions
|
|
@ -941,12 +941,16 @@ static const struct blobmsg_policy service_policy[] = {
|
||||||
static void service_list(struct blob_buf *bb)
|
static void service_list(struct blob_buf *bb)
|
||||||
{
|
{
|
||||||
void *array;
|
void *array;
|
||||||
|
char val[32] = {0};
|
||||||
|
char cmd[] = "grep -hsw bbfdm_add_service /etc/init.d/*|wc -l";
|
||||||
|
|
||||||
array = blobmsg_open_array(bb, "supported_cmd");
|
array = blobmsg_open_array(bb, "supported_cmd");
|
||||||
blobmsg_add_string(bb, NULL, "register");
|
blobmsg_add_string(bb, NULL, "register");
|
||||||
blobmsg_add_string(bb, NULL, "list");
|
blobmsg_add_string(bb, NULL, "list");
|
||||||
blobmsg_close_array(bb, array);
|
blobmsg_close_array(bb, array);
|
||||||
|
|
||||||
|
run_cmd(cmd, val, 32);
|
||||||
|
blobmsg_add_u32(bb, "expected_services_num", atoi(val));
|
||||||
array = blobmsg_open_array(bb, "registered_service");
|
array = blobmsg_open_array(bb, "registered_service");
|
||||||
get_list_of_registered_service(&head_registered_service, bb);
|
get_list_of_registered_service(&head_registered_service, bb);
|
||||||
blobmsg_close_array(bb, array);
|
blobmsg_close_array(bb, array);
|
||||||
|
|
|
||||||
|
|
@ -208,3 +208,44 @@ int get_instance_mode(int instance_mode)
|
||||||
|
|
||||||
return 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)
|
||||||
|
{
|
||||||
|
if (dst == NULL || src == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (n > 1) {
|
||||||
|
strncpy(dst, src, n - 1);
|
||||||
|
dst[n - 1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,18 +74,7 @@ int get_instance_mode(int instance_mode);
|
||||||
print_warning("[%s:%d] " fmt, __func__, __LINE__, ##args)
|
print_warning("[%s:%d] " fmt, __func__, __LINE__, ##args)
|
||||||
|
|
||||||
int get_resolved_paths(struct dmctx *bbf_ctx, char *qpath, struct list_head *resolved_paths);
|
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);
|
||||||
// glibc doesn't guarantee a 0 termianted string on strncpy
|
void strncpyt(char *dst, const char *src, size_t n);
|
||||||
// strncpy with always 0 terminated string
|
|
||||||
static inline void strncpyt(char *dst, const char *src, size_t n)
|
|
||||||
{
|
|
||||||
if (dst == NULL || src == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (n > 1) {
|
|
||||||
strncpy(dst, src, n - 1);
|
|
||||||
dst[n - 1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* COMMON_H */
|
#endif /* COMMON_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue