/*
 * &check_id;
 *   Health check program for the Linux Health Checker
 *
 * TODO: specify copyright
 *
 * Author(s): &check_author;
 *
 * TODO: specify license. Note: the parts of this file that were generated
 *       by lnxhc are not copyrighted and can be distributed under any license.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>


/* Defines. */
&c_ex_def_list;

/* Global variables. */

/* Non-zero if health check program should output additional information. */
static int verbose;

/* Non-zero if health check program should output debugging information. */
static int debug;

/* Health check ID. */
static char *check_id;

/* Health check installation directory. */
static char *check_dir;

/* Path to the file used to report exceptions. */
static char *ex_file;

&c_param_def_list;&c_si_def_list;

/* Functions. */

/*
 * lnxhc_setup - retrieve input from framework
 */
static void lnxhc_setup()
{
	char *verbose_str;
	char *debug_str;

	/* Retrieve values from environment variables. */
	verbose_str = getenv("LNXHC_VERBOSE");
	debug_str = getenv("LNXHC_DEBUG");
	check_id = getenv("LNXHC_CHECK_ID");
	check_dir = getenv("LNXHC_CHECK_DIR");
	ex_file = getenv("LNXHC_EXCEPTION");
&c_param_get_list;&c_si_get_list;
	/* Ensure that we are called by the lnxhc framework. */
	if (!verbose_str || !debug_str || !check_id || !check_dir || !ex_file) {
		fprintf(stderr, "Error: this program cannot be called "
				"directly.\nPlease use the 'lnxhc run' "
				"function to call this program.\n");
		exit(1);
	}

	/* Parse verbose flag. */
	verbose = atoi(verbose_str);

	/* Parse debug flag. */
	debug = atoi(debug_str);
}

/*
 * lnxhc_exception - report exception
 * @ex_id: ID of the exception to report
 */
static void lnxhc_exception(const char *ex_id)
{
	FILE *file;

	file = fopen(ex_file, "a");
	if (!file) {
		fprintf(stderr, "Error: could not open exception file '%s': "
			"%s\n", ex_file, strerror(errno));
		exit(1);
	}
	fprintf(file, "%s\n", ex_id);
	fclose(file);
}

/*
 * lnxhc_exception_var - report value of an exception template variable
 * @var_id: ID of the exception template variable
 * @value: value of the exception template variable
 */
static void lnxhc_exception_var(const char *var_id, const char *value)
{
	FILE *file;

	file = fopen(ex_file, "a");
	if (!file) {
		fprintf(stderr, "Error: could not open exception file '%s': "
			"%s\n", ex_file, strerror(errno));
		exit(1);
	}
	fprintf(file, "%s=%s\n", var_id, value);
	fclose(file);
}


int main(int argc, char *argv[])
{
	/* Initialize global variables. */
	lnxhc_setup();

	/* TODO:
	 * 1. Check parameters for correct values (param_*).
	 * 2. Access sysinfo data (filenames available in sysinfo_*).
	 * 3. Perform analysis.
	 * 4. If an exception is found, write its ID and values for exception
	 *    template variables to file ex_file.
	 *
	 * See 'man lnxhc_check_program' for more information.
	 */

	/*
	 * Sample exception reporting. TODO: call this only if an exception
	 * was identified.
	 */
&c_ex_report_list;
	/*
	 * Sample exception variable reporting. TODO: call this only if an
	 * exception was identified.
	 */
	lnxhc_exception_var("var", "value");

	return 0;
}
