chiark / gitweb /
timestamp processing
[ypp-sc-tools.main.git] / yarrg / convert.c
index 42467f2fe773fe44646d9e804acef067d429f8bc..49fc3ed7151d879c2a69201662d42168dc26114e 100644 (file)
@@ -152,6 +152,32 @@ static void rsync_core(const char *stem, const char *suffix,
 void fetch_with_rsync_gz(const char *stem) { rsync_core(stem,".gz",""); }
 void fetch_with_rsync(const char *stem) { rsync_core(stem,"","z"); }
 
+static void get_timestamp(void) {
+  FILE *tf;
+  pid_t child;
+  sysassert( tf= tmpfile() );
+
+  sysassert( (child= fork()) != -1 );
+  if (!child) {
+    sysassert( dup2(fileno(tf),1)==1 );
+    EXECLP_HELPER("database-info-fetch","timestamp",(char*)0);
+  }
+  waitpid_check_exitstatus(child,"timestamp request",0);
+
+  sysassert( fseek(tf,0,SEEK_SET) == 0 );
+  static char lbuf[30];
+  int l= fread(lbuf,1,sizeof(lbuf),tf);
+  sysassert( !ferror(tf) );
+  assert( feof(tf) );
+  assert( l>1 );
+  l--;
+  assert( lbuf[l]=='\n' );
+  lbuf[l]= 0;
+
+  sysassert(! setenv("YPPSC_DATA_TIMESTAMP",lbuf,1) );
+  fclose(tf);
+}
+
 static void set_server(const char *envname, const char *defprotocol,
                       const char *defvalue, const char *defvalue_test,
                       const char *userspecified,
@@ -323,6 +349,9 @@ int main(int argc, char **argv) {
     o_screenshot_fn= masprintf("%s/_pages.ppm.gz", get_vardir());
 
   /* Actually do the work */
+
+  if ((o_flags & ff_upload) && (o_flags & ff_use_yarrg))
+    get_timestamp();
             
   canon_colour_prepare();