void Variant::xmlWrite(QDomDocument& doc, QDomNode& node) const { QDomElement elem = createEmptyElement(doc, typeName(type())); if (isBuiltIn()) VariantBase::xmlWrite(doc, elem); else variantData()->xmlWrite(doc, elem); }
void Variant::operator = (VariantData* newval) { if (newval != (VariantData*)this || !isBuiltIn()) { teardown(); VariantBase::operator = (newval->lock()); } }
int main() { char *args[MAX_ARGS]; int bg, status; pid_t pid, ppid = getpid(); pos = 0; jobs = 0; headP = malloc(sizeof(proc)); if (headP == NULL) return -1; char *parLine = "shell"; push(headP, 0, parLine); // set head proc to parent shell for convenience while (1) { signal(SIGUSR1, histHandler); // signal(SIGCHLD, procHandler); int cnt = getcmd("\n>> ", args, &bg); if (cnt < 0) continue; status = isBuiltIn(args, cnt); if (status == 0) continue; else if (status == 1) if (!isBuiltIn(args, cnt)) continue; pid = fork(); if (pid == -1) perror("fork"); // child else if (pid == 0) { if (execvp(args[0], args) < 0) { printf("exec failure: %s\n", strerror(errno)); kill(ppid, SIGUSR1); exit(EXIT_FAILURE); } else exit(EXIT_SUCCESS); } // parent // note: background processes are implemented such that calling 'r x' on a process implemented as a background process // requires an additional '&' to run that process as a background process as well else { if (bg == 1) { bg = 0; push(headP, pid, hist[(pos-1)%(MAX_HISTORY+1)].lineptr); freecmd(args); kill(ppid, SIGCONT); } else { status=0; waitpid(pid, &status, WUNTRACED); if (status == -1) printf("An error occured in waiting for child proccess %d\n", pid); } } } return 0; }
int main (int argc, char **argv) { char * cmdLine; char * username; char ** cmd; char hostname[256]; size_t len = 256; struct sigaction new_action, old_action; /* Inicializa a lista que guarda os processos que rodam em background */ childs = malloc(sizeof(LIST)); ListCreate(childs); /* Inicializa a variável que guarda o ID do processo atual do foreground */ fgChildPid = 0; child_handler_lock = 0; /* Set up the structure to specify the new action. */ new_action.sa_handler = termination_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGINT, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGINT, &new_action, NULL); sigaction (SIGHUP, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGHUP, &new_action, NULL); sigaction (SIGTERM, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGTERM, &new_action, NULL); new_action.sa_handler = child_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGCHLD, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGCHLD, &new_action, NULL); new_action.sa_handler = sigtstop_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGTSTP, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGTSTP, &new_action, NULL); /*inicializa lista que guarda o historico de comandos */ history = malloc(sizeof(struct node)); history->cmd = NULL; history->next = NULL; /* Pega o nome do usuario atual e da máquina */ username = getlogin(); gethostname(hostname, len); asprintf(&userdir, "/home/%s", username); /* Coloca o diretório do usuário como diretório inicial */ chdir(userdir); while (1) { printPrompt(username, hostname); output_r = input_r = 0; rewind(stdin); cmdLine = readline(); if(strcmp(cmdLine, "") != 0) { add_history(cmdLine); cmd = parse(cmdLine); int cmd_id = isBuiltIn(cmd[0]); if(cmd_id >= 0) callBuiltIn(cmd_id, cmd[1]); else { if((childPid = fork()) == 0) { if(output_r) { fd_out = open(output_r_filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IRGRP | S_IWGRP | S_IWUSR, 0666); dup2(fd_out, 1); } if(input_r) { fd_in = open(input_r_filename, O_RDONLY, 0666); dup2(fd_in, 0); } fgChildPid = childPid; int i = execvp(cmd[0], cmd); if (output_r) close(fd_out); if (input_r) close(fd_in); if(i < 0) { printf("%s: command not found\n", cmd[0]); exit(101); } } else { /*Após criar o processo filho, o pai insere em uma lista ligada o novo processo */ int status; pid_t pidfg; ITEM * p; p = malloc(sizeof(ITEM)); p->pid = childPid; p->isBackground = isBackground; strcpy(p->status, "Running"); strcpy(p->command, cmdLine); ListInsert(childs, p); isBackground = 0; /*E espera ele terminar, caso seja um processo de foreground */ if(!p->isBackground) { child_handler_lock = 1; pidfg = waitpid(childPid, &status, WUNTRACED); child_handler_lock = 0; if ((pidfg >= 0) && (WIFSTOPPED(status) == 0)) ListRemoveByPid(childs, childPid); } } } free_parse(); free(cmdLine); } } }
bool ShaderVariable::isEmulatedBuiltIn() const { return isBuiltIn() && name != mappedName; }
VariantBase::operator const VariantData*() const { return isBuiltIn()? 0 : val; }
void Variant::teardown() { if (!isBuiltIn()) variantData()->release(); }
VariantType Variant::type() const { if (isBuiltIn()) return VariantBase::type(); return variantData()->type(); }