Beispiel #1
0
/* cleanly close the connection to a given UPS */
static void drop_connection(utype_t *ups)
{
    upsdebugx(2, "Dropping connection to UPS [%s]", ups->sys);

    ups->commstate = 0;
    ups->linestate = 0;
    clearflag(&ups->status, ST_LOGIN);
    clearflag(&ups->status, ST_CONNECTED);

    upscli_disconnect(&ups->conn);
}
Beispiel #2
0
/*
 * loop through all threads till they stoped
 * setting stop will flag threads to stop
 */
static void *managethread(void *data) {
	struct thread_pvt *thread;
	int last = 0;

	if (!(thread = get_thread_from_id())) {
		return NULL;
	}

	for(;;) {
		/*if im the last one leave this is done locked to make sure no items are added/removed*/
		objlock(threads);
		if (!(bucket_list_cnt(threads->list) - last)) {
			if (threads->manager) {
				objunref(threads->manager);
				threads->manager = NULL;
			}
			objunlock(threads);
			objunref(thread);
			break;
		}
		objunlock(threads);

		/* Ive been joined so i can leave when im alone*/
		if (testflag(thread, TL_THREAD_JOIN)) {
			clearflag(thread, TL_THREAD_JOIN);
			last = 1;
		}

		/*Cancel all running threads*/
		if (testflag(thread, TL_THREAD_STOP)) {
			clearflag(thread, TL_THREAD_STOP);
			/* Stop any more threads*/
			objlock(threads);
			if (threads->manager) {
				objunref(threads->manager);
				threads->manager = NULL;
			}
			objunlock(threads);

			/* cancel all threads now that they stoped*/
			bucketlist_callback(threads->list, stop_threads, thread);
			last = 1;
		}
#ifdef __WIN32__
		Sleep(1000);
#else
		sleep(1);
#endif
	}
	return NULL;
}
Beispiel #3
0
/* deal with the contents of STATUS or ups.status for this ups */
static void parse_status(utype_t *ups, char *status)
{
    char	*statword, *ptr;

    clear_alarm();

    upsdebugx(2, "%s: [%s]", __func__, status);

    /* empty response is the same as a dead ups */
    if (!strcmp(status, "")) {
        ups_is_gone(ups);
        return;
    }

    ups_is_alive(ups);

    /* clear these out early if they disappear */
    if (!strstr(status, "LB"))
        clearflag(&ups->status, ST_LOWBATT);
    if (!strstr(status, "FSD"))
        clearflag(&ups->status, ST_FSD);

    statword = status;

    /* split up the status words and parse each one separately */
    while (statword != NULL) {
        ptr = strchr(statword, ' ');
        if (ptr)
            *ptr++ = '\0';

        upsdebugx(3, "parsing: [%s]", statword);

        if (!strcasecmp(statword, "OL"))
            ups_on_line(ups);
        if (!strcasecmp(statword, "OB"))
            ups_on_batt(ups);
        if (!strcasecmp(statword, "LB"))
            ups_low_batt(ups);
        if (!strcasecmp(statword, "RB"))
            upsreplbatt(ups);

        /* do it last to override any possible OL */
        if (!strcasecmp(statword, "FSD"))
            ups_fsd(ups);

        update_crittimer(ups);

        statword = ptr;
    }
}
Beispiel #4
0
bool_t end_file_fun(void *user, const char_t *file, const char_t **xpaths) {
  parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user;
  if( pinfo ) {

    if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) {

      cp_end_target_rcm(&pinfo->rcm, file);

    } else {

      rm_end_file_rcm(&pinfo->rcm, file);

      if( !checkflag(pinfo->rcm.flags, RCM_WRITE_FILES) ) {
	/* this only occurs the first time the target is seen */
	if( (strcmp(file, pinfo->target) == 0) && pinfo->tempfile ) {
	  close(pinfo->tempfd);
	  pinfo->tempfd = -1;
	  clearflag(&pinfo->rcm.flags, RCM_RM_OUTPUT);
	}
      }
    }

    return TRUE;
  }
  return FALSE;
}
Beispiel #5
0
void trainerschool_test_done(){
    generic_callback1();
    if(!fading_is_active()){
        clearflag(MAP_BGN_AUTO_ALIGN_OFF);   
        *((bool*) 0x03000EA8) = false;
        callback1_set(map_reload);
    }
}
Beispiel #6
0
/* handle connecting to upsd, plus get SSL going too if possible */
static int try_connect(utype_t *ups)
{
    int	flags = 0, ret;

    upsdebugx(1, "Trying to connect to UPS [%s]", ups->sys);

    clearflag(&ups->status, ST_CONNECTED);

    /* force it if configured that way, just try it otherwise */
    if (forcessl == 1)
        flags |= UPSCLI_CONN_REQSSL;
    else
        flags |= UPSCLI_CONN_TRYSSL;

    if (opt_af == AF_INET)
        flags |= UPSCLI_CONN_INET;

    if (opt_af == AF_INET6)
        flags |= UPSCLI_CONN_INET6;

    ret = upscli_connect(&ups->conn, ups->hostname, ups->port, flags);

    if (ret < 0) {
        upslogx(LOG_ERR, "UPS [%s]: connect failed: %s",
                ups->sys, upscli_strerror(&ups->conn));

        ups_is_gone(ups);
        return 0;
    }

    ret = try_ssl(ups);

    if (ret == 0)
        return 0;	/* something broke while trying SSL */

    /* we're definitely connected now */
    setflag(&ups->status, ST_CONNECTED);

    /* now try to authenticate to upsd */

    ret = do_upsd_auth(ups);

    if (ret == 1)
        return 1;		/* everything is happy */

    /* something failed in the auth so we may not be completely logged in */

    /* FUTURE: do something beyond the error msgs from do_upsd_auth? */

    return 0;
}
Beispiel #7
0
static void stop_threads(void *data, void *data2) {
	struct thread_pvt *thread = data;
	struct thread_pvt *man = data2;

	/*Dont footbullet*/
	if (!pthread_equal(man->thr, thread->thr)) {
		if (thread->sighandler) {
			pthread_kill(thread->thr, SIGTERM);
		}
		if (testflag(thread, TL_THREAD_CAN_CANCEL) && testflag(thread, TL_THREAD_RUN)) {
			pthread_cancel(thread->thr);
		}
		clearflag(thread, TL_THREAD_RUN);
	}
}
Beispiel #8
0
/*
 * close all threads when we get SIGHUP
 */
