Exemple #1
0
/* called after SIGHUP */
void conf_reload(void)
{
    upstype_t	*upstmp, *upsnext;

    upslogx(LOG_INFO, "SIGHUP: reloading configuration");

    /* see if we can access upsd.conf before blowing away the config */
    if (!check_file("upsd.conf"))
        return;

    /* reset retain flags on all known UPS entries */
    upstmp = firstups;
    while (upstmp) {
        upstmp->retain = 0;
        upstmp = upstmp->next;
    }

    /* reload from ups.conf */
    read_upsconf();
    upsconf_add(1);			/* 1 = reloading */

    /* now reread upsd.conf */
    load_upsdconf(1);		/* 1 = reloading */

    /* now delete all UPS entries that didn't get reloaded */

    upstmp = firstups;

    while (upstmp) {
        /* upstmp may be deleted during this pass */
        upsnext = upstmp->next;

        if (upstmp->retain == 0)
            delete_ups(upstmp);

        upstmp = upsnext;
    }

    /* did they actually delete the last UPS? */
    if (firstups == NULL)
        upslogx(LOG_WARNING, "Warning: no UPSes currently defined!");

    /* and also make sure upsd.users can be read... */
    if (!check_file("upsd.users"))
        return;

    /* delete all users */
    user_flush();

    /* and finally reread from upsd.users */
    user_load();
}
Exemple #2
0
int main(int argc, char **argv)
{
	int	i;
	char	*prog;
	void	(*command)(const ups_t *) = NULL;

	printf("Network UPS Tools - UPS driver controller %s\n",
		UPS_VERSION);

	prog = argv[0];
	while ((i = getopt(argc, argv, "+htu:r:DV")) != -1) {
		switch(i) {
			case 'r':
				pt_root = optarg;
				break;

			case 't':
				testmode = 1;
				break;

			case 'u':
				pt_user = optarg;
				break;

			case 'V':
				exit(EXIT_SUCCESS);

			case 'D':
				nut_debug_level++;
				break;

			case 'h':
			default:
				help(prog);
				break;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc < 1)
		help(prog);

	if (testmode) {
		printf("*** Testing mode: not calling exec/kill\n");

		if (nut_debug_level < 2)
			nut_debug_level = 2;
	}

	upsdebugx(2, "\n"
		   "If you're not a NUT core developer, chances are that you're told to enable debugging\n"
		   "to see why a driver isn't working for you. We're sorry for the confusion, but this is\n"
		   "the 'upsdrvctl' wrapper, not the driver you're interested in.\n\n"
		   "Below you'll find one or more lines starting with 'exec:' followed by an absolute\n"
		   "path to the driver binary and some command line option. This is what the driver\n"
		   "starts and you need to copy and paste that line and append the debug flags to that\n"
		   "line (less the 'exec:' prefix).\n");

	if (!strcmp(argv[0], "start"))
		command = &start_driver;

	if (!strcmp(argv[0], "stop"))
		command = &stop_driver;

	if (!strcmp(argv[0], "shutdown"))
		command = &shutdown_driver;

	if (!command)
		fatalx(EXIT_FAILURE, "Error: unrecognized command [%s]", argv[0]);

	driverpath = xstrdup(DRVPATH);	/* set default */

	atexit(exit_cleanup);

	read_upsconf();

	if (argc == 1)
		send_all_drivers(command);
	else
		send_one_driver(command, argv[1]);

	if (exec_error)
		exit(EXIT_FAILURE);

	exit(EXIT_SUCCESS);
}