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