int get_terminal_state(struct steal_pty_state *steal, pid_t target) { struct procstat *procstat; struct kinfo_proc *kp; unsigned int cnt; int err = 0; procstat = procstat_open_sysctl(); kp = procstat_getprocs(procstat, KERN_PROC_PID, target, &cnt); if (kp == NULL || cnt < 1) goto done; if (kp->ki_tdev == NODEV) { error("Child is not connected to a pseudo-TTY. Unable to steal TTY."); err = EINVAL; goto done; } if ((err = find_terminal_emulator(steal))) return err; done: procstat_freeprocs(procstat, kp); procstat_close(procstat); return err; }
int get_terminal_state(struct steal_pty_state *steal, pid_t target) { int err; if ((err = read_proc_stat(target, &steal->target_stat))) return err; if (major(steal->target_stat.ctty) != UNIX98_PTY_SLAVE_MAJOR) { error("Child is not connected to a pseudo-TTY. Unable to steal TTY."); return EINVAL; } if ((err = find_terminal_emulator(steal))) return err; return 0; }
int main(int argc, char **argv) { struct stat st; int i; int *previousDepth; prog_name = argv[0]; plMenuNodes = WMCreateArray(8); /* grows on demand */ menu = (WMTreeNode *)NULL; parse = NULL; validateFilename = NULL; /* assemblePLMenuFunc passes this around */ previousDepth = (int *)wmalloc(sizeof(int)); *previousDepth = -1; /* currently this is used only by the xdg parser, but it might be useful * in the future localizing other menus, so it won't hurt to have it here. */ parse_locale(NULL, &env_lang, &env_ctry, &env_enc, &env_mod); terminal = find_terminal_emulator(); for (i = 1; i < argc; i++) { if (strncmp(argv[i], "-parser", 7) == 0 && (argv[i][7] == '=' || argv[i][7] == ':' || /* for legacy compatibility */ argv[i][7] == '\0')) { const char *name; if (argv[i][7] == '\0') { if (++i > argc) { fprintf(stderr, "%s: Missing parser name after \"-parser\"\n", prog_name); return 2; } name = argv[i]; } else { name = argv[i] + 8; } if (strcmp(name, "xdg") == 0) { parse = &parse_xdg; } else if (strcmp(name, "wmconfig") == 0) { parse = &parse_wmconfig; validateFilename = &wmconfig_validate_file; } else { fprintf(stderr, "%s: Unknown parser \"%s\"\n", prog_name, name); return 2; } continue; } if (strcmp(argv[i], "--version") == 0) { printf("%s (Window Maker %s)\n", prog_name, VERSION); return 0; } if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0) { print_help(); return 0; } if (parse == NULL) { fprintf(stderr, "%s: argument \"%s\" with no valid parser\n", prog_name, argv[i]); return 2; } #if DEBUG fprintf(stderr, "%s: Using parser \"%s\" to process \"%s\"\n", prog_name, get_parser_name(), argv[i]); #endif if (stat(argv[i], &st) == -1) { fprintf(stderr, "%s: unable to stat \"%s\", %s\n", prog_name, argv[i], strerror(errno)); return 1; } else if (S_ISREG(st.st_mode)) { parse(argv[i], addWMMenuEntryCallback); } else if (S_ISDIR(st.st_mode)) { nftw(argv[i], dirParseFunc, 16, FTW_PHYS); } else { fprintf(stderr, "%s: \"%s\" is not a file or directory\n", prog_name, argv[i]); return 1; } } if (!menu) { fprintf(stderr, "%s: parsers failed to create a valid menu\n", prog_name); return 1; } WMSortTree(menu, menuSortFunc); WMTreeWalk(menu, assemblePLMenuFunc, previousDepth, True); i = WMGetArrayItemCount(plMenuNodes); if (i > 2) { /* more than one submenu unprocessed is almost certainly an error */ fprintf(stderr, "%s: unprocessed levels on the stack. fishy.\n", prog_name); return 3; } else if (i > 1 ) { /* possibly the top-level attachment is not yet done */ WMPropList *first, *next; next = WMPopFromArray(plMenuNodes); first = WMPopFromArray(plMenuNodes); WMAddToPLArray(first, next); WMAddToArray(plMenuNodes, first); } puts(WMGetPropListDescription((WMPropList *)WMGetFromArray(plMenuNodes, 0), True)); return 0; }