Index: bgrd.c ================================================================== --- bgrd.c +++ bgrd.c @@ -168,14 +168,13 @@ } child: { close(rd); - // redirect stdout and stderr to our pty master + // redirect stdout (NOT stderr) to our pty master dup2(wr, 1); - dup2(wr, 2); close(wr); execv(argv[1],argv+2); return 1; // THIS SHOULD NEVER HAPPEN } } Index: xpriv.c ================================================================== --- xpriv.c +++ xpriv.c @@ -144,11 +144,26 @@ struct termios initial_state; void sigusr(int a) { if (global -> op == mode_kill) run = false; } void sigterm(int a) { run = false; } -enum res register_window(const char* id, bool weak) { +void spawn(pid_t ssha, const char* const sockn) { + if (ssha = fork()) { + char pid_s_buf[16]; + char* pid_s = itoa(ssha, pid_s_buf, sizeof(pid_s_buf)); + while (access(sockn, F_OK)); + // avoid nasty race condition + setenv("SSH_AGENT_PID", pid_s, true); + setenv("SSH_AUTH_SOCK", sockn, true); + global -> agent = ssha; + } else { + close(1); close(0); + execlp("ssh-agent","ssh-agent","-D", "-a",sockn,0); + } +} + +enum res register_window(const char* const id, bool weak, const char* const name) { // the id field denotes the path to the shared memory // in use, and allows the user to have multiple // contexts by creating aliases to the binary int fd = shm_open(id, O_CREAT | O_EXCL | O_RDWR, 0600); ftruncate(fd, sizeof(struct signal)); @@ -204,11 +219,12 @@ } else { // now we start ssh-agent and set the proper environment // variables pid_t ssha; - /* messy part */ { + if (name == NULL) { + /* messy part */ const char* tmp; //tmpdir defined? if (!(tmp = getenv("TMPDIR"))) tmp = "/tmp"; size_t tmpsz = strlen(tmp); char sockn[tmpsz + 1 + sizeof "ssh." @@ -227,24 +243,13 @@ *i = '0' + (*i % (25 * 2 + 10)); if (*i > '9') *i += 7; if (*i > 'Z') *i += ('a' - 'Z'); } - if (ssha = fork()) { - char pid_s_buf[16]; - char* pid_s = itoa(ssha, pid_s_buf, sizeof(pid_s_buf)); - while (access(sockn, F_OK)); - // avoid nasty race condition - setenv("SSH_AGENT_PID", pid_s, true); - setenv("SSH_AUTH_SOCK", sockn, true); - s -> agent = ssha; - } else { - close(1); close(0); - execlp("ssh-agent","ssh-agent","-D", "-a",sockn,0); - } - } - + spawn(ssha, sockn); + } else spawn(ssha, name); + pid_t sad; int p; if (sad = fork()) { int added; waitpid(sad, &added, 0); @@ -298,22 +303,29 @@ } int main(int sz, char** argv) { enum mode op = mode_go; bool init_weak = false; + const char* init_named = NULL; for(int i = 1; iwid)); } } else if (op == mode_register) - return bad(register_window(shid,init_weak)); + return bad(register_window(shid,init_weak,init_named)); else if (op == mode_kill) return bad(kill_window(shid)); else if (op == mode_usage) { write(1,"\e[1musage:\e[0m ",15); write(1, argv[0], strlen(argv[0]));