int main(int argc, char **argv) { extern char **environ; t_sllist *myenv; int fd; build_env(environ, &myenv); if (argc > 1) { if (!access(argv[1], R_OK)) { fd = xopen(argv[1], O_RDONLY, 0644); xdup2(fd, 0); mysh(1, &myenv); xclose(fd); } else fprintf(stderr, "%s %s\n", "Unable to access :", argv[1]); } else mysh(!isatty(0), &myenv); free_env(myenv); auto_comp(NULL, NULL, DEL, NULL); return (EXIT_SUCCESS); }
static void clean_and_exit_minishell(void) { free_builtins(shell); free_env(shell); free(shell); shell = NULL; }
void free_env(t_env **envc) { if (*envc && (*envc)->next) free_env(&(*envc)->next); else if (*envc) env_delone(envc); }
int main(int argc, char **argv, char **envp) { t_env *env; char *line; env = get_env_list(envp); if (argc > 1) handle_options(argv, env); signal(SIGINT, &sig_handler); while (42) { prompt(env); line = get_next_line(0); if (line == NULL || line_isblank(line)) { if (line == NULL) my_putchar('\n'); continue; } else if (my_strcmp(line, "exit") == 0) break; else mysh_cmdparse(line, &env); free(line); } free_env(env); return (0); }
void run_amcleanup( char *config_name) { pid_t amcleanup_pid; char *amcleanup_program; char *amcleanup_options[4]; char **env; switch(amcleanup_pid = fork()) { case -1: return; break; case 0: /* child process */ amcleanup_program = g_strjoin(NULL, sbindir, "/", "amcleanup", NULL); amcleanup_options[0] = amcleanup_program; amcleanup_options[1] = "-p"; amcleanup_options[2] = config_name; amcleanup_options[3] = NULL; env = safe_env(); execve(amcleanup_program, amcleanup_options, env); free_env(env); error("exec %s: %s", amcleanup_program, strerror(errno)); /*NOTREACHED*/ default: break; } waitpid(amcleanup_pid, NULL, 0); }
static void handle_op_message(uint32_t in_type, struct strbuf *in, struct strbuf *out) { struct op *op = get_local_op(in_type); struct strbuf in_plain = STRBUF_INIT, out_plain = STRBUF_INIT; char *envp[16]; if (!op) fatal("operation %x does not exist", in_type); debug("running op: %s", op->name); /* TEMPORARY */ if (!client_username()) fatal("unathenticated"); gss_decipher(in, &in_plain); make_env(envp, "LANG", "C", "CEO_USER", client_username(), "CEO_CONFIG_DIR", config_dir, NULL); char *argv[] = { op->path, NULL, }; if (spawnvemu(op->path, argv, envp, &in_plain, &out_plain, 0, op->user)) fatal("child %s failed", op->path); gss_encipher(&out_plain, out); if (!out->len) fatal("no response from op"); free_env(envp); strbuf_release(&in_plain); strbuf_release(&out_plain); }
Destroy( ETInst *inst ) { if ( inst ) { if ( inst->env ) free_env( inst->env ); free( inst ); } }
int read_env (int fd, char ***envp) { int envc = 0; int i; if (read_n (fd, &envc, sizeof (int)) < 0) { fprintf (stderr, "systemsafe: read_env: %s\n", strerror (errno)); return (-1); } if (!(*envp = malloc ((envc + 1) * sizeof (**envp)))) { fprintf (stderr, "systemsafe: read_env: malloc: %s\n", strerror (errno)); return (-1); } for (i = 0; i < envc; i++) { char *entry; if (read_string (fd, &entry) < 0) { fprintf (stderr, "systemsafe: %s\n", strerror (errno)); free_env (*envp); return (-1); } if (strncmp ("LD_PRELOAD=", entry, 10) == 0) entry [11] = '\0'; (*envp)[i] = entry; } (*envp)[envc] = NULL; return (0); }
static void finalize(void *userdata) { plugin_environment *env = (plugin_environment *)userdata; //Free all stuff that you have allocated here. free_env(env); }
static Envelope *create_env( LWChannelID *chan ) { LWChanGroupID group; LWEnvelopeID lwenv; LWEnvKeyframeID lwkey; Envelope *env; Key *key, *tail = NULL; double val; env = calloc( 1, sizeof( Envelope )); if ( !env ) return NULL; group = chinfo->channelParent( chan ); lwenv = chinfo->channelEnvelope( chan ); lwkey = NULL; envf->egGet( lwenv, group, LWENVTAG_PREBEHAVE, &env->behavior[ 0 ] ); envf->egGet( lwenv, group, LWENVTAG_POSTBEHAVE, &env->behavior[ 1 ] ); while ( lwkey = envf->nextKey( lwenv, lwkey )) { key = calloc( 1, sizeof( Key )); if ( !key ) { free_env( env ); return NULL; } key->prev = tail; if ( tail ) tail->next = key; else env->key = key; tail = key; env->nkeys++; envf->keyGet( lwenv, lwkey, LWKEY_SHAPE, &key->shape ); envf->keyGet( lwenv, lwkey, LWKEY_VALUE, &val ); key->value = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_TIME, &val ); key->time = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_TENSION, &val ); key->tension = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_CONTINUITY, &val ); key->continuity = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_BIAS, &val ); key->bias = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_PARAM_0, &val ); key->param[ 0 ] = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_PARAM_1, &val ); key->param[ 1 ] = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_PARAM_2, &val ); key->param[ 2 ] = ( float ) val; envf->keyGet( lwenv, lwkey, LWKEY_PARAM_3, &val ); key->param[ 3 ] = ( float ) val; } return env; }
//------------------------------------------------------------------------------ static void apply_env(const env_block_t* block) { env_block_t to_clear; capture_env(&to_clear); apply_env_impl(&to_clear, 1); free_env(&to_clear); apply_env_impl(block, 0); }
void free_env(Env * node) { if (node -> Nil) { free(node); } else { free_env(node -> Cons); free_string(node -> key); free_string(node -> val); free(node); } }
void handle_options(char **argv, t_env *env) { if (my_strcmp(argv[1], "--version") == 0) print_version(env); else if (my_strcmp(argv[1], "--cake") == 0) my_printf("You will be baked, and then there will be cake.\n"); else my_printf("%s -- Unknown option: %s\n", MYSH_APPNAME, argv[1]); free_env(env); exit (0); }
void free_envs( void ) { list < environment_data * >::iterator en; for( en = envlist.begin( ); en != envlist.end( ); ) { environment_data *env = *en; ++en; free_env( env ); } }
void free_all(t_shell *shell) { free_env(shell->env); free(shell->tokens); free(shell->builtins); if (shell->alias != NULL) free_alias(shell->alias); if (shell->command_name != NULL) free(shell->command_name); free(shell->hist_name); free(shell); }
void free_shell(t_shell **shell) { if (shell && *shell) { ft_memdel((void **)&(*shell)->prompt); ft_deltab(&((*shell)->envc)); ft_deltab(&(*shell)->cmd); ft_deltab(&(*shell)->path); free_env(&(*shell)->env); ft_memdel((void **)shell); } }
void special_free(char ***command, int nb) { int i; i = 0; while (i != nb) { if (command[i] != NULL) free_env(command[i]); i++; } free(command); }
/** see init-sph-lib for documentation */ SCM scm_primitive_process_create(SCM scm_executable, SCM scm_arguments, SCM scm_input_port, SCM scm_output_port, SCM scm_error_port, SCM scm_env, SCM scm_keep_descriptors, SCM scm_path_open_flags) { int path_open_flags = (scm_is_true(scm_path_open_flags) ? scm_to_int(scm_path_open_flags) : 0); char **arguments = scm_string_list_to_string_pointer_array(scm_arguments); char **env = ((SCM_BOOL_F == scm_env) ? environ : scm_string_list_to_string_pointer_array(scm_env)); char *executable = scm_to_locale_string(scm_executable); imht_set_t *keep; int input; int output; int error; char *input_path = 0; char *output_path = 0; char *error_path = 0; port_argument_set_fd(scm_input_port, input, input_path); port_argument_set_fd(scm_output_port, output, output_path); port_argument_set_fd(scm_error_port, error, error_path); if (scm_list_to_imht_set(scm_keep_descriptors, (&keep))) { return (SCM_BOOL_F); }; int process_id = fork(); if (!(0 == process_id)) { free(arguments); free(executable); imht_set_destroy(keep); if (!(SCM_BOOL_F == scm_env)) { free_env(env); }; return ((scm_from_int(process_id))); }; ensure_fd(input, O_RDONLY, input_path); ensure_fd(output, (O_WRONLY | O_CREAT | path_open_flags), output_path); ensure_fd(error, (O_WRONLY | O_CREAT | path_open_flags), error_path); imht_set_add(keep, input); imht_set_add(keep, output); imht_set_add(keep, error); close_file_descriptors_from(3, keep); set_standard_streams(input, output, error); execve(executable, arguments, env); _exit(127); return (SCM_UNSPECIFIED); };
int key_release(int keycode, t_env *e) { if (keycode == KEY_RIGHT) e->keys->right = FALSE; if (keycode == KEY_LEFT) e->keys->left = FALSE; if (keycode == KEY_UP) e->keys->up = FALSE; if (keycode == KEY_DOWN) e->keys->down = FALSE; if (keycode == KEY_ESC) { free_env(e); exit(0); } return (0); }
int calc_expr(t_env *env) { int result; t_node *node; node = env->queue_start; while (node) { if (is_operator(node->data[0]) && node->data[1] == '\0') //if operator, pop two values from stack, calculate and add back the result calculate_value(env, node->data[0]); else add_to_stack(env, node->data); //if number, add to stack node = node->next; } result = ft_atoi(env->stack->data); free_env(env); return (result); }
int main(void) { t_env *env; env = init_env(); parse(env) ? tt_pl("") : error(); if (env->nodes) { set_weight_end(env, find_end(env), 0) ? 0 : error(); sort_nodes(env->nodes, env->nb_nodes); print_result(env, 0, 0); env->path_found ? solve(env) : error(); print_result(env, 0, 1); } else error(); free_env(env); return (0); }
cell_t * apply_lambda( lambda_t * lambda, cell_t * operands, struct Env * env ){ struct Env * lenv = bind_operands( lambda, operands, env ); cell_t * s_expression = lambda->body; cell_t * value; while( body_iter != NULL ){ garbage_collect(); value = eval( s_expression, lenv ); s_expression = s_expression->next; } free_env( lenv ); return value; }
static void handle_system_request (int fd) { char *cmd, *path, **env, **oldenv; int rc; if ((rc = read_string (fd, &cmd)) < 0) { fprintf (stderr, "systemsafe: read cmd: %s\n", strerror (errno)); exit (0); } if (rc == 0) /* EOF, time to exit */ exit (0); if (read_string (fd, &path) < 0) { fprintf (stderr, "systemsafe: read path: %s\n", strerror (errno)); exit (0); } if (read_env (fd, &env) < 0) { fprintf (stderr, "systemsafe: read env: %s\n", strerror (errno)); exit (0); } if (chdir (path) < 0) fprintf (stderr, "systemsafe: Failed to chdir to %s: %s\n", path, strerror (errno)); oldenv = environ; environ = env; rc = (*real_system) (cmd); write_n (fd, &rc, sizeof (int)); environ = oldenv; free_env (env); free (cmd); free (path); return; }
/** The runtime entrypoint. The (C ABI) main function generated by rustc calls `rust_start`, providing the address of the Rust ABI main function, the platform argument vector, and a `crate_map` the provides some logging metadata. */ extern "C" CDECL int rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) { #ifndef _WIN32 pthread_key_create(&sched_key, NULL); #endif // Load runtime configuration options from the environment. // FIXME #1497: Should provide a way to get these from the command // line as well. rust_env *env = load_env(argc, argv); global_crate_map = crate_map; update_gc_metadata(crate_map); update_log_settings(crate_map, env->logspec); rust_kernel *kernel = new rust_kernel(env); // Create the main task rust_sched_id sched_id = kernel->main_sched_id(); rust_scheduler *sched = kernel->get_scheduler_by_id(sched_id); assert(sched != NULL); rust_task *root_task = sched->create_task(NULL, "main"); // Schedule the main Rust task root_task->start((spawn_fn)main_fn, NULL, NULL); // At this point the task lifecycle is responsible for it // and our pointer may not be valid root_task = NULL; // Run the kernel until all schedulers exit int ret = kernel->run(); delete kernel; free_env(env); return ret; }
t_envi *my_triple_array(char **cut, t_envi *instuctions) { int i; i = 0; instuctions->nb_cmd = 0; while (cut[i] != NULL) i++; if ((instuctions->command = malloc(sizeof(char **) * (i + 1))) == NULL) return (NULL); i = 0; while (cut[i] != NULL) { instuctions->command[i] = my_str_to_wordtab(cut[i], ' '); instuctions->nb_cmd++; i++; } instuctions->command[i] = NULL; free_env(cut); return (instuctions); }
extern "C" CDECL int rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) { rust_env *env = load_env(); update_log_settings(crate_map, env->logspec); check_claims = env->check_claims; rust_srv *srv = new rust_srv(env); rust_kernel *kernel = new rust_kernel(srv, env->num_sched_threads); rust_task *root_task = kernel->create_task(NULL, "main"); rust_scheduler *sched = root_task->sched; command_line_args *args = new (kernel, "main command line args") command_line_args(root_task, argc, argv); DLOG(sched, dom, "startup: %d args in 0x%" PRIxPTR, args->argc, (uintptr_t)args->args); for (int i = 0; i < args->argc; i++) { DLOG(sched, dom, "startup: arg[%d] = '%s'", i, args->argv[i]); } root_task->start(main_fn, (uintptr_t)args->args); int ret = kernel->start_task_threads(); delete args; delete kernel; delete srv; free_env(env); #if !defined(__WIN32__) // Don't take down the process if the main thread exits without an // error. if (!ret) pthread_exit(NULL); #endif return ret; }
extern "C" CDECL int rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) { rust_env *env = load_env(); update_log_settings(crate_map, env->logspec); check_claims = env->check_claims; rust_srv *srv = new rust_srv(env); rust_kernel *kernel = new rust_kernel(srv, env->num_sched_threads); rust_scheduler *sched = kernel->get_default_scheduler(); rust_task_id root_id = sched->create_task(NULL, "main", MAIN_STACK_SIZE); rust_task *root_task = kernel->get_task_by_id(root_id); I(kernel, root_task != NULL); rust_task_thread *thread = root_task->thread; command_line_args *args = new (kernel, "main command line args") command_line_args(root_task, argc, argv); DLOG(thread, dom, "startup: %d args in 0x%" PRIxPTR, args->argc, (uintptr_t)args->args); for (int i = 0; i < args->argc; i++) { DLOG(thread, dom, "startup: arg[%d] = '%s'", i, args->argv[i]); } root_task->start((spawn_fn)main_fn, NULL, args->args); root_task->deref(); root_task = NULL; int ret = kernel->start_schedulers(); delete args; delete kernel; delete srv; free_env(env); return ret; }
//------------------------------------------------------------------------------ void prepare_env_for_inputrc() { // Give readline a chance to find the inputrc by modifying the // environment slightly. char buffer[1024]; void* env_handle; env_block_t env_block; capture_env(&env_block); // HOME is where Readline will expand ~ to. { static const char home_eq[] = "HOME="; int size = sizeof_array(home_eq); strcpy(buffer, home_eq); get_config_dir(buffer + size - 1, sizeof_array(buffer) - size); putenv(buffer); } // INPUTRC is the path where looks for it's configuration file. { static const char inputrc_eq[] = "INPUTRC="; int size = sizeof_array(inputrc_eq); strcpy(buffer, inputrc_eq); get_dll_dir(buffer + size - 1, sizeof_array(buffer) - size); str_cat(buffer, "/clink_inputrc_base", sizeof_array(buffer)); putenv(buffer); } apply_env(&env_block); free_env(&env_block); }
int main(int ac, char **av, char **env) { struct termios reset; t_le le; t_env *data_env; if (ac && av) ; if (tcgetattr(0, &reset) == -1) message_handling(); g_name_prog = NULL; signal(SIGWINCH, update_size); data_env = create_env(env); data_env->reset = reset; fill_env(&data_env, env); if (init_term(data_env) == 0) message_handling(); init_env(&le, data_env); data_env->le = le; loop_prompt(data_env); free_env(&data_env); reset_term(reset); return (0); }
static void *initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { /* * get the config */ OSyncPluginConfig *config = osync_plugin_info_get_config(info); if (!config) { osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config."); goto error; } /* * You need to specify the <some name>_environment somewhere with * all the members you need */ plugin_environment *env = osync_try_malloc0(sizeof(plugin_environment), error); if (!env) goto error; env->sink_envs = NULL; osync_trace(TRACE_INTERNAL, "The config: %s", osync_plugin_info_get_config(info)); /* * Process the config here and set the options on your environment */ /* * Process plugin specific advanced options */ OSyncList *optslist = osync_plugin_config_get_advancedoptions(config); for (; optslist; optslist = optslist->next) { OSyncPluginAdvancedOption *option = optslist->data; const char *val = osync_plugin_advancedoption_get_value(option); const char *name = osync_plugin_advancedoption_get_name(option); if (!strcmp(name,"<your-option>")) { if (!strcmp(val, "<your-value>")) { /* * set a varaible to a specific value */; } } } /* * Process Ressource options */ int i, numobjs = osync_plugin_info_num_objtypes(info); for (i = 0; i < numobjs; i++) { sink_environment *sinkenv = osync_try_malloc0(sizeof(sink_environment), error); if (!sinkenv) goto error_free_env; sinkenv->sink = osync_plugin_info_nth_objtype(info, i); osync_assert(sinkenv->sink); const char *objtype = osync_objtype_sink_get_name(sinkenv->sink); OSyncPluginResource *res = osync_plugin_config_find_active_resource(config, objtype); /* get objformat sinks */ OSyncList *s = osync_plugin_resource_get_objformat_sinks(res); for (; s; s = s->next) { OSyncObjFormatSink *fsink = s->data; // there could be only one sink const char *objformat = osync_objformat_sink_get_objformat(fsink); osync_assert(objformat); osync_trace(TRACE_INTERNAL, "objtype %s has objformat %s", objtype, objformat); } /* Every sink can have different functions ... */ OSyncObjTypeSinkFunctions functions; memset(&functions, 0, sizeof(functions)); functions.connect = connect; functions.disconnect = disconnect; functions.get_changes = get_changes; functions.commit = commit_change; functions.sync_done = sync_done; /* We pass the OSyncFileDir object to the sink, so we dont have to look it up * again once the functions are called */ osync_objtype_sink_set_functions(sinkenv->sink, functions, sinkenv); osync_trace(TRACE_INTERNAL, "The configdir: %s", osync_plugin_info_get_configdir(info)); char *tablepath = osync_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); sinkenv->hashtable = osync_hashtable_new(tablepath, objtype, error); osync_free(tablepath); env->sink_envs = osync_list_append(env->sink_envs, sinkenv); } //Now your return your struct. return (void *) env; error_free_env: free_env(env); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; }