char *var;
char *val;
FILE *fp;
+ int ret = -EINVAL;
if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
ErrPrint("Invalid argument\n");
goto out;
}
- if (!strcmp(var, "debug")) {
- if (!strcmp(cmd, "set")) {
- g_conf.debug_mode = !strcmp(val, "true");
- } else if (!strcmp(cmd, "get")) {
+ if (!strcasecmp(var, "debug")) {
+ if (!strcasecmp(cmd, "set")) {
+ g_conf.debug_mode = !strcasecmp(val, "on");
+ } else if (!strcasecmp(cmd, "get")) {
}
+ ret = g_conf.debug_mode;
+ } else if (!strcasecmp(var, "slave_max_load")) {
+ if (!strcasecmp(cmd, "set")) {
+ g_conf.slave_max_load = atoi(val);
+ } else if (!strcasecmp(cmd, "get")) {
+ }
+ ret = g_conf.slave_max_load;
}
liveinfo_open_fifo(info);
liveinfo_close_fifo(info);
goto out;
}
- fprintf(fp, "%d\nEOD\n", g_conf.debug_mode);
+ fprintf(fp, "%d\nEOD\n", ret);
liveinfo_close_fifo(info);
out:
int input_fd;
int verbose;
+
+ int age;
} s_info = {
.fifo_handle = -EINVAL,
.fd = -EINVAL,
.cmd = NOP,
.input_fd = STDIN_FILENO,
.verbose = 0,
+ .age = 0,
};
char *optarg;
free(path);
}
+static void provider_del_cb(struct node *node)
+{
+ struct slave *info;
+
+ info = node_data(node);
+ if (!info)
+ return;
+
+ free(info->pkgname);
+ free(info->abi);
+ free(info->state);
+ free(info);
+}
+
+static void package_del_cb(struct node *node)
+{
+ struct package *info;
+
+ info = node_data(node);
+ if (!info)
+ return;
+
+ free(info->pkgid);
+ free(info->slavename);
+ free(info->abi);
+ free(info);
+}
+
+static void inst_del_cb(struct node *node)
+{
+ struct instance *info;
+
+ info = node_data(node);
+ if (!info)
+ return;
+
+ free(info->id);
+ free(info->cluster);
+ free(info->category);
+ free(info->state);
+ free(info);
+}
+
static inline void ls(void)
{
struct node *node;
int is_package;
int is_provider;
int is_instance;
+ struct node *next_node;
if (!(node_mode(s_info.targetdir) & NODE_READ)) {
printf("Access denied\n");
while (node) {
if (is_package) {
struct package *info;
+
+ next_node = node_next_sibling(node);
+ if (node_age(node) != s_info.age) {
+ node_delete(node, package_del_cb);
+ node = next_node;
+ continue;
+ }
+
info = node_data(node);
printf(" %3d %20s %5s ", info->inst_count, info->slavename ? info->slavename : "-", info->abi ? info->abi : "-");
} else if (is_provider) {
struct slave *info;
+
+ next_node = node_next_sibling(node);
+ if (node_age(node) != s_info.age) {
+ node_delete(node, provider_del_cb);
+ node = next_node;
+ continue;
+ }
+
info = node_data(node);
printf(" %3d %5s %5.2f ", info->loaded_inst, info->abi ? info->abi : "-", info->ttl);
} else if (is_instance) {
struct instance *info;
struct stat stat;
char buf[4096];
+
+ next_node = node_next_sibling(node);
+
+ if (node_age(node) != s_info.age) {
+ node_delete(node, inst_del_cb);
+ node = next_node;
+ continue;
+ }
+
info = node_data(node);
printf(" %5.2f %6s %10s %10s %4dx%-4d ", info->period, info->state, info->cluster, info->category, info->width, info->height);
node = node_next_sibling(node);
cnt++;
}
+
printf("Total: %d\n", cnt);
}
com_core_packet_send_only(s_info.fd, packet);
packet_destroy(packet);
s_info.cmd = SLAVE_LIST;
+ s_info.age++;
+}
+
+/*!
+ * var = debug, slave_max_load
+ * cmd = set / get
+ */
+static void send_command(const char *cmd, const char *var, const char *val)
+{
+ struct packet *packet;
+
+ if (s_info.cmd != NOP) {
+ printf("Previous command is not finished\n");
+ return;
+ }
+
+ packet = packet_create_noack("master_ctrl", "sss", cmd, var, val);
+ com_core_packet_send_only(s_info.fd, packet);
+ packet_destroy(packet);
+ s_info.cmd = MASTER_CTRL;
+ s_info.age++;
}
static void send_pkg_list(void)
com_core_packet_send_only(s_info.fd, packet);
packet_destroy(packet);
s_info.cmd = PKG_LIST;
+ s_info.age++;
}
static void send_inst_delete(void)
packet = packet_create_noack("pkg_ctrl", "sss", "rminst", name, inst->id);
com_core_packet_send_only(s_info.fd, packet);
packet_destroy(packet);
-
s_info.cmd = INST_CTRL;
+ s_info.age++;
}
static void send_inst_list(const char *pkgname)
com_core_packet_send_only(s_info.fd, packet);
packet_destroy(packet);
s_info.cmd = INST_LIST;
+ s_info.age++;
}
static inline void help(void)
printf("\e[32mrm [PKG_ID|INST_ID] - Delete package or instance\e[0m\n");
printf("\e[32mcat [FILE] - Open a file to get some detail information\e[0m\n");
printf("\e[32mpull [FILE] - Pull given file to host dir\e[0m\n");
+ printf("\e[32mset [debug] [on|off] Set the control variable of master provider\e[0m\n");
printf("\e[32mexit - \e[0m\n");
printf("\e[32mquit - \e[0m\n");
printf("----------------------------------------------------------------------------\n");
return;
}
- if (sscanf(cmd, "%255[^ ] %4095s", command, argument) == 2)
+ if (sscanf(cmd, "%255[^ ] %4095[^\\0]", command, argument) == 2)
cmd = command;
if (!strcasecmp(cmd, "exit") || !strcasecmp(cmd, "quit")) {
ecore_main_loop_quit();
+ } else if (!strcasecmp(cmd, "set")) {
+ char variable[4096] = { '0', };
+ char value[4096] = { '0', };
+
+ if (sscanf(argument, "%4095[^ ] %4095[^ ]", variable, value) != 2) {
+ printf("Invalid argument(%s): set [VAR] [VAL]\n", argument);
+ goto out;
+ }
+
+ send_command(cmd, variable, value);
+ } else if (!strcasecmp(cmd, "get")) {
+ send_command(cmd, argument, "");
} else if (!strcasecmp(cmd, "ls")) {
const char *name;
struct node *parent;
pkginfo->abi = NULL;
}
+ node_set_age(node, s_info.age);
+
pkginfo->slavename = strdup(slavename);
if (!pkginfo->slavename)
printf("Error: %s\n", strerror(errno));
} else {
slaveinfo = node_data(node);
}
+
+ node_set_age(node, s_info.age);
+
free(slaveinfo->pkgname);
free(slaveinfo->abi);
free(slaveinfo->state);
instinfo = node_data(node);
}
+ node_set_age(node, s_info.age);
+
free(instinfo->id);
free(instinfo->cluster);
free(instinfo->category);
case INST_CTRL:
sscanf(buffer, "%d", &i);
printf("%s\n", strerror(i));
+ printf("Result: %d\n", i);
break;
case SLAVE_CTRL:
sscanf(buffer, "%d", &i);
+ printf("Result: %d\n", i);
break;
case MASTER_CTRL:
sscanf(buffer, "%d", &i);
+ printf("Result: %d\n", i);
break;
default:
break;
struct node *parent;
unsigned char mode;
+ int age;
struct {
struct node *next;
int errno; /* External symbol */
-char *node_to_abspath(struct node *node)
+char *node_to_abspath(const struct node *node)
{
char *path;
char *ptr;
- struct node *tmp;
+ const struct node *tmp;
int len = 0;
tmp = node;
tmp = node_parent(tmp);
}
- path = malloc(len + 2); /* '/' and '\0' */
+ path = malloc(len + 3); /* '/' and '\0' */
if (!path)
return NULL;
path[0] = '/';
path[1] = '\0';
} else {
- ptr = path + len;
+ ptr = path + len + 1;
*ptr = '\0';
+ ptr--;
+ *ptr = '/';
tmp = node;
while (tmp && node_name(tmp)) {
ptr -= (strlen(node_name(tmp)) + 1);
{
switch ( ch )
{
+ case '\0':
case '/':
return 1;
case '.':
return 4;
}
-static inline void abspath(char* pBuffer, char* pRet)
+static inline void abspath(const char* pBuffer, char* pRet)
{
int idx=0;
int state = 1;
break;
case 2:
if ( state == 1 ) {
- if ( idx > 0 ) idx --;
+ if ( idx > 1 ) idx --;
} else {
pRet[idx] = pBuffer[src_idx];
idx ++;
// Only can go to the 1 or 4
if ( state == 1 ) {
idx -= 2;
- if ( idx < 0 ) idx = 0;
+ if ( idx < 1 ) idx = 1;
- while ( idx > 0 && pRet[idx] != '/' ) idx --;
- if ( idx > 0 && pRet[idx] == '/' ) idx --;
- while ( idx > 0 && pRet[idx] != '/' ) idx --;
+ while ( idx > 1 && pRet[idx] != '/' ) idx --; /* Remove .. */
+ if ( idx > 1 && pRet[idx] == '/' ) idx --;
+ while ( idx > 1 && pRet[idx] != '/' ) idx --; /* Remove parent folder */
}
case 4:
pRet[idx] = pBuffer[src_idx];
}
}
-struct node *node_find(const struct node *node, char *path)
+struct node *node_find(const struct node *node, const char *path)
{
- int len;
+ int len = 0;
char *ptr;
char *buffer;
+ if (*path != '/') {
+ while (node->parent && path[0] == '.' && path[1] == '.') {
+ if (path[2] != '/' && path[2] != '\0')
+ break;
+
+ path += 2;
+ path += (path[2] == '/');
+ node = node->parent;
+ }
+ }
+
buffer = malloc(strlen(path) + 3); /* add 2 more bytes */
- if (!buffer)
+ if (!buffer) {
+ printf("Error: %s\n", strerror(errno));
return NULL;
+ }
abspath(path, buffer);
- ptr = buffer;
+ ptr = buffer;
do {
ptr += (*ptr == '/');
for (len = 0; ptr[len] && ptr[len] != '/'; len++);
}
node = node->child;
- if (!node) {
- free(buffer);
- return NULL;
- }
+ if (!node)
+ break;
while (node) {
if (!strncmp(node->name, ptr, len) && node->name[len] == '\0') {
return node;
}
-void node_destroy(struct node *node)
+void *node_destroy(struct node *node)
{
+ void *data;
+
+ data = node->data;
free(node->name);
free(node);
+
+ return data;
+}
+
+void node_delete(struct node *node, void (del_cb)(struct node *node))
+{
+ struct node *tmp;
+ struct node *next;
+ struct node *parent;
+
+ if (node->sibling.prev)
+ node->sibling.prev->sibling.next = node->sibling.next;
+
+ if (node->sibling.next)
+ node->sibling.next->sibling.prev = node->sibling.prev;
+
+ if (node->parent) {
+ node->parent->child = NULL;
+ node->parent = NULL;
+ }
+
+ tmp = node;
+ while (tmp) {
+ while (tmp->child) tmp = tmp->child;
+
+ parent = tmp->parent;
+ next = tmp->sibling.next;
+
+ if (del_cb)
+ del_cb(tmp);
+
+ node_destroy(tmp);
+
+ if (next)
+ tmp = next;
+ else if (parent)
+ tmp = parent;
+ else
+ tmp = NULL;
+ }
}
struct node * const node_next_sibling(const struct node *node)
return node->name;
}
+void node_set_age(struct node *node, int age)
+{
+ node->age = age;
+}
+
+int node_age(struct node *node)
+{
+ return node->age;
+}
+
/* End of a file */