当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Sync函数代码示例

本文整理汇总了Golang中syscall.Sync函数的典型用法代码示例。如果您正苦于以下问题:Golang Sync函数的具体用法?Golang Sync怎么用?Golang Sync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Sync函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestAppendReader

func TestAppendReader(t *testing.T) {
	kv := NewAppend(KV_APPENDFILE)
	kv.Set("a", []byte("foo"))
	if err := <-kv.Sync(); err != nil {
		t.Error(err)
	}
	syscall.Sync()

	r := NewAppend(KV_APPENDFILE)
	if a := r.Get("a"); string(a) != "foo" {
		t.Error(a)
	}
	r.Close()

	kv.Set("a", []byte("bar"))
	if err := <-kv.Sync(); err != nil {
		t.Error(err)
	}
	syscall.Sync()

	r = NewAppend(KV_APPENDFILE)
	if a := r.Get("a"); string(a) != "bar" {
		t.Error(a)
	}
	r.Close()

	kv.Close()
	os.Remove(KV_APPENDFILE)
}
开发者ID:pombredanne,项目名称:kveer,代码行数:29,代码来源:append_test.go

示例2: SysInit

func SysInit() error {
	cfg, err := config.LoadConfig()
	if err != nil {
		return err
	}

	_, err = config.ChainCfgFuncs(cfg,
		loadImages,
		func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
			p, err := compose.GetProject(cfg, false)
			if err != nil {
				return cfg, err
			}
			return cfg, p.Up()
		},
		func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
			syscall.Sync()
			return cfg, nil
		},
		func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
			log.Infof("RancherOS %s started", config.VERSION)
			return cfg, nil
		})
	return err
}
开发者ID:heliang-whut,项目名称:os,代码行数:25,代码来源:sysinit.go

示例3: TestFileParallel

func TestFileParallel(t *testing.T) {
	kv1 := NewFile(KV_FILE)
	kv1.Set("a", []byte("foo"))
	kv1.Set("b", []byte("bar"))
	<-kv1.Sync()

	kv2 := NewFile(KV_FILE)
	if a := kv2.Get("a"); string(a) != "foo" {
		t.Error(a)
	}

	kv1.Set("a", []byte("baz"))
	<-kv1.Sync()

	syscall.Sync()

	// New reader should get new value
	kv3 := NewFile(KV_FILE)
	if a := kv3.Get("a"); string(a) != "baz" {
		t.Error(a)
	}
	kv3.Close()

	// Old reader shall still have the previous value
	if a := kv2.Get("a"); string(a) != "foo" {
		t.Error(a)
	}
	kv2.Close()

	// But new client should get the new value
	os.Remove(KV_FILE)
}
开发者ID:pombredanne,项目名称:kveer,代码行数:32,代码来源:file_test.go

示例4: reboot

func reboot() {
	log.Infof("Rebooting the system")
	if debugLevel > 0 {
		log.Info("Squashing reboot for debug init")
		return
	}

	syscall.Sync()
	syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
}
开发者ID:vmware,项目名称:vic,代码行数:10,代码来源:main_linux.go

示例5: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	// Nothing can faile
	syscall.Sync()
}
开发者ID:HarryBird,项目名称:go-coreutils,代码行数:10,代码来源:sync_linux.go

示例6: halt

// exit cleanly shuts down the system
func halt() {
	log.Infof("Powering off the system")
	if strings.HasSuffix(os.Args[0], "-debug") {
		log.Info("Squashing power off for debug tether")
		return
	}

	syscall.Sync()
	syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
}
开发者ID:vmware,项目名称:vic,代码行数:11,代码来源:main_linux.go

示例7: doRestartApp

func doRestartApp() {
	time.Sleep(1)
	syscall.Sync()
	out, err := exec.Command("/bin/systemctl", "restart", "stratux").Output()
	if err != nil {
		log.Printf("restart error: %s\n%s", err.Error(), out)
	} else {
		log.Printf("restart: %s\n", out)
	}
}
开发者ID:jpoirier,项目名称:stratux,代码行数:10,代码来源:managementinterface.go

示例8: reboot

func reboot() {
	log.Infof("Rebooting the system")
	if strings.HasSuffix(os.Args[0], "-debug") {
		log.Info("Squashing reboot for debug init")
		return
	}

	syscall.Sync()
	syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
}
开发者ID:kjplatz,项目名称:vic,代码行数:10,代码来源:main_linux.go

示例9: luksUnmount

func luksUnmount() (err error) {
	args := []string{conf.mountPoint}
	cmd := "/bin/umount"

	status.Log(syslog.LOG_NOTICE, "unmounting encrypted volume on %s", conf.mountPoint)

	syscall.Sync()
	_, err = execCommand(cmd, args, true, "")

	return
}
开发者ID:jmptrader,项目名称:interlock,代码行数:11,代码来源:luks.go

示例10: reboot

