mirror of https://github.com/BOINC/boinc.git
Add the missing API functions to the local backend
git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@2246 a7169a2c-3604-0410-bc95-c702d8d87f7a
This commit is contained in:
parent
a3fbc457fc
commit
89e2644dfe
|
@ -1,3 +1,9 @@
|
|||
dcapi (0.9-25) unstable; urgency=low
|
||||
|
||||
* Add some missing API functions for the local backend.
|
||||
|
||||
-- Gábor Gombás <gombasg@sztaki.hu> Tue, 08 Sep 2009 17:27:04 +0200
|
||||
|
||||
dcapi (0.9-24) unstable; urgency=low
|
||||
|
||||
* Add symbols files support for the shared libraries
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -33,9 +34,9 @@
|
|||
* Global variables
|
||||
*/
|
||||
|
||||
DC_ResultCallback _DC_result_callback/*_dc_resultcb*/;
|
||||
DC_SubresultCallback _DC_subresult_callback/*_dc_subresultcb*/;
|
||||
DC_MessageCallback _DC_message_callback/*_dc_messagecb*/;
|
||||
DC_ResultCallback _DC_result_callback;
|
||||
DC_SubresultCallback _DC_subresult_callback;
|
||||
DC_MessageCallback _DC_message_callback;
|
||||
|
||||
char project_uuid_str[37];
|
||||
uuid_t project_uuid;
|
||||
|
@ -128,6 +129,21 @@ void DC_setMasterCb(DC_ResultCallback resultcb, DC_SubresultCallback subresultcb
|
|||
_DC_message_callback = msgcb;
|
||||
}
|
||||
|
||||
void DC_setResultCb(DC_ResultCallback cb)
|
||||
{
|
||||
_DC_result_callback = cb;
|
||||
}
|
||||
|
||||
void DC_setSubresultCb(DC_SubresultCallback cb)
|
||||
{
|
||||
_DC_subresult_callback = cb;
|
||||
}
|
||||
|
||||
void DC_setMessageCb(DC_MessageCallback cb)
|
||||
{
|
||||
_DC_message_callback = cb;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* Functions
|
||||
|
@ -616,6 +632,16 @@ int DC_submitWU(DC_Workunit *wu)
|
|||
return DC_OK;
|
||||
}
|
||||
|
||||
int DC_cancelWU(DC_Workunit *wu)
|
||||
{
|
||||
if (!wu || wu->state != DC_WU_RUNNING)
|
||||
return DC_ERR_BADPARAM;
|
||||
|
||||
kill(wu->pid, SIGTERM);
|
||||
wu->state = DC_WU_ABORTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
DC_Workunit *_DC_getWUByName(const char *name)
|
||||
{
|
||||
DC_Workunit *wu;
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <dc.h>
|
||||
#include <dc_internal.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
@ -63,7 +65,7 @@ struct _DC_Workunit
|
|||
char *uuid_str;
|
||||
DC_WUState state;
|
||||
char *workdir;
|
||||
int pid;
|
||||
pid_t pid;
|
||||
|
||||
/* Input file definitions. Elements are of type DC_LogicalFile */
|
||||
GList *input_files;
|
||||
|
@ -82,6 +84,7 @@ struct _DC_Result
|
|||
DC_Workunit *wu;
|
||||
|
||||
int exit_code;
|
||||
double cpu_time;
|
||||
|
||||
/* List of output files. Elements are of type DC_PhysicalFile */
|
||||
GList *output_files;
|
||||
|
|
|
@ -104,28 +104,72 @@ DC_Workunit *DC_getResultWU(DC_Result *result)
|
|||
return result->wu;
|
||||
}
|
||||
|
||||
static int wait_result(DC_Result *result)
|
||||
{
|
||||
struct rusage rusage;
|
||||
pid_t pid;
|
||||
|
||||
if (!result->wu->pid)
|
||||
return 0;
|
||||
|
||||
pid = wait4(result->wu->pid, &result->exit_code, WNOHANG, &rusage);
|
||||
if (pid != result->wu->pid)
|
||||
{
|
||||
DC_log(LOG_ERR, "wu with pid %d not exited according to waitpid. retval: %d",
|
||||
result->wu->pid, pid);
|
||||
return DC_ERR_SYSTEM;
|
||||
}
|
||||
|
||||
result->cpu_time = rusage.ru_utime.tv_sec +
|
||||
(double)rusage.ru_utime.tv_usec / 1000000 +
|
||||
rusage.ru_stime.tv_sec +
|
||||
(double)rusage.ru_stime.tv_usec / 1000000;
|
||||
|
||||
/* Make sure we do not call wait4() again */
|
||||
result->wu->pid = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DC_getResultExit(const DC_Result *result)
|
||||
{
|
||||
int status;
|
||||
pid_t retval, pid;
|
||||
int ret;
|
||||
|
||||
pid = (pid_t)result->wu->pid;
|
||||
|
||||
retval = waitpid(pid, &status, WNOHANG);
|
||||
if (retval != pid)
|
||||
if (!result)
|
||||
{
|
||||
DC_log(LOG_ERR, "DC_getResultExit: wu with pid %d not exited according to waitpid. retval: %d",
|
||||
pid, retval);
|
||||
DC_log(LOG_ERR, "%s: Missing result", __func__);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
ret = wait_result((DC_Result *)result); /* XXX */
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
if (!WIFEXITED(result->exit_code))
|
||||
{
|
||||
DC_log(LOG_WARNING, "DC_getResultExit: wu with pid %d terminated not normally.",
|
||||
result->wu->pid); /* XXX pid is 0 at this point */
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!WIFEXITED(status))
|
||||
return WEXITSTATUS(result->exit_code);
|
||||
}
|
||||
|
||||
double DC_getResultCPUTime(const DC_Result *result)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
DC_log(LOG_WARNING, "DC_getResultExit: wu with pid %d terminated not normally.", pid);
|
||||
return -1;
|
||||
DC_log(LOG_ERR, "%s: Missing result", __func__);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return WEXITSTATUS(status);
|
||||
ret = wait_result((DC_Result *)result); /* XXX */
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
return result->cpu_time;
|
||||
}
|
||||
|
||||
char *DC_getResultOutput(const DC_Result *result, const char *logicalFileName)
|
||||
|
|
Loading…
Reference in New Issue