dbtool shows end users error messages from MySQL
authoradamch <adamch>
Thu, 22 Nov 2007 21:38:02 +0000 (21:38 +0000)
committeradamch <adamch>
Thu, 22 Nov 2007 21:38:02 +0000 (21:38 +0000)
src/plugins/mysql.sml
src/slave.sig
src/slave.sml

index 5114e17..3cfa94f 100644 (file)
@@ -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,
index c413a07..7471d86 100644 (file)
@@ -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
index 01d872c..ba31da8 100644 (file)
@@ -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"