Skip to content

Commit

Permalink
Add support for ldconfig ldconfig-linux commands in plist
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Jan 31, 2021
1 parent b343cb2 commit 8df0b98
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 23 deletions.
18 changes: 2 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,20 @@
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

*.pico
*.depend

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# built man pages
*.gz
26 changes: 21 additions & 5 deletions libmport/bundle_read_install_pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ create_sample_file(mportInstance *mport, char *cwd, const char *file)

/**
* Get the list of assets (plist entries) from the stub attached database (package we are installing)
* filtered on entries that are not pre/post exec.
* filtered on entries that are not pre/post exec groups.
*/
static int
mport_bundle_read_get_assetlist(mportInstance *mport, mportPackageMeta *pkg, mportAssetList **alist_p, enum phase state)
Expand All @@ -297,15 +297,15 @@ mport_bundle_read_get_assetlist(mportInstance *mport, mportPackageMeta *pkg, mpo
}
} else if (state == ACTUALINSTALL) {
if (mport_db_prepare(mport->db, &stmt,
"SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type not in (%d, %d)",
pkg->name, ASSET_PREEXEC, ASSET_POSTEXEC) != MPORT_OK) {
"SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type not in (%d, %d, %d, %d)",
pkg->name, ASSET_PREEXEC, ASSET_POSTEXEC, ASSET_LDCONFIG, ASSET_LDCONFIG_LINUX) != MPORT_OK) {
sqlite3_finalize(stmt);
RETURN_CURRENT_ERROR;
}
} else if (state == POSTINSTALL) {
if (mport_db_prepare(mport->db, &stmt,
"SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d)",
pkg->name, ASSET_CWD, ASSET_POSTEXEC) != MPORT_OK) {
"SELECT type,data,checksum,owner,grp,mode FROM stub.assets WHERE pkg=%Q and type in (%d, %d, %d, %d)",
pkg->name, ASSET_CWD, ASSET_POSTEXEC, ASSET_LDCONFIG, ASSET_LDCONFIG_LINUX) != MPORT_OK) {
sqlite3_finalize(stmt);
RETURN_CURRENT_ERROR;
}
Expand Down Expand Up @@ -887,6 +887,22 @@ run_postexec(mportInstance *mport, mportPackageMeta *pkg)
if (mport_run_asset_exec(mport, e->data, cwd, file) != MPORT_OK)
goto ERROR;
break;
case ASSET_LDCONFIG:
if (mport_xsystem(mport, "/usr/sbin/service ldconfig restart > /dev/null") != MPORT_OK) {
goto ERROR;
}
break;
case ASSET_LDCONFIG_LINUX:
if (e->data == NULL) {
if (mport_xsystem(mport, "/compat/linux/sbin/ldconfig") != MPORT_OK) {
goto ERROR;
}
} else {
if (mport_xsystem(mport, "%s/sbin/ldconfig", e->data) != MPORT_OK) {
goto ERROR;
}
}
break;
default:
/* do nothing */
break;
Expand Down
76 changes: 75 additions & 1 deletion libmport/delete_primative.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "mport_private.h"

static int run_unexec(mportInstance *, mportPackageMeta *, mportAssetListEntryType);
static int run_unldconfig(mportInstance *, mportPackageMeta *);
static int run_pkg_deinstall(mportInstance *, mportPackageMeta *, const char *);
static int delete_pkg_infra(mportInstance *, mportPackageMeta *);
static int check_for_upwards_depends(mportInstance *, mportPackageMeta *);
Expand Down Expand Up @@ -115,6 +116,9 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)
if (run_unexec(mport, pack, ASSET_PREUNEXEC) != MPORT_OK)
RETURN_CURRENT_ERROR;

if (run_unldconfig(mport, pack) != MPORT_OK)
RETURN_CURRENT_ERROR;

if (run_pkg_deinstall(mport, pack, "DEINSTALL") != MPORT_OK)
RETURN_CURRENT_ERROR;

Expand All @@ -131,7 +135,7 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)
break;