static int manager_sig(int sig, void *data) {
#ifndef __WIN32
	struct thread_pvt *thread;

	if (!(thread = get_thread_from_id())) {
		return 0;
	}


	switch(sig) {
		case SIGHUP:
			clearflag(thread, TL_THREAD_RUN);
			break;
		case SIGINT:
		case SIGTERM:
			clearflag(thread, TL_THREAD_RUN);
			setflag(thread, TL_THREAD_STOP);
	}
	objunref(thread);
	return 1;
#else
	return 0;
#endif
}
Beispiel #9
0
static void thread_cleanup(void *data) {
	struct thread_pvt *thread = data;

	/*remove from thread list manager unrefs threads in cleanup run 1st*/
	remove_bucket_item(threads->list, thread);

	/*Run cleanup*/
	clearflag(thread, TL_THREAD_RUN);
	setflag(thread, TL_THREAD_DONE);
	if (thread->cleanup) {
		thread->cleanup(thread->data);
	}

	/*remove thread reference*/
	objunref(thread);
}
Beispiel #10
0
static void ups_on_batt(utype_t *ups)
{
    if (flag_isset(ups->status, ST_ONBATT)) { 	/* no change */
        upsdebugx(4, "%s: %s (no change)", __func__, ups->sys);
        return;
    }

    sleepval = pollfreqalert;	/* bump up polling frequency */

    ups->linestate = 0;

    upsdebugx(3, "%s: %s (first time)", __func__, ups->sys);

    /* must have changed from OL to OB, so notify */

    do_notify(ups, NOTIFY_ONBATT);
    setflag(&ups->status, ST_ONBATT);
    clearflag(&ups->status, ST_ONLINE);
}
Beispiel #11
0
static void ups_on_line(utype_t *ups)
{
    if (flag_isset(ups->status, ST_ONLINE)) { 	/* no change */
        upsdebugx(4, "%s: %s (no change)", __func__, ups->sys);
        return;
    }

    sleepval = pollfreq;

    upsdebugx(3, "%s: %s (first time)", __func__, ups->sys);

    /* ignore the first OL at startup, otherwise send the notifier */
    if (ups->linestate != -1)
        do_notify(ups, NOTIFY_ONLINE);

    ups->linestate = 1;

    setflag(&ups->status, ST_ONLINE);
    clearflag(&ups->status, ST_ONBATT);
}
Beispiel #12
0
/** Ensure the object may be modified without hurting others, throws if this
 *  is not the case. */
