Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/alts.1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for a simple per-system or per-user override of the default configuration.
alts -h --- this help screen
alts -l[name] --- list programs or just one with given name
alts [-u] [-s] -n <program> [-p <alt_priority>]
sets an override with a given priority as default
sets the alternative with the given priority as default
if priority is not set, then resets to default by removing override
-u -- user override, default for non-root users
-s -- system override, default for root users
Expand Down
18 changes: 16 additions & 2 deletions utils/alternatives.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include "utils.h"
#include "../src/libalternatives.h"
#include "../config.h"

const char binname[] = "alts";

extern int printInstalledBinariesAndTheirOverrideStates(const char *program);

static int printTargetBinary(const char *program)
{
struct AlternativeLink *target = NULL;
Expand Down Expand Up @@ -186,6 +185,19 @@ static int processOptions(int argc, char *argv[])
}
}

if (!command) {
command = 1;
if (!program && optind < argc) {
program = argv[optind++];
// TODO: actually this one should check for path
// starting with / and then print the
// alternative that belongs to the specified binary
// TODO: check next arg too and use it to
// set the alternative to the specified
// binary
}
}

switch (command) {
case 'h':
printHelp();
Expand All @@ -195,6 +207,8 @@ static int processOptions(int argc, char *argv[])
case 0:
printHelp();
return -1;
case 1:
return printInstalledBinariesAndTheirSetting(program);
case 'l':
return printInstalledBinariesAndTheirOverrideStates(program);
case 't':
Expand Down
49 changes: 49 additions & 0 deletions utils/list_binaries.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,52 @@ int printInstalledBinariesAndTheirOverrideStates(const char *program)

return ret;
}


static int printInstalledBinaryAndItsSetting(const char *program)
{
int ret = 0;
struct AlternativeLink *alts = NULL;

int priority = libalts_read_configured_priority(program, NULL);

if (priority > 0) {
ret = libalts_load_exact_priority_binary_alternatives(program, priority, &alts);
if (ret != 0) {
priority = 0;
}
}
if (priority == 0)
ret = libalts_load_highest_priority_binary_alternatives(program, &alts);

if (ret == 0 && alts) {
printf("%s\t%s\n", program, alts->target);
}

return ret;
}

int printInstalledBinariesAndTheirSetting(const char *program)
{
char **binary_names_array = NULL;
size_t bin_size = 0;
int ret = 0;

if (program) {
return printInstalledBinaryAndItsSetting(program);
}

if (libalts_load_available_binaries(&binary_names_array, &bin_size) != 0) {
perror(binname);
return 1;
}

qsort_r(&binary_names_array[0], bin_size, sizeof(char*), strcmpp, NULL);

for (size_t i = 0; i < bin_size; ++i) {
if (printInstalledBinaryAndItsSetting(binary_names_array[i]))
ret = 1;
}

return ret;
}
1 change: 1 addition & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ enum ConsistencyCheckFlags
CONSISTENCY_LOAD_ADDITIONAL_BINARIES = 1
};

int printInstalledBinariesAndTheirSetting(const char *program);
int printInstalledBinariesAndTheirOverrideStates(const char *program);
int checkGroupConsistencies(const struct InstalledBinaryData *data, unsigned n_binaries, enum ConsistencyCheckFlags flags, struct ConsistencyError **errors, unsigned *n_errors);