X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Finvitation.c;fp=src%2Finvitation.c;h=110e3953be34be066c0add8ce0785db69d838f09;hp=a94460e86ea23fa15ddbfdd10349028b21ced84d;hb=2e318f379992a730f592b4c5261d26d8e1a38cfd;hpb=00398a60ec317740bcec83c5a524c5a95ce7f1c2 diff --git a/src/invitation.c b/src/invitation.c index a94460e8..110e3953 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -142,12 +142,19 @@ char *get_my_hostname() { } } + if(!tty) { + if(!hostname) { + fprintf(stderr, "Could not determine the external address or hostname. Please set Address manually.\n"); + return NULL; + } + goto save; + } + again: - printf("Please enter your host's external address or hostname"); + fprintf(stderr, "Please enter your host's external address or hostname"); if(hostname) - printf(" [%s]", hostname); - printf(": "); - fflush(stdout); + fprintf(stderr, " [%s]", hostname); + fprintf(stderr, ": "); if(!fgets(line, sizeof line, stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); @@ -571,7 +578,7 @@ make_names: if(!access(tinc_conf, F_OK)) { fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf); - if(!tty || confbasegiven) + if(confbasegiven) return false; // Generate a random netname, ask for a better one later. @@ -747,7 +754,7 @@ make_names: check_port(name); ask_netname: - if(ask_netname) { + if(ask_netname && tty) { fprintf(stderr, "Enter a new netname: "); if(!fgets(line, sizeof line, stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); @@ -771,6 +778,8 @@ ask_netname: make_names(); } + fprintf(stderr, "Configuration stored in: %s\n", confbase); + return true; } @@ -854,10 +863,8 @@ int cmd_join(int argc, char *argv[]) { if(argc > 1) { invitation = argv[1]; } else { - if(tty) { - printf("Enter invitation URL: "); - fflush(stdout); - } + if(tty) + fprintf(stderr, "Enter invitation URL: "); errno = EPIPE; if(!fgets(line, sizeof line, stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));