void basic::ensure_if_modifiable() const
{
    if (get_refcount() > 1)
        throw(std::runtime_error("cannot modify multiply referenced object"));
    clearflag(status_flags::hash_calculated | status_flags::evaluated);
}
Beispiel #13
0
int main(int argc, char **argv) {
  signed char op;
  parserinfo_mv_t pinfo;
  filelist_t fl;

  struct option longopts[] = {
    { "version", 0, NULL, MV_VERSION },
    { "help", 0, NULL, MV_HELP },
    { "write-files", 0, NULL, MV_FILES },
    { "prepend", 0, NULL, MV_PREPEND },
    { "replace", 0, NULL, MV_REPLACE },
    { "append", 0, NULL, MV_APPEND },
    { 0 }
  };

  progname = "xml-mv";
  inputfile = "";
  inputline = 0;

  if( create_parserinfo_mv(&pinfo) ) {

    while( (op = getopt_long(argc, argv, "",
			     longopts, NULL)) > -1 ) {
      set_option_mv(op, optarg, &pinfo);
    }

    init_signal_handling(SIGNALS_DEFAULT);
    init_file_handling();
    init_tempfile_handling();
    init_rollback_handling();

    if( !checkflag(pinfo.rcm.flags,RCM_CP_PREPEND|RCM_CP_APPEND) ) {
      setflag(&pinfo.rcm.flags,RCM_CP_APPEND);
      setflag(&pinfo.rcm.flags,RCM_CP_REPLACE);
    } 

    if( create_filelist(&fl, -1, argv + optind, FILELIST_MIN2) ) {

      pinfo.files = getfiles_filelist(&fl);
      pinfo.xpaths = getxpaths_filelist(&fl);
      pinfo.n = getsize_filelist(&fl);
    
      if( pinfo.n < 2 ) { 
	errormsg(E_FATAL, "no target specified (try --help).\n");
      }

      pinfo.target = pinfo.files[pinfo.n - 1];
      pinfo.tpaths = pinfo.xpaths[pinfo.n - 1];

      if( !checkflag(pinfo.rcm.flags,RCM_WRITE_FILES) ) {
	/* When --write-files is not selected, we cannot write
	 * to the files on the command line. So we use the following
	 * trick to implement moves within the target file (last on command
	 * line): we replace all instances of the target with a common
	 * tempfile, which we can write to as required. The first instance
	 * of the target is not replaced, since it must be read (to copy
	 * its contents into the tempfile).
	 */
	substitute_target(&pinfo);
      }

      if( stdparse2(pinfo.n - 1, pinfo.files, pinfo.xpaths, &pinfo.std) ) {

	if( reinit_parserinfo_mv(&pinfo) ) {
	  /* output always to stdout */
	  setflag(&pinfo.rcm.flags, RCM_CP_OUTPUT);
	  clearflag(&pinfo.rcm.flags, RCM_RM_OUTPUT);

	  stdparse2(1, &pinfo.files[pinfo.n - 1], 
		    &pinfo.xpaths[pinfo.n - 1], &pinfo.std);

	}

      }

      free_filelist(&fl);
    }

    exit_rollback_handling();
    exit_tempfile_handling();
    exit_file_handling();      
    exit_signal_handling();

    free_parserinfo_mv(&pinfo);
  }

  return EXIT_SUCCESS;
}
Beispiel #14
0
BOOL
rf_queue_add(address_item *addr, address_item **paddr_local,
  address_item **paddr_remote, router_instance *rblock, struct passwd *pw)
{
addr->prop.domain_data = deliver_domain_data;         /* Save these values for */
addr->prop.localpart_data = deliver_localpart_data;   /* use in the transport */

/* Handle a local transport */

if (addr->transport != NULL && addr->transport->info->local)
  {
  ugid_block ugid;

  /* Default uid/gid and transport-time home directory are from the passwd file
  when check_local_user is set, but can be overridden by explicit settings.
  When getting the home directory out of the password information, set the
  flag that prevents expansion later. */

  if (pw != NULL)
    {
    addr->uid = pw->pw_uid;
    addr->gid = pw->pw_gid;
    setflag(addr, af_uid_set|af_gid_set|af_home_expanded);
    addr->home_dir = string_copy(US pw->pw_dir);
    }

  if (!rf_get_ugid(rblock, addr, &ugid)) return FALSE;
  rf_set_ugid(addr, &ugid);

  /* transport_home_directory (in rblock->home_directory) takes priority;
  otherwise use the expanded value of router_home_directory. The flag also
  tells the transport not to re-expand it. */

  if (rblock->home_directory != NULL)
    {
    addr->home_dir = rblock->home_directory;
    clearflag(addr, af_home_expanded);
    }
  else if (addr->home_dir == NULL && testflag(addr, af_home_expanded))
    addr->home_dir = deliver_home;

  addr->current_dir = rblock->current_directory;

  addr->next = *paddr_local;
  *paddr_local = addr;
  }

/* For a remote transport, set up the fallback host list, and keep a count of
the total number of addresses routed to remote transports. */

else
  {
  addr->fallback_hosts = rblock->fallback_hostlist;
  addr->next = *paddr_remote;
  *paddr_remote = addr;
  remote_delivery_count++;
  }

DEBUG(D_route)
  {
  debug_printf("queued for %s transport: local_part = %s\ndomain = %s\n"
    "  errors_to=%s\n",
    (addr->transport == NULL)? US"<unset>" : addr->transport->name,
    addr->local_part, addr->domain, addr->prop.errors_address);
  debug_printf("  domain_data=%s localpart_data=%s\n", addr->prop.domain_data,
    addr->prop.localpart_data);
  }

return TRUE;
}
Beispiel #15
0
/* change some UPS parameters during reloading */
static void redefine_ups(utype_t *ups, int pv, const char *un,
                         const char *pw, const char *master)
{
    ups->retain = 1;

    if (ups->pv != pv) {
        upslogx(LOG_INFO, "UPS [%s]: redefined power value to %d",
                ups->sys, pv);
        ups->pv = pv;
    }

    totalpv += ups->pv;

    if (ups->un) {
        if (strcmp(ups->un, un) != 0) {
            upslogx(LOG_INFO, "UPS [%s]: redefined username",
                    ups->sys);

            free(ups->un);

            ups->un = xstrdup(un);

            /*
             * if not logged in force a reconnection since this
             * may have been redefined to make a login work
             */

            if (!flag_isset(ups->status, ST_LOGIN)) {
                upslogx(LOG_INFO, "UPS [%s]: retrying connection",
                        ups->sys);

                drop_connection(ups);
            }

        }	/* if (strcmp(ups->un, un) != 0) { */

    } else {

        /* adding a username? (going to new style MONITOR line) */

        if (un) {
            upslogx(LOG_INFO, "UPS [%s]: defined username",
                    ups->sys);

            ups->un = xstrdup(un);

            /* possibly force reconnection - see above */

            if (!flag_isset(ups->status, ST_LOGIN)) {
                upslogx(LOG_INFO, "UPS [%s]: retrying connection",
                        ups->sys);

                drop_connection(ups);
            }

        }	/* if (un) */
    }

    /* paranoia */
    if (!ups->pw)
        ups->pw = xstrdup("");	/* give it a bogus, but non-NULL one */

    /* obviously don't put the new password in the syslog... */
    if (strcmp(ups->pw, pw) != 0) {
        upslogx(LOG_INFO, "UPS [%s]: redefined password", ups->sys);

        free(ups->pw);
        ups->pw = xstrdup(pw);

        /* possibly force reconnection - see above */

        if (!flag_isset(ups->status, ST_LOGIN)) {
            upslogx(LOG_INFO, "UPS [%s]: retrying connection",
                    ups->sys);

            drop_connection(ups);
        }
    }

    /* slave -> master */
    if ((!strcasecmp(master, "master")) && (!flag_isset(ups->status, ST_MASTER))) {
        upslogx(LOG_INFO, "UPS [%s]: redefined as master", ups->sys);
        setflag(&ups->status, ST_MASTER);

        /* reset connection to ensure master mode gets checked */
        drop_connection(ups);
        return;
    }

    /* master -> slave */
    if ((!strcasecmp(master, "slave")) && (flag_isset(ups->status, ST_MASTER))) {
        upslogx(LOG_INFO, "UPS [%s]: redefined as slave", ups->sys);
        clearflag(&ups->status, ST_MASTER);
        return;
    }
}