func()

in lib/ec2macosinit/systemconfig.go [298:321]


func (c *SystemConfigModule) checkSSHDReturn() (success bool, err error) {
	// Launchd can provide status on processes running, this gets that output to be parsed
	out, _ := executeCommand([]string{"launchctl", "list"}, "", []string{})
	// Start a line by line scanner
	scanner := bufio.NewScanner(strings.NewReader(out.stdout))
	for scanner.Scan() {
		// Fetch the next line
		line := scanner.Text()
		// If the line contains "sshd." then the real SSHD is started, not just the dummy sshd wrapper
		if strings.Contains(line, "sshd.") {
			// Strip the newline, then split on tabs to get fields
			launchctlFields := strings.Split(strings.Replace(line, "\n", "", -1), "\t")
			// Take the second field which is the process exit code on start
			retValue, err := strconv.ParseBool(launchctlFields[1])
			if err != nil {
				return false, fmt.Errorf("ec2macosinit: failed to get sshd exit code: %s", err)
			}
			// Return true for zero (good exit) otherwise false
			return !retValue, nil
		}
	}
	// If all of "launchctl list" output doesn't have a status, simply return false since its not running
	return false, nil
}