00001 #include <unistd.h>
00002 #ifndef CVSTAG
00003 #define CVSTAG "undefined"
00004 #endif
00005
00006 #include <stdio.h>
00007 #include <math.h>
00008 #include <stdlib.h>
00009 #include <time.h>
00010 #include <sys/time.h>
00011 #include <sys/resource.h>
00012 #include "jsoc_main.h"
00013
00014
00015 extern char *savestr;
00016
00017
00018 char *cvsinfo_set_history = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/mag/synop/apps/synop-set_history.c,v 1.1 2016/05/05 19:49:28 arta Exp $";
00019
00020 long long set_history(DRMS_Link_t *histlink)
00021 {
00022 int status=0;
00023 int len;
00024 long long hold;
00025 TIME tnow, UNIX_epoch = -220924792.000;
00026 char path[DRMS_MAXPATHLEN+1];
00027 DRMS_Record_t *histrec = drms_create_record(drms_env,
00028 histlink->info->target_series,
00029 DRMS_PERMANENT,
00030 &status);
00031
00032 if (status != DRMS_SUCCESS)
00033 {
00034 fprintf(stderr,"ERROR: could not open a record in history dataseries %s, status = %d\n", histlink->info->target_series, status);
00035 return -1;
00036 }
00037
00038 if ((len=readlink("/proc/self/exe", path, DRMS_MAXPATHLEN)) == -1)
00039 {
00040 fprintf(stderr, "ERROR: cannot locate binary\n");
00041 drms_close_record(histrec, DRMS_FREE_RECORD);
00042 return -1;
00043 }
00044 else
00045 path[len]='\0';
00046
00047 status = drms_setkey_string(histrec, "MODPATH", path);
00048 if (status != DRMS_SUCCESS)
00049 {
00050 fprintf(stderr,"ERROR: problem writing keyword MODPATH in history dataseries, status = %d\n", status);
00051 drms_close_record(histrec, DRMS_FREE_RECORD);
00052 return -1;
00053 }
00054 status = drms_setkey_string(histrec, "MODNAME", cmdparams.argv[0]);
00055 if (status != DRMS_SUCCESS)
00056 {
00057 fprintf(stderr,"ERROR: problem writing keyword MODNAME in history dataseries, status = %d\n", status);
00058 drms_close_record(histrec, DRMS_FREE_RECORD);
00059 return -1;
00060 }
00061 status = drms_setkey_string(histrec, "ARGSUSED", savestr);
00062 if (status != DRMS_SUCCESS)
00063 {
00064 fprintf(stderr,"ERROR: problem writing keyword ARGSUSED in history dataseries, status = %d\n", status);
00065 drms_close_record(histrec, DRMS_FREE_RECORD);
00066 return -1;
00067 }
00068 status = drms_setkey_string(histrec, "CVSTAG", CVSTAG);
00069 if (status != DRMS_SUCCESS)
00070 {
00071 fprintf(stderr,"ERROR: problem writing keyword CVSTAG in history dataseries, status = %d\n", status);
00072 drms_close_record(histrec, DRMS_FREE_RECORD);
00073 return -1;
00074 }
00075 tnow = (double)time(NULL);
00076 tnow += UNIX_epoch;
00077 status = drms_setkey_time(histrec, "DATE", tnow);
00078 if (status != DRMS_SUCCESS)
00079 {
00080 fprintf(stderr,"ERROR: problem writing keyword DATE in history dataseries, status = %d\n", status);
00081 drms_close_record(histrec, DRMS_FREE_RECORD);
00082 return -1;
00083 }
00084
00085 hold=histrec->recnum;
00086 drms_close_record(histrec, DRMS_INSERT_RECORD);
00087 return hold;
00088 }