Ejemplo n.º 1
0
/**
* @brief performs a copy of the virtual file exposed by the LM_DUMP kernel
* module and raises a 'RAMDUMP' event.
*
* @param reason - string containing the translated startup reason
*
* @retval returns -1 if a problem occurs (no LM_DUMP file..). 0 otherwise.
*/
static int crashlog_check_ramdump(const char * reason)
{
    char destination[PATHMAX] = {'\0'};
    char *crashtype = RAMDUMP_EVENT;
    int dir;
    const char *dateshort = get_current_time_short(1);
    char *key;

    dir = find_new_crashlog_dir(MODE_CRASH);
    if (dir < 0) {
        LOGE("%s: Cannot get a valid new crash directory...\n", __FUNCTION__);
        key = raise_event(CRASHEVENT, crashtype, NULL, NULL);
        LOGE("%-8s%-22s%-20s%s\n", CRASHEVENT, key, get_current_time_long(0), crashtype);
        free(key);
        return -1;
    }
    /* Copy */
    if( !file_exists(LM_DUMP_FILE) )
        LOGE("%s: can't find file %s - error is %s.\n",
             __FUNCTION__, LM_DUMP_FILE, strerror(errno) );
    else {
        snprintf(destination, sizeof(destination), "%s%d/%s_%s.bin",
                 CRASH_DIR, dir, SAVED_LM_BUFFER_NAME, dateshort);
        do_copy_eof(LM_DUMP_FILE, destination);
    }

    if ( !file_exists(LBR_DUMP_FILE) )
        LOGE("%s: can't find file %s - error is %s.\n",
             __FUNCTION__, LBR_DUMP_FILE, strerror(errno) );
    else {
       destination[0] = '\0';
       snprintf(destination, sizeof(destination), "%s%d/%s_%s.txt",
                CRASH_DIR, dir, SAVED_LBR_BUFFER_NAME, dateshort);
       do_copy_eof(LBR_DUMP_FILE, destination);
    }

    do_last_kmsg_copy(dir);

    /* If startup reason contains "WDT_" without "FAKE", retrieve WDT crash event context */
    if (strstr(reason, "WDT_") && !strstr(reason, "FAKE")) {
        snprintf(destination, sizeof(destination), "%s%d/", CRASH_DIR, dir);
        flush_aplog(APLOG_BOOT, "WDT", &dir, get_current_time_short(0));
        usleep(TIMEOUT_VALUE);
        do_log_copy("WDT", dir, get_current_time_short(0), APLOG_TYPE);
    }

    destination[0] = '\0';
    snprintf(destination, sizeof(destination), "%s%d/", CRASH_DIR, dir);
    key = raise_event(CRASHEVENT, crashtype, NULL, destination);
    LOGE("%-8s%-22s%-20s%s %s\n", CRASHEVENT, key, get_current_time_long(0),
            crashtype, destination);
    free(key);

    return 0;
}
static void
idle_prefs_idle_enable_changed(const gchar * prefs_name)
{
	if(prefs_bool(PREFS_IDLE_ENABLE)) {
		/* create timer */
		if(idle_check_timeout <= 0)
			idle_check_timeout = g_timeout_add(IDLE_CHECK_PERIOD_MS, idle_check_cb, 0);
	} else {
		/* enter the IDLE_NOT mode, if we're disabling idle functionality
		 * and we are in IDLE_AWAY or IDLE_OFFLINE modes
		 */

		/* destroy timer source */
		if(idle_check_timeout>0) {
			g_source_remove(idle_check_timeout);
			idle_check_timeout = 0;
		}

		/* enter the IDLE_NOT mode */
		if(idle_mode != IDLE_NOT) {
			idle_mode = IDLE_NOT;
			raise_event(EVENT_IDLE_NOT, NULL, 0);
		}
	}
}
Ejemplo n.º 3
0
/**
* @brief performs all checks required in RAMDUMP mode.
* In this mode, numerous checks are bypassed.
*
* @param[in] test : test mode flag
*
* @retval returns -1 if a problem occurs (no LM_DUMP file..). 0 otherwise.
*/
int do_ramdump_checks(int test) {

    char startupreason[32] = { '\0', };
    char watchdog[16] = { '\0', };
    char lastuptime[32] = { '\0', };
    char *key;

    strcpy(watchdog,"WDT");

    /* Read the wake-up source */
    read_startupreason(startupreason);
    /* Get the last UPTIME value and write current UPTIME one in history events file */
    uptime_history(lastuptime);
    /* Change log directories permission rights */
    update_logs_permission();

    /* Checks for panic */
    crashlog_check_panic_events(startupreason, watchdog, test);
    /* Dump Lakemore file and raises CRASH RAMDUMP event */
    crashlog_check_ramdump(startupreason);

    /* Raise REBOOT event*/
    key = raise_event(SYS_REBOOT, RAMCONSOLE, NULL, NULL);
    LOGE("%-8s%-22s%-20s%s\n", SYS_REBOOT, key, get_current_time_long(0), RAMCONSOLE);
    free(key);

    request_global_reset();

    return 0;
}
static gboolean
sess_set_topic(session_t * session, const gchar * topic)
{
	gpointer v[2];

	g_assert(session && session->topic && topic);

	if(!strcmp(session->topic, topic)) {
		/* not changed */
		return FALSE;
	}

	/* update session topic text */
	g_free(session->topic);
	session->topic = g_strdup(topic);

	if(session->type==SESSTYPE_CHANNEL) {
		/* write the new topic onto the channel page */
		sess_write(session, SESSTEXT_TOPIC, _("Topic: \"%s\""), topic);
	}

	/* notify session topic change */
	EVENT_V(v, 0) = (gpointer)session;
	EVENT_V(v, 1) = (gpointer)topic;
	raise_event(EVENT_SESSION_TOPIC_CHANGED, v, SESSION_TOPIC_READONLY(session));

	return TRUE;	/* topic was changed */
}
/* prefs_store:
 *	save configuration settings to configuration file
 */
