Code cleanup and check for OOM condition with wl_array_add

Summary:
wayland: Check wl_array_add return for OOM condition
cosmetic: Make error return check syntax consistent with rest of code
wayland: Reuse use_adj to track child-forced adjust
wayland: Refactor to collapse if chain
wayland: Refactor _e_comp_wl_client_priority_adjust to collapse if chain
 + This uses early returns to unwrap a couple if clauses to make the code a bit less nesty.
wayland: Refactor if statements for consistency with rest of file

Reviewers: cedric, zmike, devilhorns

Subscribers: devilhorns, cedric

Differential Revision: https://phab.enlightenment.org/D2034
This commit is contained in:
Bryce Harrington 2015-02-24 14:47:56 -05:00 committed by Chris Michael
parent d89681fa3c
commit 40998b8a6e
2 changed files with 57 additions and 67 deletions

View File

@ -391,51 +391,46 @@ _e_comp_wl_evas_cb_mouse_wheel(void *data, Evas *evas EINA_UNUSED, Evas_Object *
static void
_e_comp_wl_client_priority_adjust(int pid, int set, int adj, Eina_Bool use_adj, Eina_Bool adj_child, Eina_Bool do_child)
{
Eina_List *files;
char *file, buff[PATH_MAX];
FILE *f;
int pid2, ppid;
int num_read;
int n;
n = set;
if (use_adj) n = (getpriority(PRIO_PROCESS, pid) + adj);
if (use_adj)
n = (getpriority(PRIO_PROCESS, pid) + adj);
else
n = set;
setpriority(PRIO_PROCESS, pid, n);
if (do_child)
{
Eina_List *files;
char *file, buff[PATH_MAX];
FILE *f;
int pid2, ppid;
if (adj_child)
use_adj = EINA_TRUE;
files = ecore_file_ls("/proc");
EINA_LIST_FREE(files, file)
{
if (isdigit(file[0]))
{
snprintf(buff, sizeof(buff), "/proc/%s/stat", file);
if ((f = fopen(buff, "r")))
{
pid2 = -1;
ppid = -1;
if (fscanf(f, "%i %*s %*s %i %*s", &pid2, &ppid) == 2)
{
fclose(f);
if (ppid == pid)
{
if (adj_child)
_e_comp_wl_client_priority_adjust(pid2, set,
adj, EINA_TRUE,
adj_child, do_child);
else
_e_comp_wl_client_priority_adjust(pid2, set,
adj, use_adj,
adj_child, do_child);
}
}
else
fclose(f);
}
}
free(file);
}
}
if (!do_child)
return;
files = ecore_file_ls("/proc");
EINA_LIST_FREE(files, file)
{
if (!isdigit(file[0]))
continue;
snprintf(buff, sizeof(buff), "/proc/%s/stat", file);
if ((f = fopen(buff, "r")))
{
pid2 = -1;
ppid = -1;
num_read = fscanf(f, "%i %*s %*s %i %*s", &pid2, &ppid);
fclose(f);
if (num_read == 2 && ppid == pid)
_e_comp_wl_client_priority_adjust(pid2, set,
adj, use_adj,
adj_child, do_child);
}
free(file);
}
}
static void
@ -640,12 +635,10 @@ _e_comp_wl_evas_cb_ping(void *data, Evas_Object *obj EINA_UNUSED, void *event EI
E_Client *ec;
if (!(ec = data)) return;
if (!(ec->comp_data->shell.ping)) return;
if (!(ec->comp_data->shell.surface)) return;
if (ec->comp_data->shell.ping)
{
if (ec->comp_data->shell.surface)
ec->comp_data->shell.ping(ec->comp_data->shell.surface);
}
ec->comp_data->shell.ping(ec->comp_data->shell.surface);
}
static void

View File

@ -616,6 +616,19 @@ _e_shell_cb_shell_surface_get(struct wl_client *client, struct wl_resource *reso
cdata->shell.unmap = _e_shell_surface_unmap;
}
static void
_e_xdg_surface_state_add(struct wl_resource *resource, struct wl_array *states, uint32_t state)
{
uint32_t *s;
s = wl_array_add(states, sizeof(*s));
if (s)
*s = state;
else
wl_resource_post_no_memory(resource);
return;
}
static void
_e_xdg_shell_surface_configure_send(struct wl_resource *resource, uint32_t edges, int32_t width, int32_t height)
{
@ -639,27 +652,13 @@ _e_xdg_shell_surface_configure_send(struct wl_resource *resource, uint32_t edges
wl_array_init(&states);
if (ec->fullscreen)
{
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_FULLSCREEN;
}
_e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_FULLSCREEN);
else if (ec->maximized)
{
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_MAXIMIZED;
}
_e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_MAXIMIZED);
if (edges != 0)
{
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_RESIZING;
}
_e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_RESIZING);
if (ec->focused)
{
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_ACTIVATED;
}
_e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_ACTIVATED);
serial = wl_display_next_serial(ec->comp->wl_comp_data->wl.disp);
if (ec->netwm.type != E_WINDOW_TYPE_POPUP_MENU)
@ -1418,8 +1417,7 @@ _e_shell_cb_bind(struct wl_client *client, void *data, uint32_t version, uint32_
return;
}
res = wl_resource_create(client, &wl_shell_interface, MIN(version, 1), id);
if (!res)
if (!(res = wl_resource_create(client, &wl_shell_interface, MIN(version, 1), id)))
{
wl_client_post_no_memory(client);
return;
@ -1442,8 +1440,7 @@ _e_xdg_shell_cb_bind(struct wl_client *client, void *data, uint32_t version, uin
return;
}
res = wl_resource_create(client, &xdg_shell_interface, MIN(version, 1), id);
if (!res)
if (!(res = wl_resource_create(client, &xdg_shell_interface, MIN(version, 1), id)))
{
wl_client_post_no_memory(client);
return;