~cdv/snapmgr

72de655acc1c129fcc99810a6977f1c3d3128e2c — Chris Vittal 4 years ago beb4828 0.0.2
Use syslog for output
2 files changed, 10 insertions(+), 8 deletions(-)

M meson.build
M snapmgr.c
M meson.build => meson.build +1 -1
@@ 1,6 1,6 @@
project('snapmgr', 'c',
	license : 'GPL-3.0-only',
  version : '0.0.1',
  version : '0.0.2',
  default_options : ['warning_level=2', 'c_std=c11'])

cc = meson.get_compiler('c')

M snapmgr.c => snapmgr.c +9 -7
@@ 5,6 5,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>



@@ 14,7 15,7 @@ static void
assert_cap(void)
{
	if (geteuid() != 0) {
		fprintf(stderr, "insufficient permissions\n");
		syslog(LOG_ERR, "insufficient permissions\n");
		exit(1);
	}
}


@@ 25,13 26,12 @@ take(const char *vol, const char *path)

	int dfd = open(path, O_RDONLY | O_DIRECTORY);
	if (dfd < 0) {
		fprintf(stderr, "open('%s'):", path);
		perror(NULL);
		syslog(LOG_ERR, "open('%s'): %m", path);
		return 1;
	}
	int vfd = open(vol, O_RDONLY | O_DIRECTORY);
	if (vfd < 0) {
		perror("open(root)");
		syslog(LOG_ERR, "open('%s'): %m", vol);
		return 1;
	}



@@ 44,11 44,11 @@ take(const char *vol, const char *path)
	err = btrfs_util_create_snapshot_fd2(vfd, dfd, name, 0, NULL, NULL);
	int ret;
	if (err) {
		fprintf(stderr, "snapmgr: could not create snapshot %s - %s\n",
		syslog(LOG_ERR, "snapmgr: could not create snapshot %s - %s\n",
			name, btrfs_util_strerror(err));
		ret = 1;
	} else {
		fprintf(stderr, "success! created snapshot %s/%s\n", path, name);
		syslog(LOG_INFO, "created snapshot %s/%s\n", path, name);
		ret = 0;
	}



@@ 83,6 83,8 @@ usage(const char *argv0)
int
main(int argc, char *argv[])
{
	openlog("snapmgr", LOG_NDELAY | LOG_PERROR, LOG_USER);
	atexit(closelog);
	int ret = 1;
	if (argc == 1) {
		goto print_usage;


@@ 100,7 102,7 @@ main(int argc, char *argv[])
	} else if (strcmp(argv[1], "help") == 0) {
		ret = 0;
	} else {
		fprintf(stderr, "error: unknown subcommand %s\n", argv[1]);
		fprintf(stderr, "error: unknown subcommand %s", argv[1]);
	}

print_usage: