void start_cfg(void) { const char *home; int quiet = 0; cfg_cmd_q = cmdq_new(NULL); cfg_cmd_q->emptyfn = cfg_default_done; cfg_finished = 0; cfg_references = 1; cfg_client = TAILQ_FIRST(&clients); if (cfg_client != NULL) cfg_client->references++; load_cfg(TMUX_CONF, cfg_cmd_q, 1); if (cfg_file == NULL && (home = find_home()) != NULL) { xasprintf(&cfg_file, "%s/.tmux.conf", home); quiet = 1; } if (cfg_file != NULL) load_cfg(cfg_file, cfg_cmd_q, quiet); cmdq_continue(cfg_cmd_q); }
static void tool_initialization(int argc, const char* argv[]) { atexit(cleanup_routine); #if !defined(WIN32_BUILD) || defined(__CYGWIN__) // Define alternate stack stack_t alternate_stack; // Allocate a maximum of 1 Mbyte or more if MINSIGSTKSZ was // bigger than that (this is unlikely) int allocated_size = 1024 * 1024; if (MINSIGSTKSZ > 1024*1024) { allocated_size = MINSIGSTKSZ; } _alternate_signal_stack = malloc(allocated_size); alternate_stack.ss_flags = 0; alternate_stack.ss_size = allocated_size; alternate_stack.ss_sp = (void*)_alternate_signal_stack; if (alternate_stack.ss_sp == 0 || sigaltstack(&alternate_stack, /* oss */ NULL) != 0) { running_error("Setting alternate signal stack failed (%s)\n", strerror(errno)); } // Program signals struct sigaction terminating_sigaction; memset(&terminating_sigaction, 0, sizeof(terminating_sigaction)); terminating_sigaction.sa_handler = terminating_signal_handler; // Use alternate stack and we want the signal be reset when it happens terminating_sigaction.sa_flags = SA_RESETHAND | SA_ONSTACK; // Block all blockable signals while handling the termination sigfillset(&terminating_sigaction.sa_mask); int result = 0; result |= sigaction(SIGSEGV, &terminating_sigaction, /* old_sigaction */ NULL); result |= sigaction(SIGQUIT, &terminating_sigaction, /* old_sigaction */ NULL); result |= sigaction(SIGINT, &terminating_sigaction, /* old_sigaction */ NULL); result |= sigaction(SIGTERM, &terminating_sigaction, /* old_sigaction */ NULL); result |= sigaction(SIGABRT, &terminating_sigaction, /* old_sigaction */ NULL); if (result != 0) { running_error("Signal programming failed with '%s'\n", strerror(errno)); } #endif memset(&compilation_process, 0, sizeof(compilation_process)); compilation_process.argc = argc; compilation_process.argv = (const char**)argv; compilation_process.exec_basename = give_basename(argv[0]); // Find my own directory compilation_process.home_directory = find_home(argv[0]); }
void start_cfg(void) { char *cause = NULL; const char *home; cfg_cmd_q = cmdq_new(NULL); cfg_cmd_q->emptyfn = cfg_default_done; cfg_finished = 0; cfg_references = 1; cfg_client = TAILQ_FIRST(&clients); if (cfg_client != NULL) cfg_client->references++; if (access(TMUX_CONF, R_OK) == 0) { if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) cfg_add_cause("%s: %s", TMUX_CONF, cause); } else if (errno != ENOENT) cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno)); if (cfg_file == NULL && (home = find_home()) != NULL) { xasprintf(&cfg_file, "%s/.tmux.conf", home); if (access(cfg_file, R_OK) != 0 && errno == ENOENT) { free(cfg_file); cfg_file = NULL; } } if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) cfg_add_cause("%s: %s", cfg_file, cause); free(cause); cmdq_continue(cfg_cmd_q); }
void Elevator::operateElevator() { if(m_homeState == homingComplete) { controlElevator(); } else { find_home(); } }
/*@only@*/ char *tildeexpand(const char *name) { char *tmp; const char *home; size_t l, tl; if (!tilde_expand) return xstrdup(name); if (name[0] != '~') return xstrdup(name); /* figure length of user name */ l = strspn(&name[1], "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789._-"); /* Portable Filename Character Set */ if (l > 0) { /* got a parameter to the tilde */ tmp = (char *)xmalloc(l + 1); memcpy(tmp, &name[1], l); /* we want exactly the first l characters but as C string, * so stuff the NUL byte */ tmp[l] = '\0'; home = find_home_user(tmp); xfree(tmp); } else { /* plain tilde */ home = find_home(false); } if (home == NULL) { return xstrdup(name); } tl = strlen(name) + strlen(home) - l + 1; tmp = (char *)xmalloc(tl); (void)strlcpy(tmp, home, tl); /* no need to insert a slash here, name[l] contains one */ if (strlcat(tmp, name + l + 1, tl) >= tl) internal_error; return tmp; }
/* Find the history file to load/save from/to. */ static char * status_prompt_find_history_file(void) { const char *home, *history_file; char *path; history_file = options_get_string(global_options, "history-file"); if (*history_file == '\0') return (NULL); if (*history_file == '/') return (xstrdup(history_file)); if (history_file[0] != '~' || history_file[1] != '/') return (NULL); if ((home = find_home()) == NULL) return (NULL); xasprintf(&path, "%s%s", home, history_file + 1); return (path); }
/* Start a job running, if it isn't already. */ struct job * job_run(const char *cmd, struct session *s, const char *cwd, void (*callbackfn)(struct job *), void (*freefn)(void *), void *data) { struct job *job; struct environ *env; pid_t pid; int nullfd, out[2]; const char *home; if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0) return (NULL); env = environ_create(); environ_copy(global_environ, env); if (s != NULL) environ_copy(s->environ, env); server_fill_environ(s, env); switch (pid = fork()) { case -1: environ_free(env); close(out[0]); close(out[1]); return (NULL); case 0: /* child */ clear_signals(1); if (cwd == NULL || chdir(cwd) != 0) { if ((home = find_home()) == NULL || chdir(home) != 0) chdir("/"); } environ_push(env); environ_free(env); if (dup2(out[1], STDIN_FILENO) == -1) fatal("dup2 failed"); if (dup2(out[1], STDOUT_FILENO) == -1) fatal("dup2 failed"); if (out[1] != STDIN_FILENO && out[1] != STDOUT_FILENO) close(out[1]); close(out[0]); nullfd = open(_PATH_DEVNULL, O_RDWR, 0); if (nullfd < 0) fatal("open failed"); if (dup2(nullfd, STDERR_FILENO) == -1) fatal("dup2 failed"); if (nullfd != STDERR_FILENO) close(nullfd); closefrom(STDERR_FILENO + 1); execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL); fatal("execl failed"); } /* parent */ environ_free(env); close(out[1]); job = xmalloc(sizeof *job); job->state = JOB_RUNNING; job->cmd = xstrdup(cmd); job->pid = pid; job->status = 0; LIST_INSERT_HEAD(&all_jobs, job, lentry); job->callbackfn = callbackfn; job->freefn = freefn; job->data = data; job->fd = out[0]; setblocking(job->fd, 0); job->event = bufferevent_new(job->fd, NULL, job_write_callback, job_callback, job); bufferevent_enable(job->event, EV_READ|EV_WRITE); log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid); return (job); }
int main(int argc, char **argv) { char *s, *path, *label, **var, tmp[PATH_MAX]; char in[256]; const char *home; long long pid; int opt, flags, keys, session; #if defined(DEBUG) && defined(__OpenBSD__) malloc_options = (char *) "AFGJPX"; #endif setlocale(LC_TIME, ""); flags = 0; label = path = NULL; login_shell = (**argv == '-'); while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUVv")) != -1) { switch (opt) { case '2': flags |= CLIENT_256COLOURS; break; case 'c': free(shell_cmd); shell_cmd = xstrdup(optarg); break; case 'C': if (flags & CLIENT_CONTROL) flags |= CLIENT_CONTROLCONTROL; else flags |= CLIENT_CONTROL; break; case 'V': printf("%s %s\n", __progname, VERSION); exit(0); case 'f': free(cfg_file); cfg_file = xstrdup(optarg); break; case 'l': login_shell = 1; break; case 'L': free(label); label = xstrdup(optarg); break; case 'q': break; case 'S': free(path); path = xstrdup(optarg); break; case 'u': flags |= CLIENT_UTF8; break; case 'v': debug_level++; break; default: usage(); } } argc -= optind; argv += optind; if (shell_cmd != NULL && argc != 0) usage(); if (!(flags & CLIENT_UTF8)) { /* * If the user has set whichever of LC_ALL, LC_CTYPE or LANG * exist (in that order) to contain UTF-8, it is a safe * assumption that either they are using a UTF-8 terminal, or * if not they know that output from UTF-8-capable programs may * be wrong. */ if ((s = getenv("LC_ALL")) == NULL || *s == '\0') { if ((s = getenv("LC_CTYPE")) == NULL || *s == '\0') s = getenv("LANG"); } if (s != NULL && (strcasestr(s, "UTF-8") != NULL || strcasestr(s, "UTF8") != NULL)) flags |= CLIENT_UTF8; } environ_init(&global_environ); for (var = environ; *var != NULL; var++) environ_put(&global_environ, *var); if (getcwd(tmp, sizeof tmp) != NULL) environ_set(&global_environ, "PWD", tmp); options_init(&global_options, NULL); options_table_populate_tree(server_options_table, &global_options); options_init(&global_s_options, NULL); options_table_populate_tree(session_options_table, &global_s_options); options_set_string(&global_s_options, "default-shell", "%s", getshell()); options_init(&global_w_options, NULL); options_table_populate_tree(window_options_table, &global_w_options); /* Enable UTF-8 if the first client is on UTF-8 terminal. */ if (flags & CLIENT_UTF8) { options_set_number(&global_s_options, "status-utf8", 1); options_set_number(&global_s_options, "mouse-utf8", 1); options_set_number(&global_w_options, "utf8", 1); } /* Override keys to vi if VISUAL or EDITOR are set. */ if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) { if (strrchr(s, '/') != NULL) s = strrchr(s, '/') + 1; if (strstr(s, "vi") != NULL) keys = MODEKEY_VI; else keys = MODEKEY_EMACS; options_set_number(&global_s_options, "status-keys", keys); options_set_number(&global_w_options, "mode-keys", keys); } /* Locate the configuration file. */ if (cfg_file == NULL) { home = find_home(); if (home != NULL) { xasprintf(&cfg_file, "%s/.tmux.conf", home); if (access(cfg_file, R_OK) != 0 && errno == ENOENT) { free(cfg_file); cfg_file = NULL; } } } /* Get path from environment. */ s = getenv("TMUX"); if (s != NULL && sscanf(s, "%255[^,],%lld,%d", in, &pid, &session) == 3) environ_path = xstrdup(in); /* * Figure out the socket path. If specified on the command-line with -S * or -L, use it, otherwise try $TMUX or assume -L default. */ if (path == NULL) { /* If no -L, use the environment. */ if (label == NULL) { if (environ_path != NULL) path = xstrdup(environ_path); else label = xstrdup("default"); } /* -L or default set. */ if (label != NULL) { if ((path = makesocketpath(label)) == NULL) { fprintf(stderr, "can't create socket: %s\n", strerror(errno)); exit(1); } } } free(label); if (strlcpy(socket_path, path, sizeof socket_path) >= sizeof socket_path) { fprintf(stderr, "socket path too long: %s\n", path); exit(1); } free(path); #ifdef HAVE_SETPROCTITLE /* Set process title. */ setproctitle("%s (%s)", __progname, socket_path); #endif /* Pass control to the client. */ ev_base = osdep_event_init(); exit(client_main(argc, argv, flags)); }
/* Start a job running, if it isn't already. */ struct job * job_run(const char *cmd, struct session *s, const char *cwd, job_update_cb updatecb, job_complete_cb completecb, job_free_cb freecb, void *data) { struct job *job; struct environ *env; pid_t pid; int nullfd, out[2]; const char *home; if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0) return (NULL); /* * Do not set TERM during .tmux.conf, it is nice to be able to use * if-shell to decide on default-terminal based on outside TERM. */ env = environ_for_session(s, !cfg_finished); switch (pid = fork()) { case -1: environ_free(env); close(out[0]); close(out[1]); return (NULL); case 0: /* child */ clear_signals(1); if (cwd == NULL || chdir(cwd) != 0) { if ((home = find_home()) == NULL || chdir(home) != 0) chdir("/"); } environ_push(env); environ_free(env); if (dup2(out[1], STDIN_FILENO) == -1) fatal("dup2 failed"); if (dup2(out[1], STDOUT_FILENO) == -1) fatal("dup2 failed"); if (out[1] != STDIN_FILENO && out[1] != STDOUT_FILENO) close(out[1]); close(out[0]); nullfd = open(_PATH_DEVNULL, O_RDWR, 0); if (nullfd < 0) fatal("open failed"); if (dup2(nullfd, STDERR_FILENO) == -1) fatal("dup2 failed"); if (nullfd != STDERR_FILENO) close(nullfd); closefrom(STDERR_FILENO + 1); execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL); fatal("execl failed"); } /* parent */ environ_free(env); close(out[1]); job = xmalloc(sizeof *job); job->state = JOB_RUNNING; job->cmd = xstrdup(cmd); job->pid = pid; job->status = 0; LIST_INSERT_HEAD(&all_jobs, job, entry); job->updatecb = updatecb; job->completecb = completecb; job->freecb = freecb; job->data = data; job->fd = out[0]; setblocking(job->fd, 0); job->event = bufferevent_new(job->fd, job_read_callback, job_write_callback, job_error_callback, job); bufferevent_enable(job->event, EV_READ|EV_WRITE); log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid); return (job); }
int main( int argc, char *argv[] ) { #ifdef __linux__ if (!gtk_init_check(&argc, &argv)) { printf("GTK is sad :-(\n"); return 0; } #endif #ifdef __HAIKU__ // Fix for haiku not starting apps in their home directory find_home(); #endif if( hively_init() ) { SDL_Flip(ssrf); quitting = FALSE; while( !quitting ) { if (needaflip) { SDL_Flip(ssrf); needaflip = FALSE; } if( !SDL_WaitEvent( &event ) ) break; do { switch( event.type ) { case SDL_QUIT: quitting = gui_maybe_quit(); break; default: if (aboutwin_open) about_handler(0); else gui_handler(0); break; } } while (SDL_PollEvent(&event)); if( pref_dorestart ) { if( !gui_restart() ) quitting = TRUE; pref_dorestart = FALSE; } } rp_stop(); } hively_shutdown(); return 0; }