Exemple #1
0
Fichier : log.c Projet : bsmr-i3/i3
/*
 * Initializes logging by creating an error logfile in /tmp (or
 * XDG_RUNTIME_DIR, see get_process_filename()).
 *
 * Will be called twice if --shmlog-size is specified.
 *
 */
void init_logging(void) {
    if (!errorfilename) {
        if (!(errorfilename = get_process_filename("errorlog")))
            fprintf(stderr, "Could not initialize errorlog\n");
        else {
            errorfile = fopen(errorfilename, "w");
            if (!errorfile) {
                fprintf(stderr, "Could not initialize errorlog on %s: %s\n",
                        errorfilename, strerror(errno));
            } else {
                if (fcntl(fileno(errorfile), F_SETFD, FD_CLOEXEC)) {
                    fprintf(stderr, "Could not set close-on-exec flag\n");
                }
            }
        }
    }
    if (physical_mem_bytes == 0) {
#if defined(__APPLE__)
        int mib[2] = {CTL_HW, HW_MEMSIZE};
        size_t length = sizeof(long long);
        sysctl(mib, 2, &physical_mem_bytes, &length, NULL, 0);
#else
        physical_mem_bytes = (long long)sysconf(_SC_PHYS_PAGES) *
                             sysconf(_SC_PAGESIZE);
#endif
    }
    /* Start SHM logging if shmlog_size is > 0. shmlog_size is SHMLOG_SIZE by
     * default on development versions, and 0 on release versions. If it is
     * not > 0, the user has turned it off, so let's close the logbuffer. */
    if (shmlog_size > 0 && logbuffer == NULL)
        open_logbuffer();
    else if (shmlog_size <= 0 && logbuffer)
        close_logbuffer();
    atexit(purge_zerobyte_logfile);
}
Exemple #2
0
char *store_restart_layout(void) {
    setlocale(LC_NUMERIC, "C");
    yajl_gen gen = yajl_gen_alloc(NULL);

    dump_node(gen, croot, true);

    setlocale(LC_NUMERIC, "");

    const unsigned char *payload;
    size_t length;
    y(get_buf, &payload, &length);

    /* create a temporary file if one hasn't been specified, or just
     * resolve the tildes in the specified path */
    char *filename;
    if (config.restart_state_path == NULL) {
        filename = get_process_filename("restart-state");
        if (!filename)
            return NULL;
    } else {
        filename = resolve_tilde(config.restart_state_path);
    }

    int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
    if (fd == -1) {
        perror("open()");
        free(filename);
        return NULL;
    }

    size_t written = 0;
    while (written < length) {
        int n = write(fd, payload + written, length - written);
        /* TODO: correct error-handling */
        if (n == -1) {
            perror("write()");
            free(filename);
            close(fd);
            return NULL;
        }
        if (n == 0) {
            DLOG("write == 0?\n");
            free(filename);
            close(fd);
            return NULL;
        }
        written += n;
        DLOG("written: %zd of %zd\n", written, length);
    }
    close(fd);

    if (length > 0) {
        DLOG("layout: %.*s\n", (int)length, payload);
    }

    y(free);

    return filename;
}
Exemple #3
0
/*
 * Called when the user releases the mouse button. Checks whether the
 * coordinates are over a button and executes the appropriate action.
 *
 */
