View | Details | Raw Unified | Return to bug 246981 | Differences between
and this patch

Collapse All | Expand All

(-)b/pkg-plugin-template/Makefile (-9 / +8 lines)
Lines 1-18 Link Here
1
.include <bsd.own.mk>
1
.include <bsd.own.mk>
2
2
3
LIB=		pkg-plugin-template
4
INCS=		template.h
5
#WARNS=		6
6
PREFIX?=	/usr/local
3
PREFIX?=	/usr/local
7
LIBDIR=		${PREFIX}/lib
4
LIBDIR=		${PREFIX}/lib/pkg/
8
INCLUDEDIR=	${PREFIX}/include
5
SHLIB_DIR?=	${LIBDIR}/
9
SHLIB_MAJOR=	0
6
SHLIB_NAME?=	${PLUGIN_NAME}.so
10
7
8
PLUGIN_NAME=	template
11
SRCS=		template.c
9
SRCS=		template.c
12
10
13
CFLAGS+=	-std=c99 -fPIC -shared
11
PKGFLAGS!=	pkgconf --cflags pkg
14
CFLAGS+=	-I${INCLUDEDIR}
12
CFLAGS+=	${PKGFLAGS}
15
13
16
DEBUG_FLAGS+=  -g -O0
14
beforeinstall:
15
	${INSTALL} -d ${LIBDIR}
17
16
18
.include <bsd.lib.mk>
17
.include <bsd.lib.mk>
(-)b/pkg-plugin-template/README.md (-7 / +19 lines)
Lines 16-40 Once the plugin is built you can install it using the following command: Link Here
16
16
17
	$ make install 
17
	$ make install 
18
	
18
	
19
The plugin will be installed as a shared library in ${PREFIX}/lib/libpkg-plugin-template.so
19
The plugin will be installed as a shared library in ${PREFIX}/lib/pkg/template.so (or wherever
20
the *PKG\_PLUGINS\_DIR* option points to).
20
21
21
## Configuring the plugin
22
## Configuring the plugin
22
23
23
In order to configure the plugin simply copy the *template.conf* file to the pkgng plugins directory,
24
In order to configure the plugin simply copy the *template.conf* file to the pkgng plugins directory,
24
which by default is set to */usr/local/etc/pkg/plugins*, unless you've specified it elsewhere by 
25
which by default is set to */usr/local/etc/pkg*, unless you've specified it elsewhere by
25
using the *PKG\_PLUGINS\_DIR* option.
26
using the *PLUGINS\_CONF\_DIR* option.
26
27
27
	$ cp /path/to/pkg-plugins-template/template.conf /usr/local/etc/pkg/plugins/
28
	$ cp /path/to/pkg-plugins-template/template.conf /usr/local/etc/pkg/
28
	
29
	
30
## Enabling the plugin
31
32
To use the plugin, tell pkgng about it by adding it to the *PLUGINS* option in ${PREFIX}/etc/pkg.conf.
33
Also make sure *PKG\_ENABLE\_PLUGINS* is set to true:
34
35
	PKG_ENABLE_PLUGINS = true;
36
	PLUGINS [
37
		"foo",
38
		"template",
39
	]
40
29
## Testing the plugin
41
## Testing the plugin
30
42
31
To test the plugin, first check that it is recongnized and
43
To test the plugin, first check that it is recongnized and
32
loaded by pkgng by executing the `pkg plugins` command:
44
loaded by pkgng by executing the `pkg plugins` command:
33
45
34
	$ pkg plugins
46
	$ pkg plugins
35
	NAME       DESC                                VERSION    LOADED    
47
	NAME       DESC                                VERSION
36
	foo        Foo plugin for pkg                  1.1        YES       
48
	foo        Foo plugin for pkg                  1.1.0
37
	template   Template plugin for pkgng           1.0        YES       
49
	template   Template plugin for pkgng           1.0.0