if (ret != SQLITE_ROW) {
/* some error occured */
/* some error occurred */
SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(mport->db));
sqlite3_finalize(stmt);
RETURN_CURRENT_ERROR;
Expand Down Expand Up @@ -212,6 +216,11 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)
mport_call_msg_cb(mport, "Could not execute %s: %s", data, mport_err_string());
}
break;
case ASSET_LDCONFIG:
if (mport_xsystem(mport, "/usr/sbin/service ldconfig restart > /dev/null") != MPORT_OK) {
mport_call_msg_cb(mport, "Could not run ldconfig: %s", mport_err_string());
}
break;
case ASSET_DIR:
case ASSET_DIRRM:
case ASSET_DIRRMTRY:
Expand Down Expand Up @@ -267,6 +276,71 @@ mport_delete_primative(mportInstance *mport, mportPackageMeta *pack, int force)
return MPORT_OK;
}

static int
run_unldconfig(mportInstance *mport, mportPackageMeta *pkg) {
int ret;
char cwd[FILENAME_MAX];
sqlite3_stmt *assets = NULL;
sqlite3 *db;
const char *data;
mportAssetListEntryType type;

db = mport->db;

/* Process @ldconfig steps */
if (mport_db_prepare(db, &assets, "SELECT type, data FROM assets WHERE pkg=%Q and type in (%d, %d)", pkg->name,
ASSET_LDCONFIG, ASSET_LDCONFIG_LINUX) != MPORT_OK)
goto UNLDCONFIG_ERROR;

(void) strlcpy(cwd, pkg->prefix, sizeof(cwd));

if (mport_chdir(mport, cwd) != MPORT_OK)
goto UNLDCONFIG_ERROR;

while (1) {
ret = sqlite3_step(assets);

if (ret == SQLITE_DONE)
break;

if (ret != SQLITE_ROW) {
SET_ERROR(MPORT_ERR_FATAL, sqlite3_errmsg(db));
goto UNLDCONFIG_ERROR;
}
type = (mportAssetListEntryType) sqlite3_column_int(assets, 0);
data = sqlite3_column_text(assets, 1);

switch(type) {
case ASSET_LDCONFIG:
if (mport_xsystem(mport, "/usr/sbin/service ldconfig restart > /dev/null") != MPORT_OK) {
goto UNLDCONFIG_ERROR;
}
break;
case ASSET_LDCONFIG_LINUX:
if (data == NULL) {
if (mport_xsystem(mport, "/compat/linux/sbin/ldconfig") != MPORT_OK) {
goto UNLDCONFIG_ERROR;
}
} else {
if (mport_xsystem(mport, "%s/sbin/ldconfig", data) != MPORT_OK) {
goto UNLDCONFIG_ERROR;
}
}
break;
default:
break;
}
}
sqlite3_finalize(assets);
mport_pkgmeta_logevent(mport, pkg, type == ASSET_LDCONFIG ? "ldconfig" : "ldconfig-linux");

return MPORT_OK;

UNLDCONFIG_ERROR:
sqlite3_finalize(assets);
RETURN_CURRENT_ERROR;
}

static int
run_unexec(mportInstance *mport, mportPackageMeta *pkg, mportAssetListEntryType type) {
int ret;
Expand Down
2 changes: 1 addition & 1 deletion libmport/mport.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ enum _AssetListEntryType {
ASSET_SAMPLE, ASSET_SHELL,
ASSET_PREEXEC, ASSET_PREUNEXEC, ASSET_POSTEXEC, ASSET_POSTUNEXEC,
ASSET_FILE_OWNER_MODE, ASSET_DIR_OWNER_MODE,
ASSET_SAMPLE_OWNER_MODE
ASSET_SAMPLE_OWNER_MODE, ASSET_LDCONFIG, ASSET_LDCONFIG_LINUX
};

typedef enum _AssetListEntryType mportAssetListEntryType;
Expand Down
4 changes: 4 additions & 0 deletions libmport/plist.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ parse_command(const char *s) {
return ASSET_SAMPLE_OWNER_MODE;
if (STRING_EQ(s, "shell"))
return ASSET_SHELL;
if (STRING_EQ(s, "ldconfig-linux"))
return ASSET_LDCONFIG_LINUX;
if (STRING_EQ(s, "ldconfig"))
return ASSET_LDCONFIG;

/* special case, starts with ( as in @(root,wheel,0755) */
if (s[0] == '(')
Expand Down

0 comments on commit 8df0b98

Please sign in to comment.