Skip to content

Commit 95927ef

Browse files
authored
webOS: webOS 1 and 2 compatibility (set HOME, check folder is writeable, fix version check) (#18601)
1 parent c09f75a commit 95927ef

File tree

6 files changed

+112
-47
lines changed

6 files changed

+112
-47
lines changed

Makefile.common

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,13 +1289,15 @@ ifeq ($(HAVE_WAYLAND), 1)
12891289
OBJ += gfx/drivers_context/wayland_vk_ctx.o
12901290
endif
12911291

1292-
ifeq ($(WEBOS), 1)
1293-
OBJ += input/common/wayland_common_webos.o
1294-
OBJ += gfx/common/wayland/webos-foreign.o
1295-
OBJ += gfx/common/wayland/webos-input-manager.o
1296-
OBJ += gfx/common/wayland/webos-shell.o
1297-
OBJ += gfx/common/wayland/webos-surface-group.o
1298-
endif
1292+
ifeq ($(WEBOS), 1)
1293+
OBJ += input/common/wayland_common_webos.o
1294+
OBJ += gfx/common/wayland/webos-shell.o
1295+
ifeq ($(HAVE_WEBOS_EXTRA_PROTOS), 1)
1296+
OBJ += gfx/common/wayland/webos-foreign.o
1297+
OBJ += gfx/common/wayland/webos-input-manager.o
1298+
OBJ += gfx/common/wayland/webos-surface-group.o
1299+
endif
1300+
endif
12991301

13001302
DEF_FLAGS += $(WAYLAND_CFLAGS) $(WAYLAND_CURSOR_CFLAGS)
13011303
LIBS += $(WAYLAND_LIBS) $(WAYLAND_CURSOR_LIBS)

Makefile.webos

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ HAVE_UPDATE_ASSETS = 1
133133
HAVE_UPDATE_CORES = 1
134134
HAVE_UPDATE_CORE_INFO = 1
135135
HAVE_USERLAND ?= 0
136+
HAVE_WEBOS_EXTRA_PROTOS ?= 0
136137
HAVE_CORE_INFO_CACHE = 1
137138
HAVE_WAYLAND ?= 0
138139

@@ -188,6 +189,9 @@ ifeq ($(HAVE_WAYLAND),1)
188189
DEFINES += -DHAVE_WAYLAND=1
189190
WAYLAND_LIBS = -lwayland-client -lwayland-cursor -lwayland-egl
190191
endif
192+
ifeq ($(HAVE_WEBOS_EXTRA_PROTOS),1)
193+
DEFINES += -DHAVE_WEBOS_EXTRA_PROTOS=1
194+
endif
191195
ifeq ($(HAVE_USERLAND),1)
192196
DEFINES += -DHAVE_USERLAND
193197
WAYLAND_LIBS += -lhelpers

frontend/drivers/platform_unix.c

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797

9898
#include "platform_unix.h"
9999

100+
#ifdef WEBOS
101+
#include <formats/rjson.h>
102+
#endif
103+
100104
#ifdef ANDROID
101105
static void frontend_unix_set_sustained_performance_mode(bool on);
102106

@@ -1308,57 +1312,56 @@ const char *retroarch_get_webos_version(char *s, size_t len,
13081312
FILE *f = fopen("/usr/lib/os-release", "r");
13091313
if (!f)
13101314
{
1311-
/* fallback to starfish-release */
1312-
f = fopen("/etc/starfish-release", "r");
1315+
/* fallback to nyx os_info.json */
1316+
f = fopen("/var/run/nyx/os_info.json", "r");
13131317
if (!f)
13141318
return strlcpy(s, "webOS (unknown)", len), "webOS (unknown)";
13151319

1316-
/* Example content:
1317-
Rockhopper release 3.9.0-62709 (dreadlocks2-dudhwa) */
1318-
char line[256];
1319-
if (fgets(line, sizeof(line), f))
1320-
{
1321-
char *nl = strchr(line, '\n');
1322-
if (nl) *nl = '\0';
1323-
snprintf(pretty, sizeof(pretty), "webOS - %s", line);
1320+
/* read whole file into buffer */
1321+
char buf[4096];
1322+
size_t n = fread(buf, 1, sizeof(buf)-1, f);
1323+
fclose(f);
1324+
buf[n] = '\0';
13241325

1325-
/* Try parse after the word "release", else first digit run in the line */
1326-
char *ver = strstr(line, "release");
1327-
if (ver)
1328-
{
1329-
ver += strlen("release");
1330-
while (*ver == ' ') ver++;
1331-
}
1332-
else
1333-
{
1334-
/* find first digit in the line */
1335-
ver = line;
1336-
while (*ver && ((*ver < '0') || (*ver > '9'))) ver++;
1337-
if (!*ver) ver = NULL;
1338-
}
1326+
rjson_t *json = rjson_open_string(buf, n);
1327+
enum rjson_type t;
1328+
const char *key = NULL, *val = NULL;
1329+
const char *name_str = NULL, *release_str = NULL;
13391330

1340-
if (ver)
1331+
while ((t = rjson_next(json)) != RJSON_DONE && t != RJSON_ERROR)
1332+
{
1333+
if (t == RJSON_STRING)
13411334
{
1342-
char *endptr = NULL;
1343-
long maj = strtol(ver, &endptr, 10);
1344-
if (endptr != ver)
1335+
key = rjson_get_string(json, NULL);
1336+
t = rjson_next(json);
1337+
if (t == RJSON_STRING)
13451338
{
1346-
if (major) *major = (int)maj;
1347-
if (endptr && *endptr == '.' && minor)
1348-
{
1349-
long min = strtol(endptr + 1, NULL, 10);
1350-
/* only set minor if a number was present */
1351-
const char *p = endptr + 1;
1352-
if (p && (*p >= '0' && *p <= '9'))
1353-
*minor = (int)min;
1354-
}
1339+
val = rjson_get_string(json, NULL);
1340+
if (strcmp(key, "webos_name") == 0)
1341+
name_str = val;
1342+
else if (strcmp(key, "webos_release") == 0)
1343+
release_str = val;
13551344
}
13561345
}
13571346
}
1358-
fclose(f);
1347+
rjson_free(json);
13591348

1360-
if (pretty[0] == '\0')
1361-
strlcpy(pretty, "webOS (unknown)", sizeof(pretty));
1349+
if (name_str && release_str)
1350+
snprintf(pretty, sizeof(pretty), "%s %s", name_str, release_str);
1351+
else if (name_str)
1352+
snprintf(pretty, sizeof(pretty), "%s", name_str);
1353+
else
1354+
snprintf(pretty, sizeof(pretty), "webOS (unknown)");
1355+
1356+
if (release_str) {
1357+
char *endptr = NULL;
1358+
long maj = strtol(release_str, &endptr, 10);
1359+
if (major) *major = (int)maj;
1360+
if (endptr && *endptr == '.' && minor)
1361+
*minor = (int)strtol(endptr+1, NULL, 10);
1362+
else if (minor)
1363+
*minor = 0;
1364+
}
13621365

13631366
return strlcpy(s, pretty, len), pretty;
13641367
}

input/common/wayland_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,11 @@ typedef struct gfx_ctx_wayland_data
180180
struct wl_shell_surface *shell_surface;
181181
struct wl_webos_shell *webos_shell;
182182
struct wl_webos_shell_surface *webos_shell_surface;
183+
#ifdef HAVE_WEBOS_EXTRA_PROTOS
183184
struct wl_webos_foreign *webos_foreign;
184185
struct wl_webos_surface_group_compositor *webos_surface_group_compositor;
185186
struct wl_webos_input_manager *webos_input_manager;
187+
#endif
186188
#endif
187189
data_offer_ctx *current_drag_offer;
188190
#ifdef HAVE_LIBDECOR_H

input/common/wayland_common_webos.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
#include "../input_keymaps.h"
3535

3636
#include "../../gfx/common/wayland/webos-shell.h"
37+
38+
#ifdef HAVE_WEBOS_EXTRA_PROTOS
3739
#include "../../gfx/common/wayland/webos-foreign.h"
3840
#include "../../gfx/common/wayland/webos-surface-group.h"
3941
#include "../../gfx/common/wayland/webos-input-manager.h"
42+
#endif
4043

4144
#ifdef HAVE_USERLAND
4245
#include <webos-helpers/libhelpers.h>
@@ -260,6 +263,7 @@ static void wl_registry_handle_global_webos(void *data,
260263
wl->webos_shell = (struct wl_webos_shell*)wl_registry_bind(reg,
261264
id, &wl_webos_shell_interface, 1);
262265
}
266+
#ifdef HAVE_WEBOS_EXTRA_PROTOS
263267
else if (string_is_equal(interface, "wl_webos_foreign"))
264268
{
265269
wl->webos_foreign = (struct wl_webos_foreign*)wl_registry_bind(reg,
@@ -276,6 +280,7 @@ static void wl_registry_handle_global_webos(void *data,
276280
wl->webos_input_manager = (struct wl_webos_input_manager*)wl_registry_bind(reg,
277281
id, &wl_webos_input_manager_interface, 1);
278282
}
283+
#endif
279284
}
280285

281286
static void wl_registry_handle_global_remove_webos(void *data,
@@ -385,12 +390,14 @@ void gfx_ctx_wl_destroy_resources_webos(gfx_ctx_wayland_data_t *wl)
385390
if (wl->surface)
386391
wl_surface_destroy(wl->surface);
387392

393+
#ifdef HAVE_WEBOS_EXTRA_PROTOS
388394
if (wl->webos_input_manager)
389395
wl_webos_input_manager_destroy(wl->webos_input_manager);
390396
if (wl->webos_surface_group_compositor)
391397
wl_webos_surface_group_compositor_destroy(wl->webos_surface_group_compositor);
392398
if (wl->webos_foreign)
393399
wl_webos_foreign_destroy(wl->webos_foreign);
400+
#endif
394401
if (wl->seat)
395402
wl_seat_destroy(wl->seat);
396403
if (wl->webos_shell)

retroarch.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545

4646
#if defined(WEBOS)
4747
#include <sys/resource.h>
48+
#include <sys/types.h>
49+
#include <sys/stat.h>
50+
#include <unistd.h>
4851
#include "input/common/wayland_common_webos.h"
4952
#endif
5053

@@ -5955,6 +5958,30 @@ void main_exit(void *args)
59555958
#endif
59565959
}
59575960

5961+
#if defined(WEBOS)
5962+
/* make a directory recursively */
5963+
static int mkdir_p(const char *path, mode_t mode)
5964+
{
5965+
char tmp[PATH_MAX_LENGTH];
5966+
char *p = NULL;
5967+
size_t len;
5968+
5969+
snprintf(tmp, sizeof(tmp), "%s", path);
5970+
len = strlen(tmp);
5971+
if (tmp[len - 1] == '/')
5972+
tmp[len - 1] = 0;
5973+
5974+
for (p = tmp + 1; *p; p++) {
5975+
if (*p == '/') {
5976+
*p = 0;
5977+
mkdir(tmp, mode);
5978+
*p = '/';
5979+
}
5980+
}
5981+
return mkdir(tmp, mode);
5982+
}
5983+
#endif
5984+
59585985
/**
59595986
* main_entry:
59605987
*
@@ -5992,6 +6019,26 @@ int rarch_main(int argc, char *argv[], void *data)
59926019
#endif
59936020

59946021
#if defined(WEBOS)
6022+
/* compatibility with webOS 1 and 2 */
6023+
const char *home = getenv("HOME");
6024+
const char *appId = getenv("APPID");
6025+
char new_path[PATH_MAX_LENGTH];
6026+
6027+
if (home)
6028+
{
6029+
if (!appId || !*appId || strcmp(appId, "com.palm.devmode.openssh") == 0)
6030+
appId = WEBOS_APP_ID;
6031+
6032+
snprintf(new_path, sizeof(new_path), "/%s/.config", home);
6033+
if (access(new_path, F_OK) != 0 && mkdir(new_path, 0775) != 0)
6034+
{
6035+
snprintf(new_path, sizeof(new_path), "/media/developer/temp/webosbrew/%s", appId);
6036+
if (mkdir_p(new_path, 0775) != 0 && errno != EEXIST)
6037+
RARCH_ERR("FATAL: mkdir_p failed for '%s': %s\n", new_path, strerror(errno));
6038+
setenv("HOME", new_path, 1);
6039+
}
6040+
}
6041+
59956042
/* compatibility with webOS 3 - 5 */
59966043
if (getenv("EGL_PLATFORM") == NULL)
59976044
setenv("EGL_PLATFORM", "wayland", 0);

0 commit comments

Comments
 (0)