2013-09-29 00:21:18 +04:00
|
|
|
/* v/main.c
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <gmp.h>
|
|
|
|
#include <stdint.h>
|
2018-03-21 05:23:33 +03:00
|
|
|
#include <limits.h>
|
2013-09-29 00:21:18 +04:00
|
|
|
#include <uv.h>
|
|
|
|
#include <sigsegv.h>
|
|
|
|
#include <curses.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <term.h>
|
|
|
|
#include <dirent.h>
|
2015-10-31 15:17:04 +03:00
|
|
|
#include <openssl/ssl.h>
|
2018-03-12 19:16:44 +03:00
|
|
|
#include <openssl/rand.h>
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2018-03-12 19:09:49 +03:00
|
|
|
#include "h2o.h"
|
|
|
|
|
2014-11-05 03:29:08 +03:00
|
|
|
#define U3_GLOBAL
|
2013-09-29 00:21:18 +04:00
|
|
|
#define C3_GLOBAL
|
|
|
|
#include "all.h"
|
2015-06-24 04:28:38 +03:00
|
|
|
#include "vere/vere.h"
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2018-03-21 05:23:33 +03:00
|
|
|
/* Require unsigned char
|
|
|
|
*/
|
|
|
|
STATIC_ASSERT(( 0 == CHAR_MIN && UCHAR_MAX == CHAR_MAX ), "unsigned char required");
|
|
|
|
|
2014-02-26 00:18:07 +04:00
|
|
|
/* _main_readw(): parse a word from a string.
|
|
|
|
*/
|
2014-11-06 06:10:22 +03:00
|
|
|
static u3_noun
|
2014-02-26 00:18:07 +04:00
|
|
|
_main_readw(const c3_c* str_c, c3_w max_w, c3_w* out_w)
|
|
|
|
{
|
2014-03-08 04:19:38 +04:00
|
|
|
c3_c* end_c;
|
|
|
|
c3_w par_w = strtoul(str_c, &end_c, 0);
|
2014-02-26 00:18:07 +04:00
|
|
|
|
2014-03-08 04:19:38 +04:00
|
|
|
if ( *str_c != '\0' && *end_c == '\0' && par_w < max_w ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
*out_w = par_w;
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3y;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
2014-11-05 04:18:47 +03:00
|
|
|
else return c3n;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-11-08 01:54:59 +03:00
|
|
|
static c3_c hostbuf[2048]; // kill me
|
|
|
|
|
2015-05-19 21:38:23 +03:00
|
|
|
/* _main_presig(): prefix optional sig.
|
|
|
|
*/
|
|
|
|
c3_c*
|
|
|
|
_main_presig(c3_c* txt_c)
|
|
|
|
{
|
|
|
|
c3_c* new_c = malloc(2 + strlen(txt_c));
|
|
|
|
|
|
|
|
if ( '~' == *txt_c ) {
|
|
|
|
strcpy(new_c, txt_c);
|
|
|
|
} else {
|
|
|
|
new_c[0] = '~';
|
|
|
|
strcpy(new_c + 1, txt_c);
|
|
|
|
}
|
|
|
|
return new_c;
|
|
|
|
}
|
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
/* _main_getopt(): extract option map from command line.
|
|
|
|
*/
|
2014-11-06 06:10:22 +03:00
|
|
|
static u3_noun
|
2013-09-29 00:21:18 +04:00
|
|
|
_main_getopt(c3_i argc, c3_c** argv)
|
|
|
|
{
|
|
|
|
c3_i ch_i;
|
2014-03-08 04:19:38 +04:00
|
|
|
c3_w arg_w;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
u3_Host.ops_u.abo = c3n;
|
|
|
|
u3_Host.ops_u.bat = c3n;
|
|
|
|
u3_Host.ops_u.dem = c3n;
|
2017-10-27 00:59:04 +03:00
|
|
|
u3_Host.ops_u.dry = c3n;
|
|
|
|
u3_Host.ops_u.fog = c3n;
|
|
|
|
u3_Host.ops_u.gab = c3n;
|
2017-10-30 13:17:14 +03:00
|
|
|
u3_Host.ops_u.git = c3n;
|
2018-10-02 02:56:14 +03:00
|
|
|
u3_Host.ops_u.has = c3n;
|
2017-10-31 03:41:48 +03:00
|
|
|
u3_Host.ops_u.net = c3n;
|
2017-10-27 00:59:04 +03:00
|
|
|
u3_Host.ops_u.mem = c3n;
|
|
|
|
u3_Host.ops_u.nuu = c3n;
|
2014-11-05 04:18:47 +03:00
|
|
|
u3_Host.ops_u.pro = c3n;
|
2015-05-20 03:04:08 +03:00
|
|
|
u3_Host.ops_u.qui = c3n;
|
2015-10-31 15:17:04 +03:00
|
|
|
u3_Host.ops_u.rep = c3n;
|
2017-10-27 00:59:04 +03:00
|
|
|
u3_Host.ops_u.tex = c3n;
|
|
|
|
u3_Host.ops_u.veb = c3n;
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_Host.ops_u.kno_w = DefaultKernel;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2018-10-10 18:18:54 +03:00
|
|
|
while ( (ch_i=getopt(argc, argv,"G:B:K:A:w:u:e:f:F:k:l:n:p:r:NabcdgqsvxMPDXRS")) != -1 ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
switch ( ch_i ) {
|
2014-07-30 21:53:30 +04:00
|
|
|
case 'M': {
|
2014-11-05 04:18:47 +03:00
|
|
|
u3_Host.ops_u.mem = c3y;
|
2014-07-30 21:53:30 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-01-26 20:50:32 +03:00
|
|
|
case 'B': {
|
|
|
|
u3_Host.ops_u.pil_c = strdup(optarg);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-24 21:56:44 +03:00
|
|
|
case 'G': {
|
|
|
|
u3_Host.ops_u.gen_c = strdup(optarg);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-29 20:04:57 +03:00
|
|
|
case 'A': {
|
|
|
|
u3_Host.ops_u.arv_c = strdup(optarg);
|
|
|
|
break;
|
|
|
|
}
|
2018-10-10 18:18:54 +03:00
|
|
|
case 'e': {
|
|
|
|
u3_Host.ops_u.eth_c = strdup(optarg);
|
|
|
|
break;
|
|
|
|
}
|
2018-08-10 19:58:21 +03:00
|
|
|
case 'F': {
|
|
|
|
u3_Host.ops_u.fak_c = _main_presig(optarg);
|
|
|
|
break;
|
|
|
|
}
|
2015-06-03 02:17:55 +03:00
|
|
|
case 'w': {
|
2015-05-19 21:38:23 +03:00
|
|
|
u3_Host.ops_u.who_c = _main_presig(optarg);
|
2015-06-06 05:29:05 +03:00
|
|
|
u3_Host.ops_u.nuu = c3y;
|
2015-06-03 02:17:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-10-27 19:19:39 +03:00
|
|
|
case 'u': {
|
2017-10-27 19:44:37 +03:00
|
|
|
u3_Host.ops_u.url_c = strdup(optarg);
|
|
|
|
break;
|
2017-10-27 19:19:39 +03:00
|
|
|
}
|
2015-10-27 00:03:14 +03:00
|
|
|
case 'x': {
|
|
|
|
u3_Host.ops_u.tex = c3y;
|
|
|
|
break;
|
|
|
|
}
|
2014-03-18 05:55:24 +04:00
|
|
|
case 'X': {
|
2015-10-27 00:03:14 +03:00
|
|
|
u3_Host.ops_u.fog = c3y;
|
2014-03-18 05:55:24 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-01-15 23:59:08 +04:00
|
|
|
case 'f': {
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == _main_readw(optarg, 100, &u3_Host.ops_u.fuz_w) ) {
|
|
|
|
return c3n;
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-09-07 04:35:17 +03:00
|
|
|
case 'K': {
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == _main_readw(optarg, 256, &u3_Host.ops_u.kno_w) ) {
|
|
|
|
return c3n;
|
2014-02-24 23:27:57 +04:00
|
|
|
}
|
2014-02-26 00:18:07 +04:00
|
|
|
break;
|
|
|
|
}
|
2018-10-29 18:48:05 +03:00
|
|
|
case 'k': {
|
|
|
|
u3_Host.ops_u.key_c = strdup(optarg);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-26 00:18:07 +04:00
|
|
|
case 'l': {
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == _main_readw(optarg, 65536, &arg_w) ) {
|
|
|
|
return c3n;
|
2014-09-11 04:01:32 +04:00
|
|
|
} else u3_Host.ops_u.rop_s = arg_w;
|
2014-01-17 22:12:42 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-01-17 21:42:47 +04:00
|
|
|
case 'n': {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_Host.ops_u.nam_c = strdup(optarg);
|
2014-01-17 21:42:47 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-01-15 21:16:50 +04:00
|
|
|
case 'p': {
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == _main_readw(optarg, 65536, &arg_w) ) {
|
|
|
|
return c3n;
|
2014-09-11 04:01:32 +04:00
|
|
|
} else u3_Host.ops_u.por_s = arg_w;
|
2014-01-15 21:16:50 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-02-26 00:18:07 +04:00
|
|
|
case 'r': {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_Host.ops_u.raf_c = strdup(optarg);
|
2014-02-26 00:18:07 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-10-31 15:17:04 +03:00
|
|
|
case 'R': {
|
|
|
|
u3_Host.ops_u.rep = c3y;
|
|
|
|
return c3y;
|
|
|
|
}
|
2017-10-31 03:41:48 +03:00
|
|
|
case 'N': { u3_Host.ops_u.net = c3y; break; }
|
2014-11-05 04:18:47 +03:00
|
|
|
case 'a': { u3_Host.ops_u.abo = c3y; break; }
|
|
|
|
case 'b': { u3_Host.ops_u.bat = c3y; break; }
|
|
|
|
case 'c': { u3_Host.ops_u.nuu = c3y; break; }
|
|
|
|
case 'd': { u3_Host.ops_u.dem = c3y; break; }
|
|
|
|
case 'g': { u3_Host.ops_u.gab = c3y; break; }
|
2014-11-29 05:19:11 +03:00
|
|
|
case 'P': { u3_Host.ops_u.pro = c3y; break; }
|
2014-12-01 03:06:08 +03:00
|
|
|
case 'D': { u3_Host.ops_u.dry = c3y; break; }
|
2015-05-20 03:04:08 +03:00
|
|
|
case 'q': { u3_Host.ops_u.qui = c3y; break; }
|
2014-11-05 04:18:47 +03:00
|
|
|
case 'v': { u3_Host.ops_u.veb = c3y; break; }
|
2017-10-30 13:17:14 +03:00
|
|
|
case 's': { u3_Host.ops_u.git = c3y; break; }
|
2018-10-02 02:56:14 +03:00
|
|
|
case 'S': { u3_Host.ops_u.has = c3y; break; }
|
2013-09-29 00:21:18 +04:00
|
|
|
case '?': default: {
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:08:43 +03:00
|
|
|
if ( 0 != u3_Host.ops_u.fak_c ) {
|
2018-10-18 01:56:12 +03:00
|
|
|
if ( 28 < strlen(u3_Host.ops_u.fak_c) ) {
|
|
|
|
fprintf(stderr, "fake comets are disallowed\r\n");
|
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:08:43 +03:00
|
|
|
u3_Host.ops_u.who_c = strdup(u3_Host.ops_u.fak_c);
|
2018-08-10 19:58:21 +03:00
|
|
|
}
|
|
|
|
|
2018-10-10 09:08:43 +03:00
|
|
|
c3_t imp_t = ( (0 != u3_Host.ops_u.who_c) && (4 == strlen(u3_Host.ops_u.who_c)) );
|
2018-08-10 19:58:21 +03:00
|
|
|
|
|
|
|
if ( (0 != u3_Host.ops_u.fak_c) && (c3n == u3_Host.ops_u.nuu) ) {
|
|
|
|
fprintf(stderr, "-F only makes sense on initial boot\n");
|
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XX revisit
|
|
|
|
if ( (0 == u3_Host.ops_u.fak_c) && (c3y == u3_Host.ops_u.net) ) {
|
2018-10-17 01:02:55 +03:00
|
|
|
// fprintf(stderr, "-N only makes sense with -F\n");
|
|
|
|
u3_Host.ops_u.net = c3n;
|
2018-08-10 19:58:21 +03:00
|
|
|
} else if ( (0 == u3_Host.ops_u.fak_c) && (c3n == u3_Host.ops_u.net) ) {
|
2017-10-31 03:41:48 +03:00
|
|
|
u3_Host.ops_u.net = c3y; /* remote networking is always on in real mode. */
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:08:43 +03:00
|
|
|
if ( u3_Host.ops_u.arv_c != 0 && !imp_t ) {
|
2016-10-25 03:23:43 +03:00
|
|
|
fprintf(stderr, "-A only makes sense when creating a new galaxy\n");
|
2016-08-29 20:04:57 +03:00
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:08:43 +03:00
|
|
|
if ( u3_Host.ops_u.arv_c == 0 && imp_t ) {
|
2016-08-29 20:04:57 +03:00
|
|
|
fprintf(stderr, "can't create a new galaxy without specifying "
|
|
|
|
"the initial sync path with -A\n");
|
|
|
|
return c3n;
|
|
|
|
}
|
2017-10-31 03:41:48 +03:00
|
|
|
|
2018-10-10 18:38:32 +03:00
|
|
|
if ( u3_Host.ops_u.gen_c != 0 && u3_Host.ops_u.nuu == c3n ) {
|
|
|
|
fprintf(stderr, "-G only makes sense when bootstrapping a new instance\n");
|
2016-10-24 21:56:44 +03:00
|
|
|
return c3n;
|
|
|
|
}
|
2017-10-31 03:41:48 +03:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( u3_Host.ops_u.rop_s == 0 && u3_Host.ops_u.raf_c != 0 ) {
|
2014-02-26 00:18:07 +04:00
|
|
|
fprintf(stderr, "The -r flag requires -l.\n");
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3n;
|
2014-02-26 00:18:07 +04:00
|
|
|
}
|
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == u3_Host.ops_u.bat ) {
|
|
|
|
u3_Host.ops_u.dem = c3y;
|
|
|
|
u3_Host.ops_u.nuu = c3y;
|
2014-01-16 05:41:30 +04:00
|
|
|
}
|
|
|
|
|
2016-01-27 00:31:26 +03:00
|
|
|
if ( u3_Host.ops_u.nuu != c3y && u3_Host.ops_u.pil_c != 0) {
|
2016-01-26 20:50:32 +03:00
|
|
|
fprintf(stderr, "-B only makes sense when bootstrapping a new instance\n");
|
|
|
|
return c3n;
|
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2018-09-07 04:35:17 +03:00
|
|
|
if ( u3_Host.ops_u.nuu != c3y && u3_Host.ops_u.key_c != 0) {
|
2018-10-29 18:48:05 +03:00
|
|
|
fprintf(stderr, "-k only makes sense when bootstrapping a new instance\n");
|
2018-09-07 04:35:17 +03:00
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:17:14 +03:00
|
|
|
if ( u3_Host.ops_u.nuu != c3y && u3_Host.ops_u.url_c != 0 ) {
|
2017-10-27 19:19:39 +03:00
|
|
|
fprintf(stderr, "-u only makes sense when bootstrapping a new instance\n");
|
|
|
|
return c3n;
|
2017-10-30 13:43:03 +03:00
|
|
|
|
2017-10-30 13:17:14 +03:00
|
|
|
} else if ( u3_Host.ops_u.nuu == c3y
|
|
|
|
&& u3_Host.ops_u.url_c == 0
|
|
|
|
&& u3_Host.ops_u.git == c3n ) {
|
2017-10-30 13:43:03 +03:00
|
|
|
|
2018-06-09 04:06:14 +03:00
|
|
|
u3_Host.ops_u.url_c = "https://bootstrap.urbit.org/urbit-" URBIT_VERSION ".pill";
|
2017-10-30 13:43:03 +03:00
|
|
|
|
|
|
|
} else if ( u3_Host.ops_u.nuu == c3y
|
|
|
|
&& u3_Host.ops_u.url_c == 0
|
|
|
|
&& u3_Host.ops_u.arv_c == 0 ) {
|
|
|
|
|
|
|
|
fprintf(stderr, "-s only makes sense with -A\n");
|
|
|
|
return c3n;
|
2017-10-27 19:19:39 +03:00
|
|
|
}
|
|
|
|
|
2016-01-27 00:36:22 +03:00
|
|
|
if ( u3_Host.ops_u.pil_c != 0 ) {
|
|
|
|
struct stat s;
|
|
|
|
if ( stat(u3_Host.ops_u.pil_c, &s) != 0 ) {
|
|
|
|
fprintf(stderr, "pill %s not found\n", u3_Host.ops_u.pil_c);
|
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 04:35:17 +03:00
|
|
|
if ( u3_Host.ops_u.key_c != 0 ) {
|
|
|
|
struct stat s;
|
|
|
|
if ( stat(u3_Host.ops_u.key_c, &s) != 0 ) {
|
|
|
|
fprintf(stderr, "keyfile %s not found\n", u3_Host.ops_u.key_c);
|
|
|
|
return c3n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( u3_Host.ops_u.nam_c == 0 ) {
|
|
|
|
u3_Host.ops_u.nam_c = getenv("HOSTNAME");
|
|
|
|
if ( u3_Host.ops_u.nam_c == 0 ) {
|
2014-01-17 21:42:47 +04:00
|
|
|
c3_w len_w = sysconf(_SC_HOST_NAME_MAX) + 1;
|
|
|
|
|
2014-11-08 01:54:59 +03:00
|
|
|
u3_Host.ops_u.nam_c = hostbuf;
|
2014-09-11 04:01:32 +04:00
|
|
|
if ( 0 != gethostname(u3_Host.ops_u.nam_c, len_w) ) {
|
2014-01-17 21:42:47 +04:00
|
|
|
perror("gethostname");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-16 07:28:22 +04:00
|
|
|
|
2015-11-20 00:01:58 +03:00
|
|
|
if ( argc != (optind + 1) && u3_Host.ops_u.who_c != 0 ) {
|
|
|
|
u3_Host.dir_c = strdup(1 + u3_Host.ops_u.who_c);
|
|
|
|
}
|
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
if ( argc != (optind + 1) ) {
|
2015-06-06 05:29:05 +03:00
|
|
|
return u3_Host.dir_c ? c3y : c3n;
|
2013-12-19 00:42:29 +04:00
|
|
|
} else {
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
c3_c* ash_c;
|
|
|
|
|
|
|
|
if ( (ash_c = strrchr(argv[optind], '/')) && (ash_c[1] == 0) ) {
|
|
|
|
*ash_c = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-16 04:10:15 +03:00
|
|
|
u3_Host.dir_c = strdup(argv[optind]);
|
2014-11-05 04:18:47 +03:00
|
|
|
return c3y;
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_ve_usage(): print usage and exit.
|
2013-09-29 00:21:18 +04:00
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ve_usage(c3_i argc, c3_c** argv)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2017-10-27 00:12:02 +03:00
|
|
|
c3_c *use_c[] = {
|
|
|
|
"Urbit: a personal server operating function\n",
|
|
|
|
"https://urbit.org\n",
|
|
|
|
"Version " URBIT_VERSION "\n",
|
|
|
|
"\n",
|
|
|
|
"Usage: %s [options...] ship_name\n",
|
|
|
|
"where ship_name is a @p phonetic representation of an urbit address\n",
|
|
|
|
"without the leading '~', and options is some subset of the following:\n",
|
|
|
|
"\n",
|
2016-08-29 20:11:10 +03:00
|
|
|
"-A dir Use dir for initial galaxy sync\n",
|
2017-10-27 00:31:22 +03:00
|
|
|
"-b Batch create\n",
|
|
|
|
"-B pill Bootstrap from this pill\n",
|
|
|
|
"-c pier Create a new urbit in pier/\n",
|
|
|
|
"-d Daemon mode\n",
|
|
|
|
"-D Recompute from events\n",
|
2018-10-18 00:28:46 +03:00
|
|
|
"-e url Ethereum gateway\n",
|
2018-08-10 19:58:21 +03:00
|
|
|
"-F ship Fake keys; also disables networking\n",
|
2017-10-27 00:31:22 +03:00
|
|
|
"-f Fuzz testing\n",
|
|
|
|
"-g Set GC flag\n",
|
2018-10-29 18:48:05 +03:00
|
|
|
"-K stage Start at Hoon kernel version stage\n",
|
|
|
|
"-k keys Private key file\n",
|
2017-10-27 00:31:22 +03:00
|
|
|
"-l port Initial peer port\n",
|
|
|
|
"-M Memory madness\n",
|
2015-10-07 07:39:38 +03:00
|
|
|
"-n host Set unix hostname\n",
|
2018-01-29 21:21:46 +03:00
|
|
|
"-N Enable networking in fake mode (-F)\n",
|
2018-10-18 00:28:46 +03:00
|
|
|
"-p ames_port Set the ames port to bind to\n",
|
2015-10-07 07:39:38 +03:00
|
|
|
"-P Profiling\n",
|
2017-10-27 00:31:22 +03:00
|
|
|
"-q Quiet\n",
|
2015-10-29 01:18:19 +03:00
|
|
|
"-r host Initial peer address\n",
|
2015-10-31 15:17:04 +03:00
|
|
|
"-R Report urbit build info\n",
|
2017-10-30 13:17:14 +03:00
|
|
|
"-s Pill URL from arvo git hash\n",
|
2017-10-27 19:19:39 +03:00
|
|
|
"-u url URL from which to download pill\n",
|
2017-10-27 00:31:22 +03:00
|
|
|
"-v Verbose\n",
|
2018-10-18 00:28:46 +03:00
|
|
|
"-w name Boot as ~name\n",
|
2017-10-27 00:31:22 +03:00
|
|
|
"-x Exit immediately\n",
|
2017-10-27 00:12:02 +03:00
|
|
|
"-Xwtf Skip last event\n",
|
|
|
|
"\n",
|
|
|
|
"Development Usage:\n",
|
|
|
|
" To create a development ship, use a fakezod:\n",
|
|
|
|
" %s -FI zod -A /path/to/arvo/folder -B /path/to/pill -c zod\n",
|
|
|
|
"\n",
|
|
|
|
" For more information about developing on urbit, see:\n",
|
|
|
|
" https://github.com/urbit/urbit/blob/master/CONTRIBUTING.md\n",
|
|
|
|
"\n",
|
|
|
|
"Simple Usage: \n",
|
2015-11-17 06:29:27 +03:00
|
|
|
" %s -c <mycomet> to create a comet (anonymous urbit)\n",
|
|
|
|
" %s -w <myplanet> -t <myticket> if you have a ticket\n",
|
|
|
|
" %s <myplanet or mycomet> to restart an existing urbit\n",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2015-10-08 20:17:15 +03:00
|
|
|
c3_i i;
|
2015-11-17 06:29:27 +03:00
|
|
|
for ( i=0; use_c[i]; i++ ) {
|
|
|
|
fprintf(stderr, use_c[i], argv[0]);
|
2015-10-07 07:39:38 +03:00
|
|
|
}
|
2013-09-29 00:21:18 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
#if 0
|
|
|
|
/* u3_ve_panic(): panic and exit.
|
2013-09-29 00:21:18 +04:00
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ve_panic(c3_i argc, c3_c** argv)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: gross system failure\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
#endif
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
/* u3_ve_sysopt(): apply option map to system state.
|
2013-09-29 00:21:18 +04:00
|
|
|
*/
|
|
|
|
static void
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ve_sysopt()
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-11-16 04:10:15 +03:00
|
|
|
u3_Local = strdup(u3_Host.dir_c);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
#if 0
|
2013-09-29 00:21:18 +04:00
|
|
|
static jmp_buf Signal_buf;
|
|
|
|
#ifndef SIGSTKSZ
|
|
|
|
# define SIGSTKSZ 16384
|
|
|
|
#endif
|
|
|
|
static uint8_t Sigstk[SIGSTKSZ];
|
|
|
|
|
|
|
|
volatile enum { sig_none, sig_overflow, sig_interrupt } Sigcause;
|
|
|
|
|
2014-03-05 02:48:59 +04:00
|
|
|
static void _main_cont(void *arg1, void *arg2, void *arg3)
|
|
|
|
{
|
|
|
|
(void)(arg1);
|
|
|
|
(void)(arg2);
|
|
|
|
(void)(arg3);
|
|
|
|
siglongjmp(Signal_buf, 1);
|
|
|
|
}
|
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
static void
|
|
|
|
overflow_handler(int emergency, stackoverflow_context_t scp)
|
|
|
|
{
|
|
|
|
if ( 1 == emergency ) {
|
|
|
|
write(2, "stack emergency\n", strlen("stack emergency" + 2));
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
Sigcause = sig_overflow;
|
2014-03-05 02:48:59 +04:00
|
|
|
sigsegv_leave_handler(_main_cont, NULL, NULL, NULL);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-10 05:27:02 +04:00
|
|
|
// Install signal handlers and set buffers.
|
|
|
|
//
|
|
|
|
// Note that we use the sigmask-restoring variant. Essentially, when
|
|
|
|
// we get a signal, we force the system back into the just-booted state.
|
|
|
|
// If anything goes wrong during boot (above), it's curtains.
|
|
|
|
{
|
|
|
|
if ( 0 != sigsetjmp(Signal_buf, 1) ) {
|
|
|
|
switch ( Sigcause ) {
|
|
|
|
case sig_overflow: printf("[stack overflow]\r\n"); break;
|
|
|
|
case sig_interrupt: printf("[interrupt]\r\n"); break;
|
|
|
|
default: printf("[signal error!]\r\n"); break;
|
|
|
|
}
|
|
|
|
Sigcause = sig_none;
|
|
|
|
|
|
|
|
signal(SIGINT, SIG_DFL);
|
|
|
|
stackoverflow_deinstall_handler();
|
|
|
|
|
|
|
|
// Print the trace, do a GC, etc.
|
|
|
|
//
|
|
|
|
// This is half-assed at present, so we exit.
|
|
|
|
//
|
|
|
|
u3_lo_sway(0, u3k(u3_wire_tax(u3_Wire)));
|
|
|
|
|
|
|
|
u3_lo_bail(u3A);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ( -1 == stackoverflow_install_handler
|
|
|
|
(overflow_handler, Sigstk, SIGSTKSZ) )
|
|
|
|
{
|
|
|
|
fprintf(stderr, "overflow_handler: install failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
signal(SIGINT, interrupt_handler);
|
|
|
|
signal(SIGIO, SIG_IGN);
|
|
|
|
}
|
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
static void
|
|
|
|
interrupt_handler(int x)
|
|
|
|
{
|
|
|
|
Sigcause = sig_interrupt;
|
|
|
|
longjmp(Signal_buf, 1);
|
|
|
|
}
|
2014-09-11 04:01:32 +04:00
|
|
|
#endif
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-10-11 09:32:58 +04:00
|
|
|
#define GRAB
|
2014-10-10 05:27:02 +04:00
|
|
|
|
2015-10-31 15:17:04 +03:00
|
|
|
static void
|
|
|
|
report(void)
|
|
|
|
{
|
|
|
|
printf("---------\nLibraries\n---------\n");
|
|
|
|
printf("gmp: %s\n", gmp_version);
|
|
|
|
printf("sigsegv: %d.%d\n", (libsigsegv_version >> 8) & 0xff, libsigsegv_version & 0xff);
|
|
|
|
printf("openssl: %s\n", SSLeay_version(SSLEAY_VERSION));
|
|
|
|
printf("curses: %s\n", curses_version());
|
2015-10-31 22:10:01 +03:00
|
|
|
printf("libuv: %s\n", uv_version_string());
|
2018-03-12 19:09:49 +03:00
|
|
|
printf("libh2o: %d.%d.%d\n", H2O_LIBRARY_VERSION_MAJOR, H2O_LIBRARY_VERSION_MINOR, H2O_LIBRARY_VERSION_PATCH);
|
2015-10-31 15:17:04 +03:00
|
|
|
}
|
|
|
|
|
2015-11-27 21:52:24 +03:00
|
|
|
void
|
|
|
|
_stop_exit(c3_i int_i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\r\n[received keyboard stop signal, exiting]\r\n");
|
|
|
|
u3_lo_bail();
|
|
|
|
}
|
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
c3_i
|
|
|
|
main(c3_i argc,
|
|
|
|
c3_c** argv)
|
|
|
|
{
|
|
|
|
// Parse options.
|
|
|
|
//
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3n == _main_getopt(argc, argv) ) {
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ve_usage(argc, argv);
|
2013-09-29 00:21:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2014-05-13 23:22:07 +04:00
|
|
|
|
2015-10-31 15:17:04 +03:00
|
|
|
if ( c3y == u3_Host.ops_u.rep ) {
|
|
|
|
report();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-01 20:23:29 +03:00
|
|
|
if ( c3y == u3_Host.ops_u.nuu ) {
|
|
|
|
struct stat s;
|
|
|
|
if ( !stat(u3_Host.dir_c, &s) ) {
|
2015-10-13 07:32:16 +03:00
|
|
|
fprintf(stderr, "tried to create, but %s already exists\n", u3_Host.dir_c);
|
2015-11-10 08:55:40 +03:00
|
|
|
fprintf(stderr, "normal usage: %s %s\n", argv[0], u3_Host.dir_c);
|
2015-10-01 20:23:29 +03:00
|
|
|
exit(1);
|
2015-11-17 06:29:27 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct stat s;
|
|
|
|
if ( -1 == stat(u3_Host.dir_c, &s) ) {
|
|
|
|
fprintf(stderr, "%s: urbit not found\n", u3_Host.dir_c);
|
|
|
|
u3_ve_usage(argc, argv);
|
2015-10-01 20:23:29 +03:00
|
|
|
}
|
2015-10-10 04:31:07 +03:00
|
|
|
}
|
2015-10-27 00:03:14 +03:00
|
|
|
|
2015-10-18 06:29:59 +03:00
|
|
|
#if 0
|
2015-10-10 04:31:07 +03:00
|
|
|
if ( 0 == getuid() ) {
|
|
|
|
chroot(u3_Host.dir_c);
|
|
|
|
u3_Host.dir_c = "/";
|
|
|
|
}
|
2015-10-18 06:29:59 +03:00
|
|
|
#endif
|
2014-09-11 04:01:32 +04:00
|
|
|
u3_ve_sysopt();
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2015-10-27 00:03:14 +03:00
|
|
|
// Block profiling signal, which should be delievered to exactly one thread.
|
|
|
|
//
|
|
|
|
if ( _(u3_Host.ops_u.pro) ) {
|
|
|
|
sigset_t set;
|
|
|
|
|
|
|
|
sigemptyset(&set);
|
|
|
|
sigaddset(&set, SIGPROF);
|
|
|
|
if ( 0 != pthread_sigmask(SIG_BLOCK, &set, NULL) ) {
|
|
|
|
perror("pthread_sigmask");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-27 21:52:24 +03:00
|
|
|
// Handle SIGTSTP as if it was SIGTERM.
|
|
|
|
//
|
|
|
|
signal(SIGTSTP, _stop_exit);
|
|
|
|
|
2014-06-10 01:56:56 +04:00
|
|
|
printf("~\n");
|
2015-06-06 01:07:40 +03:00
|
|
|
// printf("welcome.\n");
|
2016-10-25 17:53:44 +03:00
|
|
|
printf("urbit %s\n", URBIT_VERSION);
|
2015-06-06 01:07:40 +03:00
|
|
|
printf("urbit: home is %s\n", u3_Host.dir_c);
|
|
|
|
// printf("vere: hostname is %s\n", u3_Host.ops_u.nam_c);
|
2014-05-13 23:22:07 +04:00
|
|
|
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( c3y == u3_Host.ops_u.dem && c3n == u3_Host.ops_u.bat ) {
|
2015-06-06 01:07:40 +03:00
|
|
|
printf("urbit: running as daemon\n");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
2014-09-23 21:11:59 +04:00
|
|
|
// Seed prng. Don't panic -- just for fuzz testing.
|
2014-03-04 23:17:34 +04:00
|
|
|
//
|
2014-02-26 00:18:07 +04:00
|
|
|
srand(getpid());
|
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
// Instantiate process globals.
|
|
|
|
{
|
2014-11-29 05:19:11 +03:00
|
|
|
/* Boot the image and checkpoint. Set flags.
|
2014-09-11 04:01:32 +04:00
|
|
|
*/
|
2014-11-29 05:19:11 +03:00
|
|
|
{
|
|
|
|
/* Set pier directory.
|
|
|
|
*/
|
|
|
|
u3C.dir_c = u3_Host.dir_c;
|
|
|
|
|
|
|
|
/* Set GC flag.
|
|
|
|
*/
|
|
|
|
if ( _(u3_Host.ops_u.gab) ) {
|
|
|
|
u3C.wag_w |= u3o_debug_ram;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set profile flag.
|
|
|
|
*/
|
|
|
|
if ( _(u3_Host.ops_u.pro) ) {
|
|
|
|
u3C.wag_w |= u3o_debug_cpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set verbose flag.
|
|
|
|
*/
|
|
|
|
if ( _(u3_Host.ops_u.veb) ) {
|
|
|
|
u3C.wag_w |= u3o_verbose;
|
|
|
|
}
|
2015-05-20 03:04:08 +03:00
|
|
|
|
|
|
|
/* Set quiet flag.
|
|
|
|
*/
|
|
|
|
if ( _(u3_Host.ops_u.qui) ) {
|
|
|
|
u3C.wag_w |= u3o_quiet;
|
|
|
|
}
|
2014-12-01 03:06:08 +03:00
|
|
|
|
|
|
|
/* Set dry-run flag.
|
|
|
|
*/
|
|
|
|
if ( _(u3_Host.ops_u.dry) ) {
|
|
|
|
u3C.wag_w |= u3o_dryrun;
|
|
|
|
}
|
2018-10-02 02:56:14 +03:00
|
|
|
|
|
|
|
/* Set hashboard flag
|
|
|
|
*/
|
|
|
|
if ( _(u3_Host.ops_u.has) ) {
|
|
|
|
u3C.wag_w |= u3o_hashless;
|
|
|
|
}
|
2014-11-29 05:19:11 +03:00
|
|
|
}
|
2016-08-28 20:03:38 +03:00
|
|
|
u3m_boot(u3_Host.ops_u.nuu,
|
|
|
|
u3_Host.ops_u.gab,
|
|
|
|
u3_Host.dir_c,
|
2017-10-27 19:19:39 +03:00
|
|
|
u3_Host.ops_u.pil_c,
|
2017-10-28 03:12:57 +03:00
|
|
|
u3_Host.ops_u.url_c,
|
|
|
|
u3_Host.ops_u.arv_c);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-24 11:38:37 +04:00
|
|
|
/* Start Arvo.
|
2014-09-11 04:01:32 +04:00
|
|
|
*/
|
2014-10-11 09:32:58 +04:00
|
|
|
#if 1
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-11 04:01:32 +04:00
|
|
|
struct timeval tim_tv;
|
|
|
|
u3_noun now;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-11 04:01:32 +04:00
|
|
|
gettimeofday(&tim_tv, 0);
|
|
|
|
now = u3_time_in_tv(&tim_tv);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
u3v_start(now);
|
2014-09-24 11:38:37 +04:00
|
|
|
}
|
2014-10-10 05:27:02 +04:00
|
|
|
#endif
|
2014-09-25 01:29:19 +04:00
|
|
|
#if 0
|
2014-09-24 11:38:37 +04:00
|
|
|
/* Initial checkpoint.
|
|
|
|
*/
|
2014-11-05 04:18:47 +03:00
|
|
|
if ( _(u3_Host.ops_u.nuu) ) {
|
2014-09-24 11:38:37 +04:00
|
|
|
printf("about to save.\r\n");
|
2014-11-06 03:20:01 +03:00
|
|
|
u3e_save();
|
2014-09-24 11:38:37 +04:00
|
|
|
printf("saved.\r\n");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-25 01:29:19 +04:00
|
|
|
#endif
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
2018-03-12 19:16:44 +03:00
|
|
|
SSL_library_init();
|
|
|
|
SSL_load_error_strings();
|
|
|
|
|
|
|
|
{
|
|
|
|
c3_i rad;
|
|
|
|
c3_y buf[4096];
|
|
|
|
|
|
|
|
// RAND_status, at least on OS X, never returns true.
|
|
|
|
// 4096 bytes should be enough entropy for anyone, right?
|
|
|
|
rad = open("/dev/urandom", O_RDONLY);
|
|
|
|
if ( 4096 != read(rad, &buf, 4096) ) {
|
|
|
|
perror("rand-seed");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
RAND_seed(buf, 4096);
|
|
|
|
close(rad);
|
|
|
|
}
|
|
|
|
|
2014-11-06 03:20:01 +03:00
|
|
|
// u3e_grab("main", u3_none);
|
2015-05-19 21:38:23 +03:00
|
|
|
//
|
2014-10-10 05:27:02 +04:00
|
|
|
u3_lo_loop();
|
2014-10-11 09:32:58 +04:00
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
return 0;
|
|
|
|
}
|