static gboolean
prefs_store()
{
	FILE * cf;

	/* open config file */
	cf = fopen(prefs_file_path, "wb");
	if(!cf) {
		log_ferror(_(LOG_PREFS), g_strdup_printf(
			_("Cannot save configuration settings to file \"%s\": %s"),
			prefs_file_path, strerror(errno)));
	} else {
		/* store settings to file */
		prefs_write_xml_to(cf);
		fclose(cf);

		log_fevent(_(LOG_PREFS), g_strdup_printf(
			_("Configuration settings were stored in \"%s\""),
			prefs_file_path));
	}

	/* config values now are in sync with those on the disk */
	prefs_values_saved = TRUE;
	raise_event(EVENT_PREFS_SAVED, NULL, 0);
	
	return TRUE;
}
static void
dlg_response(GtkDialog * dlg_w, gint response, struct netselect_dlg * dlg)
{
    switch(response) {
    case GTK_RESPONSE_OK:
        /* set network & port */
        prefs_set(PREFS_NET_TYPE, gtk_option_menu_get_history(
                      GTK_OPTION_MENU(dlg->net_type_option)));
        prefs_set(PREFS_NET_PORT, gtk_spin_button_get_value_as_int(
                      GTK_SPIN_BUTTON(dlg->net_port_spin)));
        prefs_set(PREFS_NET_USE_MULTICAST,
                  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dlg->net_use_multicast_w)));
        prefs_set(PREFS_NET_MULTICAST_ADDR, dlg->detect_multicast_addr);
        prefs_set(PREFS_NET_BROADCAST_MASK, dlg->detect_broadcast_mask);

        prefs_set(PREFS_NET_IS_CONFIGURED, TRUE);

        /* hide the dialog */
        netselect_dlg_destroy(&main_netselect_dlg);
        break;
    case GTK_RESPONSE_CANCEL:
    case GTK_RESPONSE_DELETE_EVENT:
        if(!prefs_bool(PREFS_NET_IS_CONFIGURED)) {
            /* one cannot get away without network configured :) */
            raise_event(EVENT_IFACE_EXIT, NULL, 0);
        } else {
            /* network is already configured, destroy the dialog and do nothing */
            netselect_dlg_destroy(&main_netselect_dlg);
        }
        break;
    }
}
Ejemplo n.º 7
0
/* brings interface down and runs a user-supplied script */
static int if_release()
{
	wmlog_msg(2, "Starting if-release script...");
	raise_event("if-release");
	tap_close(tap_fd, tap_dev);
	return 0;
}
Ejemplo n.º 8
0
/* brings interface up and runs a user-supplied script */
static int if_up()
{
	tap_bring_up(tap_fd, tap_dev);
	wmlog_msg(2, "Starting if-up script...");
	raise_event("if-up");
	tap_if_up = 1;
	return 0;
}
Ejemplo n.º 9
0
Archivo: control.c Proyecto: WareX97/K2
int destroy_control(control_t* ctrl) {
	raise_event(ctrl, EVENT_DNIT, 0);
	
	ctrl->events = 0;
	ctrl->invalidate = 0;
	
	return 0;
}
Ejemplo n.º 10
0
Archivo: control.c Proyecto: WareX97/K2
int invalidate(control_t* ctrl) {
	if(ctrl)
		ctrl->invalidate = 1;
		
	raise_event(ctrl, EVENT_INVALIDATE, 0);
		
	return validate(ctrl);
}
Ejemplo n.º 11
0
            void generic_event(wxE & event)
            {
                this->GetNextHandler()->ProcessEvent(event);

                wx_event_info ei = {win, NULL};

                raise_event(E::value, ei);
            }
Ejemplo n.º 12
0
/* brings interface down and runs a user-supplied script */
static int if_down()
{
	if (!tap_if_up) return 0;
	tap_if_up = 0;
	wmlog_msg(2, "Starting if-down script...");
	raise_event("if-down");
	tap_bring_down(tap_fd, tap_dev);
	return 0;
}
Ejemplo n.º 13
0
            void on_resize(wxSizeEvent & event)
            {
                this->GetNextHandler()->ProcessEvent(event);

                point pt(event.GetSize().GetWidth(), event.GetSize().GetHeight());

                wx_event_info ei = {win, &pt};

                raise_event(resize::value, ei);
            }
Ejemplo n.º 14
0
            void mouse_event(wxMouseEvent & event)
            {
                this->GetNextHandler()->ProcessEvent(event);

                point pt(event.GetX(), event.GetY());

                wx_event_info ei = {win, &pt};

                raise_event(E::value, ei);
            }
sess_id
sess_new(
	enum session_type type,
	const gchar * name,
	gboolean closeable,
	gpointer user_id)
{
	session_t * s;
	gboolean first_sess;

	g_assert(name!=NULL && strlen(name));

	/* check if we have such a session already */
	if(sess_find(type, name)) return NULL;

	/* alloc and fill in session_t */
	s = g_malloc(sizeof(session_t));
	s->name = g_strdup(name);
	s->topic = g_strdup("");
	s->topic_readonly = type!=SESSTYPE_CHANNEL;
	s->type = type;
	s->hilited = FALSE;
	s->uid = type==SESSTYPE_PRIVATE ? user_id: NULL;
	s->closeable = closeable;

	/* insert into the list */
	first_sess = sess_list==NULL;
	sess_list = g_list_append(sess_list, (gpointer)s);

	/* create gui session */
	gui_page_new(
		type, name, NULL, closeable,
		DEFAULT_SESSION_SIZE, (void*)s, user_id);

	/* write out the text */
	switch(type) {
	case SESSTYPE_PRIVATE:
		sess_write(s, SESSTEXT_NOTIFY, _("Chat with %n has been opened"), name);
		break;
	case SESSTYPE_CHANNEL:
		sess_write(s, SESSTEXT_NOTIFY, _("Joined channel %h"), name);
		break;
	default:
		break;
	}

	/* inform about changes */
	raise_event(EVENT_SESSION_OPENED, (void*)s, (int)type);

	return (sess_id)s;
}
Ejemplo n.º 16
0
/* brings interface up and runs a user-supplied script */
static int if_create()
{
	tap_fd = tap_open(tap_dev);
	if (tap_fd < 0) {
		wmlog_msg(0, "failed to allocate tap interface");
		wmlog_msg(0,
				"You should have TUN/TAP driver compiled in the kernel or as a kernel module.\n"
				"If 'modprobe tun' doesn't help then recompile your kernel.");
		exit_release_resources(1);
	}
	tap_set_hwaddr(tap_fd, tap_dev, wd_status.mac);
	tap_set_mtu(tap_fd, tap_dev, 1386);
	set_coe(tap_fd);
	wmlog_msg(0, "Allocated tap interface: %s", tap_dev);
	wmlog_msg(2, "Starting if-create script...");
	raise_event("if-create");
	return 0;
}
void sess_delete(sess_id s)
{
	g_assert(PSESSION_T(s));

	/* inform about delete */
	raise_event(EVENT_SESSION_CLOSED, (void*)s, (int)PSESSION_T(s)->type);

	/* delete from gui */
	gui_page_delete((void*)s);

	/* delete from list */
	sess_list = g_list_remove(sess_list, (gpointer)s);

	/* cleanup the struct */
	g_free(PSESSION_T(s)->name);
	g_free(PSESSION_T(s)->topic);
	g_free(PSESSION_T(s));
}
Ejemplo n.º 18
0
        static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
        {
            msw_window * mswwin = mythos_window_from_native(hwnd);
            msw_event_info ei = {mswwin, uMsg, wParam, lParam, NULL};

            LRESULT wrapped_result = 1;

            // call wrapped window proc first (if any)
            if (mswwin->wrapped_proc)
            {
                wrapped_result = ::CallWindowProc(mswwwin->wrapped_proc, hwnd, uMsg, wParam, lParam);
            }

            switch (uMsg)
            {
            case WM_PAINT:
                return raise_event(evt::paint::value, ei) && wrapped_result;
            case WM_LBUTTONDOWN:
                return raise_event(evt::l_button_down::value, ei) && wrapped_result;
            case WM_MBUTTONDOWN:
                return raise_event(evt::m_button_down::value, ei) && wrapped_result;
            case WM_RBUTTONDOWN:
                return raise_event(evt::r_button_down::value, ei) && wrapped_result;
            case WM_LBUTTONUP:
                return raise_event(evt::l_button_up::value, ei) && wrapped_result;
            case WM_MBUTTONUP:
                return raise_event(evt::m_button_up::value, ei) && wrapped_result;
            case WM_RBUTTONUP:
                return raise_event(evt::r_button_up::value, ei) && wrapped_result;
            case WM_MOUSEMOVE:
                return raise_event(evt::mouse_move::value, ei) && wrapped_result;
            case WM_SIZE:
                return raise_event(evt::resize::value, ei) && wrapped_result;
            };

            return wrapped_result;
        }
