Commit 2dc70bb0 authored by aTc's avatar aTc

Merge branch 'master' of https://github.com/slaeshjag/dbp into upstream

parents bd5f5413 b74ebdfb
......@@ -35,5 +35,5 @@ state_file=/var/lib/dbp/dbp.state
;; If not commented out, launch executables via an extra wrapper allowing user pre-run/post-run scrips
;; This can also be used to set up launch enviroments for different ABI/CPU-architectures
;; run_script without index is used when a dbp is lacking the Arch key, or if it's set to "any".
;;run_script=/etc/dbp/run_script
run_script=/etc/dbp/run_script
run_script[armhf]=/etc/dbp/run_script
......@@ -262,6 +262,8 @@ int loop_mount(const char *image, const char *id, const char *user, const char *
goto illegal_dirname;
if (strchr(user_dir, '=') || strchr(img_dir, '=') || strchr(rodata_dir, '='))
goto illegal_dirname;
if (strchr(user_dir, ',') || strchr(img_dir, ',') || strchr(rodata_dir, ','))
goto illegal_dirname;
if (!stat(rodata_dir, &st))
if (S_ISDIR(st.st_mode))
......
......@@ -162,7 +162,7 @@ namespace Run {
pkg_arch = pkg.desktop_file.lookup("Arch", "", "Package Entry");
if (pkg_arch == "any" || pkg_arch == null)
pkg_arch = "";
run_script = DBP.Config.config.df.lookup("run_script", pkg_arch, "Package Entry");
run_script = DBP.Config.config.df.lookup("run_script", pkg_arch, "Package Daemon Config");
if (run_script == "")
run_script = null;
......
......@@ -58,7 +58,7 @@ static int daemon_nuke_dir(char *dir) {
return 0;
for (readdir_r(d, &de, &result); result; readdir_r(d, &de, &result))
if (strstr(de.d_name, DBP_META_PREFIX) == de.d_name)
sprintf(path, "%s/%s", dir, de.d_name), unlink(path);
snprintf(path, PATH_MAX, "%s/%s", dir, de.d_name), unlink(path);
closedir(d);
return 1;
}
......@@ -73,7 +73,7 @@ static int daemon_nuke_execs() {
if (!(d = opendir(config_struct.exec_directory)))
return 0;
for (readdir_r(d, &de, &result); result; readdir_r(d, &de, &result)) {
sprintf(path, "%s/%s", config_struct.exec_directory, de.d_name);
snprintf(path, PATH_MAX, "%s/%s", config_struct.exec_directory, de.d_name);
if (!(fp = fopen(path, "r")))
continue;
*buff = 0;
......
......@@ -56,6 +56,8 @@ static int package_find(struct package_s *p, const char *id) {
static int package_id_validate(const char *pkg_id) {
int i;
if (!strcmp(pkg_id, "..") || !strcmp(pkg_id, "."))
return 0;
for (i = 0; pkg_id[i]; i++)
if (!(pkg_id[i] >= 'a' && pkg_id[i] <= 'z') && !(pkg_id[i] >= 'A' && pkg_id[i] <= 'Z')
......@@ -137,16 +139,16 @@ static void package_desktop_write(struct package_s *p, int id, const char *fname
df = desktop_parse(data);
if ((sec = desktop_lookup_section(df, "Desktop Entry")) < 0)
goto desktop_free;
goto write;
if ((ent = desktop_lookup_entry(df, "Icon", "", sec)) < 0)
goto write;
sprintf(writename, "%s/%s%s_%s", config_struct.icon_directory, DBP_META_PREFIX, pkg_id, df->section[sec].entry[ent].value);
snprintf(writename, PATH_MAX, "%s/%s%s_%s", config_struct.icon_directory, DBP_META_PREFIX, pkg_id, df->section[sec].entry[ent].value);
free(df->section[sec].entry[ent].value);
df->section[sec].entry[ent].value = strdup(writename);
write:
sprintf(writename, "%s/%s%s_%s", config_struct.desktop_directory, DBP_META_PREFIX, pkg_id, fname);
snprintf(writename, PATH_MAX, "%s/%s%s_%s", config_struct.desktop_directory, DBP_META_PREFIX, pkg_id, fname);
if (!(fp = fopen(writename, "w")))
goto desktop_free;
desktop_write(df, writename);
......@@ -231,7 +233,7 @@ static void package_meta_exec_export(const char *exec, int env, struct package_s
return;
exec_tok = strdup(exec);
for (tok = strtok_r(exec_tok, ";", &saveptr); tok; tok = strtok_r(NULL, ";", &saveptr)) {
sprintf(path, "%s/%s", config_struct.exec_directory, find_filename(tok));
snprintf(path, PATH_MAX, "%s/%s", config_struct.exec_directory, find_filename(tok));
if (!access(path, F_OK)) {
fprintf(dbp_error_log, "Executable collision! %s already exists\n", path);
continue;
......@@ -278,7 +280,7 @@ static void package_meta_extract(const char *path, struct package_s *p, int id,
archive_read_data(a, data, size);
data[size] = 0;
if (strstr(pathname, "icons/") == pathname) {
sprintf(writename, "%s/%s%s_%s",
snprintf(writename, PATH_MAX, "%s/%s%s_%s",
config_struct.icon_directory, DBP_META_PREFIX, pkg_id,
find_filename(pathname));
......@@ -382,7 +384,7 @@ static void package_crawl(struct package_s *p, const char *device, const char *p
if (!package_filename_interesting(dir.d_name))
continue;
name_buff = malloc(strlen(path) + 2 + strlen(dir.d_name));
sprintf(name_buff, "%s/%s", path, dir.d_name);
snprintf(name_buff, PATH_MAX, "%s/%s", path, dir.d_name);
package_register(p, name_buff, device, mount, &n);
free(name_buff);
}
......@@ -404,7 +406,7 @@ void package_crawl_mount(struct package_s *p, const char *device, const char *pa
for (i = 0; i < config_struct.search_dirs; i++) {
new_path = realloc(new_path, strlen(path) + 2 + strlen(config_struct.search_dir[i]));
sprintf(new_path, "%s/%s", path, config_struct.search_dir[i]);
snprintf(new_path, PATH_MAX, "%s/%s", path, config_struct.search_dir[i]);
package_crawl(p, device, new_path, path);
}
......@@ -424,7 +426,7 @@ static void package_kill_prefix(const char *dir, const char *prefix, int meta) {
return;
for (readdir_r(d, &de, &result); result; readdir_r(d, &de, &result))
if (strstr(de.d_name, prefix) == de.d_name) {
sprintf(full, "%s/%s", dir, de.d_name), unlink(full);
snprintf(full, PATH_MAX, "%s/%s", dir, de.d_name), unlink(full);
if (meta)
comm_dbus_announce_rem_meta(full);
}
......@@ -436,7 +438,7 @@ static void package_kill_prefix(const char *dir, const char *prefix, int meta) {
static void package_meta_remove(const char *pkg_id, int announce) {
char prefix[PATH_MAX];
sprintf(prefix, "%s%s_", DBP_META_PREFIX, pkg_id);
snprintf(prefix, PATH_MAX, "%s%s_", DBP_META_PREFIX, pkg_id);
package_kill_prefix(config_struct.icon_directory, prefix, 0);
package_kill_prefix(config_struct.desktop_directory, prefix, announce);
......
......@@ -11,11 +11,16 @@
# anything surrounded by an ! followed by % is replaced with
# actual values by dbpd when the special folder is populated
export DBP_IMAGE_DIR="`dbp-cfg image_mount_dir`/!%package_id!"
# Only use this environment variable. The mechanism for determening the union mount
# directory may change in the future
export DBP_UNION_DIR="`dbp-cfg union_mount_dir`/!%package_id!"
export DBP_EXEC="!%package_id!"
if [ !%package_enviroment! == 1 ]; then
# This is where pre/post launch env setup should be done
union_dir="`dbp-cfg union_mount_dir`/!%package_id!"
# chdir is done by dbp-run, as the union mount might not exist before
# dbp-run is runned
dbp-run --gui-errors --log-output --chdir !%package_id! !%package_binary! "$@"
......
......@@ -5,4 +5,45 @@
## environment override, and should as such only be for invoking user pre/post run
## scripts, and the likes.
# Set up a library directory
lib_dir="$DBP_IMAGE_DIR/lib"
if [[ ":$LD_LIBRARY_PATH:" != *":$lib_dir:"* ]]; then
export LD_LIBRARY_PATH="$lib_dir:$LD_LIBRARY_PATH"
fi
# source pre-run scripts
if [ -a "$DBP_UNION_DIR/package.prerun" ]; then
. "$DBP_UNION_DIR/package.prerun"
fi
if [ -a "$DBP_UNION_DIR/package.user_prerun" ]; then
. "$DBP_UNION_DIR/package.user_prerun"
fi
if [ -a "$DBP_UNION_DIR/$DBP_EXEC.prerun" ]; then
. "$DBP_UNION_DIR/$DBP_EXEC.prerun"
fi
if [ -a "$DBP_UNION_DIR/$DBP_EXEC.user_prerun" ]; then
. "$DBP_UNION_DIR/$DBP_EXEC.user_prerun"
fi
# Execute the program
"$@"
# source post-run scripts
if [ -a "$DBP_UNION_DIR/package.postrun" ]; then
. "$DBP_UNION_DIR/package.postrun"
fi
if [ -a "$DBP_UNION_DIR/package.user_postrun" ]; then
. "$DBP_UNION_DIR/package.user_postrun"
fi
if [ -a "$DBP_UNION_DIR/$DBP_EXEC.postrun" ]; then
. "$DBP_UNION_DIR/$DBP_EXEC.postrun"
fi
if [ -a "$DBP_UNION_DIR/$DBP_EXEC.user_postrun" ]; then
. "$DBP_UNION_DIR/$DBP_EXEC.user_postrun"
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment