about summary refs log tree commit diff
path: root/mom.lua
diff options
context:
space:
mode:
Diffstat (limited to 'mom.lua')
-rw-r--r--mom.lua22
1 files changed, 17 insertions, 5 deletions
diff --git a/mom.lua b/mom.lua
index ef0f4c8..3cc5696 100644
--- a/mom.lua
+++ b/mom.lua
@@ -41,11 +41,12 @@ end
 -- { IDENTIFIER, "line", "meow" }
 -- this is to make multiplexing easier
 -- you must also give it a queue to send to (the rx_queue)
-function mom.create(m, command, rx_id, rx_queue)
+function mom.create(m, command, rx_id, rx_queue, directory)
 	local id = {}
 
 	m.clients[id] = {
 		command = assert(command),
+		directory = assert(directory),
 		rx_id = assert(rx_id),
 		tx_queue = fifo.new(),
 		rx_queue = assert(rx_queue),
@@ -59,6 +60,13 @@ function mom.create(m, command, rx_id, rx_queue)
 	return id, m.clients[id].tx_queue, m.clients[id].rx_queue
 end
 
+local function error_wait(err)
+	print("error: " .. err)
+	print("say something to try again")
+	io.read("*l")
+	os.exit(100)
+end
+
 function mom.start_process(m, id)
 	local proc_out_rx, proc_out_tx = std.pipe()
 	if not (proc_out_rx and proc_out_tx) then return nil, "can't create pipe" end
@@ -73,8 +81,14 @@ function mom.start_process(m, id)
 		std.close(proc_in_tx)
 		std.dup2(proc_in_rx, std.STDIN_FILENO)
 		std.dup2(proc_out_tx, std.STDOUT_FILENO)
-		std.execp(m.clients[id].command[1], { select(2, table.unpack(m.clients[id].command)) }) -- meh
-		os.exit(100) -- TODO
+		std.dup2(proc_out_tx, std.STDERR_FILENO)
+		local ok, err = std.chdir(m.clients[id].directory)
+		if not ok then
+			error_wait(err)
+		end
+
+		local _, err = std.execp(m.clients[id].command[1], { select(2, table.unpack(m.clients[id].command)) }) -- meh
+		error_wait(err)
 	else
 		m.pids[pid] = id
 		std.close(proc_in_rx)
@@ -128,8 +142,6 @@ function mom.tend(m)
 		if pid and status ~= "running" then
 			local client_id = m.pids[pid]
 			m.pids[pid] = nil
-			-- TODO: only restart sometimes
-			mom.start_process(m, client_id)
 			m.clients[client_id].rx_queue:put({ "quit" })
 		end
 	end