2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <sys/types.h>
28 #include <glib-object.h>
31 #include <com-core_packet.h>
34 #include <livebox-service.h>
41 #define PROMPT "liveinfo "
91 Ecore_Fd_Handler *fd_handler;
92 Ecore_Fd_Handler *in_handler;
96 struct node *targetdir;
105 .fifo_handle = -EINVAL,
113 .input_fd = STDIN_FILENO,
124 static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler);
126 static Eina_Bool process_line_cb(void *data)
128 input_cb(NULL, NULL);
129 return ECORE_CALLBACK_CANCEL;
132 static inline void prompt(const char *cmdline)
136 if (s_info.input_fd != STDIN_FILENO) {
137 /* To prevent recursive call, add function to the main loop (idler) */
138 ecore_idler_add(process_line_cb, NULL);
142 path = node_to_abspath(s_info.curdir);
143 printf(PROMPT"%s # %s", path, cmdline ? cmdline : "");
147 static void provider_del_cb(struct node *node)
151 info = node_data(node);
161 static void package_del_cb(struct node *node)
163 struct package *info;
165 info = node_data(node);
170 free(info->slavename);
175 static void inst_del_cb(struct node *node)
177 struct instance *info;
179 info = node_data(node);
185 free(info->category);
190 static inline void ls(void)
197 struct node *next_node;
199 if (!(node_mode(s_info.targetdir) & NODE_READ)) {
200 printf("Access denied\n");
204 is_package = node_name(s_info.targetdir) && !strcmp(node_name(s_info.targetdir), "package");
205 is_provider = !is_package && node_name(s_info.targetdir) && !strcmp(node_name(s_info.targetdir), "provider");
206 is_instance = !is_package && !is_provider && node_parent(s_info.targetdir) && node_name(node_parent(s_info.targetdir)) && !strcmp(node_name(node_parent(s_info.targetdir)), "package");
208 node = node_child(s_info.targetdir);
211 struct package *info;
213 next_node = node_next_sibling(node);
214 if (node_age(node) != s_info.age) {
215 node_delete(node, package_del_cb);
220 info = node_data(node);
221 printf(" %3d %20s %5s ", info->inst_count, info->slavename ? info->slavename : "(none)", info->abi ? info->abi : "?");
222 } else if (is_provider) {
225 next_node = node_next_sibling(node);
226 if (node_age(node) != s_info.age) {
227 node_delete(node, provider_del_cb);
232 info = node_data(node);
233 printf(" %3d %5s %5.2f ", info->loaded_inst, info->abi ? info->abi : "?", info->ttl);
234 } else if (is_instance) {
235 struct instance *info;
239 next_node = node_next_sibling(node);
241 if (node_age(node) != s_info.age) {
242 node_delete(node, inst_del_cb);
247 info = node_data(node);
249 printf(" %5.2f %6s %10s %10s %4dx%-4d ", info->period, info->state, info->cluster, info->category, info->width, info->height);
250 snprintf(buf, sizeof(buf), "/opt/usr/share/live_magazine/reader/%s", node_name(node));
251 if (lstat(buf, &stat) < 0)
252 printf("%3d ERR ", errno);
254 printf("%2.2lf KB ", (double)stat.st_size / 1024.0f);
257 if (node_type(node) == NODE_DIR)
258 printf("%s/", node_name(node));
259 else if (node_type(node) == NODE_FILE)
260 printf("%s", node_name(node));
263 node = node_next_sibling(node);
267 printf("Total: %d\n", cnt);
270 static void send_slave_list(void)
272 struct packet *packet;
274 if (s_info.cmd != NOP) {
275 printf("Previous command is not finished\n");
279 packet = packet_create_noack("slave_list", "d", 0.0f);
281 printf("Failed to create a packet\n");
285 com_core_packet_send_only(s_info.fd, packet);
286 packet_destroy(packet);
287 s_info.cmd = SLAVE_LIST;
292 * var = debug, slave_max_load
295 static void send_command(const char *cmd, const char *var, const char *val)
297 struct packet *packet;
299 if (s_info.cmd != NOP) {
300 printf("Previous command is not finished\n");
304 packet = packet_create_noack("master_ctrl", "sss", cmd, var, val);
305 com_core_packet_send_only(s_info.fd, packet);
306 packet_destroy(packet);
307 s_info.cmd = MASTER_CTRL;
311 static int pkglist_cb(const char *appid, const char *lbid, int is_prime, void *data)
313 struct node *parent = data;
315 struct package *info;
317 node = node_find(parent, lbid);
319 info = node_data(node);
321 printf("Invalid node\n");
326 info->pkgid = strdup(appid);
328 printf("Error: %s\n", strerror(errno));
332 node_set_age(node, s_info.age);
336 info = calloc(1, sizeof(*info));
338 printf("Error: %s\n", strerror(errno));
342 info->pkgid = strdup(appid);
344 printf("Error: %s\n", strerror(errno));
349 info->primary = is_prime;
351 node = node_create(parent, lbid, NODE_DIR);
358 node_set_mode(node, NODE_READ | NODE_EXEC);
359 node_set_data(node, info);
360 node_set_age(node, s_info.age);
364 static void send_pkg_list(void)
366 struct packet *packet;
368 if (s_info.cmd != NOP) {
369 printf("Previous command is not finished\n");
373 packet = packet_create_noack("pkg_list", "d", 0.0f);
375 printf("Failed to create a packet\n");
379 com_core_packet_send_only(s_info.fd, packet);
380 packet_destroy(packet);
381 s_info.cmd = PKG_LIST;
384 livebox_service_get_pkglist(pkglist_cb, s_info.targetdir);
387 static void send_inst_delete(void)
389 struct packet *packet;
392 struct instance *inst;
394 if (s_info.cmd != NOP) {
395 printf("Previous command is not finished\n");
399 parent = node_parent(s_info.targetdir);
401 printf("Invalid argument\n");
405 if (!node_parent(parent)) {
406 printf("Invalid argument\n");
410 name = node_name(node_parent(parent));
411 if (!name || strcmp(name, "package")) {
412 printf("Invalid argument\n");
416 inst = node_data(s_info.targetdir);
417 name = node_name(parent);
419 packet = packet_create_noack("pkg_ctrl", "sss", "rminst", name, inst->id);
420 com_core_packet_send_only(s_info.fd, packet);
421 packet_destroy(packet);
422 s_info.cmd = INST_CTRL;
426 static void send_inst_list(const char *pkgname)
428 struct packet *packet;
430 if (s_info.cmd != NOP) {
431 printf("Previous command is not finished\n");
435 packet = packet_create_noack("inst_list", "s", pkgname);
437 printf("Failed to create a packet\n");
441 com_core_packet_send_only(s_info.fd, packet);
442 packet_destroy(packet);
443 s_info.cmd = INST_LIST;
447 static inline void help(void)
449 printf("liveinfo - Livebox utility\n");
450 printf("------------------------------ [Command list] ------------------------------\n");
451 printf("
\e[32mcd [PATH] - Change directory
\e[0m\n");
452 printf("
\e[32mls [ | PATH] - List up content as a file
\e[0m\n");
453 printf("
\e[32mrm [PKG_ID|INST_ID] - Delete package or instance
\e[0m\n");
454 printf("
\e[32mcat [FILE] - Open a file to get some detail information
\e[0m\n");
455 printf("
\e[32mpull [FILE] - Pull given file to host dir
\e[0m\n");
456 printf("
\e[32mset [debug] [on|off] Set the control variable of master provider
\e[0m\n");
457 printf("
\e[32mexit -
\e[0m\n");
458 printf("
\e[32mquit -
\e[0m\n");
459 printf("----------------------------------------------------------------------------\n");
462 static inline void init_directory(void)
465 s_info.rootdir = node_create(NULL, NULL, NODE_DIR);
468 node_set_mode(s_info.rootdir, NODE_READ | NODE_EXEC);
470 node = node_create(s_info.rootdir, "provider", NODE_DIR);
472 node_destroy(s_info.rootdir);
473 s_info.rootdir = NULL;
476 node_set_mode(node, NODE_READ | NODE_EXEC);
478 node = node_create(s_info.rootdir, "package", NODE_DIR);
480 node_destroy(node_child(s_info.rootdir));
481 node_destroy(s_info.rootdir);
482 s_info.rootdir = NULL;
485 node_set_mode(node, NODE_READ | NODE_EXEC);
487 s_info.curdir = s_info.rootdir;
491 static inline void fini_directory(void)
495 static inline void do_command(const char *cmd)
498 char argument[4096] = { '\0', };
500 if (!strlen(cmd) || *cmd == '#') {
505 if (sscanf(cmd, "%255[^ ] %s", command, argument) == 2)
508 if (!strcasecmp(cmd, "exit") || !strcasecmp(cmd, "quit")) {
509 ecore_main_loop_quit();
510 } else if (!strcasecmp(cmd, "set")) {
511 char variable[4096] = { '0', };
512 char value[4096] = { '0', };
514 if (sscanf(argument, "%4095[^ ] %s", variable, value) != 2) {
515 printf("Invalid argument(%s): set [VAR] [VAL]\n", argument);
519 send_command(cmd, variable, value);
520 } else if (!strcasecmp(cmd, "get")) {
521 send_command(cmd, argument, "");
522 } else if (!strcasecmp(cmd, "ls")) {
527 s_info.targetdir = (*argument == '/') ? s_info.rootdir : s_info.curdir;
528 s_info.targetdir = node_find(s_info.targetdir, argument);
530 s_info.targetdir = s_info.curdir;
533 if (!s_info.targetdir) {
534 printf("%s is not exists\n", argument);
538 name = node_name(s_info.targetdir);
540 if (!strcmp(name, "package")) {
541 if (s_info.cmd == NOP) {
546 printf("Waiting the server response\n");
548 } else if (!strcmp(name, "provider")) {
549 if (s_info.cmd == NOP) {
554 printf("Waiting the server response\n");
559 parent = node_parent(s_info.targetdir);
560 if (parent && node_name(parent)) {
561 if (!strcmp(node_name(parent), "package")) {
562 if (s_info.cmd != NOP) {
563 printf("Waiting the server response\n");
566 send_inst_list(name);
572 } else if (!strcasecmp(cmd, "cd")) {
576 if (s_info.cmd != NOP) {
577 printf("Waiting the server response\n");
581 s_info.targetdir = (*argument == '/') ? s_info.rootdir : s_info.curdir;
582 s_info.targetdir = node_find(s_info.targetdir, argument);
583 if (!s_info.targetdir) {
584 printf("%s is not exists\n", argument);
588 if (node_type(s_info.targetdir) != NODE_DIR) {
589 printf("Unable change directory to %s\n", argument);
593 if (!(node_mode(s_info.targetdir) & NODE_EXEC)) {
594 printf("Access denied %s\n", argument);
598 s_info.curdir = s_info.targetdir;
599 } else if (!strcasecmp(cmd, "rm")) {
603 if (s_info.cmd != NOP) {
604 printf("Waiting the server response\n");
608 s_info.targetdir = (*argument == '/') ? s_info.rootdir : s_info.curdir;
609 s_info.targetdir = node_find(s_info.targetdir, argument);
610 if (!s_info.targetdir) {
611 printf("%s is not exists\n", argument);
615 if (!(node_mode(s_info.targetdir) & NODE_WRITE)) {
616 printf("Access denied %s\n", argument);
621 } else if (!strcasecmp(cmd, "help")) {
624 printf("Unknown command - \"help\"\n");
632 static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
635 static char cmd_buffer[256];
641 fd = ecore_main_fd_handler_fd_get(fd_handler);
643 printf("FD is not valid: %d\n", fd);
644 return ECORE_CALLBACK_CANCEL;
647 fd = s_info.input_fd;
652 * Using this routine, we can implement the command recommend algorithm.
653 * When a few more characters are matched with history of command, we can show it to user
654 * Then the user will choose one or write new command
658 while ((ret = read(fd, &ch, sizeof(ch))) == sizeof(ch)) {
660 case 0x08: /* BKSP */
661 cmd_buffer[idx] = '\0';
664 cmd_buffer[idx] = ' ';
669 cmd_buffer[idx] = '\0';
675 cmd_buffer[idx] = '\0';
677 if (s_info.input_fd == STDIN_FILENO || s_info.verbose)
678 putc((int)'\n', stdout);
679 do_command(cmd_buffer);
680 memset(cmd_buffer, 0, sizeof(cmd_buffer));
682 /* Make a main loop processing for command handling */
683 return ECORE_CALLBACK_RENEW;
685 cmd_buffer[idx++] = ch;
687 if (s_info.input_fd == STDIN_FILENO || s_info.verbose)
688 putc((int)ch, stdout);
690 if (idx == sizeof(cmd_buffer) - 1) {
691 cmd_buffer[idx] = '\0';
692 printf("\nCommand buffer is overflow: %s\n", cmd_buffer);
699 if (ret < 0 && !fd_handler)
700 ecore_main_loop_quit();
702 return ECORE_CALLBACK_RENEW;
705 static void processing_line_buffer(const char *buffer)
726 struct package *pkginfo;
727 struct instance *instinfo;
728 struct slave *slaveinfo;
731 switch (s_info.cmd) {
733 if (sscanf(buffer, "%d %255[^ ] %255[^ ] %255[^ ] %d %d %d", &pid, slavename, pkgname, abi, &refcnt, &fault_count, &list_count) != 7) {
734 printf("Invalid format : [%s]\n", buffer);
738 node = node_find(s_info.targetdir, pkgname);
740 pkginfo = calloc(1, sizeof(*pkginfo));
742 printf("Error: %s\n", strerror(errno));
746 pkginfo->pkgid = strdup("conf.file");
748 printf("Error: %s\n", strerror(errno));
750 pkginfo->primary = 1;
752 node = node_create(s_info.targetdir, pkgname, NODE_DIR);
754 free(pkginfo->pkgid);
756 printf("Failed to create a new node (%s)\n", pkgname);
760 node_set_mode(node, NODE_READ | NODE_EXEC);
761 node_set_data(node, pkginfo);
763 pkginfo = node_data(node);
765 printf("Package info is inavlid\n");
769 free(pkginfo->slavename);
772 pkginfo->slavename = NULL;
776 node_set_age(node, s_info.age);
778 pkginfo->slavename = strdup(slavename);
779 if (!pkginfo->slavename)
780 printf("Error: %s\n", strerror(errno));
782 pkginfo->abi = strdup(abi);
784 printf("Error: %s\n", strerror(errno));
787 pkginfo->refcnt = refcnt;
788 pkginfo->fault_count = fault_count;
789 pkginfo->inst_count = list_count;
792 if (sscanf(buffer, "%d %[^ ] %[^ ] %[^ ] %d %d %d %[^ ] %d %d %lf", &pid, slavename, pkgname, abi, &secured, &refcnt, &fault_count, state, &loaded_inst, &loaded_pkg, &ttl) != 11) {
793 printf("Invalid format : [%s]\n", buffer);
796 node = node_find(s_info.targetdir, slavename);
798 slaveinfo = calloc(1, sizeof(*slaveinfo));
800 printf("Error: %s\n", strerror(errno));
804 node = node_create(s_info.targetdir, slavename, NODE_DIR);
810 node_set_mode(node, NODE_READ | NODE_EXEC);
811 node_set_data(node, slaveinfo);
813 slaveinfo = node_data(node);
816 node_set_age(node, s_info.age);
818 free(slaveinfo->pkgname);
819 free(slaveinfo->abi);
820 free(slaveinfo->state);
822 slaveinfo->pkgname = strdup(pkgname);
823 if (!slaveinfo->pkgname)
824 printf("Error: %s\n", strerror(errno));
826 slaveinfo->abi = strdup(abi);
828 printf("Error: %s\n", strerror(errno));
830 slaveinfo->state = strdup(state);
831 if (!slaveinfo->state)
832 printf("Error: %s\n", strerror(errno));
834 slaveinfo->pid = pid;
835 slaveinfo->secured = secured;
836 slaveinfo->refcnt = refcnt;
837 slaveinfo->fault_count = fault_count;
838 slaveinfo->loaded_inst = loaded_inst;
839 slaveinfo->loaded_pkg = loaded_pkg;
840 slaveinfo->ttl = ttl;
843 if (sscanf(buffer, "%[^ ] %[^ ] %[^ ] %lf %[^ ] %d %d", inst_id, cluster, category, &period, state, &width, &height) != 7) {
844 printf("Invalid format : [%s]\n", buffer);
848 for (i = strlen(inst_id); i > 0 && inst_id[i] != '/'; i--);
849 i += (inst_id[i] == '/');
851 node = node_find(s_info.targetdir, inst_id + i);
853 instinfo = calloc(1, sizeof(*instinfo));
855 printf("Error: %s\n", strerror(errno));
859 node = node_create(s_info.targetdir, inst_id + i, NODE_FILE);
865 node_set_mode(node, NODE_READ | NODE_WRITE);
866 node_set_data(node, instinfo);
868 instinfo = node_data(node);
871 node_set_age(node, s_info.age);
874 free(instinfo->cluster);
875 free(instinfo->category);
876 free(instinfo->state);
878 instinfo->id = strdup(inst_id);
880 printf("Error: %s\n", strerror(errno));
882 instinfo->cluster = strdup(cluster);
883 if (!instinfo->cluster)
884 printf("Error: %s\n", strerror(errno));
886 instinfo->category = strdup(category);
887 if (!instinfo->category)
888 printf("Error: %s\n", strerror(errno));
890 instinfo->state = strdup(state);
891 if (!instinfo->state)
892 printf("Error: %s\n", strerror(errno));
894 instinfo->period = period;
895 instinfo->width = width;
896 instinfo->height = height;
899 sscanf(buffer, "%d", &i);
900 printf("%s\n", strerror(i));
901 printf("Result: %d\n", i);
904 sscanf(buffer, "%d", &i);
905 printf("Result: %d\n", i);
908 sscanf(buffer, "%d", &i);
909 printf("Result: %d\n", i);
916 static inline void do_line_command(void)
918 switch (s_info.cmd) {
940 static Eina_Bool read_cb(void *data, Ecore_Fd_Handler *fd_handler)
943 static char *line_buffer = NULL;
944 static int line_index = 0;
945 static int bufsz = 256;
948 fd = ecore_main_fd_handler_fd_get(fd_handler);
950 printf("FD is not valid: %d\n", fd);
951 return ECORE_CALLBACK_CANCEL;
954 if (read(fd, &ch, sizeof(ch)) != sizeof(ch)) {
955 printf("Error: %s\n", strerror(errno));
956 return ECORE_CALLBACK_CANCEL;
961 line_buffer = malloc(bufsz);
963 printf("Error: %s\n", strerror(errno));
964 return ECORE_CALLBACK_CANCEL;
968 if (ch == '\n') { /* End of a line */
969 if (line_index == bufsz - 1) {
971 new_buf = realloc(line_buffer, bufsz + 2);
973 printf("Error: %s\n", strerror(errno));
978 return ECORE_CALLBACK_CANCEL;
981 line_buffer = new_buf;
984 line_buffer[line_index] = '\0';
986 if (!strcmp(line_buffer, "EOD")) {
990 processing_line_buffer(line_buffer);
1000 line_buffer[line_index++] = ch;
1001 if (line_index == bufsz - 1) {
1003 new_buf = realloc(line_buffer, bufsz);
1005 printf("Error: %s\n", strerror(errno));
1010 return ECORE_CALLBACK_CANCEL;
1013 line_buffer = new_buf;
1017 return ECORE_CALLBACK_RENEW;
1020 static int ret_cb(pid_t pid, int handle, const struct packet *packet, void *data)
1022 const char *fifo_name;
1025 if (packet_get(packet, "si", &fifo_name, &ret) != 2) {
1026 printf("Invalid packet\n");
1031 printf("Returns %d\n", ret);
1035 printf("FIFO: %s\n", fifo_name);
1037 s_info.fifo_handle = open(fifo_name, O_RDONLY | O_NONBLOCK);
1038 if (s_info.fifo_handle < 0) {
1039 printf("Error: %s\n", strerror(errno));
1040 s_info.fifo_handle = -EINVAL;
1041 ecore_main_loop_quit();
1045 s_info.fd_handler = ecore_main_fd_handler_add(s_info.fifo_handle, ECORE_FD_READ, read_cb, NULL, NULL, NULL);
1046 if (!s_info.fd_handler) {
1047 printf("Failed to add a fd handler\n");
1048 close(s_info.fifo_handle);
1049 s_info.fifo_handle = -EINVAL;
1050 ecore_main_loop_quit();
1056 if (s_info.input_fd == STDIN_FILENO) {
1057 if (fcntl(s_info.input_fd, F_SETFL, O_NONBLOCK) < 0)
1058 printf("Error: %s\n", strerror(errno));
1060 s_info.in_handler = ecore_main_fd_handler_add(s_info.input_fd, ECORE_FD_READ, input_cb, NULL, NULL, NULL);
1061 if (!s_info.in_handler) {
1062 printf("Failed to add a input handler\n");
1063 ecore_main_loop_quit();
1071 static int disconnected_cb(int handle, void *data)
1073 printf("Disconnected\n");
1074 ecore_main_loop_quit();
1078 static int connected_cb(int handle, void *data)
1080 struct packet *packet;
1082 printf("Connected\n");
1084 packet = packet_create("liveinfo_hello", "d", 0.0f);
1086 printf("Failed to build a packet for hello\n");
1087 com_core_packet_client_fini(s_info.fd);
1088 s_info.fd = -EINVAL;
1094 if (com_core_packet_async_send(s_info.fd, packet, 0.0f, ret_cb, NULL) < 0) {
1095 printf("Failed to send a packet hello\n");
1096 packet_destroy(packet);
1097 com_core_packet_client_fini(s_info.fd);
1098 s_info.fd = -EINVAL;
1102 packet_destroy(packet);
1106 int main(int argc, char *argv[])
1108 struct termios ttystate;
1109 static struct method s_table[] = {
1115 static struct option long_options[] = {
1116 { "batchmode", required_argument, 0, 'b' },
1117 { "help", no_argument, 0, 'h' },
1118 { "verbose", required_argument, 0, 'v' },
1125 c = getopt_long(argc, argv, "b:hv:", long_options, &option_index);
1128 if (!optarg || !*optarg) {
1129 printf("Invalid argument\n");
1134 if (s_info.input_fd != STDIN_FILENO) {
1135 /* Close the previously, opened file */
1136 close(s_info.input_fd);
1139 s_info.input_fd = open(optarg, O_RDONLY);
1140 if (s_info.input_fd < 0) {
1141 printf("Unable to access %s (%s)\n", optarg, strerror(errno));
1149 if (!optarg || !*optarg) {
1150 printf("Invalid argument\n");
1155 s_info.verbose = !strcmp(optarg, "true");
1165 com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1166 com_core_add_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL);
1167 livebox_service_init();
1169 s_info.fd = com_core_packet_client_init(SOCKET_FILE, 0, s_table);
1170 if (s_info.fd < 0) {
1171 printf("Failed to make a connection\n");
1175 if (s_info.input_fd == STDIN_FILENO) {
1176 printf("Type your command on below empty line\n");
1178 if (tcgetattr(s_info.input_fd, &ttystate) < 0) {
1179 printf("Error: %s\n", strerror(errno));
1181 ttystate.c_lflag &= ~(ICANON | ECHO);
1182 ttystate.c_cc[VMIN] = 1;
1184 if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0)
1185 printf("Error: %s\n", strerror(errno));
1188 printf("Batch mode enabled\n");
1191 if (setvbuf(stdout, (char *)NULL, _IONBF, 0) != 0)
1192 printf("Error: %s\n", strerror(errno));
1196 ecore_main_loop_begin();
1199 livebox_service_fini();
1201 if (s_info.fd > 0) {
1202 com_core_packet_client_fini(s_info.fd);
1203 s_info.fd = -EINVAL;
1206 if (s_info.fd_handler) {
1207 ecore_main_fd_handler_del(s_info.fd_handler);
1208 s_info.fd_handler = NULL;
1211 if (s_info.input_fd == STDIN_FILENO) {
1212 ttystate.c_lflag |= ICANON | ECHO;
1213 if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0)
1214 printf("Error: %s\n", strerror(errno));
1216 close(s_info.input_fd);
1219 if (s_info.fifo_handle > 0) {
1220 close(s_info.fifo_handle);
1221 s_info.fifo_handle = -EINVAL;
1224 if (s_info.in_handler) {
1225 ecore_main_fd_handler_del(s_info.in_handler);
1226 s_info.in_handler = NULL;
1230 putc((int)'\n', stdout);