本文整理汇总了Golang中github.com/lxc/lxd/shared.Debugf函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugf函数的具体用法?Golang Debugf怎么用?Golang Debugf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: eventsSocket
func eventsSocket(r *http.Request, w http.ResponseWriter) error {
listener := eventListener{}
typeStr := r.FormValue("type")
if typeStr == "" {
typeStr = "logging,operation"
}
c, err := shared.WebsocketUpgrader.Upgrade(w, r, nil)
if err != nil {
return err
}
listener.active = make(chan bool, 1)
listener.connection = c
listener.id = uuid.NewRandom().String()
listener.messageTypes = strings.Split(typeStr, ",")
eventsLock.Lock()
eventListeners[listener.id] = &listener
eventsLock.Unlock()
shared.Debugf("New events listener: %s", listener.id)
<-listener.active
eventsLock.Lock()
delete(eventListeners, listener.id)
eventsLock.Unlock()
listener.connection.Close()
shared.Debugf("Disconnected events listener: %s", listener.id)
return nil
}
示例2: ConnStateHandler
func (m *ConnPidMapper) ConnStateHandler(conn net.Conn, state http.ConnState) {
unixConn := conn.(*net.UnixConn)
switch state {
case http.StateNew:
pid, err := getPid(unixConn)
if err != nil {
shared.Debugf("Error getting pid for conn %s", err)
} else {
m.m[unixConn] = pid
}
case http.StateActive:
return
case http.StateIdle:
return
case http.StateHijacked:
/*
* The "Hijacked" state indicates that the connection has been
* taken over from net/http. This is useful for things like
* developing websocket libraries, who want to upgrade the
* connection to a websocket one, and not use net/http any
* more. Whatever the case, we want to forget about it since we
* won't see it either.
*/
delete(m.m, unixConn)
case http.StateClosed:
delete(m.m, unixConn)
default:
shared.Debugf("Unknown state for connection %s", state)
}
}
示例3: verifyAdminPwd
func (d *Daemon) verifyAdminPwd(password string) bool {
value, err := dbPasswordGet(d.db)
if err != nil {
shared.Debugf("verifyAdminPwd: %s", err)
return false
}
buff, err := hex.DecodeString(value)
if err != nil {
shared.Debugf("hex decode failed")
return false
}
salt := buff[0:PW_SALT_BYTES]
hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8, 1, PW_HASH_BYTES)
if err != nil {
shared.Debugf("failed to create hash to check")
return false
}
if !bytes.Equal(hash, buff[PW_SALT_BYTES:]) {
shared.Debugf("Bad password received")
return false
}
shared.Debugf("Verified the admin password")
return true
}
示例4: untar
func untar(tarball string, path string) error {
extractArgs, _, err := detectCompression(tarball)
if err != nil {
return err
}
command := "tar"
args := []string{}
if !canMknod {
// if we are running in a userns where we cannot mknod,
// then run with a seccomp filter which turns mknod into a
// a noop. The container config had better know how to bind
// mount the devices in at container start.
args = append(args, "--exclude=dev/*")
}
args = append(args, "-C", path, "--numeric-owner")
args = append(args, extractArgs...)
args = append(args, tarball)
output, err := exec.Command(command, args...).CombinedOutput()
if err != nil {
shared.Debugf("Unpacking failed")
shared.Debugf(string(output))
return err
}
return nil
}
示例5: Connect
func (op *operation) Connect(r *http.Request, w http.ResponseWriter) (chan error, error) {
if op.class != operationClassWebsocket {
return nil, fmt.Errorf("Only websocket operations can be connected")
}
if op.status != shared.Running {
return nil, fmt.Errorf("Only running operations can be connected")
}
chanConnect := make(chan error, 1)
op.lock.Lock()
go func(op *operation, chanConnect chan error) {
err := op.onConnect(op, r, w)
if err != nil {
chanConnect <- err
shared.Debugf("Failed to handle %s operation: %s: %s", op.class.String(), op.id, err)
return
}
chanConnect <- nil
shared.Debugf("Handled %s operation: %s", op.class.String(), op.id)
}(op, chanConnect)
op.lock.Unlock()
shared.Debugf("Connected %s operation: %s", op.class.String(), op.id)
return chanConnect, nil
}
示例6: main
func main() {
if err := run(); err != nil {
// The action we take depends on the error we get.
switch t := err.(type) {
case *url.Error:
shared.Debugf("url.Error caught in main(). Op: %s, URL: %s, Err: %s\n", t.Op, t.URL, t.Err)
switch u := t.Err.(type) {
case *net.OpError:
shared.Debugf("Inner error type is a net.OpError: Op: %s Net: %s Addr: %s Err: %T", u.Op, u.Net, u.Addr, u.Err)
if u.Op == "dial" && u.Net == "unix" {
// The unix socket we are trying to conect to is refusing our connection attempt. Perhaps the server is not running?
// Let's at least tell the user about it, since it's hard to get information on wether something is actually listening.
fmt.Fprintf(os.Stderr, fmt.Sprintf(gettext.Gettext("Cannot connect to unix socket at %s Is the server running?\n"), u.Addr))
os.Exit(1)
}
default:
shared.Debugf("url.Error's inner Err type is %T", u)
}
default:
shared.Debugf("Error caught in main: %T\n", t)
}
fmt.Fprintf(os.Stderr, gettext.Gettext("error: %v\n"), err)
os.Exit(1)
}
}
示例7: RsyncSend
// RsyncSend sets up the sending half of an rsync, to recursively send the
// directory pointed to by path over the websocket.
func RsyncSend(path string, conn *websocket.Conn) error {
cmd, dataSocket, stderr, err := rsyncSendSetup(path)
if dataSocket != nil {
defer dataSocket.Close()
}
if err != nil {
return err
}
readDone, writeDone := shared.WebsocketMirror(conn, dataSocket, dataSocket)
output, err := ioutil.ReadAll(stderr)
if err != nil {
shared.Debugf("problem reading rsync stderr %s", err)
}
if err := cmd.Wait(); err != nil {
shared.Debugf("problem with rsync send of %s: %s: %s", path, err, string(output))
}
<-readDone
<-writeDone
return err
}
示例8: removeImgWorkdir
func removeImgWorkdir(d *Daemon, builddir string) {
vgname, _, err := getServerConfigValue(d, "core.lvm_vg_name")
if err != nil {
shared.Debugf("Error checking server config: %v", err)
}
matches, _ := filepath.Glob(fmt.Sprintf("%s/*.lv", builddir))
if len(matches) > 0 {
if len(matches) > 1 {
shared.Debugf("Unexpected - more than one .lv file in builddir. using first: %v", matches)
}
lvsymlink := matches[0]
if lvpath, err := os.Readlink(lvsymlink); err != nil {
shared.Debugf("Error reading target of symlink '%s'", lvsymlink)
} else {
err = shared.LVMRemoveLV(vgname, filepath.Base(lvpath))
if err != nil {
shared.Debugf("Error removing LV '%s': %v", lvpath, err)
}
}
}
if d.BackingFs == "btrfs" {
/* cannot rm -rf /a if /a/b is a subvolume, so first delete subvolumes */
/* todo: find the .btrfs file under dir */
fnamelist, _ := shared.ReadDir(builddir)
for _, fname := range fnamelist {
subvol := filepath.Join(builddir, fname)
btrfsDeleteSubvol(subvol)
}
}
if remErr := os.RemoveAll(builddir); remErr != nil {
shared.Debugf("Error deleting temporary directory: %s", remErr)
}
}
示例9: untar
func untar(tarball string, path string) error {
extractArgs, _, err := detectCompression(tarball)
if err != nil {
return err
}
command := "tar"
args := []string{}
if runningInUserns {
args = append(args, "--wildcards")
args = append(args, "--exclude=dev/*")
args = append(args, "--exclude=./dev/*")
args = append(args, "--exclude=rootfs/dev/*")
args = append(args, "--exclude=rootfs/./dev/*")
}
args = append(args, "-C", path, "--numeric-owner")
args = append(args, extractArgs...)
args = append(args, tarball)
output, err := exec.Command(command, args...).CombinedOutput()
if err != nil {
shared.Debugf("Unpacking failed")
shared.Debugf(string(output))
return err
}
return nil
}
示例10: rsyncWebsocket
func rsyncWebsocket(cmd *exec.Cmd, conn *websocket.Conn) error {
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
shared.WebsocketMirror(conn, stdin, stdout)
data, err2 := ioutil.ReadAll(stderr)
if err2 != nil {
shared.Debugf("error reading rsync stderr: %s", err2)
return err2
}
shared.Debugf("Stderr from rsync: %s", data)
err = cmd.Wait()
if err != nil {
shared.Debugf("rsync recv error %s: %s", err, string(data))
}
return err
}
示例11: untarImage
func untarImage(imagefname string, destpath string) error {
compression, _, err := detectCompression(imagefname)
if err != nil {
return err
}
args := []string{"-C", destpath, "--numeric-owner"}
switch compression {
case COMPRESSION_TAR:
args = append(args, "-xf")
case COMPRESSION_GZIP:
args = append(args, "-zxf")
case COMPRESSION_BZ2:
args = append(args, "--jxf")
case COMPRESSION_LZMA:
args = append(args, "--lzma", "-xf")
default:
args = append(args, "-Jxf")
}
args = append(args, imagefname)
output, err := exec.Command("tar", args...).CombinedOutput()
if err != nil {
shared.Debugf("image unpacking failed\n")
shared.Debugf(string(output))
return err
}
return nil
}
示例12: deviceTaskScheduler
func deviceTaskScheduler(d *Daemon) {
chHotplug, err := deviceMonitorProcessors()
if err != nil {
shared.Log.Error("scheduler: couldn't setup uevent watcher, no automatic re-balance")
return
}
shared.Debugf("Scheduler: doing initial balance")
deviceTaskBalance(d)
for {
select {
case e := <-chHotplug:
if len(e) != 2 {
shared.Log.Error("Scheduler: received an invalid hotplug event")
continue
}
shared.Debugf("Scheduler: %s is now %s: re-balancing", e[0], e[1])
deviceTaskBalance(d)
case e := <-deviceSchedRebalance:
if len(e) != 3 {
shared.Log.Error("Scheduler: received an invalid rebalance event")
continue
}
shared.Debugf("Scheduler: %s %s %s: re-balancing", e[0], e[1], e[2])
deviceTaskBalance(d)
}
}
}
示例13: verifyAdminPwd
func (d *Daemon) verifyAdminPwd(password string) bool {
q := "SELECT value FROM config WHERE key=\"core.trust_password\""
value := ""
argIn := []interface{}{}
argOut := []interface{}{&value}
err := dbQueryRowScan(d.db, q, argIn, argOut)
if err != nil || value == "" {
shared.Debugf("verifyAdminPwd: no password is set")
return false
}
buff, err := hex.DecodeString(value)
if err != nil {
shared.Debugf("hex decode failed")
return false
}
salt := buff[0:PW_SALT_BYTES]
hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8, 1, PW_HASH_BYTES)
if err != nil {
shared.Debugf("failed to create hash to check")
return false
}
if !bytes.Equal(hash, buff[PW_SALT_BYTES:]) {
shared.Debugf("Bad password received")
return false
}
shared.Debugf("Verified the admin password")
return true
}
示例14: deviceEventListener
func deviceEventListener(d *Daemon) {
chNetlink, err := deviceNetlinkListener()
if err != nil {
shared.Log.Error("scheduler: couldn't setup netlink listener")
return
}
for {
select {
case e := <-chNetlink:
if len(e) != 3 {
shared.Log.Error("Scheduler: received an invalid hotplug event")
continue
}
if e[0] == "cpu" {
shared.Debugf("Scheduler: %s: %s is now %s: re-balancing", e[0], e[1], e[2])
deviceTaskBalance(d)
}
if e[0] == "net" && e[2] == "add" {
shared.Debugf("Scheduler: %s: %s has been added: updating network priorities", e[0], e[1])
deviceNetworkPriority(d, e[1])
}
case e := <-deviceSchedRebalance:
if len(e) != 3 {
shared.Log.Error("Scheduler: received an invalid rebalance event")
continue
}
shared.Debugf("Scheduler: %s %s %s: re-balancing", e[0], e[1], e[2])
deviceTaskBalance(d)
}
}
}
示例15: pruneExpiredImages
func pruneExpiredImages(d *Daemon) {
shared.Debugf("Pruning expired images")
expiry, err := d.ConfigValueGet("images.remote_cache_expiry")
if err != nil {
shared.Log.Error("Unable to read the images.remote_cache_expiry key")
return
}
if expiry == "" {
expiry = "10"
}
expiryInt, err := strconv.Atoi(expiry)
if err != nil {
shared.Log.Error("Invalid value for images.remote_cache_expiry", log.Ctx{"err": err})
return
}
images, err := dbImagesGetExpired(d.db, expiryInt)
if err != nil {
shared.Log.Error("Unable to retrieve the list of expired images", log.Ctx{"err": err})
return
}
for _, fp := range images {
if err := doDeleteImage(d, fp); err != nil {
shared.Log.Error("Error deleting image", log.Ctx{"err": err, "fp": fp})
}
}
shared.Debugf("Done pruning expired images")
}