#include "debug.h"
#include "lipe_object_attrs.h"
+#include "lipe_version.h"
#include "policy.h"
#define OPT_LOG_LEVEL 4
#define OPT_MAX_SCAN_SECS 5
#define OPT_PIDFILE 6
+#define OPT_VERSION 7
#define LPCC_PURGE_LOG(level, fmt, ...) \
llapi_error((level) | LLAPI_MSG_NO_ERRNO, 0, fmt, ##__VA_ARGS__)
json_object *j_all = json_object_new_object();
+ /* version and revision */
+ snprintf(buff, ARRAY_SIZE(buff), "%s-%s", PACKAGE_VERSION, LIPE_RELEASE);
+ json_object_object_add(j_all, "version", json_object_new_string(buff));
+ json_object_object_add(j_all, "revison", json_object_new_string(LIPE_REVISION));
+
+ /* time, fsname, and cache usage */
curr = time(NULL);
ctime_r(&curr, buff);
buff[strlen(buff) - 1] = '\0';
usage = lpcc_purge_get_fs_usage(opt.o_cache);
json_object_object_add(j_all, "cache_usage", json_object_new_double(usage));
+ /* configuration */
json_object *j_config = json_object_new_object();
json_object_object_add(j_config, "mount", json_object_new_string(opt.o_mount));
json_object_object_add(j_config, "cache", json_object_new_string(opt.o_cache));
json_object_object_add(j_config, "log_level", json_object_new_string(log_level_to_str(llapi_msg_get_level())));
json_object_object_add(j_all, "config", j_config);
+ /* stats */
json_object *j_stats = json_object_new_object();
json_object_object_add(j_stats, "scan_times", json_object_new_int64(stats.s_scan_times));
json_object_object_add(j_stats, "total_purged_objs", json_object_new_int64(stats.s_total_purged_objs));
json_object_object_add(j_stats, "purged_objs", json_object_new_int64(stats.s_purged_objs));
json_object_object_add(j_all, "stats", j_stats);
+ /* convert the JSON object to string and print to file */
const char *str = json_object_to_json_string_ext(j_all,
JSON_C_TO_STRING_PRETTY |
JSON_C_TO_STRING_SPACED |
"\t --pidfile=FILE, the pidfile name (default: /var/run/lpcc_purge-RWID.pid)\n"
"\t --clear-hashdir, clear empty hash dir after detaching file\n"
"\t --dry-run, scan once but do not detach file really\n"
+ "\t --version, print version information and exit\n"
"\t-h, --help, print this help message\n",
program_invocation_short_name,
{ "pidfile", required_argument, NULL, OPT_PIDFILE},
{ "clear-hashdir", no_argument, NULL, OPT_CLEAR_HASHDIR},
{ "max-scan-secs", required_argument, NULL, OPT_MAX_SCAN_SECS},
+ { "version", no_argument, NULL, OPT_VERSION},
{ "help", no_argument, NULL, 'h' },
{ NULL }
};
}
opt.o_max_scan_secs = value;
break;
+ case OPT_VERSION:
+ lipe_version();
+ exit(0);
default:
llapi_error(LLAPI_MSG_FATAL, -EINVAL,
"invalid argument: '%s'",