func reboot(code int) {
	err := shutDownContainers()
	if err != nil {
		log.Error(err)
	}

	syscall.Sync()

	err = syscall.Reboot(code)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:jgatkinsn,项目名称:os,代码行数:13,代码来源:power.go

示例11: Flush

func (store *dirStore) Flush() <-chan error {
	// In disk store flush does not really return any errors because it can not
	// know which write goroutines are now running so it can't collect their
	// errors, also Sync() doesn't return errors either. So error channel is just
	// to meet the interface requirements and to wait for Flush() to complete.
	c := make(chan error)
	go func() {
		store.wg.Wait()
		syscall.Sync()
		close(c)
	}()
	return c
}
开发者ID:zserge,项目名称:kv,代码行数:13,代码来源:store.go

示例12: tincStatServer

// tincStatServer serves data pulled from the tinc log file
// Tinc logs connection and network information after getting a USR1 and USR2
// The following output is current:
//
//{
//  "total_bytes_in": 115324,
//  "total_bytes_out": 67990,
//  "connections": [
//    {
//      "name": "some_random_node",
//      "ip": "192.0.2.15",
//      "port": 2003
//    }
//  ]
//}
func tincStatServer(w http.ResponseWriter, req *http.Request) {
	// Get tinc pid
	tincPid, err := findTincPid()
	if err != nil {
		log.Fatalf("findTincPid: %s", err)
	}

	// Get first list of lines
	lines1, err := readLines("/var/log/tinc/tinc.log")
	if err != nil {
		log.Fatalf("readLines: %s", err)
	}
	// Send signals
	usr12(tincPid)
	// Confirm flush of data to file
	syscall.Sync()
	// Get second list of lines
	lines2, err := readLines("/var/log/tinc/tinc.log")
	if err != nil {
		log.Fatalf("readLines: %s", err)
	}

	// Print out and save unique lines in the second set
	var loglines []string
	for i, line := range lines2 {
		if list_contains(line, lines1) == false {
			fmt.Println(i, line)
			loglines = append(loglines, line)
		}
	}

	// Convert the raw loglines output to a tincstat object
	ts, err := parseTincStat(loglines)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	// Create the JSON representation of tinc status
	data, err := json.MarshalIndent(ts, " ", "")
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	// Write the HTTP response headers and body.
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	io.WriteString(w, string(data))
}
开发者ID:nibalizer,项目名称:tincstat,代码行数:65,代码来源:tincstat.go

示例13: TestAppendOverwrite

func TestAppendOverwrite(t *testing.T) {
	kv := NewAppend(KV_APPENDFILE)
	kv.Set("a", []byte("foo"))
	kv.Set("a", []byte("bar"))
	kv.Set("a", []byte("baz"))
	kv.Close()

	syscall.Sync()

	kv = NewAppend(KV_APPENDFILE)
	if a := kv.Get("a"); string(a) != "baz" {
		t.Error(a)
	}

	os.Remove(KV_APPENDFILE)
}
开发者ID:pombredanne,项目名称:kveer,代码行数:16,代码来源:append_test.go

示例14: RunWatchdog

func RunWatchdog() {
	log.Println("started watchdog")
	for {
		watchmutex.Lock()
		if watchlock != "" && watchcmd != nil {
			syscall.Sync()
			_, err := os.Stat(watchlock)
			if err != nil {
				log.Println(err)
				log.Println("killing process behind", watchlock)
				errK := watchcmd.Process.Kill()
				if errK != nil {
					log.Println(errK)
				}
				watchlock = ""
				watchcmd = nil
			}
		}
		watchmutex.Unlock()
		time.Sleep(*flag_poll)
	}
}
开发者ID:barnex,项目名称:mumax-daemon,代码行数:22,代码来源:watchdog.go

示例15: TestLarge

func TestLarge(t *testing.T) {
	dir, err := ioutil.TempDir("", "large")
	require.NoError(t, err)

	t.Log(dir)

	f, err := OpenLarge(dir, 1<<10)
	require.NoError(t, err)
	defer f.Close()

	data := []byte("hello world")

	n, err := f.WriteAt(data, 0)
	require.NoError(t, err)
	require.Equal(t, len(data), n)

	b := make([]byte, len(data))
	n, err = f.ReadAt(b, 0)
	require.NoError(t, err)
	require.Equal(t, len(data), n)
	require.Equal(t, data, b)

	n, err = f.WriteAt(data, 1020)
	require.NoError(t, err)
	require.Equal(t, len(data), n)

	b = make([]byte, len(data))
	n, err = f.ReadAt(b, 1020)
	require.NoError(t, err)
	require.Equal(t, len(data), n)
	require.Equal(t, data, b)

	syscall.Sync()

	_, err = os.Stat(path.Join(dir, "0"))
	require.NoError(t, err)
	_, err = os.Stat(path.Join(dir, "1"))
	require.NoError(t, err)
}
开发者ID:justmao945,项目名称:tama,代码行数:39,代码来源:large_test.go


注:本文中的syscall.Sync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。