int main(){ p0 = (proc*)malloc(sizeof(proc)); p1 = (proc*)malloc(sizeof(proc)); p0->next = p1; p0->prev = NULL; p1->next = NULL; p1->prev = p0; int recv = fork(); if(recv < 0){ printf("Failed to fork\n"); exit(-1); }else if(recv == 0){ cons_connect(); console_loop(); }else{ printf("I'm parent!!\n"); while(1){ print_items(); sleep(5); } } return 0; }
void console_start(void) { console_loop(); }
int main(int argc,char *argv[]) { Allinit(); S_BOARD pos[1]; S_SEARCHINFO info[1]; info->quit = FALSE; info->depth = SETDEPTH; pos->hashtable->ptable=NULL; inithashtable(pos->hashtable,64); setbuf(stdin,NULL); setbuf(stdout,NULL); int argnum =0; for(argnum = 0; argnum < argc; argnum++) { if(strncmp(argv[argnum],"NoBook",6)==0) { engineoptions->usebook = FALSE; printf("Book Off\n"); } } printf("Welcome to abhi_engine! type cons for console mode ...\n"); char line[256]; while(TRUE) { memset(line,0,sizeof(line)); fflush(stdout); if(!fgets(line,256,stdin)) continue; if(line[0]=='\n') continue; if(!strncmp(line,"uci",3)) { uci_loop(pos,info); if(info->quit == TRUE) break; continue; } else if(!strncmp(line,"xboard",6)) { xboard_loop(pos,info); if(info->quit == TRUE) break; continue; } else if(!strncmp(line,"cons",4)) { console_loop(pos,info); if(info->quit == TRUE) break; continue; } else if(!strncmp(line,"quit",4)) break; } free(pos->hashtable->ptable); cleanpolybook(); return 0; }
int main(int argc, char **argv) { struct termios attr; int domid; char *sopt = "hn:"; int ch; unsigned int num = 0; int opt_ind=0; struct option lopt[] = { { "type", 1, 0, 't' }, { "num", 1, 0, 'n' }, { "help", 0, 0, 'h' }, { 0 }, }; char *dom_path = NULL, *path = NULL; int spty, xsfd; struct xs_handle *xs; char *end; console_type type = CONSOLE_INVAL; while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch(ch) { case 'h': usage(argv[0]); exit(0); break; case 'n': num = atoi(optarg); break; case 't': if (!strcmp(optarg, "serial")) type = CONSOLE_SERIAL; else if (!strcmp(optarg, "pv")) type = CONSOLE_PV; else { fprintf(stderr, "Invalid type argument\n"); fprintf(stderr, "Console types supported are: serial, pv\n"); exit(EINVAL); } break; default: fprintf(stderr, "Invalid argument\n"); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } } if (optind >= argc) { fprintf(stderr, "DOMID should be specified\n"); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } domid = strtol(argv[optind], &end, 10); if (end && *end) { fprintf(stderr, "Invalid DOMID `%s'\n", argv[optind]); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } xs = xs_daemon_open(); if (xs == NULL) { err(errno, "Could not contact XenStore"); } signal(SIGTERM, sighandler); dom_path = xs_get_domain_path(xs, domid); if (dom_path == NULL) err(errno, "xs_get_domain_path()"); if (type == CONSOLE_INVAL) { xc_dominfo_t xcinfo; xc_interface *xc_handle = xc_interface_open(0,0,0); if (xc_handle == NULL) err(errno, "Could not open xc interface"); xc_domain_getinfo(xc_handle, domid, 1, &xcinfo); /* default to pv console for pv guests and serial for hvm guests */ if (xcinfo.hvm) type = CONSOLE_SERIAL; else type = CONSOLE_PV; xc_interface_close(xc_handle); } path = malloc(strlen(dom_path) + strlen("/device/console/0/tty") + 5); if (path == NULL) err(ENOMEM, "malloc"); if (type == CONSOLE_SERIAL) snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, "%s/serial/%d/tty", dom_path, num); else { if (num == 0) snprintf(path, strlen(dom_path) + strlen("/console/tty") + 1, "%s/console/tty", dom_path); else snprintf(path, strlen(dom_path) + strlen("/device/console/%d/tty") + 5, "%s/device/console/%d/tty", dom_path, num); } /* FIXME consoled currently does not assume domain-0 doesn't have a console which is good when we break domain-0 up. To keep us user friendly, we'll bail out here since no data will ever show up on domain-0. */ if (domid == 0) { fprintf(stderr, "Can't specify Domain-0\n"); exit(EINVAL); } /* Set a watch on this domain's console pty */ if (!xs_watch(xs, path, "")) err(errno, "Can't set watch for console pty"); xsfd = xs_fileno(xs); /* Wait a little bit for tty to appear. There is a race condition that occurs after xend creates a domain. This code might be running before consoled has noticed the new domain and setup a pty for it. */ spty = get_pty_fd(xs, path, 5); if (spty == -1) { err(errno, "Could not read tty from store"); } init_term(spty, &attr); init_term(STDIN_FILENO, &attr); console_loop(spty, xs, path); restore_term(STDIN_FILENO, &attr); free(path); free(dom_path); return 0; }
int main(int argc, char **argv) { struct termios attr; int domid; char *sopt = "h"; int ch; int opt_ind=0; struct option lopt[] = { { "help", 0, 0, 'h' }, { 0 }, }; char *path; int spty, xsfd; struct xs_handle *xs; char *end; while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch(ch) { case 'h': usage(argv[0]); exit(0); break; } } if ((argc - optind) != 1) { fprintf(stderr, "Invalid number of arguments\n"); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } domid = strtol(argv[optind], &end, 10); if (end && *end) { fprintf(stderr, "Invalid DOMID `%s'\n", argv[optind]); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } xs = xs_daemon_open(); if (xs == NULL) { err(errno, "Could not contact XenStore"); } signal(SIGTERM, sighandler); path = xs_get_domain_path(xs, domid); if (path == NULL) err(errno, "xs_get_domain_path()"); path = realloc(path, strlen(path) + strlen("/console/tty") + 1); if (path == NULL) err(ENOMEM, "realloc"); strcat(path, "/console/tty"); /* FIXME consoled currently does not assume domain-0 doesn't have a console which is good when we break domain-0 up. To keep us user friendly, we'll bail out here since no data will ever show up on domain-0. */ if (domid == 0) { fprintf(stderr, "Can't specify Domain-0\n"); exit(EINVAL); } /* Set a watch on this domain's console pty */ if (!xs_watch(xs, path, "")) err(errno, "Can't set watch for console pty"); xsfd = xs_fileno(xs); /* Wait a little bit for tty to appear. There is a race condition that occurs after xend creates a domain. This code might be running before consoled has noticed the new domain and setup a pty for it. */ spty = get_pty_fd(xs, path, 5); if (spty == -1) { err(errno, "Could not read tty from store"); } init_term(spty, &attr); init_term(STDIN_FILENO, &attr); console_loop(spty, xs, path); restore_term(STDIN_FILENO, &attr); free(path); return 0; }