From: Adam Chlipala Date: Thu, 22 Nov 2007 21:38:02 +0000 (+0000) Subject: dbtool shows end users error messages from MySQL X-Git-Tag: release_2010-11-19~109 X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/commitdiff_plain/abcfe83a703476c6fe29ee1ff071f84dac415ab2 dbtool shows end users error messages from MySQL --- diff --git a/src/plugins/mysql.sml b/src/plugins/mysql.sml index 5114e17..3cfa94f 100644 --- a/src/plugins/mysql.sml +++ b/src/plugins/mysql.sml @@ -31,39 +31,29 @@ fun adduser {user, passwd} = NONE => SOME "No password given" | SOME passwd => if validPasswd passwd then - if Slave.shell [Config.MySQL.adduser, user, " ", passwd] then - NONE - else - SOME "Error executing CREATE USER script" + Option.map (fn s => "Error executing CREATE USER script:\n" ^ s) + (Slave.shellOutput [Config.MySQL.adduser, user, " ", passwd]) else SOME "Password contains characters besides letters, digits, and !.-_" fun passwd {user, passwd} = if validPasswd passwd then - if Slave.shell [Config.MySQL.passwd, user, " ", passwd] then - NONE - else - SOME "Error executing SET PASSWORD script" + Option.map (fn s => "Error executing SET PASSWORD script:\n" ^ s) + (Slave.shellOutput [Config.MySQL.passwd, user, " ", passwd]) else SOME "Password contains characters besides letters, digits, and !.-_" fun createdb {user, dbname} = - if Slave.shell [Config.MySQL.createdb, user, " ", dbname] then - NONE - else - SOME "Error executing CREATE DATABASE script" + Option.map (fn s => "Error executing CREATE DATABASE script:\n" ^ s) + (Slave.shellOutput [Config.MySQL.createdb, user, " ", dbname]) fun dropdb {user, dbname} = - if Slave.shell [Config.MySQL.dropdb, user, " ", dbname] then - NONE - else - SOME "Error executing DROP DATABASE script" + Option.map (fn s => "Error executing DROP DATABASE script:\n" ^ s) + (Slave.shellOutput [Config.MySQL.dropdb, user, " ", dbname]) fun grant {user, dbname} = - if Slave.shell [Config.MySQL.grant, user, " ", dbname] then - NONE - else - SOME "Error executing GRANT script" + Option.map (fn s => "Error executing GRANT script:\n" ^ s) + (Slave.shellOutput [Config.MySQL.grant, user, " ", dbname]) val _ = Dbms.register ("mysql", {getpass = SOME Client.getpass, adduser = adduser, diff --git a/src/slave.sig b/src/slave.sig index c413a07..7471d86 100644 --- a/src/slave.sig +++ b/src/slave.sig @@ -45,6 +45,7 @@ signature SLAVE = sig val shell : string list -> bool val shellF : string list * (string -> string) -> unit + val shellOutput : string list -> string option val concatTo : (string -> bool) -> string -> unit (* Search through the result configuration hierarchy for all files matching diff --git a/src/slave.sml b/src/slave.sml index 01d872c..ba31da8 100644 --- a/src/slave.sml +++ b/src/slave.sml @@ -82,6 +82,25 @@ fun shellF (ss, msg) = ErrorMsg.error NONE (msg s) end +fun shellOutput ss = + let + val proc = Unix.execute ("/bin/bash", ["-c", String.concat ss ^ " 2>&1"]) + val inf = Unix.textInstreamOf proc + + fun loop out = + case TextIO.inputLine inf of + NONE => String.concat (rev out) + | SOME line => loop (line :: out) + + val lines = loop [] + in + print lines; + if OS.Process.isSuccess (Unix.reap proc) then + NONE + else + SOME lines + end + fun hostname () = let val inf = TextIO.openIn "/etc/hostname"