Skip to content

Commit 7482756

Browse files
committed
Changes to build on musl/alpine
1 parent 145d6f8 commit 7482756

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

common.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,26 @@ nvlist_ptr new_property_nvlist() {
5454
int property_nvlist_add(nvlist_ptr list, const char *prop, const char *value) {
5555
return nvlist_add_string(list, prop, value);
5656
}
57+
58+
int redirect_libzfs_stdout(int to) {
59+
int save, res;
60+
save = dup(STDOUT_FILENO);
61+
if (save < 0) {
62+
return save;
63+
}
64+
res = dup2(to, STDOUT_FILENO);
65+
if (res < 0) {
66+
return res;
67+
}
68+
return save;
69+
}
70+
71+
int restore_libzfs_stdout(int saved) {
72+
int res;
73+
fflush(stdout);
74+
res = dup2(saved, STDOUT_FILENO);
75+
if (res < 0) {
76+
return res;
77+
}
78+
close(saved);
79+
}

common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package zfs
1010

1111
/*
12-
#cgo CFLAGS: -I /usr/include/libzfs -I /usr/include/libspl -DHAVE_IOCTL_IN_SYS_IOCTL_H
12+
#cgo CFLAGS: -I /usr/include/libzfs -I /usr/include/libspl -DHAVE_IOCTL_IN_SYS_IOCTL_H -D_GNU_SOURCE
1313
#cgo LDFLAGS: -lzfs -lzpool -lnvpair
1414
1515
#include <stdlib.h>

common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* using libzfs from go language, make go code shorter and more readable.
33
*/
44

5+
#ifndef loff_t
6+
#define loff_t off_t
7+
#endif
58
#define INT_MAX_NAME 256
69
#define INT_MAX_VALUE 1024
710
#define ZAP_OLDMAXVALUELEN 1024
@@ -35,3 +38,6 @@ void free_properties(property_list_t *root);
3538
nvlist_ptr new_property_nvlist();
3639
int property_nvlist_add(nvlist_ptr ptr, const char* prop, const char *value);
3740

41+
int redirect_libzfs_stdout(int to);
42+
int restore_libzfs_stdout(int saved);
43+

sendrecv.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,12 @@ func (d *Dataset) SendSize(FromName string, flags SendFlags) (size int64, err er
230230
defer r.Close()
231231
go func() {
232232
var tmpe error
233-
saveOut := C.dup(C.fileno(C.stdout))
234-
if res := C.dup2(C.int(w.Fd()), C.fileno(C.stdout)); res < 0 {
235-
tmpe = fmt.Errorf("Redirection of zfslib stdout failed %d", res)
233+
saveOut := C.redirect_libzfs_stdout(C.int(w.Fd()))
234+
if saveOut < 0 {
235+
tmpe = fmt.Errorf("Redirection of zfslib stdout failed %d", saveOut)
236236
} else {
237237
tmpe = d.send(FromName, w, &flags)
238-
C.fflush(C.stdout)
239-
C.dup2(saveOut, C.fileno(C.stdout))
238+
C.restore_libzfs_stdout(saveOut)
240239
}
241240
w.Close()
242241
errch <- tmpe

zpool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ nvlist_ptr get_zpool_vdev_tree(nvlist_ptr nv);
7979

8080
nvlist_ptr go_zpool_search_import(libzfs_handle_ptr zfsh, int paths, char **path, boolean_t do_scan);
8181

82-
__uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags);
82+
uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags);
8383
int set_zpool_vdev_offline(zpool_list_t *pool, const char *path, boolean_t istmp, boolean_t force);
8484
int do_zpool_clear(zpool_list_t *pool, const char *device, u_int32_t rewind_policy);
8585

zpool_vdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "zpool.h"
99

1010

11-
__uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags) {
11+
uint64_t set_zpool_vdev_online(zpool_list_t *pool, const char *path, int flags) {
1212
vdev_state_t newstate = VDEV_STATE_UNKNOWN;
1313
zpool_vdev_online(pool->zph, path, flags, &newstate);
1414
return newstate;

0 commit comments

Comments
 (0)