38
50
39
If the plugin shows up correctly then you are good to go! :)
51
If the plugin shows up correctly then you are good to go! :)
40
52
(-)b/pkg-plugin-template/template.c (-22 / +92 lines)
Lines 30-40 Link Here
30
/* Include pkg */
30
/* Include pkg */
31
#include <pkg.h>
31
#include <pkg.h>
32
32
33
/* Include any plugin headers here */
33
/* Define plugin name and configuration settings */
34
#include "template.h"
34
static const char PLUGIN_NAME[] = "template";
35
static const char CFG_TEXT[] = "text";
36
static const char CFG_COUNT[] = "count";
37
static const char CFG_FLAG[] = "flag";
38
static const char CFG_COLORS[] = "colors";
35
39
36
/* Define the plugin name */
40
/* Maintain a reference to ourself */
37
#define PLUGIN_NAME "template"
41
static struct pkg_plugin *self;
38
42
39
/*
43
/*
40
 * The plugin *must* provide an init function that is called by the library.
44
 * The plugin *must* provide an init function that is called by the library.
Lines 47-53 Link Here
47
 *
51
 *
48
 * The plugin's init function prototype should be in the following form:
52
 * The plugin's init function prototype should be in the following form:
49
 *
53
 *
50
 * int pkg_plugins_init_<plugin> (void);
54
 * int pkg_plugins_init (void);
51
 *
55
 *
52
 * No arguments are passed to the plugin's init function.
56
 * No arguments are passed to the plugin's init function.
53
 *
57
 *
Lines 55-62 Link Here
55
 * upon failure EPKG_FATAL ( > 0 ) is returned to the caller.
59
 * upon failure EPKG_FATAL ( > 0 ) is returned to the caller.
56
 */
60
 */
57
int
61
int
58
pkg_plugins_init_template(void)
62
pkg_plugin_init(struct pkg_plugin *p)
59
{
63
{
64
	/* Keep a reference to our plugin object, so it can be used inside the callback functions */
65
	self = p;
66
67
	/*
68
	 * Declare the plugin's metadata
69
	 *
70
	 * This information is shown by 'pkg plugins'.
71
	 *
72
	 */
73
74
	pkg_plugin_set(p, PKG_PLUGIN_NAME, PLUGIN_NAME);
75
	pkg_plugin_set(p, PKG_PLUGIN_DESC, "Template plugin for pkgng");
76
	pkg_plugin_set(p, PKG_PLUGIN_VERSION, "1.0.0");
77
78
	/*
79
	 * Register configuration settings
80
	 *
81
	 * Declares
82
	 * - key (the name of the setting in the configuration file)
83
	 * - type (type of the setting, one of PKG_STRING, PKG_BOOL, PKG_INT, PKG_ARRAY)
84
	 * - default value (value if not set in the configuration file, provide empty string for no default)
85
	 *
86
	 */
87
88
	pkg_plugin_conf_add(p, PKG_STRING, CFG_TEXT, "");
89
	pkg_plugin_conf_add(p, PKG_INT, CFG_COUNT, "0");
90
	pkg_plugin_conf_add(p, PKG_BOOL, CFG_FLAG, "false");
91
	pkg_plugin_conf_add(p, PKG_ARRAY, CFG_COLORS, "");
92
93
	/* Parse the configuration file for above settings. Do not forget this! */
94
	pkg_plugin_parse(p);
95
60
	/*
96
	/*
61
	 * Register two functions for hooking into the library
97
	 * Register two functions for hooking into the library
62
	 *
98
	 *
Lines 68-82 pkg_plugins_init_template(void) Link Here
68
	 *
104
	 *
69
	 */
105
	 */
70
106
71
	/* printf(">>> Plugin '%s' is about to hook into pkgng.. yay! :)\n", PLUGIN_NAME); */
107
	/* printf(">>> Plugin '%s' is about to hook into pkgng.. yay! :)\n", pkg_plugin_get(p, PKG_PLUGIN_NAME)); */
72
	
108
	
73
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGINS_HOOK_PRE_INSTALL, &my_callback1) != EPKG_OK) {
109
	if (pkg_plugin_hook_register(p, PKG_PLUGIN_HOOK_PRE_INSTALL, &my_callback1) != EPKG_OK) {
74
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
110
		pkg_plugin_error(p, "failed to hook into the library");
75
		return (EPKG_FATAL);
111
		return (EPKG_FATAL);
76
	}
112
	}
77
	
113
	
78
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGINS_HOOK_POST_INSTALL, &my_callback2) != EPKG_OK) {
114
	if (pkg_plugin_hook_register(p, PKG_PLUGIN_HOOK_POST_INSTALL, &my_callback2) != EPKG_OK) {
79
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
115
		pkg_plugin_error(p, "failed to hook into the library");
80
		return (EPKG_FATAL);
116
		return (EPKG_FATAL);
81
	}
117
	}
