bump deps

This commit is contained in:
Xiang Li
2013-11-22 08:59:24 -08:00
parent 68e7455374
commit 8a0496cfae
139 changed files with 9266 additions and 8246 deletions

View File

@ -12,7 +12,15 @@ const (
listenFdsStart = 3
)
func Files() []*os.File {
func Files(unsetEnv bool) []*os.File {
if unsetEnv {
// there is no way to unset env in golang os package for now
// https://code.google.com/p/go/issues/detail?id=6423
defer os.Setenv("LISTEN_PID", "")
defer os.Setenv("LISTEN_FDS", "")
}
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil || pid != os.Getpid() {
return nil
@ -24,7 +32,7 @@ func Files() []*os.File {
files := []*os.File(nil)
for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ {
syscall.CloseOnExec(fd)
files = append(files, os.NewFile(uintptr(fd), "LISTEN_FD_" + strconv.Itoa(fd)))
files = append(files, os.NewFile(uintptr(fd), "LISTEN_FD_"+strconv.Itoa(fd)))
}
return files
}

View File

@ -25,32 +25,36 @@ type Conn struct {
dispatch map[string]func(dbus.Signal)
}
func New() *Conn {
func New() (*Conn, error) {
c := new(Conn)
c.initConnection()
if err := c.initConnection(); err != nil {
return nil, err
}
c.initJobs()
c.initSubscription()
c.initDispatch()
return c
return c, nil
}
func (c *Conn) initConnection() {
func (c *Conn) initConnection() error {
var err error
c.sysconn, err = dbus.SystemBusPrivate()
if err != nil {
return
return err
}
err = c.sysconn.Auth(nil)
if err != nil {
c.sysconn.Close()
return
return err
}
err = c.sysconn.Hello()
if err != nil {
c.sysconn.Close()
return
return err
}
c.sysobj = c.sysconn.Object("org.freedesktop.systemd1", dbus.ObjectPath("/org/freedesktop/systemd1"))
@ -65,8 +69,10 @@ func (c *Conn) initConnection() {
err = c.sysobj.Call("org.freedesktop.systemd1.Manager.Subscribe", 0).Store()
if err != nil {
c.sysconn.Close()
return
return err
}
return nil
}
func (c *Conn) initDispatch() {

View File

@ -164,3 +164,53 @@ type UnitStatus struct {
JobType string // The job type as string
JobPath dbus.ObjectPath // The job object path
}
// EnableUnitFiles() may be used to enable one or more units in the system (by
// creating symlinks to them in /etc or /run).
//
// It takes a list of unit files to enable (either just file names or full
// absolute paths if the unit files are residing outside the usual unit
// search paths), and two booleans: the first controls whether the unit shall
// be enabled for runtime only (true, /run), or persistently (false, /etc).
// The second one controls whether symlinks pointing to other units shall
// be replaced if necessary.
//
// This call returns one boolean and an array with the changes made. The
// boolean signals whether the unit files contained any enablement
// information (i.e. an [Install]) section. The changes list consists of
// structures with three strings: the type of the change (one of symlink
// or unlink), the file name of the symlink and the destination of the
// symlink.
func (c *Conn) EnableUnitFiles(files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) {
var carries_install_info bool
result := make([][]interface{}, 0)
err := c.sysobj.Call("EnableUnitFiles", 0, files, runtime, force).Store(&carries_install_info, &result)
if err != nil {
return false, nil, err
}
resultInterface := make([]interface{}, len(result))
for i := range result {
resultInterface[i] = result[i]
}
changes := make([]EnableUnitFileChange, len(result))
changesInterface := make([]interface{}, len(changes))
for i := range changes {
changesInterface[i] = &changes[i]
}
err = dbus.Store(resultInterface, changesInterface...)
if err != nil {
return false, nil, err
}
return carries_install_info, changes, nil
}
type EnableUnitFileChange struct {
Type string // Type of the change (one of symlink or unlink)
Filename string // File name of the symlink
Destination string // Destination of the symlink
}

View File

@ -20,9 +20,7 @@ import (
// used for construction of the scope only and specifies the initial PIDs to
// add to the scope object.
type Property property
type property struct {
type Property struct {
Name string
Value dbus.Variant
}
@ -38,96 +36,95 @@ type execStart struct {
// the executed command. See
// http://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart=
func PropExecStart(command []string, uncleanIsFailure bool) Property {
return Property(
property{
Name: "ExecStart",
Value: dbus.MakeVariant(
[]execStart{
execStart{
Path: command[0],
Args: command,
UncleanIsFailure: uncleanIsFailure,
}})})
execStarts := []execStart{
execStart{
Path: command[0],
Args: command,
UncleanIsFailure: uncleanIsFailure,
},
}
return Property{
Name: "ExecStart",
Value: dbus.MakeVariant(execStarts),
}
}
// PropRemainAfterExit sets the RemainAfterExit service property. See
// http://www.freedesktop.org/software/systemd/man/systemd.service.html#RemainAfterExit=
func PropRemainAfterExit(b bool) Property {
return Property(
property{
Name: "RemainAfterExit",
Value: dbus.MakeVariant(b),
})
return Property{
Name: "RemainAfterExit",
Value: dbus.MakeVariant(b),
}
}
// PropDescription sets the Description unit property. See
// http://www.freedesktop.org/software/systemd/man/systemd.unit#Description=
func PropDescription(desc string) Property {
return Property(
property{
Name: "Description",
Value: dbus.MakeVariant(desc),
})
return Property{
Name: "Description",
Value: dbus.MakeVariant(desc),
}
}
func propDependency(name string, units []string) Property {
return Property(
property{
Name: name,
Value: dbus.MakeVariant(units),
})
return Property{
Name: name,
Value: dbus.MakeVariant(units),
}
}
// PropRequires sets the Requires unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#Requires=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requires=
func PropRequires(units ...string) Property {
return propDependency("Requires", units)
}
// PropRequiresOverridable sets the RequiresOverridable unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#RequiresOverridable=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresOverridable=
func PropRequiresOverridable(units ...string) Property {
return propDependency("RequiresOverridable", units)
}
// PropRequisite sets the Requisite unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#Requisite=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requisite=
func PropRequisite(units ...string) Property {
return propDependency("Requisite", units)
}
// PropRequisiteOverridable sets the RequisiteOverridable unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#RequisiteOverridable=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequisiteOverridable=
func PropRequisiteOverridable(units ...string) Property {
return propDependency("RequisiteOverridable", units)
}
// PropWants sets the Wants unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#Wants=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Wants=
func PropWants(units ...string) Property {
return propDependency("Wants", units)
}
// PropBindsTo sets the BindsTo unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#BindsTo=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=
func PropBindsTo(units ...string) Property {
return propDependency("BindsTo", units)
}
// PropRequiredBy sets the RequiredBy unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#RequiredBy=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredBy=
func PropRequiredBy(units ...string) Property {
return propDependency("RequiredBy", units)
}
// PropRequiredByOverridable sets the RequiredByOverridable unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#RequiredByOverridable=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredByOverridable=
func PropRequiredByOverridable(units ...string) Property {
return propDependency("RequiredByOverridable", units)
}
// PropWantedBy sets the WantedBy unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#WantedBy=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#WantedBy=
func PropWantedBy(units ...string) Property {
return propDependency("WantedBy", units)
}
@ -139,55 +136,55 @@ func PropBoundBy(units ...string) Property {
}
// PropConflicts sets the Conflicts unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#Conflicts=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Conflicts=
func PropConflicts(units ...string) Property {
return propDependency("Conflicts", units)
}
// PropConflictedBy sets the ConflictedBy unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#ConflictedBy=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#ConflictedBy=
func PropConflictedBy(units ...string) Property {
return propDependency("ConflictedBy", units)
}
// PropBefore sets the Before unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#Before=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=
func PropBefore(units ...string) Property {
return propDependency("Before", units)
}
// PropAfter sets the After unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#After=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#After=
func PropAfter(units ...string) Property {
return propDependency("After", units)
}
// PropOnFailure sets the OnFailure unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#OnFailure=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#OnFailure=
func PropOnFailure(units ...string) Property {
return propDependency("OnFailure", units)
}
// PropTriggers sets the Triggers unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#Triggers=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Triggers=
func PropTriggers(units ...string) Property {
return propDependency("Triggers", units)
}
// PropTriggeredBy sets the TriggeredBy unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#TriggeredBy=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#TriggeredBy=
func PropTriggeredBy(units ...string) Property {
return propDependency("TriggeredBy", units)
}
// PropPropagatesReloadTo sets the PropagatesReloadTo unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#PropagatesReloadTo=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#PropagatesReloadTo=
func PropPropagatesReloadTo(units ...string) Property {
return propDependency("PropagatesReloadTo", units)
}
// PropRequiresMountsFor sets the RequiresMountsFor unit property. See
// http://www.freedesktop.org/software/systemd/main/systemd.unit.html#RequiresMountsFor=
// http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresMountsFor=
func PropRequiresMountsFor(units ...string) Property {
return propDependency("RequiresMountsFor", units)
}

View File

@ -1,8 +1,10 @@
package dbus
import (
"github.com/guelfey/go.dbus"
"errors"
"time"
"github.com/guelfey/go.dbus"
)
const (
@ -71,12 +73,6 @@ type SubStateUpdate struct {
SubState string
}
type Error string
func (e Error) Error() string {
return string(e)
}
// SetSubStateSubscriber writes to updateCh when any unit's substate changes.
// Althrough this writes to updateCh on every state change, the reported state
// may be more recent than the change that generated it (due to an unavoidable
@ -104,7 +100,7 @@ func (c *Conn) sendSubStateUpdate(path dbus.ObjectPath) {
return
}
info, err := c.getUnitInfo(path)
info, err := c.GetUnitInfo(path)
if err != nil {
select {
case c.subscriber.errCh <- err:
@ -120,7 +116,7 @@ func (c *Conn) sendSubStateUpdate(path dbus.ObjectPath) {
case c.subscriber.updateCh <- update:
default:
select {
case c.subscriber.errCh <- Error("update channel full!"):
case c.subscriber.errCh <- errors.New("update channel full!"):
default:
}
}
@ -128,7 +124,7 @@ func (c *Conn) sendSubStateUpdate(path dbus.ObjectPath) {
c.updateIgnore(path, info)
}
func (c *Conn) getUnitInfo(path dbus.ObjectPath) (map[string]dbus.Variant, error) {
func (c *Conn) GetUnitInfo(path dbus.ObjectPath) (map[string]dbus.Variant, error) {
var err error
var props map[string]dbus.Variant
obj := c.sysconn.Object("org.freedesktop.systemd1", path)

View File

@ -103,7 +103,7 @@ func appendVariable(w io.Writer, name, value string) {
fmt.Fprintln(w, value)
} else {
/* just write the variable and value all on one line */
fmt.Fprintf(w, "%s=%s\n", name, value)
fmt.Fprintln(w, "%s=%s", name, value)
}
}
@ -111,8 +111,8 @@ func validVarName(name string) bool {
/* The variable name must be in uppercase and consist only of characters,
* numbers and underscores, and may not begin with an underscore. (from the docs)
*/
valid := true
valid = valid && name[0] != '_'
valid := name[0] != '_'
for _, c := range name {
valid = valid && ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_'
}