static void handle_button_release(xcb_connection_t *conn, xcb_button_release_event_t *event) {
    printf("button released on x = %d, y = %d\n",
           event->event_x, event->event_y);
    /* If the user hits the close button, we exit(0) */
    if (event->event_x >= (rect.width - logical_px(32)))
        exit(0);
    button_t *button = get_button_at(event->event_x, event->event_y);
    if (!button)
        return;

    /* We need to create a custom script containing our actual command
     * since not every terminal emulator which is contained in
     * i3-sensible-terminal supports -e with multiple arguments (and not
     * all of them support -e with one quoted argument either).
     *
     * NB: The paths need to be unique, that is, don’t assume users close
     * their nagbars at any point in time (and they still need to work).
     * */
    char *script_path = get_process_filename("nagbar-cmd");

    int fd = open(script_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
    if (fd == -1) {
        warn("Could not create temporary script to store the nagbar command");
        return;
    }
    FILE *script = fdopen(fd, "w");
    if (script == NULL) {
        warn("Could not fdopen() temporary script to store the nagbar command");
        return;
    }
    fprintf(script, "#!/bin/sh\nrm %s\n%s", script_path, button->action);
    /* Also closes fd */
    fclose(script);

    char *link_path;
    char *exe_path = get_exe_path(argv0);
    sasprintf(&link_path, "%s.nagbar_cmd", script_path);
    if (symlink(exe_path, link_path) == -1) {
        err(EXIT_FAILURE, "Failed to symlink %s to %s", link_path, exe_path);
    }

    char *terminal_cmd;
    sasprintf(&terminal_cmd, "i3-sensible-terminal -e %s", link_path);
    printf("argv0 = %s\n", argv0);
    printf("terminal_cmd = %s\n", terminal_cmd);

    start_application(terminal_cmd);

    free(link_path);
    free(terminal_cmd);
    free(script_path);
    free(exe_path);

    /* TODO: unset flag, re-render */
}
Exemple #4
0
int main()
{
    
    char **cgivars;
    int i;
    char *action_event;
    int pid;
    char *action_name;
    char *process_filename;

    /** First, get the CGI variables into a list of strings **/
    cgivars = getcgivars();
 
    action_event = (char *) getvalue("action_event", cgivars);
    pid = atoi((char *) getvalue("pid", cgivars));
    action_name = (char *) getvalue("act_name", cgivars);
    process_filename = get_process_filename();
    peos_set_process_table_file(process_filename);
    peos_set_loginname(process_filename);
  

    if(strcmp(action_event, "Abort") == 0) {
        peos_notify(pid, action_name, PEOS_EVENT_ABORT);
	printf("Location: active_processes.cgi?action=continue\r\n\r\n");
    }
    

    if(strcmp(action_event, "Suspend") == 0) {
        peos_notify(pid, action_name, PEOS_EVENT_SUSPEND);
	printf("Location: active_processes.cgi?action=continue\r\n\r\n");
    }


    if(strcmp(action_event, "Run") == 0) {
	printf("Location: action_page.cgi?resource_type=requires&pid=%d&action_name=%s\r\n\r\n", pid, action_name);
    }
    
    
    if(strcmp(action_event, "Finish") == 0) {
	printf("Location: action_page.cgi?resource_type=provides&pid=%d&action_name=%s\r\n\r\n", pid, action_name);
    }
    
    
    /** Free anything that needs to be freed **/
    for (i=0; cgivars[i]; i++) free(cgivars[i]) ;
    free(cgivars) ;

    exit(0) ;    
}
Exemple #5
0
int main(int, char**)
{
	HWND previous_foreground_window = nullptr;
	for (;;)
	{
		HWND foreground_window = GetForegroundWindow();
		if (foreground_window != nullptr && foreground_window != previous_foreground_window)
		{
			//Foreground window changed.
			std::wstring filename(get_process_filename(foreground_window));
			std::wstring window_title(get_window_title(foreground_window));
			std::wstring timestamp(get_current_timestamp());
			// Format: [HH:MM:SS] name.exe | Window Title
			wprintf(L"%s %s | %s\n", timestamp.c_str(), filename.c_str(), window_title.c_str());
			previous_foreground_window = foreground_window;
		}

		Sleep(100);
	}
}
FridaHostProcessInfo *
frida_system_enumerate_processes (int * result_length1)
{
  GArray * processes;
  DWORD * pids = NULL;
  DWORD size = 64 * sizeof (DWORD);
  DWORD bytes_returned;
  guint i;

  processes = g_array_new (FALSE, FALSE, sizeof (FridaHostProcessInfo));

  do
  {
    size *= 2;
    pids = (DWORD *) g_realloc (pids, size);
    if (!EnumProcesses (pids, size, &bytes_returned))
      bytes_returned = 0;
  }
  while (bytes_returned == size);

  for (i = 0; i != bytes_returned / sizeof (DWORD); i++)
  {
    HANDLE handle;

    handle = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pids[i]);
    if (handle != NULL)
    {
      WCHAR name_utf16[MAX_PATH];
      DWORD name_length = MAX_PATH;

      if (get_process_filename (handle, name_utf16, name_length))
      {
        gchar * name, * tmp;
        FridaHostProcessInfo * process_info;
        FridaImageData * small_icon, * large_icon;

        name = g_utf16_to_utf8 ((gunichar2 *) name_utf16, -1, NULL, NULL, NULL);
        tmp = g_path_get_basename (name);
        g_free (name);
        name = tmp;

        small_icon = _frida_image_data_from_process_or_file (pids[i], name_utf16, FRIDA_ICON_SMALL);
        large_icon = _frida_image_data_from_process_or_file (pids[i], name_utf16, FRIDA_ICON_LARGE);

        g_array_set_size (processes, processes->len + 1);
        process_info = &g_array_index (processes, FridaHostProcessInfo, processes->len - 1);
        frida_host_process_info_init (process_info, pids[i], name, small_icon, large_icon);

        frida_image_data_free (large_icon);
        frida_image_data_free (small_icon);

        g_free (name);
      }

      CloseHandle (handle);
    }
  }

  g_free (pids);

  *result_length1 = processes->len;
  return (FridaHostProcessInfo *) g_array_free (processes, FALSE);
}