2006-04-10 12:39:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-05-02 08:01:58 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2006-04-10 12:39:54 +00:00
|
|
|
|
|
|
|
#include "dc_local.h"
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
DC_Result *_DC_createResult(const char *wu_name)
|
|
|
|
{
|
2006-04-11 14:21:20 +00:00
|
|
|
char *logicalName;
|
|
|
|
GList *l;
|
2006-04-10 12:39:54 +00:00
|
|
|
DC_Result *result;
|
2006-04-11 14:21:20 +00:00
|
|
|
DC_PhysicalFile *file;
|
|
|
|
FILE *f;
|
2006-04-10 12:39:54 +00:00
|
|
|
|
|
|
|
result = g_new0(DC_Result, 1);
|
|
|
|
result->wu = _DC_getWUByName(wu_name);
|
|
|
|
if (!result->wu)
|
|
|
|
{
|
|
|
|
DC_log(LOG_ERR, "Received result for unknown WU %s", wu_name);
|
|
|
|
g_free(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-04-11 14:21:20 +00:00
|
|
|
for (l = result->wu->output_files; l; l = l->next)
|
|
|
|
{
|
|
|
|
logicalName = g_strdup_printf("%s/%s", result->wu->workdir, (char *)l->data);
|
|
|
|
f = fopen(logicalName, "r");
|
|
|
|
if (f != NULL) /* File exists */
|
|
|
|
{
|
2006-04-12 11:31:33 +00:00
|
|
|
file = _DC_createPhysicalFile((char *)l->data, logicalName);
|
2006-04-11 14:21:20 +00:00
|
|
|
result->output_files = g_list_append(result->output_files, file);
|
|
|
|
result->num_outputs++;
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
g_free(logicalName);
|
|
|
|
}
|
2006-04-10 12:39:54 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _DC_destroyResult(DC_Result *result)
|
|
|
|
{
|
|
|
|
while (result->output_files)
|
|
|
|
{
|
2006-04-11 14:21:20 +00:00
|
|
|
_DC_destroyPhysicalFile((_DC_PhysicalFile *)result->output_files->data);
|
2006-04-10 12:39:54 +00:00
|
|
|
result->output_files = g_list_delete_link(result->output_files,
|
|
|
|
result->output_files);
|
|
|
|
}
|
|
|
|
g_free(result);
|
|
|
|
}
|
2006-04-12 11:31:33 +00:00
|
|
|
|
|
|
|
unsigned DC_getResultCapabilities(DC_Result *result)
|
|
|
|
{
|
2006-05-02 08:01:58 +00:00
|
|
|
return (DC_GC_STDOUT | DC_GC_STDERR | DC_GC_EXITCODE);
|
2006-04-12 11:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DC_Workunit *DC_getResultWU(DC_Result *result)
|
|
|
|
{
|
|
|
|
return result->wu;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DC_getResultExit(DC_Result *result)
|
|
|
|
{
|
2006-05-02 08:01:58 +00:00
|
|
|
int status;
|
|
|
|
pid_t retval, pid;
|
2006-04-12 11:31:33 +00:00
|
|
|
|
2006-05-02 08:01:58 +00:00
|
|
|
pid = (pid_t)result->wu->pid;
|
|
|
|
|
|
|
|
retval = waitpid(pid, &status, WNOHANG);
|
|
|
|
if (retval != pid)
|
|
|
|
{
|
|
|
|
DC_log(LOG_ERR, "DC_getResultExit: wu with pid %d not exited according to waitpid. retval: %d",
|
|
|
|
pid, retval);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WIFEXITED(status))
|
|
|
|
{
|
|
|
|
DC_log(LOG_WARNING, "DC_getResultExit: wu with pid %d terminated not normally.", pid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WEXITSTATUS(status);
|
2006-04-12 11:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *DC_getResultOutput(DC_Result *result, const char *logicalFileName)
|
|
|
|
{
|
|
|
|
char *physicalFileName;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = result->output_files; l; l = l->next)
|
|
|
|
{
|
|
|
|
DC_PhysicalFile *file = (DC_PhysicalFile *)l->data;
|
|
|
|
|
|
|
|
if(!strcmp(file->label, logicalFileName))
|
|
|
|
{
|
|
|
|
physicalFileName = strdup(file->path);
|
|
|
|
return physicalFileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-02 08:01:58 +00:00
|
|
|
if (!strcmp(logicalFileName, DC_RESULT_STDOUT))
|
|
|
|
{
|
|
|
|
char *tmp = g_strdup_printf("%s%c%s", result->wu->workdir, G_DIR_SEPARATOR, STDOUT_LABEL);
|
|
|
|
physicalFileName = strdup(tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
return physicalFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(logicalFileName, DC_RESULT_STDERR))
|
|
|
|
{
|
|
|
|
char *tmp = g_strdup_printf("%s%c%s", result->wu->workdir, G_DIR_SEPARATOR, STDERR_LABEL);
|
|
|
|
physicalFileName = strdup(tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
return physicalFileName;
|
|
|
|
}
|
|
|
|
|
2006-04-12 11:31:33 +00:00
|
|
|
DC_log(LOG_ERR, "DC_getResultOutput: The %s file is not part of the given result", logicalFileName);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|