Ejemplo n.º 19
0
Archivo: control.c Proyecto: WareX97/K2
int create_control(control_t* ctrl, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int backcolor, unsigned int forecolor, event_handler_t handler) {
	ctrl->x = x;
	ctrl->y = y;
	ctrl->width = width;
	ctrl->height = height;
	ctrl->backcolor = backcolor;
	ctrl->forecolor = forecolor;
	ctrl->invalidate = 0;
	ctrl->events = 0;
	ctrl->event_handler = handler;
	ctrl->pid = getpid();
	
	set_event(ctrl, EVENT_INIT, 1);
	set_event(ctrl, EVENT_DNIT, 1);
	set_event(ctrl, EVENT_INVALIDATE, 1);
	
	raise_event(ctrl, EVENT_INIT, 0);
	invalidate(ctrl);
	
	return 0;
}
Ejemplo n.º 20
0
/* brings interface up and runs a user-supplied script */
static int if_create()
{
	tap_fd = tap_open(tap_dev);
	if (tap_fd < 0) {
		wmlog_msg(0, "failed to allocate tap interface");
		wmlog_msg(0,
				"You should have TUN/TAP driver compiled in the kernel or as a kernel module.\n"
				"If 'modprobe tun' doesn't help then recompile your kernel.");
		exit_release_resources(1);
	}
	tap_set_hwaddr(tap_fd, tap_dev, wd_status.mac);
	tap_set_mtu(tap_fd, tap_dev, 1386);
	set_coe(tap_fd);
  
  //tap_dev pointed now to correct interface so we are free to update stistics paths
  sprintf(stat_rx_total_path, "/sys/class/net/%s/statistics/rx_bytes", tap_dev);
  sprintf(stat_tx_total_path, "/sys/class/net/%s/statistics/tx_bytes", tap_dev);
  
	wmlog_msg(0, "Allocated tap interface: %s", tap_dev);
	wmlog_msg(2, "Starting if-create script...");
	raise_event("if-create");
	return 0;
}
/*
 * updates SESSTYPE_PRIVATE session name for specified user,
 * if any; emits rename info to all the channels
 */