82
	
118
	
Lines 93-107 pkg_plugins_init_template(void) Link Here
93
 *
129
 *
94
 * The plugin's shutdown function prototype should be in the following form:
130
 * The plugin's shutdown function prototype should be in the following form:
95
 *
131
 *
96
 * int pkg_plugins_shutdown_<plugin> (void);
132
 * int pkg_plugins_shutdown (struct pkg_plugin *);
97
 *
133
 *
98
 * Upon successful shutdown of the plugin EPKG_OK (0) is returned and
134
 * Upon successful shutdown of the plugin EPKG_OK (0) is returned and
99
 * upon failure EPKG_FATAL ( > 0 ) is returned to the caller.
135
 * upon failure EPKG_FATAL ( > 0 ) is returned to the caller.
100
 */
136
 */
101
int
137
int
102
pkg_plugins_shutdown_template(void)
138
pkg_plugin_shutdown(struct pkg_plugin *p __unused)
103
{
139
{
104
	/* printf(">>> Plugin '%s' is shutting down, enough working for today.. :)\n", PLUGIN_NAME); */
140
	/* printf(">>> Plugin '%s' is shutting down, enough working for today.. :)\n", pkg_plugin_get(p, PKG_PLUGIN_NAME)); */
105
141
106
	/*
142
	/*
107
	 * Perform any cleanup if needed, e.g.:
143
	 * Perform any cleanup if needed, e.g.:
Lines 120-127 pkg_plugins_shutdown_template(void) Link Here
120
 * And now we need to define our workers,
156
 * And now we need to define our workers,
121
 * the plugin functions that carry out the real work.
157
 * the plugin functions that carry out the real work.
122
 *
158
 *
123
 * A plugin callback function accepts only one argument and
159
 * A plugin callback function must satisfy the following function pointer signature:
124
 * should return EPKG_OK (0) on success and EPKG_FATAL ( > 0 ) on failure.
160
 *
161
 * int(*pkg_plugin_callback)(void *data, struct pkgdb *db);
162
 *
163
 * It should return EPKG_OK (0) on success and EPKG_FATAL ( > 0 ) on failure.
125
 *
164
 *
126
 * Plugin callbacks must also take care of proper casting of the (void *data) argument.
165
 * Plugin callbacks must also take care of proper casting of the (void *data) argument.
127
 *
166
 *
Lines 130-145 pkg_plugins_shutdown_template(void) Link Here
130
 *
169
 *
131
 * For example if a plugin hooks into PKG_PLUGINS_HOOK_PRE_INSTALL the (void *data) passed to the
170
 * For example if a plugin hooks into PKG_PLUGINS_HOOK_PRE_INSTALL the (void *data) passed to the
132
 * called is (struct pkg_jobs *), so the plugin callback must cast it explicitely.
171
 * called is (struct pkg_jobs *), so the plugin callback must cast it explicitely.
172
 *
173
 * If the callback needs to access configuration data, a reference to the plugin object
174
 * can be kept in the global scope of this compilation unit:
175
 *
176
 * static struct pkg_plugin *self;
177
 *
133
 */
178
 */
134
int
179
int
135
my_callback1(void *data, struct pkgdb *db)
180
my_callback1(void *data, struct pkgdb *db)
136
{
181
{
137
	printf("Hey, I was just called by the library, lets see what we've got here..\n");
182
	const char *text = NULL;
183
	int64_t count = 0;
184
	bool flag = false;
185
	const pkg_object *colors = NULL;
186
	const pkg_object *color = NULL;
187
	const pkg_object *cfg = NULL;
188
	pkg_iter it = NULL;
189
190
	/* Get configuration object */
191
	cfg = pkg_plugin_conf(self);
192
193
	/* Get configuration data */
194
	flag = pkg_object_bool(pkg_object_find(cfg, CFG_FLAG));
195
	count = pkg_object_int(pkg_object_find(cfg, CFG_COUNT));
196
	text = pkg_object_string(pkg_object_find(cfg, CFG_TEXT));
197
	colors = pkg_object_find(cfg, CFG_COLORS);
198
199
200
	pkg_plugin_info(self, "Hey, I was just called by the library, lets see what we've got here..");
201
202
	pkg_plugin_info(self, "  Text: '%s'", text);
203
	pkg_plugin_info(self, "  Count: %i", count);
204
	pkg_plugin_info(self, "  Flag: %s", flag ? "true" : "false");
205
	while ((color = pkg_object_iterate(colors, &it)) != NULL) {
206
		pkg_plugin_info(self, "  Color: %s", pkg_object_string(color));
207
	}
138
208
139
	if (data == NULL)
209
	if (data == NULL)
140
		printf("Hmm.. no data for me today, guess I'll just go and grab a mohito then..\n");
210
		pkg_plugin_info(self, "Hmm.. no data for me today, guess I'll just go and grab a mohito then..");
141
	else
211
	else
142
		printf("Got some data.. okay, okay.. I'll do something useful then..\n");
212
		pkg_plugin_info(self, "Got some data.. okay, okay.. I'll do something useful then..");
143
213
144
	return (EPKG_OK);
214
	return (EPKG_OK);
145
}
215
}
Lines 150-161 my_callback1(void *data, struct pkgdb *db) Link Here
150
int
220
int
151
my_callback2(void *data, struct pkgdb *db)
221
my_callback2(void *data, struct pkgdb *db)
152
{
222
{
153
	printf("Hey, I was just called again, lets see what its all about this time..\n");
223
	pkg_plugin_info(self, "Hey, I was just called again, lets see what its all about this time..");
154
224
155
	if (data == NULL)
225
	if (data == NULL)
156
		printf("Hmm.. no data, no work.. today is my lucky day!\n");
226
		pkg_plugin_info(self, "Hmm.. no data, no work.. today is my lucky day!");
157
	else
227
	else
158
		printf("Work never ends.. I'll do something useful again..\n");
228
		pkg_plugin_info(self, "Work never ends.. I'll do something useful again..");
159
	
229
	
160
	return (EPKG_OK);
230
	return (EPKG_OK);
161
}
231
}
(-)b/pkg-plugin-template/template.conf (-25 / +20 lines)
Lines 1-26 Link Here
1
# Configuration file for pkg-plugin-template
1
# Configuration file for pkg plugin: template
2
#
3
# The file is in UCL format.  For more information on the syntax of UCL,
4
# please visit the official UCL website: http://github.com/vstakhov/libucl
5
#
6
# Also see pkg.conf(5) for general details on using plugins for pkg(8).
7
#
8
9
# String value
10
text = "Simple Text"
11
# Integer value
12
count = 5
13
# Boolean value
14
flag = true
15
# List of strings
16
colors [
17
	"red",
18
	"green",
19
	"blue",
20
]
2
21
3
### Start of required plugin options ###
4
5
# Plugin is enabled when one of 'YES', 'TRUE' or 'ON' is specified
6
enabled=YES
7
8
# Name of the plugin, used to identify the plugin to the library
9
name=template
10
11
# A short description of the plugin
12
description=Template plugin for pkgng
13
14
# Plugin version
15
version=1.0
16
17
# Path to the plugin file
18
plugin=/usr/local/lib/libpkg-plugin-template.so
19
20
### End of required plugin options ###
21
22
# Plugins can also use this file for putting plugin specific configurations
23
# For example a plugin could have the following options specified if needed and being used by the plugin
24
# zfs_pool=zroot
25
# zfs_snapshots_recursive=YES
26
# ...
(-)a/pkg-plugin-template/template.h (-38 lines)
Removed Link Here
1
/*
2
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
3
 * All rights reserved.
4
 * 
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer
10
 *    in this position and unchanged.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 * 
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef _PKG_PLUGINS_TEMPLATE_H
28
#define _PKG_PLUGINS_TEMPLATE_H
29
30
/* callback functions */
31
int my_callback1(void *data, struct pkgdb *db);
32
int my_callback2(void *data, struct pkgdb *db);
33
34
/* plugin init and shutdown functions */
35
int pkg_plugins_init_template(void);
36
int pkg_plugins_shutdown_template(void);
37
38
#endif /* !_PKG_PLUGINS_TEMPLATE_H */
(-)b/stats/stats.c (-2 / +2 lines)
Lines 39-45 static char version[] = "1.0.0"; Link Here
39
static char description[] = "Plugin for displaying package stats";
39
static char description[] = "Plugin for displaying package stats";
40
static int plugin_stats_callback(void *data, struct pkgdb *db);
40
static int plugin_stats_callback(void *data, struct pkgdb *db);
41
41
42
struct pkg_plugin *self;
42
static struct pkg_plugin *self;
43
43
44
int
44
int
45
pkg_plugin_init(struct pkg_plugin *p)
45
pkg_plugin_init(struct pkg_plugin *p)
Lines 98-104 plugin_stats_callback(void *data, struct pkgdb *db) Link Here
98
98
99
	flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE);
99
	flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE);
