provide console-socket load-scheduler # daemon mode: run pf in interactive mode, but without a console # attached. consoles can attach on a unix socket. note that it's your # responsability to make sure different instances don't collide # (i.e. interpreter state). # TCP is not used here for security reasons, but it's easy enough to # change if you want to do so. in general, i find unix pipes combined # with ssh login an effective way to have remote access. # the protocol that's used over the pipe is line based: one line in, # one line out. all printing is redirected to the pipe, and all # control characters are removed to not mess up the protocol. this is # a bit limited: no multiline responses etc, but simplicity is key # here. # it's easy enough to embed structured data in this protocol using # either string or list containers, followed by interpret words. see # the 'quoted' word below. variable console-server variable console-socket defer console-quote : >log report>stdout "\n" print>stdout ; : local-stack >r r local-variable () r> ! ; : local-io output-stack local-stack input-stack local-stack ; variable console-output : start-console # ( stream -- ) 1 fork >r # create task local variables local-io console-output local-variable ' console-interpret-string local-xt ' interpret-string is console-interpret-string # repl begin # set default quoter ' nop is console-quote # Debug # output-stack @ >log # interpret it, and capture output to string r try { read-line console-interpret-string } string dup console-output ! # save buffer for later access with-output-to-string-append recover # FIXME: pretty print error message { p cr } console-output @ with-output-to-string-append # first save the error message console-output @> # get output >r # append the error message # then check for other things (this will reset the msg) nip # discard interpreter input e_eof = if # kill task on EOF postpone [ finish then r> # 100. sleep endtry # need interpret mode after interpretation postpone [ # quote message (the interpreted code can redefine this word, # to prevent information loss due to sanitation) console-quote sanitize "\n" concat # this fails when remote side has closed connection r try print-atom # print-string-buffered recover # last-error p cr finish # all errors are fatal endtry again ; : start-console-server # ( filename -- ) dup console-socket ! "r" open-listen-unix console-server ! 0 fork begin try console-server @ dup block-read "rw" open-accept start-console recover drop endtry again ; : default-daemon-socket "/tmp/pf-" getpid >string concat ; : start-console-client console-socket @ pf-fork-console ; : quoted ' serialize is console-quote ; # it's easiest to have the tick spawn a task, so errors can get # captured more cleanly. : spawn-tick 0 fork tick-loop ; # : spawn-tick 0 fork begin tick block-poll again ; # switch to daemon mode using the word below. this doesn't spawn a # 'tick' task, which has to be done manually. (i.e. for PD, there is none) : start-daemon start-scheduler # startup the scheduler (read / write hooks) default-daemon-socket start-console-server ; # start console server on default socket