Skip to content

Commit 3c918c8

Browse files
committed
opkrun: Mount OPKs to fixed mount point
Mount OPKs to a fixed mount point, /opk by default. Since the mount point is then known, this permits the apps to use hardcoded absolute paths, which is very common in GNU/Linux. Signed-off-by: Paul Cercueil <[email protected]>
1 parent 6e90206 commit 3c918c8

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

opkrun.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@
3535
#define JZ4770FB_ENABLE_DOWNSCALING_FILE "/sys/devices/platform/jz-lcd.0/allow_downscaling"
3636
#endif
3737

38+
#ifndef OPK_MOUNTPOINT
39+
#define OPK_MOUNTPOINT "/opk"
40+
#endif
41+
3842
#define NB_PARAMS_MAX 256
3943

4044
struct params {
41-
char *mountpoint, *exec[NB_PARAMS_MAX];
45+
char *exec[NB_PARAMS_MAX];
4246
bool needs_terminal, needs_joystick, needs_gsensor, needs_downscaling;
4347
};
4448

@@ -100,8 +104,8 @@ static struct OPK * open_opk(const char *filename, const char *metadata)
100104
static int read_params(struct OPK *opk, struct params *params)
101105
{
102106
memset(params, 0, sizeof(*params));
103-
const char *exec_name = NULL, *name = NULL;
104-
size_t exec_name_len = 0, name_len = 0;
107+
const char *exec_name = NULL;
108+
size_t exec_name_len = 0;
105109

106110
for (;;) {
107111
const char *key, *val;
@@ -115,12 +119,6 @@ static int read_params(struct OPK *opk, struct params *params)
115119
if (!ret)
116120
break;
117121

118-
if (!strncmp(key, "Name", skey)) {
119-
name_len = sval;
120-
name = val;
121-
continue;
122-
}
123-
124122
if (!strncmp(key, "Exec", skey)) {
125123
exec_name_len = sval;
126124
exec_name = val;
@@ -148,7 +146,7 @@ static int read_params(struct OPK *opk, struct params *params)
148146
}
149147
}
150148

151-
if (!exec_name || !name) {
149+
if (!exec_name) {
152150
fprintf(stderr, "Unable to find the executable name\n");
153151
return -1;
154152
}
@@ -173,13 +171,6 @@ static int read_params(struct OPK *opk, struct params *params)
173171

174172
params->exec[arg] = NULL;
175173

176-
params->mountpoint = malloc(name_len + 6);
177-
sprintf(params->mountpoint, "/mnt/%.*s", (int) name_len, name);
178-
179-
for (ptr = params->mountpoint + 5; *ptr; ptr++) {
180-
if (*ptr == '\'' || *ptr == '\\')
181-
*ptr = '_';
182-
}
183174
return 0;
184175
}
185176

@@ -385,8 +376,8 @@ int main(int argc, char **argv)
385376

386377
free(params.exec[0]);
387378

388-
umount(params.mountpoint);
389-
mkdir(params.mountpoint, 0755);
379+
umount(OPK_MOUNTPOINT);
380+
mkdir(OPK_MOUNTPOINT, 0755);
390381

391382
int devnr = logetfree();
392383
if (devnr < 0)
@@ -401,14 +392,13 @@ int main(int argc, char **argv)
401392
return loopfd;
402393
}
403394

404-
ret = mount(loop_dev, params.mountpoint, "squashfs", MS_NODEV | MS_NOSUID | MS_RDONLY, 0);
395+
ret = mount(loop_dev, OPK_MOUNTPOINT, "squashfs", MS_NODEV | MS_NOSUID | MS_RDONLY, 0);
405396
if (ret < 0) {
406397
perror("Unable to mount OPK");
407-
free(params.mountpoint);
408398
return EXIT_FAILURE;
409399
}
410400

411-
chdir(params.mountpoint);
401+
chdir(OPK_MOUNTPOINT);
412402

413403
if (params.needs_terminal)
414404
enable_vtcon();
@@ -436,9 +426,8 @@ int main(int argc, char **argv)
436426
waitpid(son, &status, 0);
437427

438428
chdir("/");
439-
umount(params.mountpoint);
440-
rmdir(params.mountpoint);
441-
free(params.mountpoint);
429+
umount(OPK_MOUNTPOINT);
430+
rmdir(OPK_MOUNTPOINT);
442431

443432
ioctl(loopfd, LOOP_CLR_FD, (void *)0);
444433
close(loopfd);

0 commit comments

Comments
 (0)