directory: don't pass "fd" to updateInit()
Again, move error handling to command.c.
This commit is contained in:
parent
17b6491bcf
commit
8e3c40f032
@ -816,9 +816,27 @@ static int listHandleUpdate(int fd,
|
|||||||
nextCmd = getCommandEntryFromString(next->data, permission);
|
nextCmd = getCommandEntryFromString(next->data, permission);
|
||||||
|
|
||||||
if (cmd != nextCmd) {
|
if (cmd != nextCmd) {
|
||||||
int ret = updateInit(fd, pathList);
|
int ret = updateInit(pathList);
|
||||||
freeList(pathList);
|
freeList(pathList);
|
||||||
pathList = NULL;
|
pathList = NULL;
|
||||||
|
|
||||||
|
switch (ret) {
|
||||||
|
case 0:
|
||||||
|
commandError(fd, ACK_ERROR_UPDATE_ALREADY,
|
||||||
|
"already updating");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case -1:
|
||||||
|
commandError(fd, ACK_ERROR_SYSTEM,
|
||||||
|
"problems trying to update");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fdprintf(fd, "updating_db: %i\n", ret);
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -828,15 +846,35 @@ static int listHandleUpdate(int fd,
|
|||||||
static int handleUpdate(int fd, mpd_unused int *permission,
|
static int handleUpdate(int fd, mpd_unused int *permission,
|
||||||
mpd_unused int argc, char *argv[])
|
mpd_unused int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
int ret;
|
|
||||||
List *pathList = makeList(NULL, 1);
|
List *pathList = makeList(NULL, 1);
|
||||||
insertInList(pathList, argv[1], NULL);
|
insertInList(pathList, argv[1], NULL);
|
||||||
ret = updateInit(fd, pathList);
|
ret = updateInit(pathList);
|
||||||
freeList(pathList);
|
freeList(pathList);
|
||||||
return ret;
|
} else
|
||||||
|
ret = updateInit(NULL);
|
||||||
|
|
||||||
|
switch (ret) {
|
||||||
|
case 0:
|
||||||
|
commandError(fd, ACK_ERROR_UPDATE_ALREADY,
|
||||||
|
"already updating");
|
||||||
|
ret = -1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case -1:
|
||||||
|
commandError(fd, ACK_ERROR_SYSTEM,
|
||||||
|
"problems trying to update");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fdprintf(fd, "updating_db: %i\n", ret);
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return updateInit(fd, NULL);
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handleNext(mpd_unused int fd, mpd_unused int *permission,
|
static int handleNext(mpd_unused int fd, mpd_unused int *permission,
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
|
|
||||||
#include "command.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "listen.h"
|
#include "listen.h"
|
||||||
@ -30,7 +29,6 @@
|
|||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "volume.h"
|
#include "volume.h"
|
||||||
#include "ack.h"
|
|
||||||
#include "myfprintf.h"
|
#include "myfprintf.h"
|
||||||
#include "dbUtils.h"
|
#include "dbUtils.h"
|
||||||
#include "song_print.h"
|
#include "song_print.h"
|
||||||
@ -160,12 +158,10 @@ void readDirectoryDBIfUpdateIsFinished(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int updateInit(int fd, List * pathList)
|
int updateInit(List * pathList)
|
||||||
{
|
{
|
||||||
if (directory_updatePid > 0) {
|
if (directory_updatePid > 0)
|
||||||
commandError(fd, ACK_ERROR_UPDATE_ALREADY, "already updating");
|
return 0;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* need to block CHLD signal, cause it can exit before we
|
/* need to block CHLD signal, cause it can exit before we
|
||||||
even get a chance to assign directory_updatePID */
|
even get a chance to assign directory_updatePID */
|
||||||
@ -216,8 +212,6 @@ int updateInit(int fd, List * pathList)
|
|||||||
} else if (directory_updatePid < 0) {
|
} else if (directory_updatePid < 0) {
|
||||||
unblockSignals();
|
unblockSignals();
|
||||||
ERROR("updateInit: Problems forking()'ing\n");
|
ERROR("updateInit: Problems forking()'ing\n");
|
||||||
commandError(fd, ACK_ERROR_SYSTEM,
|
|
||||||
"problems trying to update");
|
|
||||||
directory_updatePid = 0;
|
directory_updatePid = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -228,9 +222,8 @@ int updateInit(int fd, List * pathList)
|
|||||||
directory_updateJobId = 1;
|
directory_updateJobId = 1;
|
||||||
DEBUG("updateInit: fork()'d update child for update job id %i\n",
|
DEBUG("updateInit: fork()'d update child for update job id %i\n",
|
||||||
(int)directory_updateJobId);
|
(int)directory_updateJobId);
|
||||||
fdprintf(fd, "updating_db: %i\n", (int)directory_updateJobId);
|
|
||||||
|
|
||||||
return 0;
|
return (int)directory_updateJobId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DirectoryStat *newDirectoryStat(struct stat *st)
|
static DirectoryStat *newDirectoryStat(struct stat *st)
|
||||||
|
@ -42,7 +42,12 @@ int isUpdatingDB(void);
|
|||||||
|
|
||||||
void directory_sigChldHandler(int pid, int status);
|
void directory_sigChldHandler(int pid, int status);
|
||||||
|
|
||||||
int updateInit(int fd, List * pathList);
|
/**
|
||||||
|
* Starts the tag cache update in the specified location(s). Returns
|
||||||
|
* the job id on success, -1 on error or 0 if an update is already
|
||||||
|
* running.
|
||||||
|
*/
|
||||||
|
int updateInit(List * pathList);
|
||||||
|
|
||||||
void initMp3Directory(void);
|
void initMp3Directory(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user