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 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) _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; int n;
n = set; if (use_adj)
if (use_adj) n = (getpriority(PRIO_PROCESS, pid) + adj); n = (getpriority(PRIO_PROCESS, pid) + adj);
else
n = set;
setpriority(PRIO_PROCESS, pid, n); setpriority(PRIO_PROCESS, pid, n);
if (do_child) if (adj_child)
{ use_adj = EINA_TRUE;
Eina_List *files;
char *file, buff[PATH_MAX];
FILE *f;
int pid2, ppid;
files = ecore_file_ls("/proc"); if (!do_child)
EINA_LIST_FREE(files, file) return;
{
if (isdigit(file[0])) files = ecore_file_ls("/proc");
{ EINA_LIST_FREE(files, file)
snprintf(buff, sizeof(buff), "/proc/%s/stat", file); {
if ((f = fopen(buff, "r"))) if (!isdigit(file[0]))
{ continue;
pid2 = -1;
ppid = -1; snprintf(buff, sizeof(buff), "/proc/%s/stat", file);
if (fscanf(f, "%i %*s %*s %i %*s", &pid2, &ppid) == 2) if ((f = fopen(buff, "r")))
{ {
fclose(f); pid2 = -1;
if (ppid == pid) ppid = -1;
{ num_read = fscanf(f, "%i %*s %*s %i %*s", &pid2, &ppid);
if (adj_child) fclose(f);
_e_comp_wl_client_priority_adjust(pid2, set, if (num_read == 2 && ppid == pid)
adj, EINA_TRUE, _e_comp_wl_client_priority_adjust(pid2, set,
adj_child, do_child); adj, use_adj,
else adj_child, do_child);
_e_comp_wl_client_priority_adjust(pid2, set, }
adj, use_adj,
adj_child, do_child); free(file);
} }
}
else
fclose(f);
}
}
free(file);
}
}
} }
static void 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; E_Client *ec;
if (!(ec = data)) return; if (!(ec = data)) return;
if (!(ec->comp_data->shell.ping)) return;
if (!(ec->comp_data->shell.surface)) return;
if (ec->comp_data->shell.ping) ec->comp_data->shell.ping(ec->comp_data->shell.surface);
{
if (ec->comp_data->shell.surface)
ec->comp_data->shell.ping(ec->comp_data->shell.surface);
}
} }
static void 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; 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 static void
_e_xdg_shell_surface_configure_send(struct wl_resource *resource, uint32_t edges, int32_t width, int32_t height) _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); wl_array_init(&states);
if (ec->fullscreen) if (ec->fullscreen)
{ _e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_FULLSCREEN);
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_FULLSCREEN;
}
else if (ec->maximized) else if (ec->maximized)
{ _e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_MAXIMIZED);
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_MAXIMIZED;
}
if (edges != 0) if (edges != 0)
{ _e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_RESIZING);
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_RESIZING;
}
if (ec->focused) if (ec->focused)
{ _e_xdg_surface_state_add(resource, &states, XDG_SURFACE_STATE_ACTIVATED);
s = wl_array_add(&states, sizeof(*s));
*s = XDG_SURFACE_STATE_ACTIVATED;
}
serial = wl_display_next_serial(ec->comp->wl_comp_data->wl.disp); serial = wl_display_next_serial(ec->comp->wl_comp_data->wl.disp);
if (ec->netwm.type != E_WINDOW_TYPE_POPUP_MENU) 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; return;
} }
res = wl_resource_create(client, &wl_shell_interface, MIN(version, 1), id); if (!(res = wl_resource_create(client, &wl_shell_interface, MIN(version, 1), id)))
if (!res)
{ {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
@ -1442,8 +1440,7 @@ _e_xdg_shell_cb_bind(struct wl_client *client, void *data, uint32_t version, uin
return; return;
} }
res = wl_resource_create(client, &xdg_shell_interface, MIN(version, 1), id); if (!(res = wl_resource_create(client, &xdg_shell_interface, MIN(version, 1), id)))
if (!res)
{ {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;