Changes to build on musl/alpine

This commit is contained in:
Faruk Kasumovic 2018-11-15 21:58:33 +01:00
parent 145d6f8d7d
commit 7482756d85
6 changed files with 36 additions and 8 deletions

View File

@ -54,3 +54,26 @@ nvlist_ptr new_property_nvlist() {
int property_nvlist_add(nvlist_ptr list, const char *prop, const char *value) {
return nvlist_add_string(list, prop, value);
}
int redirect_libzfs_stdout(int to) {
int save, res;
save = dup(STDOUT_FILENO);
if (save < 0) {
return save;
}
res = dup2(to, STDOUT_FILENO);
if (res < 0) {
return res;
}
return save;
}
int restore_libzfs_stdout(int saved) {
int res;
fflush(stdout);
res = dup2(saved, STDOUT_FILENO);
if (res < 0) {
return res;
}
close(saved);
}

View File

@ -9,7 +9,7 @@
package zfs
/*
#cgo CFLAGS: -I /usr/include/libzfs -I /usr/include/libspl -DHAVE_IOCTL_IN_SYS_IOCTL_H
#cgo CFLAGS: -I /usr/include/libzfs -I /usr/include/libspl -DHAVE_IOCTL_IN_SYS_IOCTL_H -D_GNU_SOURCE
#cgo LDFLAGS: -lzfs -lzpool -lnvpair
#include <stdlib.h>

View File

@ -2,6 +2,9 @@
* using libzfs from go language, make go code shorter and more readable.
*/
#ifndef loff_t
#define loff_t off_t
#endif
#define INT_MAX_NAME 256
#define INT_MAX_VALUE 1024
#define ZAP_OLDMAXVALUELEN 1024
@ -35,3 +38,6 @@ void free_properties(property_list_t *root);
nvlist_ptr new_property_nvlist();
int property_nvlist_add(nvlist_ptr ptr, const char* prop, const char *value);
int redirect_libzfs_stdout(int to);
int restore_libzfs_stdout(int saved);

View File

@ -230,13 +230,12 @@ func (d *Dataset) SendSize(FromName string, flags SendFlags) (size int64, err er
defer r.Close()
go func() {
var tmpe error
saveOut := C.dup(C.fileno(C.stdout))
if res := C.dup2(C.int(w.Fd()), C.fileno(C.stdout)); res < 0 {
tmpe = fmt.Errorf("Redirection of zfslib stdout failed %d", res)
saveOut := C.redirect_libzfs_stdout(C.int(w.Fd()))
if saveOut < 0 {
tmpe = fmt.Errorf("Redirection of zfslib stdout failed %d", saveOut)
} else {
tmpe = d.send(FromName, w, &flags)
C.fflush(C.stdout)
C.dup2(saveOut, C.fileno(C.stdout))
C.restore_libzfs_stdout(saveOut)
}
w.Close()
errch <- tmpe

View File

@ -79,7 +79,7 @@ nvlist_ptr get_zpool_vdev_tree(nvlist_ptr nv);
nvlist_ptr go_zpool_search_import(libzfs_handle_ptr zfsh, int paths, char **path, boolean_t do_scan);
__uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags);
uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags);
int set_zpool_vdev_offline(zpool_list_t *pool, const char *path, boolean_t istmp, boolean_t force);
int do_zpool_clear(zpool_list_t *pool, const char *device, u_int32_t rewind_policy);

View File

@ -8,7 +8,7 @@
#include "zpool.h"
__uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags) {
uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags) {
vdev_state_t newstate = VDEV_STATE_UNKNOWN;
zpool_vdev_online(pool->zph, path, flags, &newstate);
return newstate;