int main (int argc, char* argv[]) { if (argc < 3) { printf("Usage:\n"); printf("\t./executable <row> <column>\n"); return -1; } int row = atoi(argv[1]); int column = atoi(argv[2]); cell_type env[HEIGHT][WIDTH] = { {C, C, C, C, C, C, C, C, C, C}, {C, C, C, C, C, C, C, S, C, C}, {S, S, S, S, S, S, S, S, C, C}, {C, S, C, C, C, C, C, S, C, C}, {C, C, S, C, C, C, C, S, C, C}, {C, C, S, S, S, C, C, S, S, S}, {S, S, S, S, S, C, C, S, C, C}, {C, C, S, C, C, S, S, S, C, C}, {C, C, S, C, C, C, C, S, C, C}, {C, C, S, C, C, C, C, S, C, C} }; print_env(env); mark_godzilla_destroy_area(row, column, env); printf("\n"); print_env(env); return 0; }
int exec_env(t_struc *s, char **env2) { int i; int j; int option_i; char **new_env; i = 1; j = 1; option_i = 0; new_env = env2 ? copy_env(env2) : (char **)malloc(sizeof(char *) * 1); if (s->argc == 1) print_env(new_env); else { if (get_env_options(s, &i, &option_i) == -1) return (-1); if (option_i) new_env = (char **)malloc(sizeof(char *) * 1); s->cmd = NULL; new_env = exec_env2(s, i, j, new_env); if (s->cmd) !is_builtin(s) ? exec_cmd(s, new_env) : exec_builtin(s, new_env); else print_env(new_env); } return (0); }
static void check_cmd2(char **str, t_env *e) { int stat; pid_t fat; char *ret; ret = NULL; if (str[0] && ft_strcmp(str[0], "cd") == 0) ft_cd(str[1], e); else if (str[0] && ft_strcmp(str[0], "env") == 0) print_env(e->env); else if (str[0] && ft_strcmp(str[0], "exit") == 0) ft_exit(str); else if (str[0] && (ret = pathsys(str[0], e)) != NULL) { fat = fork(); if (fat != -1) { if (fat == 0) execve(ret, str, e->env); else waitpid(fat, &stat, 0); } if (WIFSIGNALED(stat)) ft_wrong_exit(e->shell, WTERMSIG(stat), ret); } safe_free(ret); }
int main() { init_env(); // Poorly named. Has nothing to do with env alist. init_mem(); uptr_t *env = refer(NIL); init_syms(env); uptr_t *form_p = refer(NIL); while(1) { print_env(env); print_mem(); printf_P(PSTR("> ")); *form_p = read_form(stdin); while(getc(stdin) != '\r'); print_form(eval(env, *form_p)); printf_P(PSTR("\n")); // print_mem(); __GC__(); } release(2); // Just a formality really... return 0; }
/* start simulation, program loaded, processor precise state initialized */ void sim_main(void) { fprintf(stderr, "sim: ** starting *pipe* functional simulation **\n"); /* must have natural byte/word ordering */ if (sim_swap_bytes || sim_swap_words) fatal("sim: *pipe* functional simulation cannot swap bytes or words"); /* set up initial default next PC */ /* maintain $r0 semantics */ regs.regs_R[MD_REG_ZERO] = 0; regs.regs_PC -= sizeof(md_inst_t); while (TRUE) { do_if(); do_wb(); do_id(); do_ex(); do_mem(); print_env(); write_buf(); #ifndef NO_INSN_COUNT sim_num_insn++; #endif /* !NO_INSN_COUNT */ } }
int ft_isbuiltin(t_env *env, char *line) { char **line2; int i; t_main w; i = 0; line2 = ft_strsplit(line, ' '); if (ft_strcmp(line2[0], "echo") == 0 && (i = 1)) { line = ft_strfcut(line, 5); ft_echo(line); } else if (ft_strncmp(line, "cd", 2) == 0 && (i = 1)) ft_cd(line); else if (ft_strncmp(line, "unsetenv", 7) == 0 && (i = 1)) env = ft_unsetenv(env); else if (ft_strncmp(line, "env", 2) == 0 && (i = 1)) print_env(env); else if (ft_strncmp(line, "setenv", 5) == 0 && (i = 1)) { line = ft_strrw(line); line2 = ft_strsplit(line, ' '); env = set_env(line2, env); } if (i == 1) ft_doublecoms(env, &w, 0); return (1); }
int env_builtin(t_parser *parser) { int i; t_node_cmd *node; i = 1; node = (t_node_cmd *)parser->data; if (node->cmd[i] && ft_strcmp(node->cmd[i], "--help") == 0) { print_env_usage(node); return (SUCCESS); } while (node->cmd[i] && is_env_opt(node->cmd[i])) if (handle_env_opt(node, &i) < 0) { print_env_usage(node); return (FAILURE); } if (node->cmd[i] && ft_strequ(node->cmd[i], "--")) i++; if (node->cmd[i]) { node->cmd = update_cmd(node->cmd, i); return (exec_fork(parser)); } print_env(node, node->env); return (SUCCESS); }
t_shell *set_env(t_shell *shell) { int i; int k; i = 0; k = 0; if (shell->args[0]) while (shell->args[i]) i++; while (shell->env[k] && equal_key(shell->env[k], shell->args[1]) == 0) k++; if ((i - 1 == 3 && ft_strcmp(shell->args[2], "=") == 0) || i - 1 == 2) { shell->env = ft_realloc_s(shell->env); shell->env[k] = multiple_arguments(shell->args[1], shell->args[i - 1]); } else if (i - 1 == 1) { shell->env = ft_realloc_s(shell->env); shell->env[k] = unique_argument(shell->args[1]); } else if (i - 1 == 0) print_env(shell); else ft_putendl_fd("Format: 1=2 || 1 = 2 || 1 2 || 1", 2); return (shell); }
int main(int argc, char const * const *argv) { if (argc > 1) handle_arguments(argv); print_env(); return 0; }
int main(int argc, char *argv[]) { int ch; char opts[] = "ispuU:cC:dvV:"; struct rlimit rlp; long nn; if(argc==1) return help(); while ((ch = getopt(argc,argv,opts))!=EOF) switch (ch) { case 'i': re_and_eff_ID(); break; case 's': setpgid(0,0); break; case 'p': proc_ID(); break; case 'u': printf("ulimit = %ld\n", ulimit(1)); break; case 'U': nn=atol(optarg); ulimit(2, nn); if(ulimit(1)!= nn) printf("Error, you can't change ulimit!\n"); break; case 'c': getrlimit(RLIMIT_CORE, &rlp); printf("Core size = %ld\n", rlp.rlim_cur); break; case 'C': set_core_size(optarg); break; case 'd': printf("Current work directory is: %s\n", getcwd(0,255)); break; case 'v': print_env(); break; case 'V': putenv(optarg); break; } return 0; }
int check_cmd(char **arg) { if (*arg == (void*)0) return (0); else if (ft_strcmp(arg[0], "exit") == 0) exit(1); else if (ft_strcmp(arg[0], "env") == 0) return (print_env()); else if (ft_strcmp(arg[0], "cd") == 0) return (ft_cd(arg[1])); else if (ft_strcmp(arg[0], "unsetenv") == 0) return (ft_unsetenv(arg[1])); else if (ft_strcmp(arg[0], "setenv") == 0) return (ft_setenv(arg[1], arg[2], arg[3])); return (1); }
static void sh_env(char **argv, char **env) { char **tab; if (argv[1] == NULL) print_env(env); else if (argv[1] != NULL && ft_strcmp(argv[1], "-i") == 0) { tab = (char**)ft_tabnew(2); tab[0] = NULL; tab[1] = NULL; exec_glob(argv + 2, tab); free_tab(tab); } else exec_glob(argv + 1, env); }
int check_again(UNUSED char *cmd, char **arg, UNUSED char **env) { int ret; int *jobs; jobs = NULL; ret = 0; if (my_strcmp("fg", arg[0]) == 0) { jobs = update_jobs(jobs, 0); action(jobs, 0, 0); ++ret; } if (my_strcmp("env", arg[0]) == 0) { print_env(save_my_env(NULL)); ++ret; } return (ret); }
int deal_with_env(t_shell *sh, char **arg) { char **env_cpy; int i; env_cpy = get_env(sh->env); arg++; i = 0; if (*arg) { if (*arg[0] == '-') i = deal_with_opt(sh, arg, env_cpy); else i = deal_with_arg(sh, arg, env_cpy); } else print_env(sh->env); ft_free_tab(env_cpy); return (i); }
int builtin_commands(char *name, char **args, t_env **env_list) { int ret; ret = 0; if (ft_strcmp(name, "cd") == 0 && (ret = 1)) change_cwd(args, env_list); else if (ft_strcmp(name, "env") == 0 && (ret = 1)) print_env(*env_list); else if (ft_strcmp(name, "setenv") == 0 && (ret = 1)) ft_setenv(args[1], args[2], env_list); else if (ft_strcmp(name, "unsetenv") == 0 && (ret = 1)) ft_unsetenv(args[1], env_list); else if (ft_strcmp(name, "echo") == 0 && (ret = 1)) ft_echo(args, *env_list); else if (ft_strcmp(name, "exit") == 0) ret = 1; if (ret == 1) return (1); return (0); }
int deal_with_env(t_lst *node, char *line) { char **save; char **arg; arg = ft_strsplit(line, ' '); arg++; if (*arg) { if (*arg[0] == '-') save = deal_with_opt(node, arg); else save = deal_with_arg(node, arg); if (!save || !*save) return (-1); restore_env(node, save); free(save); } else print_env(node); return (-1); }
// #include <stdio.h> void check_cmd(t_env *e) { char **str; int i; //printf("\t\tReceived command\n"); i = 0; //str = ft_split(line); // ft_memcpy(e->line, line, _POSIX2_LINE_MAX); // e->len = sizeof(line) - 1; // launch_interprete(e); str = e->argv; put_env(e); if (str[0] && ft_strcmp(str[0], "setenv") == 0) { while(str[i]) i++; if (i == 3) ft_set(e->list, str[1], str[2]); else if(i == 2) ft_set(e->list, str[1], "\0"); else if(i > 3) ft_putstr_fd("setenv: Too many arguments.\n", 2); else print_env(e->env); } else if (str[0] && ft_strcmp(str[0], "unsetenv") == 0) { if (str[1]) ft_unset(e->list, str); else ft_putstr_fd("unsetenv: Too few arguments.\n", 2); } else check_cmd2(str, e); // if (str) // ft_free_tab(&str); }
int ft_builtin2(t_env *env, char *line) { char **line2; int i; i = 0; line2 = NULL; line2 = ft_strsplit(line, ' '); line2[0] = ft_strtrim(line2[0]); if (ft_strncmp(line, "env", 2) == 0 && (i = 1)) print_env(env); else if (ft_strncmp(line, "setenv", 5) == 0 && (i = 1)) { line = ft_strtrim(line); line2 = ft_strsplit(line, ' '); env = set_env(line2, env); } else if (ft_isdigit(line[0]) == 1 && line[1] == '>' && line[2] == '&' && (i = 1)) ft_fdfuncs(line); ft_free2d(line2); return (i); }
int main (){ int pid = 0; command_t cmd = {NULL, 0, {NULL}}; char *commandline = (char *)NULL; char* username = NULL; config_t ag_config; int bg_cmd = AG_FALSE; char prompt[MAX_LINE_LEN]; /* Sets the username */ set_username (&username); /* Opens the syslog file */ openlog (username, LOG_PID, LOG_USER); /* Parses the config files for data */ parse_config (&ag_config, username); /* Initializes GNU Readline */ initialize_readline(&ag_config); /* * Main loop: * - print prompt * - read input and parse it * - either a built-in command ("cd", "?" or "exit) * - or a system command, in which case the program forks and executes it with execvp() */ if (ag_config.welcome_message != NULL && strlen (ag_config.welcome_message) > 0) { fprintf (stdout, "\n%s\n\n", ag_config.welcome_message); } while (AG_TRUE){ /* Set the prompt */ get_prompt(prompt, MAX_LINE_LEN, username); /* * Read a line of input * commandline should be deallocated with free() */ commandline = read_input (prompt); parse_command (commandline, &cmd); switch (get_cmd_code (cmd.name)){ case EMPTY_CMD: break; case CD_CMD: change_directory (cmd.argv[1], ag_config.loglevel); break; case HELP_CMD: print_help(&ag_config); break; case ENV_CMD: print_env (cmd.argv[1]); break; case EXIT_CMD: free (commandline); commandline = (char *)NULL; closelog (); return 0; case OTHER_CMD: /* Determines whether the command should run in the bg or not */ bg_cmd = runs_in_background (&cmd); pid = vfork(); if (pid == 0){ if (!check_validity (cmd, ag_config)){ if (ag_config.loglevel == 3) syslog (LOG_NOTICE, "Using command: %s.", cmd.name); execvp (cmd.argv[0], cmd.argv); fprintf (stderr, "%s: Could not execute command!\nType '?' for help.\n", cmd.name); if (ag_config.loglevel >= 2) syslog (LOG_NOTICE, "Could not execute: %s.", cmd.name); }else { fprintf (stdout, "Not allowed! \n"); if (ag_config.warnings >= 0) decrease_warnings (&ag_config); if (ag_config.loglevel >= 1) syslog (LOG_ERR, "Trying to use forbidden command: %s.", cmd.name); } _exit(EXIT_FAILURE); }else if (pid < 0){ fprintf (stderr, "Error! ... Negative PID. God knows what that means ...\n"); if (ag_config.loglevel >= 1) syslog (LOG_ERR, "Negative PID. Using command: %s.", cmd.name); }else { if (!bg_cmd) wait (0); } break; } free (commandline); commandline = (char *)NULL; } if (commandline) free (commandline); closelog(); return 0; }
int main(int argc, char *argv[]) { int ret = -EINVAL; int (*cmd)(char*) = NULL; char *url, *env; int c; umask(0077); int inval = 0; if (!is_env_set()) { print_env(ANSPASS_ENV); inval = 1; } if (!is_token_set()) { print_env(ANSPASS_TOKEN); inval = 1; } if (argc != 2 && argc != 3) { print_help(1); inval = 1; } if (inval) goto missing_options; ret = -ENOMEM; url = (char*)calloc(1, sizeof(char)*MAX_MSG_LENGTH); if (!url) goto no_url_mem; ret = -EINVAL; static struct option long_options[] = { {"add", required_argument, 0, 'a'}, {"delete", required_argument, 0, 'd'}, {"update", required_argument, 0, 'u'}, {"reset", no_argument, 0, 'r'}, {"quit", no_argument, 0, 'q'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int option_index = 0; while((c = getopt_long (argc, argv, "a:d:u:rqh", long_options, &option_index)) != -1) { if (optarg && strlen(optarg) > MAX_MSG_LENGTH - 1) { printf("Error: option too long: %s\n", optarg); goto too_long; } switch (c) { case 'a': /* Add */ cmd = &handle_add; memcpy(url, optarg, strlen(optarg)+ 1); break; case 'd': /* Delete*/ cmd = &handle_del; memcpy(url, optarg, strlen(optarg) + 1); break; case 'u': /* Update */ cmd = &handle_update; memcpy(url, optarg, strlen(optarg) + 1); break; case 'r': /* Reset */ cmd = &handle_reset; break; case 'q': /* Reset */ cmd = &handle_quit; break; case 'h': /* Help */ ret = 0; /* fall-through expected */ default: print_help(ret); goto help; } } ret = -ENOMEM; env = getenv(ANSPASS_ENV); info.env_path= (char*)calloc(1, sizeof(char)*strlen(env)+1); if (!info.env_path) goto no_env_path; strcpy(info.env_path, env); info.old_path = getcwd(NULL, 0); if (!info.old_path) goto no_old_path; if (chdir((const char *)info.env_path) < 0) { printf("Change dir %s failed: %s\n", info.env_path, strerror(errno)); goto chdir_fail; } env = getenv(ANSPASS_TOKEN); info.token = (char*)calloc(1, sizeof(char)*TOKEN_LEN+1); if (!info.token) goto no_token_mem; strncpy(info.token, env, TOKEN_LEN); ret = setup_socket(&info); if (ret) { printf("Error: Socket failed: %d\n", ret); goto socket_fail; } ret = -ENOTCONN; if (connect(info.socket, (struct sockaddr *)info.s_name, sizeof(struct sockaddr_un)) == -1) { ret = errno; printf("Error: Connection refused: %d\n", ret); goto not_connected; } ret = cmd(url); close(info.socket); not_connected: free(info.s_name); socket_fail: free(info.token); no_token_mem: if(chdir((const char *)info.old_path)) perror("chdir"); chdir_fail: free(info.old_path); no_old_path: free(info.env_path); no_env_path: too_long: help: free(url); no_url_mem: missing_options: return ret; }
int main(int argc, char *argv[]) { bool source = true; bool defer = false; struct agent_data_t data; char *password = NULL; enum action verb = ACTION_NONE; enum agent type = AGENT_DEFAULT; void (*print_env)(struct agent_data_t *data) = print_sh_env; static const struct option opts[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "defer", no_argument, 0, 'd' }, { "add", no_argument, 0, 'a' }, { "expunge", no_argument, 0, 'x' }, { "kill", no_argument, 0, 'k' }, { "reload", no_argument, 0, 'r' }, { "list", no_argument, 0, 'l' }, { "unlock", optional_argument, 0, 'u' }, { "print", no_argument, 0, 'p' }, { "sh", no_argument, 0, 's' }, { "csh", no_argument, 0, 'c' }, { "fish", no_argument, 0, 'f' }, { "agent", required_argument, 0, 't' }, { 0, 0, 0, 0 } }; while (true) { int opt = getopt_long(argc, argv, "hvdaxkrlu::pscft:", opts, NULL); if (opt == -1) break; switch (opt) { case 'h': usage(stdout); break; case 'v': printf("%s %s\n", program_invocation_short_name, ENVOY_VERSION); return 0; case 'd': defer = true; break; case 'a': verb = ACTION_FORCE_ADD; defer = false; break; case 'x': verb = ACTION_FORCE_EXPUNGE; defer = false; break; case 'k': verb = ACTION_KILL; source = false; break; case 'r': verb = ACTION_RELOAD; source = false; break; case 'l': verb = ACTION_LIST; break; case 'u': verb = ACTION_UNLOCK; password = optarg; break; case 'p': verb = ACTION_PRINT; break; case 's': print_env = print_sh_env; break; case 'c': print_env = print_csh_env; break; case 'f': print_env = print_fish_env; break; case 't': type = lookup_agent(optarg); if (type < 0) errx(EXIT_FAILURE, "unknown agent: %s", optarg); break; default: usage(stderr); } } if (get_agent(&data, type, source, defer) < 0) errx(EXIT_FAILURE, "recieved no data, did the agent fail to start?"); if (data.status == ENVOY_STOPPED) return 0; if (source) source_env(&data); switch (verb) { case ACTION_PRINT: print_env(&data); /* fall through */ case ACTION_NONE: if (data.type == AGENT_GPG_AGENT || !agent_started(&data)) break; if (defer) break; /* fall through */ case ACTION_FORCE_ADD: add_keys(&argv[optind], argc - optind); break; case ACTION_FORCE_EXPUNGE: expunge_keys(&argv[optind], argc - optind); break; case ACTION_KILL: if (envoy_kill_agent(type) < 0) errx(EXIT_FAILURE, "failed to kill agent"); break; case ACTION_RELOAD: reload_agent(&data); break; case ACTION_LIST: execlp("ssh-add", "ssh-add", "-l", NULL); err(EXIT_FAILURE, "failed to launch ssh-add"); case ACTION_UNLOCK: unlock(&data, password); break; default: break; } return 0; }
void print_env(const struct env *env){ if(env==NULL){printf(" #\n");} else{printf(" %s ",env->id);print_env(env->next);} }
int main(int argc, char *argv[]) { int first,i; char* f; group_t* group; int sh_override = -1; int list_packages = 0; for (i=1; i<argc && *argv[i] == '-'; i++) { for (f=argv[i]+1; *f; f++) switch (*f) { case 'v': debugging = 1; silent = 0; break; case 's': debugging = 0; silent = 1; break; case 'c': sh_override = 1; break; case 'b': sh_override = 0; break; case 'f': main_package_filename = argv[++i]; break; case 'l': list_packages = 1; break; default: fprintf(stderr, "usepackage: unrecognised flag '%c'\n", *f); exit(1); } } if (!list_packages && (i >= argc)) { fprintf(stderr, "\n%s %s, %s\n", PACKAGE_NAME, PACKAGE_VERSION, COPYRIGHT); fprintf(stderr, "Bug reports and comments to: %s\n", PACKAGE_BUGREPORT); fprintf(stderr, "Discussion/announcement list: %s\n\n", MAILING_LIST); fprintf(stderr, "usage: use [-vs] [-f <file>] <package> [<package>...]\n"); fprintf(stderr, " use -l\n\n"); fprintf(stderr, " -v : verbose\n"); fprintf(stderr, " -s : silence match warnings\n"); fprintf(stderr, " -f : use <file> as main packages file\n"); fprintf(stderr, " -l : list available packages\n\n"); exit(1); } DEBUG(stderr, "%s\n", PACKAGE_NAME); DEBUG(stderr, "Version: %s\n", PACKAGE_VERSION); DEBUG(stderr, "%s\n", COPYRIGHT); uname(&the_host_info); DEBUG(stderr, "host: %s\n", the_host_info.nodename); DEBUG(stderr, "operating system: %s %s\n", the_host_info.sysname, the_host_info.release); DEBUG(stderr, "architecture: %s\n", the_host_info.machine); the_shell = get_user_shell(); DEBUG(stderr, "shell: %s\n", the_shell); if (sh_override != -1) csh_user = sh_override; else csh_user = ((!strcmp(the_shell, "csh")) || (!strcmp(the_shell, "tcsh"))); the_environment = new_list(); the_scripts = new_list(); if (get_packages(&the_packages, &the_groups, &the_annotations)) { fprintf(stderr, "usepackage: couldn't load package information.\n"); exit(2); } if (list_packages) { fprintf(stderr, "\nusepackage %s, %s\n\n", VERSION, COPYRIGHT); fprintf(stderr, "Available packages are:\n\n"); list_annotations(); fprintf(stderr, "\nAvailable groups are:\n\n"); list_groups(); fprintf(stderr, "\n"); exit(0); } for (first = i, i = argc - 1 ; i >= first ; i--) { if (group = get_group(argv[i])) use_group(group); else use_package(argv[i]); } print_env(); print_scripts(); return(0); }
int main(int argc, char *argv[]) { bool source = true; struct agent_data_t data; char *password = NULL; enum action verb = ACTION_NONE; enum agent type = AGENT_DEFAULT; void (*print_env)(struct agent_data_t *data) = print_sh_env; static const struct option opts[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "add", no_argument, 0, 'a' }, { "clear", no_argument, 0, 'k' }, { "kill", no_argument, 0, 'K' }, { "list", no_argument, 0, 'l' }, { "unlock", optional_argument, 0, 'u' }, { "print", no_argument, 0, 'p' }, { "sh", no_argument, 0, 's' }, { "csh", no_argument, 0, 'c' }, { "fish", no_argument, 0, 'f' }, { "agent", required_argument, 0, 't' }, { 0, 0, 0, 0 } }; while (true) { int opt = getopt_long(argc, argv, "hvakKlu::pscft:", opts, NULL); if (opt == -1) break; switch (opt) { case 'h': usage(stdout); break; case 'v': printf("%s %s\n", program_invocation_short_name, ENVOY_VERSION); return 0; case 'a': verb = ACTION_FORCE_ADD; break; case 'k': verb = ACTION_CLEAR; source = false; break; case 'K': verb = ACTION_KILL; source = false; break; case 'l': verb = ACTION_LIST; break; case 'u': verb = ACTION_UNLOCK; password = optarg; break; case 'p': verb = ACTION_PRINT; break; case 's': print_env = print_sh_env; break; case 'c': print_env = print_csh_env; break; case 'f': print_env = print_fish_env; break; case 't': type = lookup_agent(optarg); if (type < 0) errx(EXIT_FAILURE, "unknown agent: %s", optarg); break; default: usage(stderr); } } if (get_agent(&data, type, source) < 0) errx(EXIT_FAILURE, "recieved no data, did the agent fail to start?"); if (data.status == ENVOY_STOPPED) return 0; if (source) source_env(&data); switch (verb) { case ACTION_PRINT: print_env(&data); /* fall through */ case ACTION_NONE: if (data.status != ENVOY_STARTED || data.type == AGENT_GPG_AGENT) break; /* fall through */ case ACTION_FORCE_ADD: add_keys(&argv[optind], argc - optind); break; case ACTION_CLEAR: if (data.type == AGENT_GPG_AGENT) kill(data.pid, SIGHUP); else errx(EXIT_FAILURE, "only gpg-agent supports this operation"); break; case ACTION_KILL: kill(data.pid, SIGTERM); break; case ACTION_LIST: execlp("ssh-add", "ssh-add", "-l", NULL); err(EXIT_FAILURE, "failed to launch ssh-add"); case ACTION_UNLOCK: unlock(&data, password); break; default: break; } return 0; }
void execute_cmd(void) { currcmd = currcmd % MAXCMDS; int curr = currcmd; FILE *f; if(comtab[curr].external == 0) { // Built-in Command aliasroot = NULL; aliasDepth = 0; switch(comtab[curr].code) { case CHD : { if( chdir(getHOME) ) { printf("ERROR at line %d\n", __LINE__); break; } setenv("PWD", getHOME, 1); break; } case CDX : { char* dest = cleanInput(comtab[curr].atptr[0]); if( chdir(dest) == -1 ) { printf("ERROR: \n%s is not a directory\n", dest); } char pwd[5000]; getcwd( pwd, sizeof(pwd) ); setenv("PWD", pwd, 1); break; } case SETENV : { char* name = cleanInput(comtab[curr].atptr[0]); char* word = cleanInput(comtab[curr].atptr[1]); if( setenv( name, word, 1 ) == -1 ) { printf("setenv failed, could not set %s to %s\n", name, word ); } break; } case UNSETENV : { char* name = cleanInput(comtab[curr].atptr[0]); if( getenv(name) ){ unsetenv(name); } else { printf("unsetenv failed, could not find %s\n", name); } break; } case PRINTENV : { if(ofileredir) { if(comtab[curr].append) { f = fopen(comtab[curr].outfd, "a"); } else { f = fopen(comtab[curr].outfd, "w"); } if(f == NULL) return SYSERR; } else print_env(); if(ofileredir) fclose(f); break; } case SETALIAS : { char* name = cleanInput(comtab[curr].atptr[0]); char* word = cleanInput(comtab[curr].atptr[1]); setalias(name, word); break; } case UNALIAS : { char* name = cleanInput(comtab[curr].atptr[0]); removealias(name); break; } case PRINTALIAS : { if(ofileredir) { if(comtab[curr].append) { f = fopen(comtab[curr].outfd, "a"); } else { f = fopen(comtab[curr].outfd, "w"); } } else printalias(); if(ofileredir) fclose(f); break; } case PWD : { printf("%s\n", getPWD); break; } } } else { // Handle aliasing int acurr = isalias(comtab[curr].comname); if(acurr != -1) { comtab[curr].external = 0; if(aliasroot == NULL) { aliasroot = aliastab[acurr].alname; } // Check for infinite aliasing if( aliasDepth > 30 ) { printf("ERR: Infinite aliasing detected. Exiting...\n"); return; } else { ignoreEOF = 1; parse_string(aliastab[acurr].alstring); aliasDepth++; execute_cmd(); } } else { // External Command aliasroot = NULL; aliasDepth = 0; pid_t child = fork(); int stat; int success = -1; while(waitpid(child, &stat, 0) == -1) { if(errno != EINTR) { stat = -1; break; } } if(child < 0) exit(1); else if(child == 0) { // Prepare for execv call char tmp[256]; char *paths = strcpy(tmp, getenv("PATH")); char *tok = strtok(paths, ":"); char *cmp = "./"; while(tok) { char place[255]; if(comtab[curr].comname[0] == cmp[0] || comtab[curr].comname[0] == cmp[1]) { // If destination is specified strcpy(place, comtab[curr].comname); } else { // If destination is not specified strcpy(place, tok); strcat(place, "/"); // Append command name strcat(place, comtab[curr].comname); } char *cmds[comtab[curr].nargs + 2]; cmds[0] = place; cmds[comtab[curr].nargs + 1] = (char *)NULL; int i = 0; for(i; i<comtab[curr].nargs; i++) { cmds[i+1] = comtab[curr].atptr[i]; } if(execv(place, cmds) == -1) { tok = strtok(NULL, ":"); continue; } else { _exit(0); success = 1; break; } } if(success == -1) { printf("ERR: Command not found: %s\n", comtab[curr].comname); _exit(1); } } } } currcmd += 1; comtab[currcmd].external = 0; ignoreEOF = 0; }
int main(int argc, char **argv) { config_init(); int c; while (-1 != (c = getopt(argc, argv, "n:m:k:d:p:h"))) { switch(c) { case 'n': config.num = atoi(optarg); break; case 'm': config.maxbytes = ((size_t)atoi(optarg)) * 1024 * 1024; break; case 'k': config.keysize = atoi(optarg); break; case 'd': config.datasize = atoi(optarg); break; case 'p': config.hashpower = atoi(optarg); break; case 'h': usage(); return EXIT_SUCCESS; default: usage(); return EXIT_FAILURE; } } generate_key_init(); print_env(); lru *l = lru_init(config.maxbytes, config.hashpower); char *bvalue = malloc(config.datasize); memset(bvalue, 'x', config.datasize); char *key = malloc(config.keysize); memset(key, 0, config.keysize); int gnum = config.keysize - num_; generate_key_reset(); bench_start("SET"); int i; for (i = 0; i < config.num; i++) { snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i); int r = item_set(l, key, config.keysize, bvalue, config.datasize); assert(r == 0); process_report(); } bench_stop(); print_stat(l); char *buf = malloc(config.datasize); size_t sz; generate_key_reset(); bench_start("GET"); for (i = 0; i < config.num; i++) { snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i); int r = item_get(l, key, config.keysize, buf, config.datasize, &sz); if (!r) { assert((int)sz == config.datasize); assert(memcmp(bvalue, buf, config.datasize) == 0); } memset(buf, 0, config.datasize); process_report(); } bench_stop(); print_stat(l); generate_key_reset(); bench_start("DELETE"); for (i = 0; i < config.num; i++) { snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i); item_delete(l, key, config.keysize); process_report(); } bench_stop(); print_stat(l); free(buf); free(bvalue); free(key); free(fmt_); free(key_); lru_free(l); /* printf("print any key to exit...\n"); getchar(); */ return EXIT_SUCCESS; }
void resizing_signal(int signal_n) { (void)signal_n; ioctl(STDOUT_FILENO, TIOCGWINSZ, &(g_env()->win_size)); print_env(g_env()); }
int main(int argc, char **argv) { unsigned i; int ch; const char *path; const char *search_path = 0; static unsigned zero = 0; #ifdef __STACK_CHECK__ _beginStackCheck(); atexit(stackResults); #endif // work around GNO/ME environment bug. PushVariablesGS(&zero); if (_toolErr) { errx(1, "PushVariablesGS: $%04x", _toolErr); } while ((ch = getopt(argc, argv, "-ivP:S:u:x:")) != -1) { switch(ch) { case 'v': _v++; break; case 'i': case '-': reset_env(); break; case 'u': unset_env(optarg); break; case 'x': /* GNO-specific: set prefix */ set_prefix(optarg); break; case 'P': search_path = optarg; break; case 'S': // not a posix flag. errx(1, "-S is not supported"); break; case '?': default: usage(); } } argc -= optind; argv += optind; for( ; argc; ++argv, --argc) { if (!set_env(*argv)) break; } if (!argc) { print_env(); exit(0); } path = find_path(argv[0], search_path); if (_v) { fprintf(stderr, "#env executing:\t%s\n", path); for (i = 0; i < argc; ++i) fprintf(stderr, "#env arg[%d]= '%s'\n", i, argv[i]); } execv(path, argv); exit(errno == ENOENT ? 127 : 126); return 0; }
void platform_init(void) { #ifdef LK_PROFILING unsigned int time_nand_emmc; unsigned int time_load_logo; unsigned int time_bat_init; unsigned int time_backlight; unsigned int time_show_logo; unsigned int time_boot_mode; unsigned int time_sw_env; unsigned int time_platform_init; unsigned int time_env; unsigned int time_disp_init; unsigned int time_security_init; unsigned int time_RTC_boot_Check; time_platform_init = get_timer(0); time_nand_emmc = get_timer(0); #endif dprintf(INFO, "platform_init()\n"); #ifdef DUMMY_AP dummy_ap_entry(); #endif #ifdef MTK_EMMC_SUPPORT mmc_legacy_init(1); #else #ifndef MACH_FPGA nand_init(); nand_driver_test(); #endif #endif #ifdef MTK_KERNEL_POWER_OFF_CHARGING if((g_boot_arg->boot_reason == BR_USB) && (upmu_is_chr_det() == KAL_FALSE)) { printf("[%s] Unplugged Charger/Usb between Pre-loader and Uboot in Kernel Charging Mode, Power Off \n", __func__); mt6575_power_off(); } #endif #ifdef LK_PROFILING printf("[PROFILE] ------- NAND/EMMC init takes %d ms -------- \n", get_timer(time_nand_emmc)); time_env = get_timer(0); #endif env_init(); print_env(); #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- ENV init takes %d ms -------- \n", (int)get_timer(time_env)); #endif #ifdef LK_PROFILING time_disp_init = get_timer(0); #endif //FIXME: Disable for MT6582 FPGA Ealry Porting #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP if(lcm_params->type==LCM_TYPE_DSI && lcm_params->dsi.mode ==CMD_MODE) mt_disp_init((void *)g_fb_base); #endif #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- disp init takes %d ms -------- \n", (int)get_timer(time_disp_init)); #endif #ifdef LK_PROFILING time_load_logo = get_timer(0); #endif #ifdef CONFIG_CFB_CONSOLE //FIXME: Disable for MT6582 FPGA Ealry Porting #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP drv_video_init(); #endif #endif //#endif #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP mboot_common_load_logo((unsigned long)mt_get_logo_db_addr(), "logo"); dprintf(INFO, "Show BLACK_PICTURE\n"); #endif //FIXME: Disable for MT6582 FPGA Ealry Porting #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY if(!is_low_battery(0)) { #endif mt_disp_fill_rect(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT, 0x0); mt_disp_power(TRUE); mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); mt_disp_wait_idle(); mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); mt_disp_wait_idle(); mt_disp_power(1); //power on display related modules #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY } #endif #endif #ifdef LK_PROFILING printf("[PROFILE] ------- load_logo takes %d ms -------- \n", get_timer(time_load_logo)); time_backlight = get_timer(0); #endif /*for kpd pmic mode setting*/ set_kpd_pmic_mode(); //FIXME: Disable for MT6582 FPGA Ealry Porting //#ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY if(!is_low_battery(0)) { #endif /*some lcm panel need more time to start show picture*/ msleep(50); mt65xx_backlight_on(); #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY } #endif //#endif #ifdef LK_PROFILING printf("[PROFILE] ------- backlight takes %d ms -------- \n", get_timer(time_backlight)); time_boot_mode = get_timer(0); #endif boot_mode_select(); #ifdef LK_PROFILING printf("[PROFILE] ------- boot mode select takes %d ms -------- \n", get_timer(time_boot_mode)); #endif #ifdef MTK_SECURITY_SW_SUPPORT #ifdef LK_PROFILING time_security_init = get_timer(0); #endif /* initialize security library */ #ifdef MTK_EMMC_SUPPORT sec_func_init(1); #else sec_func_init(0); #endif #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- Security init takes %d ms -------- \n", (int)get_timer(time_security_init)); #endif #endif /*Show download logo & message on screen */ if (g_boot_arg->boot_mode == DOWNLOAD_BOOT) { printf("[LK] boot mode is DOWNLOAD_BOOT\n"); #ifdef MTK_SECURITY_SW_SUPPORT /* verify da before jumping to da*/ if (sec_usbdl_enabled()) { u8 *da_addr = (u8 *)g_boot_arg->da_info.addr; u32 da_len = g_boot_arg->da_info.len; u32 sig_len = g_boot_arg->da_info.sig_len; u8 *sig_addr = (unsigned char *)da_addr + (da_len - sig_len); if (da_len == 0 || sig_len == 0) { printf("[LK] da argument is invalid\n"); printf("da_addr = 0x%x\n", da_addr); printf("da_len = 0x%x\n", da_len); printf("sig_len = 0x%x\n", sig_len); } if (sec_usbdl_verify_da(da_addr, (da_len - sig_len), sig_addr, sig_len)) { /* da verify fail */ video_printf(" => Not authenticated tool, download stop...\n"); while(1); /* fix me, should not be infinite loop in lk */ } } else #endif { printf(" DA verification disabled...\n"); } mt_disp_show_boot_logo(); video_printf(" => Downloading...\n"); mt65xx_backlight_on(); mtk_wdt_disable();//Disable wdt before jump to DA platform_uninit(); #ifdef HAVE_CACHE_PL310 l2_disable(); #endif #ifdef ENABLE_L2_SHARING config_shared_SRAM_size(); #endif arch_disable_cache(UCACHE); arch_disable_mmu(); jump_da(g_boot_arg->da_info.addr, g_boot_arg->da_info.arg1, g_boot_arg->da_info.arg2); } #ifdef LK_PROFILING time_bat_init = get_timer(0); #endif mt65xx_bat_init(); #ifdef LK_PROFILING printf("[PROFILE] ------- battery init takes %d ms -------- \n", get_timer(time_bat_init)); #endif #ifndef CFG_POWER_CHARGING #ifdef LK_PROFILING time_RTC_boot_Check = get_timer(0); #endif /* NOTE: if define CFG_POWER_CHARGING, will rtc_boot_check() in mt65xx_bat_init() */ rtc_boot_check(false); #ifdef LK_PROFILING dprintf(INFO,"[PROFILE] ------- RTC boot check Init takes %d ms -------- \n", (int)get_timer(time_RTC_boot_Check)); #endif #endif #ifdef LK_PROFILING time_show_logo = get_timer(0); #endif #ifdef MTK_KERNEL_POWER_OFF_CHARGING if(kernel_charging_boot() == 1) { #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN; charging_get_charger_type(&CHR_Type_num); if ((g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) || ((CHR_Type_num != STANDARD_HOST) && (CHR_Type_num != NONSTANDARD_CHARGER))) { dprintf(INFO, "[PROFILE] ------- g_boot_mode = %d -------- \n", g_boot_mode); #endif mt_disp_power(TRUE); mt_disp_show_low_battery(); mt_disp_wait_idle(); mt65xx_leds_brightness_set(6, 110); #ifdef MTK_BATLOWV_NO_PANEL_ON_EARLY } #endif } else if(g_boot_mode != KERNEL_POWER_OFF_CHARGING_BOOT && g_boot_mode != LOW_POWER_OFF_CHARGING_BOOT) { #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT)) { mt_disp_show_boot_logo(); } #endif } #else #ifndef DISABLE_DISPLAY_IN_LK_FOR_82_BRINGUP if (g_boot_mode != ALARM_BOOT && (g_boot_mode != FASTBOOT)) { mt_disp_show_boot_logo(); } #endif #endif #ifdef LK_PROFILING printf("[PROFILE] ------- show logo takes %d ms -------- \n", get_timer(time_show_logo)); time_sw_env= get_timer(0); #endif //sw_env(); #ifdef LK_PROFILING printf("[PROFILE] ------- sw_env takes %d ms -------- \n", get_timer(time_sw_env)); printf("[PROFILE] ------- platform_init takes %d ms -------- \n", get_timer(time_platform_init)); #endif }
void platform_init(void) { /* init timer */ //mtk_timer_init(); #ifdef LK_PROFILING unsigned int time_nand_emmc; unsigned int time_load_logo; unsigned int time_bat_init; unsigned int time_backlight; unsigned int time_show_logo; unsigned int time_boot_mode; unsigned int time_sw_env; unsigned int time_platform_init; unsigned int time_env; time_platform_init = get_timer(0); time_nand_emmc = get_timer(0); #endif dprintf(INFO, "platform_init()\n"); #ifdef MTK_MT8193_SUPPORT mt8193_init(); #endif #ifdef MTK_EMMC_SUPPORT mmc_legacy_init(1); #else nand_init(); nand_driver_test(); #endif #ifdef MTK_KERNEL_POWER_OFF_CHARGING if((g_boot_arg->boot_reason == BR_USB) && (upmu_is_chr_det() == KAL_FALSE)) { printf("[%s] Unplugged Charger/Usb between Pre-loader and Uboot in Kernel Charging Mode, Power Off \n", __func__); mt6575_power_off(); } #endif #ifdef LK_PROFILING printf("[PROFILE] ------- NAND/EMMC init takes %d ms -------- \n", get_timer(time_nand_emmc)); time_env = get_timer(0); #endif env_init(); print_env(); #ifdef LK_PROFILING printf("[PROFILE] ------- ENV init takes %d ms -------- \n", get_timer(time_env)); time_load_logo = get_timer(0); #endif mboot_common_load_logo((unsigned long)mt_get_logo_db_addr(), "logo"); #if ((!defined(MTK_NCP1851_SUPPORT)) && (!defined(MTK_BQ24196_SUPPORT))) mt_disp_power(TRUE); //power on display related modules #endif dprintf(INFO, "Show BLACK_PICTURE\n"); mt_disp_fill_rect(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT, 0x0); mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); mt_disp_update(0, 0, CFG_DISPLAY_WIDTH, CFG_DISPLAY_HEIGHT); #ifdef LK_PROFILING printf("[PROFILE] ------- load_logo takes %d ms -------- \n", get_timer(time_load_logo)); time_backlight = get_timer(0); #endif /*for kpd pmic mode setting*/ set_kpd_pmic_mode(); #if ((!defined(MTK_NCP1851_SUPPORT)) && (!defined(MTK_BQ24196_SUPPORT))) //mt65xx_backlight_on(); #endif #ifdef LK_PROFILING printf("[PROFILE] ------- backlight takes %d ms -------- \n", get_timer(time_backlight)); time_boot_mode = get_timer(0); #endif enable_PMIC_kpd_clock(); boot_mode_select(); #ifdef LK_PROFILING printf("[PROFILE] ------- boot mode select takes %d ms -------- \n", get_timer(time_boot_mode)); #endif /* initialize security library */ #ifdef MTK_EMMC_SUPPORT sec_func_init(1); #else sec_func_init(0); #endif /*Show download logo & message on screen */ if (g_boot_arg->boot_mode == DOWNLOAD_BOOT) { printf("[LK] boot mode is DOWNLOAD_BOOT\n"); /* verify da before jumping to da*/ if (sec_usbdl_enabled()) { u8 *da_addr = g_boot_arg->da_info.addr; u32 da_sig_len = DRV_Reg32(SRAMROM_BASE + 0x54); u32 da_len = da_sig_len >> 10; u32 sig_len = da_sig_len & 0x3ff; u8 *sig_addr = (unsigned char *)da_addr + (da_len - sig_len); if (da_len == 0 || sig_len == 0) { printf("[LK] da argument is invalid\n"); printf("da_addr = 0x%x\n", da_addr); printf("da_len = 0x%x\n", da_len); printf("sig_len = 0x%x\n", sig_len); } if (sec_usbdl_verify_da(da_addr, (da_len - sig_len), sig_addr, sig_len)) { /* da verify fail */ video_printf(" => Not authenticated tool, download stop...\n"); DRV_WriteReg32(SRAMROM_BASE + 0x54, 0x0); while(1); /* fix me, should not be infinite loop in lk */ } } else {