From f53d74f4660a1d73ae09468d90b963226102aea8 Mon Sep 17 00:00:00 2001 From: drdani Date: Wed, 21 Jun 2006 10:01:17 +0000 Subject: [PATCH] add debug logs configure using config file (generated by the master) implementation of message passing (send and receive) git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@738 a7169a2c-3604-0410-bc95-c702d8d87f7a --- dcapi/condor/condor_slave.c | 149 ++++++++++++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 6 deletions(-) diff --git a/dcapi/condor/condor_slave.c b/dcapi/condor/condor_slave.c index 7edefb32c8..60f558766b 100644 --- a/dcapi/condor/condor_slave.c +++ b/dcapi/condor/condor_slave.c @@ -2,17 +2,30 @@ /* c-file-style: "linux" */ /* End: */ +#include #include #include +#include +#include +#include #include "dc_common.h" #include "dc_client.h" +#include "dc_internal.h" + +#include "condor_common.h" +#include "condor_slave.h" /* Initializes the client API. */ int DC_initClient(void) { - return(0); + int ret= _DC_parseCfg(CLIENT_CONFIG_NAME); + if (ret) + fprintf(stderr, "Error parsing configfile %s", + CLIENT_CONFIG_NAME); + DC_log(LOG_DEBUG, "Slave dcapi initialized"); + return(ret); } @@ -20,9 +33,13 @@ int DC_initClient(void) char *DC_resolveFileName(DC_FileType type, const char *logicalFileName) { + /* init_log calls this fn, so it is not possible to call DC_log + from here */ + /*DC_log(LOG_DEBUG, "DC_resolveFileName(%d,%s)", + type, logicalFileName);*/ if (!strcmp(logicalFileName, DC_CHECKPOINT_FILE)) - return("dc_checkpoint.txt"); - return((char*)logicalFileName); + return(strdup(CKPT_LABEL)); + return(strdup((char*)logicalFileName)); } @@ -31,45 +48,165 @@ int DC_sendResult(const char *logicalFileName, const char *path, DC_FileMode fileMode) { - return(0); + DC_log(LOG_DEBUG, "DC_sendResult(%s,%s,%d)", + logicalFileName, + path, + fileMode); + return(DC_ERR_NOTIMPL); } +static int _DC_message_id= 0; + /* Sends a message to the master. */ int DC_sendMessage(const char *message) { - return(0); + char fn[254]; + FILE *f; + + DC_log(LOG_DEBUG, "DC_sendMessage(%s)", message); + mkdir("client_messages", S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); + _DC_message_id++; + sprintf(fn, "client_messages/message.%d", _DC_message_id); + if ((f= fopen(fn, "w")) != NULL) + { + fprintf(f, "%s", message); + fclose(f); + DC_log(LOG_DEBUG, "Message %d created", _DC_message_id); + } + else + { + DC_log(LOG_ERR, "Error creating message file (%d)", + _DC_message_id); + return(DC_ERR_SYSTEM); + } + + return(DC_OK); } /* Checks for application control events. */ DC_ClientEvent *DC_checkClientEvent(void) { - return(0); + char *dn; + DIR *d; + struct dirent *de; + int min_id; + DC_ClientEvent *e= NULL; + + dn= strdup("master_messages"); + d= opendir(dn); + min_id= -1; + while (d && + (de= readdir(d)) != NULL) + { + char *found= strstr(de->d_name, "message."); + if (found) + { + char *pos= strrchr(de->d_name, '.'); + if (pos) + { + int id= 0; + pos++; + id= strtol(pos, NULL, 10); + if (id > 0) + { + if (min_id < 0) + min_id= id; + else + if (id < min_id) + min_id= id; + } + } + } + } + if (d) + closedir(d); + if (min_id >= 0) + { + FILE *f; + dn= realloc(dn, 100); + sprintf(dn, "master_messages/message.%d", min_id); + DC_log(LOG_DEBUG, "Reading message from %s", dn); + if ((f= fopen(dn, "r")) != NULL) + { + char *cont; + int bs= 100, i; + char c; + + cont= malloc(bs); + i= 0; + cont[i]= '\0'; + while ((c= fgetc(f)) != EOF) + { + if (i > bs-2) + { + bs+= 100; + cont= realloc(cont, bs); + } + cont[i]= c; + i++; + cont[i]= '\0'; + } + if (i > 0) + { + if ((e= calloc(1, sizeof(DC_ClientEvent)))) + { + DC_log(LOG_DEBUG, "API event created: " + "%p", e); + e->type= DC_CLIENT_MESSAGE; + e->message= cont; + DC_log(LOG_DEBUG, "Message of the " + "event: %s", + e->message); + } + else + DC_log(LOG_ERR, "Failed to create " + "API event, memory allocation " + "error"); + } + fclose(f); + if (e) + unlink(dn); + } + } + if (dn) + free(dn); + return(e); } /* Destroys the event-specific data returned by DC_checkClientEvent(). */ void DC_destroyClientEvent(DC_ClientEvent *event) { + DC_log(LOG_DEBUG, "DC_destroyClientEvent(%p)", event); + if (event) + { + if (event->message) + free(event->message); + free(event); + } } /* Indicates that an application-level checkpoint has completed. */ void DC_checkpointMade(const char *fileName) { + DC_log(LOG_DEBUG, "DC_checkpointMade(%s)", fileName); } /* Informs the user interface about the fraction of work already done. */ void DC_fractionDone(double fraction) { + DC_log(LOG_DEBUG, "DC_fractionDone(%g)", fraction); } /* Finishes computation. */ void DC_finishClient(int exitcode) { + DC_log(LOG_DEBUG, "DC_finishClient(%d)", exitcode); exit(exitcode); }