static void
handle_user_rename(
	gpointer user_id, gpointer prev_nickname)
{
	gpointer v[2];
	session_t * session;

	/* find private channel with the user */
	session = (session_t*) sess_find(SESSTYPE_PRIVATE, user_name_of(user_id));
	if(session) {
		/* rename session */
		g_free(session->name);
		session->name = g_strdup(user_name_of(user_id));

		/* raise event about session name change */
		EVENT_V(v, 0) = (gpointer)session;
		EVENT_V(v, 1) = (gpointer)user_name_of(user_id);
		raise_event(EVENT_SESSION_RENAMED, v, 0);
	}
	
	/* emit 'xx has renamed in yy' to all the channels */
	emit_user_rename(user_id, prev_nickname);
}
Ejemplo n.º 22
0
void raise_warning_event(str *param, unsigned int *val, unsigned int *thr,
		str *user, str *number, unsigned int *ruleid)
{
	raise_event(ei_warn_id, param, val, thr, user, number, ruleid);
}
Ejemplo n.º 23
0
void op_fileinfo()
{
 /* Stack:

     |================================|=============================|
     |            BEFORE              |           AFTER             |
     |================================|=============================|
 top |  Key                           | Information                 |
     |--------------------------------|-----------------------------| 
     |  ADDR to file variable         |                             |
     |================================|=============================|

 Key values:           Action                         Returns
     0 FL_OPEN         Test if is open file variable  True/False
     1 FL_VOCNAME      Get VOC name of file           VOC name
     2 FL_PATH         Get file pathname              Pathname
     3 FL_TYPE         Check file type                DH:         FL_TYPE_DH  (3)
                                                      Directory:  FL_TYPE_DIR (4)
                                                      Sequential: FL_TYPE_SEQ (5)
     5 FL_MODULUS      File modulus                   Modulus value
     6 FL_MINMOD       Minimum modulus                Minimum modulus value
     7 FL_GRPSIZE      Group size                     Group size
     8 FL_LARGEREC     Large record size              Large record size
     9 FL_MERGE        Merge load percentage          Merge load
    10 FL_SPLIT        Split load percentage          Split load
    11 FL_LOAD         Current load percentage        Current load
    13 FL_AK           File has AK indices?           Boolean
    14 FL_LINE         Number of next line            Line number
  1000 FL_LOADBYTES    Current load in bytes          Current load bytes
  1001 FL_READONLY     Read only file?                Boolean
  1002 FL_TRIGGER      Get trigger function name      Call name
  1003 FL_PHYSBYTES    Physical file size             Size in bytes, excl indices
  1004 FL_VERSION      File version
  1005 FL_STATS_QUERY  Query file stats status        Boolean
  1006 FL_SEQPOS       File position                  File offset
  1007 FL_TRG_MODES    Get trigger modes              Mode mask
  1008 FL_NOCASE       File uses case insensitive ids?  Boolean
  1009 FL_FILENO       Return internal file number    File number
  1010 FL_JNL_FNO      Return journalling file no     File no, zero if not journalling
  1011 FL_AKPATH       Returns AK subfile location    Pathname of directory
  1012 FL_ID           Id of last record read         Id
  1013 FL_STATUS       As STATUS statement            Dynamic array
  1014 FL_MARK_MAPPING Is mark mapping enabled?       Boolean
  1015 FL_RECORD_COUNT Approximate record count
  1016 FL_PRI_BYTES    Primary subfile size in bytes
  1017 FL_OVF_BYTES    Overflow subfile size in bytes
  1018 FL_NO_RESIZE    Resizing inhibited?
  1019 FL_UPDATE       Update counter
  1020 FL_ENCRYPTED    File uses encryption?          Boolean
 10000 FL_EXCLUSIVE    Set exclusive access           Successful?
 10001 FL_FLAGS        Fetch file flags               File flags
 10002 FL_STATS_ON     Turn on file statistics
 10003 FL_STATS_OFF    Turn off file statistics
 10004 FL_STATS        Return file statistics
 10005 FL_SETRDONLY    Set file as read only
 */

 short int key;
 DESCRIPTOR * descr;
 FILE_VAR * fvar;
 DH_FILE * dh_file;
 char * p = NULL;
 long int n = 0;
 FILE_ENTRY * fptr;
 OSFILE fu;
 bool dynamic;
 bool internal;
 long int * q;
 STRING_CHUNK * str;
 short int i;
 double floatnum;
 u_char ftype;
 int64 n64;


 /* Get action key */

 descr = e_stack - 1;
 GetInt(descr);
 key = (short int)(descr->data.value);
 k_pop(1);

 /* Get file variable */

 descr = e_stack - 1;
 while(descr->type == ADDR) {descr = descr->data.d_addr;}


 if (key == FL_OPEN)    /* Test if file is open */
  {
   n = (descr->type == FILE_REF);
  }
 else
  {
   if (descr->type != FILE_REF) k_error(sysmsg(1200));

   fvar = descr->data.fvar;
   ftype = fvar->type;
   if (ftype == NET_FILE)  /* Network file */
    {
     str = net_fileinfo(fvar, key);
     k_dismiss();
     InitDescr(e_stack, STRING);
     (e_stack++)->data.str.saddr = str;
     return;
    }


   fptr = FPtr(fvar->file_id);

   dynamic = (ftype == DYNAMIC_FILE);
   if (dynamic) dh_file = fvar->access.dh.dh_file;

   internal = ((process.program.flags & HDR_INTERNAL) != 0);
   switch(key)
    {
     case FL_VOCNAME:     /* 1  VOC name of file */
        if (fvar->voc_name != NULL) p = fvar->voc_name;
        else p = "";
        goto set_string;

     case FL_PATH:        /* 2  File pathname */
        p = (char *)(fptr->pathname);
        goto set_string;

     case FL_TYPE:        /* 3  File type */
        /* !!FVAR_TYPES!! */
        switch(ftype)
         {
          case DYNAMIC_FILE:
             n = FL_TYPE_DH;
             break;
          case DIRECTORY_FILE:
             n = FL_TYPE_DIR;
             break;
          case SEQ_FILE:
             n = FL_TYPE_SEQ;
             break;
         }
        break;

     case FL_MODULUS:     /* 5  Modulus of file */
        if (dynamic) n = fptr->params.modulus;
        break;

     case FL_MINMOD:      /* 6  Minimum modulus of file */
        if (dynamic) n = fptr->params.min_modulus;
        break;

     case FL_GRPSIZE:     /* 7  Group size of file */
        if (dynamic) n = dh_file->group_size / DH_GROUP_MULTIPLIER;
        break;

     case FL_LARGEREC:    /* 8  Large record size */
        if (dynamic) n = fptr->params.big_rec_size;
        break;

     case FL_MERGE:       /* 9  Merge load percentage */
        if (dynamic) n = fptr->params.merge_load;
        break;

     case FL_SPLIT:       /* 10  Split load percentage */
        if (dynamic) n = fptr->params.split_load;
        break;

     case FL_LOAD:        /* 11  Load percentage */
        if (dynamic)
         {
          n = DHLoad(fptr->params.load_bytes, dh_file->group_size, fptr->params.modulus);
         }
        break;

     case FL_AK:          /* 13  File has AKs? */
        if (dynamic) n = (dh_file->ak_map != 0);
        break;

     case FL_LINE:        /* 14  Sequential file line position */
        if (ftype == SEQ_FILE)
         {
          n64 = fvar->access.seq.sq_file->line;
          if (n64 > LONG_MAX)
           {
            floatnum = (double)n64;
            goto set_float;
           }
          n = (long)n64;
         }
        break;

     case FL_LOADBYTES:   /* 1000  Load bytes */
        if (dynamic)
         {
          floatnum = (double)(fptr->params.load_bytes);
          goto set_float;
         }
        break;

     case FL_READONLY:    /* 1001  Read-only? */
        n = ((fvar->flags & FV_RDONLY) != 0);
        break;

     case FL_TRIGGER:     /* 1002  Trigger function name */
        if (dynamic)
         {
          p = dh_file->trigger_name;
          goto set_string;
         }
        break;

     case FL_PHYSBYTES:   /* 1003  Physical file size */
        switch(ftype)
         {
          case DIRECTORY_FILE:
             floatnum = (double)dir_filesize(fvar);
             break;
          case DYNAMIC_FILE:
             floatnum = (double)dh_filesize(dh_file, PRIMARY_SUBFILE) + dh_filesize(dh_file, OVERFLOW_SUBFILE);
             break;
          case SEQ_FILE:
             fu = fvar->access.seq.sq_file->fu;
             floatnum = (double)(ValidFileHandle(fu)?filelength64(fu):-1);
             break;
         }
        goto set_float;

     case FL_VERSION:     /* 1004  File version */
        if (dynamic) n = dh_file->file_version;
        break;

     case FL_STATS_QUERY: /* 1005  File statistics enabled? */
        if (dynamic) n = (fptr->stats.reset != 0);
        break;

     case FL_SEQPOS:      /* 1006  Sequential file offset */
        if (ftype == SEQ_FILE)
         {
          n64 = fvar->access.seq.sq_file->posn;
          if (n64 > LONG_MAX)
           {
            floatnum = (double)n64;
            goto set_float;
           }
          n = (long)n64;
         }
        break;

     case FL_TRG_MODES:   /* 1007  Trigger modes */
        if (dynamic) n = dh_file->trigger_modes;
        break;

     case FL_NOCASE:      /* 1008  Case insensitive ids? */
        switch(ftype)
         {
          case DIRECTORY_FILE:
          case DYNAMIC_FILE:
             n = (fptr->flags & DHF_NOCASE) != 0;
             break;
         }
        break;

     case FL_FILENO:      /* 1009  Internal file number */
        n = fvar->file_id;
        break;

     case FL_JNL_FNO:     /* 1010  Journalling file number */
        break;

     case FL_AKPATH:      /* 1011  AK subfile pathname */
        if (dynamic)
         {
          p = dh_file->akpath;
          goto set_string;
         }
        break;

     case FL_ID:          /* 1012  Id of last record read */
        k_dismiss();
        k_put_string(fvar->id, fvar->id_len, e_stack);
        e_stack++;
        return;

     case FL_STATUS:      /* 1013  STATUS array */
        str = get_file_status(fvar);
        k_dismiss();
        InitDescr(e_stack, STRING);
        (e_stack++)->data.str.saddr = str;
        return;

     case FL_MARK_MAPPING: /* 1014  Mark mapping enabled? */
        if (ftype == DIRECTORY_FILE) n = fvar->access.dir.mark_mapping;
        break;

     case FL_RECORD_COUNT: /* 1015  Approximate record count */
        if (dynamic)
         {
          floatnum = (double)(fptr->record_count);
          goto set_float;
         }
        else n = -1;

     case FL_PRI_BYTES:   /* 1016  Physical size of primary subfile */
        if (dynamic)
         {
          floatnum = (double)dh_filesize(dh_file, PRIMARY_SUBFILE);
          goto set_float;
         }
        break;

     case FL_OVF_BYTES:   /* 1017  Physical size of overflow subfile */
        if (dynamic)
         {
          floatnum = (double)dh_filesize(dh_file, OVERFLOW_SUBFILE);
          goto set_float;
         }
        break;

     case FL_NO_RESIZE:   /* 1018  Resizing inhibited? */
        if (dynamic) n = ((fptr->flags & DHF_NO_RESIZE) != 0);
        break;

     case FL_UPDATE:      /* 1019  File update counter */
        n = (long)(fptr->upd_ct);
        break;

     case FL_ENCRYPTED:   /* 1020  File uses encryption? */
        /* Recognised but returns default zero */
        break;

     case FL_EXCLUSIVE:   /* 10000  Set exclusive access mode */
        if (internal)
         {
          /* To gain exclusive access to a file it must be open only to this
             process (fptr->ref_ct = 1) and must not be open more than once
             in this process.  The latter condition only affects dynamic files
             as other types produce multiply referenced file table entries.
             We need to ensure a dynamic file is only open once so that when
             we close the file we really are going to kill off the DH_FILE
             structure. This is essential, for example, in AK creation where
             the DH_FILE structure has to change its size.                   */

          flush_dh_cache();    /* Ensure we are not stopped by a cached
                                  reference from our own process.       */
          n = FALSE;
          for (i = 0; i < 6; i++)
           {
            StartExclusive(FILE_TABLE_LOCK, 37);
            if ((fptr->ref_ct == 1)
               && ((ftype != DYNAMIC_FILE) || (dh_file->open_count == 1)))
             {
              fptr->ref_ct = -1;
              fptr->fvar_index = fvar->index;
              n = TRUE;
             }
            EndExclusive(FILE_TABLE_LOCK);

            if (n) break;

            if (i == 0)  /* First attempt */
             {
              /* Cannot gain exclusive access. Maybe some other process has
                 the file in its DH cache. Fire an EVT_FLUSH_CACHE event to
                 all processes to see if this clears the problem. We then
                 continue trying for a short time until either we get the
                 required access or we reach our retry count.              */
              raise_event(EVT_FLUSH_CACHE, -1);
             }

            Sleep(500);   /* Pause for something to happen */
           }
         }
        break;

     case FL_FLAGS:       /* 10001  File flags */
        if (dynamic && internal) n = (long int)(dh_file->flags);
        break;

     case FL_STATS_ON:    /* 10002  Enable file statistics */
        if (dynamic && internal)
         {
          memset((char *)&(fptr->stats), 0, sizeof(struct FILESTATS));
          fptr->stats.reset = qmtime();
         }
        break;

     case FL_STATS_OFF:   /* 10003  Disable file statistics */
        if (dynamic && internal) fptr->stats.reset = 0;
        break;

     case FL_STATS:       /* 10004  Return file statistics data */
        if (dynamic && internal)
         {
          str = NULL;
          ts_init(&str, 5 * FILESTATS_COUNTERS);
          for (i = 0, q = (long int *)&(fptr->stats.reset); i < FILESTATS_COUNTERS; i++, q++)
           {
            ts_printf("%ld\xfe", *q);
           }
          (void)ts_terminate();
          k_dismiss();    /* 0363 */
          InitDescr(e_stack, STRING);
          (e_stack++)->data.str.saddr = str;
          return;
         }
        break;

     case FL_SETRDONLY:   /* 10005  Set read-only */
        if (internal)
         {
          fvar->flags |= FV_RDONLY;
          if (dynamic) dh_file->flags |= DHF_RDONLY;
         }
        break;

     default:
        k_error(sysmsg(1010));
    }
  }

 /* Set integer return value on stack */

set_integer:
 k_dismiss();
 InitDescr(e_stack, INTEGER);
 (e_stack++)->data.value = n;
 return;

/* Set string return value on stack */

set_string:
 k_dismiss();
 k_put_c_string(p, e_stack);
 e_stack++;
 return;

set_float:
 if (floatnum <= (double)LONG_MAX)
  {
   n = (long)floatnum;
   goto set_integer;
  }

 k_dismiss();
 InitDescr(e_stack, FLOATNUM);
 (e_stack++)->data.float_value = floatnum;
 return;
}
Ejemplo n.º 24
0
void raise_critical_event(str *param, unsigned int *val, unsigned int *thr,
		str *user, str *number, unsigned int *ruleid)
{
	raise_event(ei_crit_id, param, val, thr, user, number, ruleid);
}
static void
sess_event_cb(enum app_event_enum event, gpointer p, int i)
{
	session_t *sid;
	gpointer event_v[2];

	if(event & EVENT_NET) {
		sess_net_event(event, p, i);
		return;
	}

	switch(event) {
	case EVENT_MAIN_INIT:
		sess_list = NULL;
		break;

	case EVENT_MAIN_REGISTER_PREFS:
		prefs_register(
			PREFS_SESS_STAMP_CHANNEL, PREFS_TYPE_BOOL,
			_("Time-stamp channel text"), NULL, NULL);
		prefs_register(
			PREFS_SESS_STAMP_PRIVATE, PREFS_TYPE_BOOL,
			_("Time-stamp private text"), NULL, NULL);
		prefs_register(
			PREFS_SESS_STAMP_STATUS, PREFS_TYPE_BOOL,
			_("Time-stamp status text"), NULL, NULL);
		prefs_register(
			PREFS_SESS_IMPORTANT_CHANNELS, PREFS_TYPE_LIST,
			_("List of channels that trigger popup on new text"), NULL, NULL);
		prefs_register(
			PREFS_SESS_SUPPRESS_RENAME_TEXT, PREFS_TYPE_BOOL,
			_("Suppress rename messages"), NULL, NULL);
		prefs_register(
			PREFS_SESS_SUPPRESS_MODE_TEXT, PREFS_TYPE_BOOL,
			_("Suppress mode change messages"), NULL, NULL);
		prefs_register(
			PREFS_SESS_SUPPRESS_JOIN_LEAVE_TEXT, PREFS_TYPE_BOOL,
			_("Suppress join/leave messages"), NULL, NULL);
		break;

	case EVENT_MAIN_PRESET_PREFS:
		prefs_set(PREFS_SESS_STAMP_CHANNEL, TRUE);
		prefs_set(PREFS_SESS_STAMP_PRIVATE, TRUE);
		prefs_set(PREFS_SESS_STAMP_STATUS, TRUE);
		break;

	case EVENT_MAIN_PRECLOSE:
		delete_all_sessions();
		break;
	case EVENT_IFACE_PAGE_SWITCH:
		/* un-hilite page if hilited */
		if(PSESSION_T(p)->hilited) {
			gui_page_hilite(p, FALSE);
			PSESSION_T(p)->hilited = FALSE;
		}
		break;
	case EVENT_IFACE_PAGE_CLOSE:
		sid = p ? (sess_id)p: sess_current();
		if(PSESSION_T(sid)->closeable) {
			/*
			 * Delete session and it's page
			 * only if it's closeable (by the user).
			 */
			sess_delete(sid);
		}
		break;
	case EVENT_IFACE_USER_OPEN_REQ:
		sess_private_open_req(p);
		break;
	case EVENT_IFACE_TOPIC_ENTER:
		sid = EVENT_V(p, 0);
		if(!SESSION_TOPIC_READONLY(sid)) {
			/* here we don't care to set topic for ALL the channels in case of QChat,
			 * as net.c will forcefully raise EVENT_NET_MSG_TOPIC_CHANGE
			 */
			if(sess_set_topic(sid, (const gchar*)EVENT_V(p, 1))) {
				EVENT_V(event_v, 0) = sid;
				EVENT_V(event_v, 1) = EVENT_V(p, 1);
				raise_event(EVENT_SESSION_TOPIC_ENTER, event_v, 0);
			}
		}
		break;
	case EVENT_IFACE_JOIN_CHANNEL:
		sid = sess_find(SESSTYPE_CHANNEL, (const gchar *)p);
		if(!sid)
			sid = sess_new(SESSTYPE_CHANNEL, (const gchar *)p, TRUE, NULL);

		sess_switch_to(sid);
		break;

	case EVENT_CMDPROC_SESSION_TEXT:
		sess_handle_my_text((const char *)p, i);
		break;
	case EVENT_USER_RENAME:
		handle_user_rename(EVENT_V(p, 0), EVENT_V(p, 1));
		break;
	case EVENT_USER_MODE_CHANGE:
		handle_user_mode_change(p, (enum user_mode_enum)i);
		break;
	default:
		break;
	}
}
Ejemplo n.º 26
0
void do_daemon() {
/* do_leap
 * Main LEAP daemon routine - Contains socket handler
 */
	char buffer[MAXIMUM_INPUT_STRING+1];
	char loginname[MAXIMUM_INPUT_STRING+1];
	char password[MAXIMUM_INPUT_STRING+1];
	char maincommand[MAXIMUM_INPUT_STRING+1];
	char tprompt[MAXIMUM_INPUT_STRING+1];
	char *result,*tresult,*plogin,*ppass;
	relation result_relation;
	int res,startscript=0;
	int serverSocket=0, on=0, port=0, status=0, childPid=0;
	struct hostent *hostPtr=NULL;
	char hostname[80]="";
	struct sockaddr_in serverName={0},clientName={0};
	struct linger linger={0};
	struct utsname sysinfo;
	int clientLength;
	tuple ctuple;

	clientLength=sizeof(clientName);

	tempdb=LEAPAPI_db_create(NULL,TEMPDB_NAME);
	res=relations_ddopen(tempdb);
	if (res!=RETURN_SUCCESS) {
		raise_error(ERROR_OPEN_DATABASE,FATAL,TEMPDB_NAME);		
	}

	/* Open the master database */
	master_db=LEAPAPI_db_create(NULL,MASTER_DB_NAME);
	res=relations_ddopen(master_db);
	if (res!=RETURN_SUCCESS) {
		raise_error(ERROR_OPEN_DATABASE,FATAL,MASTER_DB_NAME);		
	}

	if (strlen(dbtoopen)==0) {
		/* Open up the default user database */
		current_db=LEAPAPI_db_create(NULL,DEFAULT_DB);
	} else {
		current_db=LEAPAPI_db_create(NULL,dbtoopen);
	}

	res=relations_ddopen(current_db);
	if (res!=RETURN_SUCCESS) {
		raise_error(ERROR_OPEN_DATABASE,FATAL,database_name(current_db));		
	}
	
	set_variable(VAR_CURRENTDB,database_name(current_db));

	/* Check to see if the logins relation exists */
	result_relation=relation_find(master_db,LEAP_DD_LOGINS);	

	if (result_relation==NULL) {
		raise_error(ERROR_CANNOT_FIND_REL,NONFATAL,LEAP_DD_LOGINS);
		raise_message(MESSAGE,"Building %s",LEAP_DD_LOGINS);

        /* Build the leaplogins relation */
        sprintf(buffer,"(SUID,INTEGER,3),(NAME,string,25),(PASSWORD,string,25),(DEFAULTDB,string,25)");
        relation_insert(master_db,create_user_relation(master_db,buffer,LEAP_DD_LOGINS,FALSE,TRUE));

        vprocess_query(master_db,"add (%s) (%d,%s,%s,%s)",LEAP_DD_LOGINS,LEAP_SUID_DBA,LEAP_LOGIN_DBA,LEAP_PASS_DBA,MASTER_DB_NAME);
	} else {
		raise_message(MESSAGE,"Found %s!",LEAP_DD_LOGINS);
	}


	if (status_quiet!=TRUE) {
		raise_message(MESSAGE,"%s","Startup sequence initiated.");
	}

	terminate=FALSE;
	terminatenow=FALSE;

	if (status_quiet) {
			strcpy(current_prompt,"");
			set_prompt("");
	} else {
			strcpy(current_prompt,DEFAULT_PROMPT);
			set_prompt(DEFAULT_PROMPT);
	}

	if (configuration!=TRUE) {
		raise_message(MESSAGE,"Sourcing %s%s in %s",LEAP_STARTUP,LEAP_SOURCE_EXT,database_name(master_db));
		sprintf(buffer,"%s%s%s%s",database_dir(master_db),LEAP_SOURCE_DIR,LEAP_STARTUP,LEAP_SOURCE_EXT);
		assign_input_stream(buffer);
	} else {
		sprintf(buffer,"%s",configurationfile);
		assign_input_stream(buffer);
	}


	serverSocket=socket(PF_INET,SOCK_STREAM,0);

	if (serverSocket==-1) {
		raise_error(ERROR_SOCKETINIT,FATAL,"socket()");
	}

	on=1;

	status=setsockopt(serverSocket,SOL_SOCKET,SO_REUSEADDR,(const char *) &on,sizeof(on));

	if (status==-1) {
		raise_error(ERROR_SOCKETINIT,FATAL,"setsockopt(...,SO_REUSEADDR,...)");
	}
	
	linger.l_onoff=1;
	linger.l_linger=30;
	status=setsockopt(serverSocket,SOL_SOCKET,SO_LINGER,(const char *) &linger,sizeof(linger));
	if (status==-1) {
		raise_error(ERROR_SOCKETINIT,FATAL,"setsockopt(...,SO_LINGER,...)");
	}
		
	status=uname(&sysinfo);
	if (status==-1) {
		raise_error(ERROR_SOCKETINIT,FATAL,"uname");
	} else {
		strncpy(hostname,sysinfo.nodename,sizeof(hostname));
	}
		
	status=gethostname(hostname,sizeof(hostname));
	hostPtr=gethostbyname(hostname);

	if (hostPtr==NULL) {
		raise_error(ERROR_SOCKETINIT,FATAL,"gethostbyname");
	} 
	
	(void) memset(&serverName,0,sizeof(serverName));
	(void) memcpy(&serverName.sin_addr,hostPtr->h_addr,hostPtr->h_length);
	
	serverName.sin_family=AF_INET;
	serverName.sin_port=htons(LEAPD_PORT);
	status=bind(serverSocket,(struct sockaddr *) &serverName,sizeof(serverName));

	if (status<0) {
		raise_error(ERROR_SOCKETINIT,FATAL,"bind() - port %u - errno %u",LEAPD_PORT,errno);
	} else {
		raise_message(MESSAGE,"Daemon starting on machine %s, port %u",hostname,LEAPD_PORT);
	}

	status=listen(serverSocket,LEAPD_BACK_LOG);
	if (status==-1) {
		raise_error(ERROR_SOCKETINIT,FATAL,"listen()");
	}


	while (!terminatenow) {
			slaveSocket=accept(serverSocket,(struct sockaddr *) &clientName,&clientLength);

			if (slaveSocket==-1) {
				raise_error(ERROR_SOCKETINIT,FATAL,"accept()");
			}
				
			raise_message(MESSAGE,"Connection received from [%s]",inet_ntoa(clientName.sin_addr));

			raise_message(MESSAGE,"Authenication expected");

			strcpy(buffer,"Please authenticate yourself: ");
			write(slaveSocket,buffer,strlen(buffer));

			read(slaveSocket,loginname,MAXIMUM_INPUT_STRING);
			plogin=strtok(loginname,"\r\n");
			raise_message(MESSAGE,"Login [%s] connecting...",plogin);

			if (strcmp(plogin,"guest")==0) {
				strcpy(buffer,"Enter your e-mail address: ");
				write(slaveSocket,buffer,strlen(buffer));
			} else {
				strcpy(buffer,"Password: "******"project (select (%s) (%s='%s')) (%s)",LEAP_DD_LOGINS,LEAP_DDA_LOGINS_NAME,plogin,LEAP_DDA_LOGINS_PASSWORD);
			result_relation=process_query(master_db,buffer);

			status=read(slaveSocket,password,MAXIMUM_INPUT_STRING);
			ppass=strtok(password,"\r\n");

			if ((ppass!=NULL) && (status==2)) {
				*ppass='******';
			}

			ctuple=tuple_readfirst(result_relation,TUPLE_BUILD,NULL);
			if (ctuple!=NULL) {
				tuple_to_string(ctuple,buffer);
				raise_message(MESSAGE,"Password expected [%s]",buffer);
				raise_message(MESSAGE,"Password received [%s]",ppass);
			} else {
				if (strcmp(plogin,"guest")==0) {
					raise_message(MESSAGE,"Guest ID [%s]",ppass);
				} else {
					raise_message(MESSAGE,"No login [%s] exists!",plogin);
				}
			}
	
			if (((strcmp(plogin,"guest")==0))||(strcmp(buffer,ppass)==0)) {
					raise_message(MESSAGE,"Login [%s] validated!",plogin); 
					/* Enable daemon on - this will send io to client */
					status_daemon=TRUE;
				
					strcpy(buffer,"version");
					result_relation=process_query(current_db,buffer);

					/* Ok, socket is initialised! */
					while (!terminate) {

						write(slaveSocket,DEFAULT_PROMPT,sizeof(DEFAULT_PROMPT));
						status=read(slaveSocket,buffer,MAXIMUM_INPUT_STRING);
						/* Null terminate reqd....*/
						
						result=strtok(buffer,"\r\n");
						
						status_daemon=FALSE;
						raise_message(MESSAGE,"received: %s",result);
						status_daemon=TRUE;

						result_relation=process_query(current_db,result);

					}
					/* Disable daemon */
					status_daemon=FALSE;
			} else {
				raise_message(MESSAGE,"Invalid password for login [%s]",plogin);
			}

			/* Reset terminate - one client has disconnected */
			terminate=FALSE;

			raise_message(MESSAGE,"Connection closed");
			close(slaveSocket);
	}

	if (!status_quiet) { raise_message(MESSAGE,"Closing [%s] database.",database_name(current_db)); }
	
	relations_dispose_all(current_db);

	LEAPAPI_db_destroy(&current_db);

	raise_event(EVENT,"[current_db] closed.");

	if (!status_quiet) { raise_message(MESSAGE,"Closing [%s] database.",database_name(master_db)); }

	relations_dispose_all(master_db);
	
	LEAPAPI_db_destroy(&master_db);

	raise_event(EVENT,"[master_db] closed.");

	if (!status_quiet) { raise_message(MESSAGE,"Closing [%s] database.",database_name(tempdb)); }

	relations_dispose_all(tempdb);
	
	LEAPAPI_db_destroy(&tempdb);

	raise_event(EVENT,"[tempdb] closed.");
}
void prefs_set(const gchar * prefs_name, ...)
{
	va_list ap;
	struct prefs_value * value;
	guint new_guint;
	gboolean new_gboolean;
	const gchar * new_string;

	va_start(ap, prefs_name);

	value = g_hash_table_lookup(prefs_hash, prefs_name);
	if(value) {
		gboolean validated;
		union prefs_value_union value_backup;

		/* backup the current value, if the validator decides the new one is invalid */
		value_backup = value->value;

		/* check if the old value hasn't changed
		 * and if so, set the new value */
		switch(value->type) {
		case PREFS_TYPE_UINT:
			new_guint = va_arg(ap, guint);
			if(value->value.integer!=new_guint)
				value->value.integer = new_guint;
			else
				goto no_change;
			break;
		case PREFS_TYPE_BOOL:
			new_gboolean = va_arg(ap, gboolean);
			if(value->value.boolean!=new_gboolean)
				value->value.boolean = new_gboolean;
			else
				goto no_change;
			break;
		case PREFS_TYPE_STR:
			new_string = va_arg(ap, gchar*);
			if(strcmp(value->value.string, new_string))
				value->value.string = g_strdup(new_string);
			else
				goto no_change;	
			break;
		case PREFS_TYPE_LIST:
			value->value.list = util_list_copy_with_data(
				va_arg(ap, GList *),
				(util_list_data_copy_func_t*)g_strdup);
			break;
		}

		/* invoke validator to check new value */
		validated = value->validator_func != NULL
			? value->validator_func(prefs_name, value->validator_user_data)
			: TRUE;

		if(validated) {
			/* free backup data */
			prefs_free_value(value->type, &value_backup);

			/* notify that we've changed to a new value */
			g_hook_list_invoke(&value->change_hook, FALSE);
			raise_event(EVENT_PREFS_CHANGED, (gpointer)prefs_name, 0);

			/* preferences are not in sync with those on the disk */
			prefs_values_saved = FALSE;
		} else {
			/* restore backup value
			 */
			prefs_free_value(value->type, &value->value);
			value->value = value_backup;
		}
	} else {
static gboolean
idle_check_cb(gpointer dummy)
{
	unsigned idle_time; /* idle time in minutes */

	/* do not enter auto-away or auto-offline when we're in invisible mode */
	if(my_mode()==UMODE_INVISIBLE)
		return TRUE;

#ifdef _WIN32
	idle_time = winvqcc_get_last_active() / 60000;
#else
#ifdef USE_XSCREENSAVER
	static XScreenSaverInfo * xss_info = 0;
	int event_base, error_base;

	/* Query X Window System XScreenSaver extension
	 */
	if(XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) {
		if(!xss_info)
			xss_info = XScreenSaverAllocInfo();

		XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), xss_info);
		idle_time = xss_info->idle / 60000;
	} else {
		idle_time = 0;
	}
#else
	idle_time = 0;
#endif
#endif /* #ifdef _WIN32 */

	/* Check if we reached any of AUTO_AWAY/AUTO_OFFLINE timeouts
	 */
	switch(idle_mode) {
	case IDLE_NOT:
		/*  From IDLE_NOT we can get straight into AUTO_OFFLINE mode, if
		 * prefs_int(PREFS_AUTO_OFFLINE)==prefs_int(PREFS_AUTO_AWAY).
		 *  Otherwise, get into AUTO_AWAY mode.
		 */
		if(idle_time >= prefs_int(PREFS_IDLE_AUTO_OFFLINE)) {
			idle_mode = IDLE_OFFLINE;
			raise_event(EVENT_IDLE_AUTO_OFFLINE, 0, 0);
		} else if(idle_time >= prefs_int(PREFS_IDLE_AUTO_AWAY)) {
			idle_mode = IDLE_AWAY;
			raise_event(EVENT_IDLE_AUTO_AWAY, 0, 0);
		}
		break;
	case IDLE_AWAY:
		/*  From IDLE_AWAY we can get into IDLE_NOT state, if
		 * the user awakes, or into IDLE_OFFLINE, if
		 * idle_time >= prefs_int(PREFS_AUTO_OFFLINE)
		 */
		if(idle_time < prefs_int(PREFS_IDLE_AUTO_AWAY)) {
			idle_mode = IDLE_NOT;
			raise_event(EVENT_IDLE_NOT, 0, 0);
		} else if(idle_time >= prefs_int(PREFS_IDLE_AUTO_OFFLINE)) {
			idle_mode = IDLE_OFFLINE;
			raise_event(EVENT_IDLE_AUTO_OFFLINE, 0, 0);
		}
		break;
	case IDLE_OFFLINE:
		/*  From IDLE_OFFLINE, we can get into IDLE_NOT,
		 * if the user awakes
		 */
		if(idle_time < prefs_int(PREFS_IDLE_AUTO_AWAY)) {
			idle_mode = IDLE_NOT;
			raise_event(EVENT_IDLE_NOT, 0, 0);
		}
		break;
	}
	
	return TRUE;
}
Ejemplo n.º 29
0
static void
logprint(uint32_t flags, char *message, ...)
{
	va_list args;
	char buf[1024];
	int do_always = ((flags & (SC_IF_VERBOSE | SC_IF_ISATTY)) == 0);
	int do_ifverb = (flags & SC_IF_VERBOSE) && verbose;
	int do_ifisatty = (flags & SC_IF_ISATTY) && interactive;
	int code;
	static int logprint_raised = 0;

	if (do_always || do_ifverb || do_ifisatty) {
		va_start(args, message);
		/*LINTED: E_SEC_PRINTF_VAR_FMT*/
		(void) vsnprintf(buf, sizeof (buf), message, args);
		(void) fprintf(stderr, "%s: %s\n", progname, buf);
		if (!interactive) {
			switch (flags & (SC_SL_NONE | SC_SL_ERR | SC_SL_WARN)) {
			case SC_SL_ERR:
				/*LINTED: E_SEC_PRINTF_VAR_FMT*/
				syslog(LOG_ERR, buf);
				break;

			case SC_SL_WARN:
				/*LINTED: E_SEC_PRINTF_VAR_FMT*/
				syslog(LOG_WARNING, buf);
				break;

			default:
				break;
			}
		}
		va_end(args);
	}

	switch (flags & _SC_ALLEXIT) {
	case 0:
		return;

	case SC_EXIT_OK:
		code = 0;
		break;

	case SC_EXIT_PEND:
		/*
		 * Raise an ireport saying why we are exiting.  Do not
		 * raise if run as savecore -m.  If something in the
		 * raise_event codepath calls logprint avoid recursion.
		 */
		if (!mflag && logprint_raised++ == 0)
			raise_event(SC_EVENT_SAVECORE_FAILURE, buf);
		code = 2;
		break;

	case SC_EXIT_FM:
		code = 3;
		break;

	case SC_EXIT_ERR:
	default:
		if (!mflag && logprint_raised++ == 0)
			raise_event(SC_EVENT_SAVECORE_FAILURE, buf);
		code = 1;
		break;
	}

	exit(code);
}