// Attach attaches the current trace to the context
// and returns a copy of the context with that trace
// stored under the key "trace".
543284
func (t *Trace) Attach(c context.Context) context.Context {
	return context.WithValue(c, traceKey, t)
}
98760
func (c *AppInsertCall) Context(ctx context.Context) *AppInsertCall {
	c.ctx_ = ctx
	return c
}
553705
func (s *SingletonLoader) Reattach(name, pluginType string, config *plugin.ReattachConfig) (loader.PluginInstance, error) {
	return s.getPlugin(true, name, pluginType, nil, nil, config)
}
744918
func (client *Client) Attach(cid string, options *AttachOptions) (io.ReadCloser, error) {
	values := url.Values{}
	add := func(name string, val bool) {
		values.Add(name, strconv.FormatBool(val))
	}
	add("logs", options.Logs)
	add("stream", options.Stream)
	add("stdin", options.Stdin)
	add("stdout", options.Stdout)
	add("stderr", options.Stderr)

	p := fmt.Sprintf("/containers/%s/attach?%s", cid, values.Encode())
	req, err := http.NewRequest("POST", client.URL.String()+p, nil)
	if err != nil {
		return nil, fmt.Errorf("could not construct request to docker")
	}
	resp, err := client.HTTPClient.Do(req)
	if err != nil {
		if !strings.Contains(err.Error(), "connection refused") && client.TLSConfig == nil {
			return nil, fmt.Errorf("%v. Are you trying to connect to a TLS-enabled daemon without TLS?", err)
		}
		return nil, err
	}
	if resp.StatusCode == http.StatusOK {
		return resp.Body, nil
	}

	resp.Body.Close()
	switch resp.StatusCode {
	case http.StatusSwitchingProtocols:
		return nil, fmt.Errorf("docker: attach: did not send websocket request but got 101 back")
	case http.StatusBadRequest:
		// Probably shouldn't get here
		return nil, fmt.Errorf("docker: attach: invalid request parameters")
	case http.StatusInternalServerError:
		return nil, fmt.Errorf("docker: attach: internal server error")
	default:
		return nil, fmt.Errorf("docker: attach: unexpected status code %s", resp.Status)
	}
}
684958
func (m *Scheduler) attach(ctx context.Context, task *ecs.Task, stdin io.Reader, stdout, stderr io.Writer) error {
	if a, _ := arn.Parse(aws.StringValue(task.TaskArn)); a != nil {
		fmt.Fprintf(stderr, "Attaching to %s...\r\n", a.Resource)
	}

	descContainerInstanceResp, err := m.ecs.DescribeContainerInstances(&ecs.DescribeContainerInstancesInput{
		Cluster:            task.ClusterArn,
		ContainerInstances: []*string{task.ContainerInstanceArn},
	})
	if err != nil {
		return fmt.Errorf("error describing container instance (%s): %v", aws.StringValue(task.ContainerInstanceArn), err)
	}

	containerInstance := descContainerInstanceResp.ContainerInstances[0]
	descInstanceResp, err := m.ec2.DescribeInstances(&ec2.DescribeInstancesInput{
		InstanceIds: []*string{containerInstance.Ec2InstanceId},
	})
	if err != nil {
		return fmt.Errorf("error describing ec2 instance (%s): %v", aws.StringValue(containerInstance.Ec2InstanceId), err)
	}

	ec2Instance := descInstanceResp.Reservations[0].Instances[0]

	// Wait for the task to start running. It will stay in the
	// PENDING state while the container is being pulled.
	if err := m.ecs.WaitUntilTasksNotPending(&ecs.DescribeTasksInput{
		Cluster: task.ClusterArn,
		Tasks:   []*string{task.TaskArn},
	}); err != nil {
		return fmt.Errorf("error waiting for %s to transition from PENDING state: %s", aws.StringValue(task.TaskArn), err)
	}

	// Open a new connection to the Docker daemon on the EC2
	// instance where the task is running.
	d, err := m.NewDockerClient(ec2Instance)
	if err != nil {
		return fmt.Errorf("error connecting to docker daemon on %s: %v", aws.StringValue(ec2Instance.InstanceId), err)
	}

	// Find the container id for the ECS task.
	containers, err := d.ListContainers(docker.ListContainersOptions{
		All: true,
		Filters: map[string][]string{
			"label": []string{
				fmt.Sprintf("com.amazonaws.ecs.task-arn=%s", aws.StringValue(task.TaskArn)),
				//fmt.Sprintf("com.amazonaws.ecs.container-name", p)
			},
		},
	})
	if err != nil {
		return fmt.Errorf("error listing containers for task: %v", err)
	}

	if len(containers) != 1 {
		return fmt.Errorf("unable to find container for %s running on %s", aws.StringValue(task.TaskArn), aws.StringValue(ec2Instance.InstanceId))
	}

	containerID := containers[0].ID

	if err := d.AttachToContainer(docker.AttachToContainerOptions{
		Container:    containerID,
		InputStream:  stdin,
		OutputStream: stdout,
		ErrorStream:  stderr,
		Logs:         true,
		Stream:       true,
		Stdin:        true,
		Stdout:       true,
		Stderr:       true,
		RawTerminal:  true,
	}); err != nil {
		return fmt.Errorf("error attaching to container (%s): %v", containerID, err)
	}

	return nil
}
1211051
func (s *Server) Attach(ctx context.Context, req *pb.AttachRequest) (resp *pb.AttachResponse, err error) {
	const operation = "attach"
	defer func() {
		recordOperation(operation, time.Now())
		recordError(operation, err)
	}()
	logrus.Debugf("AttachRequest %+v", req)

	resp, err = s.getAttach(req)
	if err != nil {
		return nil, fmt.Errorf("unable to prepare attach endpoint")
	}

	return resp, nil
}
1346231
func (n *Node) Attach() (*rpc.Client, error) {
	n.lock.RLock()
	defer n.lock.RUnlock()

	if n.server == nil {
		return nil, ErrNodeStopped
	}
	return rpc.DialInProc(n.inprocHandler), nil
}
506184
func Attach(pid int, debugInfoDirs []string) (*Process, error) {
	dbp := New(pid)
	dbp.common = proc.NewCommonProcess(true)

	var err error
	dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) })
	if err != nil {
		return nil, err
	}
	_, _, err = dbp.wait(dbp.pid, 0)
	if err != nil {
		return nil, err
	}

	err = dbp.initialize(findExecutable("", dbp.pid), debugInfoDirs)
	if err != nil {
		dbp.Detach(false)
		return nil, err
	}
	return dbp, nil
}
1113756
func (ml *MockRouteCountLogger) AddContext(key, val string) {
	ml.logger.AddContext(key, val)
}
1361631
func (e *AudioListeners) Attach(listener AudioListener) Detacher {
	item := &audioEventItem{
		parent:   e,
		prev:     e.tail,
		listener: listener,
		streams:  make(map[*User]chan *AudioPacket),
	}
	if e.head == nil {
		e.head = item
	}
	if e.tail == nil {
		e.tail = item
	} else {
		e.tail.next = item
	}
	return item
}
1161104
func (c Changes) PatchContext(ctx context.Context) (*Patch, error) {
	return getPatchContext(ctx, "", c...)
}
1019093
func (m *MailYak) Attach(name string, r io.Reader) {
	m.attachments = append(m.attachments, attachment{
		filename: name,
		content:  r,
		inline:   false,
	})
}
1278848
func ContextTraceID(ctx context.Context) string {
	if t := ctx.Value(traceKey); t != nil {
		return t.(string)
	}
	return ""
}
1271603
func (ss StreamService) Attach(containerID string, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {
	c, err := ss.runtimeServer.GetContainerFromShortID(containerID)
	if err != nil {
		return fmt.Errorf("could not find container %q: %v", containerID, err)
	}

	if err := ss.runtimeServer.Runtime().UpdateContainerStatus(c); err != nil {
		return err
	}

	cState := c.State()
	if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) {
		return fmt.Errorf("container is not created or running")
	}

	return ss.runtimeServer.Runtime().AttachContainer(c, inputStream, outputStream, errorStream, tty, resize)
}
445881
func (d *Debugger) Attach(pid int, path string) (proc.Process, error) {
	switch d.config.Backend {
	case "native":
		return native.Attach(pid, d.config.DebugInfoDirectories)
	case "lldb":
		return betterGdbserialLaunchError(gdbserial.LLDBAttach(pid, path, d.config.DebugInfoDirectories))
	case "default":
		if runtime.GOOS == "darwin" {
			return betterGdbserialLaunchError(gdbserial.LLDBAttach(pid, path, d.config.DebugInfoDirectories))
		}
		return native.Attach(pid, d.config.DebugInfoDirectories)
	default:
		return nil, fmt.Errorf("unknown backend %q", d.config.Backend)
	}
}
1221069
func (joy *Joystick) Attached() bool {
	return C.SDL_JoystickGetAttached(joy.cptr()) == C.SDL_TRUE
}
357312
func (k Kites) Attach(token string) {
	for _, kite := range k {
		kite.Token = token
	}
}