1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-25 02:20:27 +00:00

Fix: sort syscmds by first number

This commit is contained in:
jcorporation 2018-10-16 22:38:38 +01:00
parent a81dd7e9d1
commit 5782ae2979
5 changed files with 13 additions and 6 deletions

1
contrib/syscmds/0Reboot Normal file
View File

@ -0,0 +1 @@
sudo /sbin/reboot

View File

@ -0,0 +1 @@
sudo /sbin/halt

View File

@ -113,8 +113,8 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
je = json_scanf(msg.p, msg.len, "{data: {cmd: %Q}}", &p_charbuf1);
if (je == 1) {
int_buf1 = list_get_value(&syscmds, p_charbuf1);
if (int_buf1 == 1)
n = mympd_syscmd(mpd.buf, p_charbuf1);
if (int_buf1 > -1)
n = mympd_syscmd(mpd.buf, p_charbuf1, int_buf1);
free(p_charbuf1);
}
break;
@ -1223,14 +1223,14 @@ bool mympd_state_set(char *name, char *value) {
return true;
}
int mympd_syscmd(char *buffer, char *cmd) {
int mympd_syscmd(char *buffer, char *cmd, int order) {
int len;
char filename[400];
char *line;
size_t n = 0;
ssize_t read;
snprintf(filename, 400, "%s/syscmds/%s", config.etcdir, cmd);
snprintf(filename, 400, "%s/syscmds/%d%s", config.etcdir, order, cmd);
FILE *fp = fopen(filename, "r");
if (fp == NULL) {
len = snprintf(buffer, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Can't execute cmd %s\"}", cmd);

View File

@ -211,7 +211,7 @@ void mympd_get_sticker(const char *uri, t_sticker *sticker);
void mympd_jukebox();
bool mympd_state_get(char *name, char *value);
bool mympd_state_set(char *name, char *value);
int mympd_syscmd(char *buffer, char *cmd);
int mympd_syscmd(char *buffer, char *cmd, int order);
int mympd_smartpls_save(char *smartpltype, char *playlist, char *tag, char *searchstr, int maxentries, int timerange);
int mympd_smartpls_put(char *buffer, char *playlist);
int mympd_smartpls_update_all();

View File

@ -188,6 +188,8 @@ void read_syscmds() {
DIR *dir;
struct dirent *ent;
char dirname[400];
char *cmd;
long order;
snprintf(dirname, 400, "%s/syscmds", config.etcdir);
printf("Reading syscmds: %s\n", dirname);
@ -195,7 +197,9 @@ void read_syscmds() {
while ((ent = readdir(dir)) != NULL) {
if (strncmp(ent->d_name, ".", 1) == 0)
continue;
list_push(&syscmds, ent->d_name, 1);
order = strtol(ent->d_name, &cmd, 10);
if (strcmp(cmd, "") != 0)
list_push(&syscmds, strdup(cmd), order);
}
closedir(dir);
}
@ -398,6 +402,7 @@ int main(int argc, char **argv) {
list_init(&syscmds);
read_syscmds();
list_order(&syscmds, true);
list_init(&mpd_tags);
list_init(&mympd_tags);