Commit b0bf0f18 authored by Timothy Stack's avatar Timothy Stack

Before tippty exits, remove the '/dev/tip/<node>' symlink. Also,

daemonize after making the connection to capture so an error is
reported if it cannot connect.
parent 0fd7327b
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2004, 2005 University of Utah and the Flux Group.
* All rights reserved.
*/
#include "config.h" #include "config.h"
...@@ -112,11 +117,18 @@ static void pack_buffer(buffer_t *buffer, int amount); ...@@ -112,11 +117,18 @@ static void pack_buffer(buffer_t *buffer, int amount);
static void dotippty(char *nodename); static void dotippty(char *nodename);
static char pidfilename[1024] = ""; static char pidfilename[1024] = "";
static char linkpath[128] = "";
static void sigquit(int sig) static void cleanup_atexit(void)
{ {
if (strlen(pidfilename) > 0) if (strlen(pidfilename) > 0)
unlink(pidfilename); unlink(pidfilename);
if (strlen(linkpath) > 0)
unlink(linkpath);
}
static void sigquit(int sig)
{
exit(0); exit(0);
} }
#endif #endif
...@@ -128,9 +140,12 @@ int main( int argc, char ** argv ) ...@@ -128,9 +140,12 @@ int main( int argc, char ** argv )
#if defined(LOCALBYDEFAULT) || defined(TIPPTY) #if defined(LOCALBYDEFAULT) || defined(TIPPTY)
localmode++; localmode++;
#if defined(TIPPTY)
atexit(cleanup_atexit);
#endif
#endif #endif
while ((op = getopt( argc, argv, "hlsp:rdu:c:" )) != -1) { while ((op = getopt( argc, argv, "hlp:rdu:c:" )) != -1) {
switch (op) { switch (op) {
case 'h': case 'h':
usage(name); usage(name);
...@@ -197,32 +212,18 @@ int main( int argc, char ** argv ) ...@@ -197,32 +212,18 @@ int main( int argc, char ** argv )
doConnect(); doConnect();
} }
#if defined(TIPPTY)
if (!debug) {
FILE *file;
daemon(0, 0);
signal(SIGINT, sigquit);
signal(SIGTERM, sigquit);
signal(SIGQUIT, sigquit);
snprintf(pidfilename, sizeof(pidfilename),
"%s/tippty.%s.pid",
_PATH_VARRUN, argv[0]);
if ((file = fopen(pidfilename, "w")) != NULL) {
fprintf(file, "%d\n", getpid());
fclose(file);
}
}
#endif
if (user && (getuid() == 0)) { if (user && (getuid() == 0)) {
struct passwd *pw; struct passwd *pw;
struct group *gr; struct group *gr;
uid_t uid; uid_t uid;
int rc; int rc;
if ((sscanf(user, "%d", &uid) == 1 && (pw = getpwuid(uid)) == NULL) && if (sscanf(user, "%d", &uid) == 1)
(pw = getpwnam(user)) == NULL) { pw = getpwuid(uid);
else
pw = getpwnam(user);
if (pw == NULL) {
fprintf(stderr, "invalid user: %s %d\n", user, uid); fprintf(stderr, "invalid user: %s %d\n", user, uid);
exit(1); exit(1);
} }
...@@ -244,7 +245,7 @@ int main( int argc, char ** argv ) ...@@ -244,7 +245,7 @@ int main( int argc, char ** argv )
} }
if (uploadmode) { if (uploadmode) {
int fd = 0; int fd = STDIN_FILENO;
if ((strcmp(argv[1], "-") != 0) && (fd = open(argv[1], O_RDONLY)) < 0) { if ((strcmp(argv[1], "-") != 0) && (fd = open(argv[1], O_RDONLY)) < 0) {
fprintf(stderr, "Cannot open file: %s\n", argv[1]); fprintf(stderr, "Cannot open file: %s\n", argv[1]);
...@@ -258,6 +259,7 @@ int main( int argc, char ** argv ) ...@@ -258,6 +259,7 @@ int main( int argc, char ** argv )
writeFunc(buf, rc); writeFunc(buf, rc);
} }
close(fd); close(fd);
fd = -1;
} }
exit(0); exit(0);
} }
...@@ -265,6 +267,22 @@ int main( int argc, char ** argv ) ...@@ -265,6 +267,22 @@ int main( int argc, char ** argv )
doAuthenticate(); doAuthenticate();
#if defined(TIPPTY) #if defined(TIPPTY)
if (!debug) {
FILE *file;
daemon(0, 0);
signal(SIGINT, sigquit);
signal(SIGTERM, sigquit);
signal(SIGQUIT, sigquit);
snprintf(pidfilename, sizeof(pidfilename),
"%s/tippty.%s.pid",
_PATH_VARRUN, argv[0]);
if ((file = fopen(pidfilename, "w")) != NULL) {
fprintf(file, "%d\n", getpid());
fclose(file);
}
}
dotippty(argv[0]); dotippty(argv[0]);
#else #else
doCreateTunnel(); doCreateTunnel();
...@@ -289,7 +307,7 @@ int main( int argc, char ** argv ) ...@@ -289,7 +307,7 @@ int main( int argc, char ** argv )
char * foo; char * foo;
for (foo = programToLaunch; *foo; foo++) { for (foo = programToLaunch; *foo; foo++) {
if (*foo == '@') { *foo = '%'; } if (*foo == '@') { *foo = '%'; break; }
} }
sprintf(runString, programToLaunch, portString); sprintf(runString, programToLaunch, portString);
...@@ -836,7 +854,6 @@ static void dotippty(char *nodename) ...@@ -836,7 +854,6 @@ static void dotippty(char *nodename)
buffer_t from_pty = { .inuse = 0 }, to_pty = { .inuse = 0 }; buffer_t from_pty = { .inuse = 0 }, to_pty = { .inuse = 0 };
int tweaked = 0, fd_count = 2; int tweaked = 0, fd_count = 2;
struct timeval now, before; struct timeval now, before;
char linkpath[128];
fcntl(master, F_SETFL, O_NONBLOCK); fcntl(master, F_SETFL, O_NONBLOCK);
fcntl(sock, F_SETFL, O_NONBLOCK); fcntl(sock, F_SETFL, O_NONBLOCK);
...@@ -865,7 +882,7 @@ static void dotippty(char *nodename) ...@@ -865,7 +882,7 @@ static void dotippty(char *nodename)
/* No slave connection. */ /* No slave connection. */
if (pf[0].revents & POLLIN) // Drain the input side. if (pf[0].revents & POLLIN) // Drain the input side.
rc = readFunc(to_pty.data, sizeof(to_pty.data)); rc = readFunc(to_pty.data, sizeof(to_pty.data));
if (rc < 0) if (rc <= 0)
exit(0); exit(0);
if ((pf[0].revents & POLLOUT) && from_pty.inuse > 0) { if ((pf[0].revents & POLLOUT) && from_pty.inuse > 0) {
// Drain our buffer to the output. // Drain our buffer to the output.
...@@ -888,6 +905,11 @@ static void dotippty(char *nodename) ...@@ -888,6 +905,11 @@ static void dotippty(char *nodename)
} }
else { else {
if (!tweaked) { if (!tweaked) {
/*
* XXX This next bit is a brutal hack to forcefully turn off echo on
* the pseudo terminal. Otherwise we get a nasty loop of data
* echoing back and forth.
*/
if ((slave = open(path, O_RDONLY)) >= 0) { if ((slave = open(path, O_RDONLY)) >= 0) {
struct termios tio; struct termios tio;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment