1 package setup_instruments
7 "github.com/sjmudd/pstop/lib"
10 // Error 1142: UPDATE command denied to user
11 const UPDATE_FAILED = "Error 1142"
13 type setup_instruments_row struct {
19 type SetupInstruments struct {
21 rows []setup_instruments_row
24 // Change settings to monitor wait/synch/mutex/%
25 func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) {
26 si.rows = make([]setup_instruments_row, 0, 100)
28 // populate the rows which are not set
29 sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'wait/synch/mutex/%' AND ( enabled <> 'YES' OR timed <> 'YES' )"
31 lib.Logger.Println("Collecting p_s.setup_instruments wait/synch/mutex configuration settings")
33 rows, err := dbh.Query(sql)
41 var r setup_instruments_row
45 &r.TIMED); err != nil {
48 // we collect all information even if it's mainly empty as we may reference it later
49 si.rows = append(si.rows, r)
52 if err := rows.Err(); err != nil {
55 lib.Logger.Println("- found", count, "rows whose configuration need changing")
57 // update the rows which need to be set - do multiple updates but I don't care
58 lib.Logger.Println("Updating p_s.setup_instruments to allow wait/synch/mutex configuration")
61 for i := range si.rows {
62 sql := "UPDATE setup_instruments SET enabled = 'YES', TIMED = 'YES' WHERE NAME = '" + si.rows[i].NAME + "'"
63 if _, err := dbh.Exec(sql); err == nil {
64 si.update_succeeded = true
66 if err.Error()[0:10] != UPDATE_FAILED {
73 if si.update_succeeded {
74 lib.Logger.Println(count, "rows changed in p_s.setup_instruments")
76 lib.Logger.Println( "Insufficient privileges to UPDATE setup_instruments: " . err.String() )
80 // restore any changed rows back to their original state
81 func (si *SetupInstruments) Restore(dbh *sql.DB) {
82 // If the previous update didn't work then don't try to restore
83 if ! si.update_succeeded {
84 lib.Logger.Println("Not restoring p_s.setup_instruments to its original settings as previous UPDATE had failed")
87 lib.Logger.Println("Restoring p_s.setup_instruments to its original settings")
90 // update the rows which need to be set - do multiple updates but I don't care
92 for i := range si.rows {
93 sql := "UPDATE setup_instruments SET enabled = '" + si.rows[i].ENABLED + "', TIMED = '" + si.rows[i].TIMED + "' WHERE NAME = '" + si.rows[i].NAME + "'"
94 if _, err := dbh.Exec(sql); err != nil {
99 lib.Logger.Println(count, "rows changed in p_s.setup_instruments")