100
	humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
100
	humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
101
	pkg_plugin_info(self, "Installed packages : %" PRId64 " | Disk space: %s <<<\n",
101
	pkg_plugin_info(self, "Installed packages : %" PRId64 " | Disk space: %s <<<",
102
	       pkgdb_stats(db, PKG_STATS_LOCAL_COUNT),
102
	       pkgdb_stats(db, PKG_STATS_LOCAL_COUNT),
103
	       size);
103
	       size);
104
104
(-)b/zfssnap/zfssnap.c (-20 / +20 lines)
Lines 46-63 Link Here
46
#define PLUGIN_NAME "zfssnap"
46
#define PLUGIN_NAME "zfssnap"
47
extern char **environ;
47
extern char **environ;
48
48
49
enum {
49
/* Define names of configuration settings */
50
	ZFS_FS=1,
50
static const char ZFS_DATASETS[] = "ZFS_DATASETS";
51
	ZFS_PREFIX,
51
static const char ZFS_PREFIX[] = "ZFS_PREFIX";
52
	ZFS_RECURSIVE,
52
static const char ZFS_RECURSIVE[] = "ZFS_RECURSIVE";
53
};
54
53
55
struct pkg_plugin *self;
54
static struct pkg_plugin *self;
56
55
57
static int plugins_zfssnap_callback(void *data, struct pkgdb *db);
56
static int plugins_zfssnap_callback(void *data, struct pkgdb *db);
58
57
59
static int plugins_zfssnap_fd = -1;
60
61
int
58
int
62
pkg_plugin_init(struct pkg_plugin *p)
59
pkg_plugin_init(struct pkg_plugin *p)
63
{
60
{
Lines 66-74 pkg_plugin_init(struct pkg_plugin *p) Link Here
66
	pkg_plugin_set(p, PKG_PLUGIN_DESC, "ZFS snapshot plugin");
63
	pkg_plugin_set(p, PKG_PLUGIN_DESC, "ZFS snapshot plugin");
67
	pkg_plugin_set(p, PKG_PLUGIN_VERSION, "1.0.0");
64
	pkg_plugin_set(p, PKG_PLUGIN_VERSION, "1.0.0");
68
65
69
	pkg_plugin_conf_add_list(p, ZFS_FS, "ZFS_FS");
66
	pkg_plugin_conf_add(p, PKG_ARRAY, ZFS_DATASETS, "");
70
	pkg_plugin_conf_add_string(p, ZFS_PREFIX, "ZFS_PREFIX", "pkgsnap");
67
	pkg_plugin_conf_add(p, PKG_STRING, ZFS_PREFIX, "pkgsnap");
71
	pkg_plugin_conf_add_bool(p, ZFS_RECURSIVE, "ZFS_RECURSIVE", false);
68
	pkg_plugin_conf_add(p, PKG_BOOL, ZFS_RECURSIVE, "false");
72
69
73
	pkg_plugin_parse(p);
70
	pkg_plugin_parse(p);
74
71
Lines 88-95 pkg_plugin_init(struct pkg_plugin *p) Link Here
88
int
85
int
89
pkg_plugin_shutdown(struct pkg_plugin *p __unused)
86
pkg_plugin_shutdown(struct pkg_plugin *p __unused)
90
{
87
{
91
	close(plugins_zfssnap_fd);
92
93
	return (EPKG_OK);
88
	return (EPKG_OK);
94
}
89
}
95
90
Lines 98-104 plugins_zfssnap_callback(void *data, struct pkgdb *db) Link Here
98
{
93
{
99
	char snap[MAXPATHLEN];
94
	char snap[MAXPATHLEN];
100
	struct tm *tm = NULL;
95
	struct tm *tm = NULL;
101
	struct pkg_config_value *zfs_fs;
96
	const pkg_object *zfs_datasets = NULL;
97
	const pkg_object *zfs_dataset = NULL;
102
	bool zfs_recursive = false;
98
	bool zfs_recursive = false;
103
	const char *zfs_prefix = NULL;
99
	const char *zfs_prefix = NULL;
104
	time_t t = 0;
100
	time_t t = 0;
Lines 111-116 plugins_zfssnap_callback(void *data, struct pkgdb *db) Link Here
111
		NULL,
107
		NULL,
112
		NULL,
108
		NULL,
113
	};
109
	};
110
	pkg_iter it = NULL;
111
	const pkg_object *cfg = NULL;
114
112
115
	t = time(NULL);
113
	t = time(NULL);
116
	tm = localtime(&t);
114
	tm = localtime(&t);
Lines 119-130 plugins_zfssnap_callback(void *data, struct pkgdb *db) Link Here
119
	/* assert(db != NULL); */ 
117
	/* assert(db != NULL); */ 
120
	/* assert(data != NULL); */
118
	/* assert(data != NULL); */
121
119
122
	pkg_plugin_conf_bool(self, ZFS_RECURSIVE, &zfs_recursive);
120
	cfg = pkg_plugin_conf(self);
123
	pkg_plugin_conf_string(self, ZFS_PREFIX, &zfs_prefix);
121
	zfs_recursive = pkg_object_bool(pkg_object_find(cfg, ZFS_RECURSIVE));
122
	zfs_prefix = pkg_object_string(pkg_object_find(cfg, ZFS_PREFIX));
123
	zfs_datasets = pkg_object_find(cfg, ZFS_DATASETS);
124
124
125
	while (pkg_plugin_conf_list(self, ZFS_FS, &zfs_fs) == EPKG_OK) {
125
	while ((zfs_dataset = pkg_object_iterate(zfs_datasets, &it)) != NULL) {
126
		snprintf(snap, sizeof(snap), "%s@%s-%d-%d-%d_%d.%d.%d",
126
		snprintf(snap, sizeof(snap), "%s@%s-%d-%d-%d_%d.%d.%d",
127
		    pkg_config_value(zfs_fs), zfs_prefix,
127
		    pkg_object_string(zfs_dataset), zfs_prefix,
128
		    1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
128
		    1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
129
		    tm->tm_hour, tm->tm_min, tm->tm_sec);
129
		    tm->tm_hour, tm->tm_min, tm->tm_sec);
130
130
Lines 135-142 plugins_zfssnap_callback(void *data, struct pkgdb *db) Link Here
135
			argv[2] = snap;
135
			argv[2] = snap;
136
			argv[3] = NULL;
136
			argv[3] = NULL;
137
		}
137
		}
138
		pkg_plugin_info(self, "Creating ZFS snapshot: %s", snap);
138
		pkg_plugin_info(self, "Creating%s ZFS snapshot: %s", zfs_recursive ? " recursive" : "", snap);
139
		if ((error = posix_spawn(&pid, "/sbin/zfs", NULL, NULL,
139
		if ((error = posix_spawn(&pid, "/openzfs/sbin/zfs", NULL, NULL,
140
		    __DECONST(char **, argv), environ)) != 0) {
140
		    __DECONST(char **, argv), environ)) != 0) {
141
			errno = error;
141
			errno = error;
142
			pkg_plugin_errno(self, "Failed to snapshot", snap);
142
			pkg_plugin_errno(self, "Failed to snapshot", snap);
(-)b/zfssnap/zfssnap.conf (-8 / +8 lines)
Lines 2-15 Link Here
2
# zfssnap specific options follow below
2
# zfssnap specific options follow below
3
#
3
#
4
4
5
# ZFS file system
5
# ZFS datasets
6
zfs_fs=zroot
6
ZFS_DATASETS = [
7
7
    "zroot/ROOT/default",
8
# ZFS args, '-r' for recursive snapshots creation
8
]
9
zfs_args=-r
10
11
# ZFS snapshot prefix name
12
zfs_prefix=zfssnap
13
9
10
# ZFS recursive snapshots creation (default: false)
11
#ZFS_RECURSIVE = false
14
12
13
# ZFS snapshot prefix name (default: "pkgsnap")
14
#ZFS_PREFIX = "pkgsnap"
15
15

Return to bug 246981