コード例 #1
0
ファイル: convert-leapsecs.c プロジェクト: fvigotti/skalibs
int main (int argc, char const *const *argv)
{
  stralloc sa = STRALLOC_ZERO ;
  for (;;)
  {
    struct tm tm ;
    uint64 tt ;
    time_t t ;
    char *p ;
    int r ;
    char fmt[UINT64_FMT] ;
    sa.len = 0 ;
    r = skagetln(buffer_0, &sa, '\n') ;
    if (r < 0) strerr_diefu1sys(111, "read from stdin") ;
    if (!r) break ;
    sa.s[sa.len-1] = 0 ;
    if (!strptime(sa.s, "+%Y-%m-%d", &tm)) continue ;
    tm.tm_sec = 59 ;
    tm.tm_min = 59 ;
    tm.tm_hour = 23 ;
    t = mktime(&tm) ;
    if (t < 0) strerr_diefu1sys(111, "mktime") ;
    tt = t + 10 ;
    add_leapsecs(&tt) ;
    if (!genalloc_append(uint64, &table, &tt))
      strerr_diefu1sys(111, "genalloc_append") ;
    fmt[uint64_fmt(fmt, tt)] = 0 ;
    buffer_puts(buffer_1, "  TAI_MAGIC + ") ;
    buffer_puts(buffer_1, fmt) ;
    buffer_puts(buffer_1, ",\n") ;
  }
  buffer_unput(buffer_1, 2) ;
  buffer_putsflush(buffer_1, "\n") ;
  return 0 ;
}
コード例 #2
0
int main (int argc, char const *const *argv)
{
  s6_svstatus_t status ;
  char fmt[UINT_FMT] ;
  int isup, normallyup ;
  PROG = "s6-svstat" ;
  if (argc < 2) strerr_dieusage(100, USAGE) ;
  argv++ ; argc-- ;
  if (!s6_svstatus_read(*argv, &status))
    strerr_diefu2sys(111, "read status for ", *argv) ;

  {
    struct stat st ;
    unsigned int dirlen = str_len(*argv) ;
    char fn[dirlen + 6] ;
    byte_copy(fn, dirlen, *argv) ;
    byte_copy(fn + dirlen, 6, "/down") ;
    if (stat(fn, &st) == -1)
      if (errno != ENOENT) strerr_diefu2sys(111, "stat ", fn) ;
      else normallyup = 1 ;
    else normallyup = 0 ;
  }

  taia_now_g() ;
  if (taia_future(&status.stamp)) taia_copynow(&status.stamp) ;
  taia_sub(&status.stamp, &STAMP, &status.stamp) ;

  isup = status.pid && !status.flagfinishing ;
  if (isup)
  {
    buffer_putnoflush(buffer_1small,"up (pid ", 8) ;
    buffer_putnoflush(buffer_1small, fmt, uint_fmt(fmt, status.pid)) ;
    buffer_putnoflush(buffer_1small, ") ", 2) ;
  }
  else buffer_putnoflush(buffer_1small, "down ", 5) ;

  buffer_putnoflush(buffer_1small, fmt, uint64_fmt(fmt, status.stamp.sec.x)) ;
  buffer_putnoflush(buffer_1small," seconds", 8) ;

  if (isup && !normallyup)
    buffer_putnoflush(buffer_1small, ", normally down", 15) ;
  if (!isup && normallyup)
    buffer_putnoflush(buffer_1small, ", normally up", 13) ;
  if (isup && status.flagpaused)
    buffer_putnoflush(buffer_1small, ", paused", 8) ;
  if (!isup && (status.flagwant == 'u'))
    buffer_putnoflush(buffer_1small, ", want up", 10) ;
  if (isup && (status.flagwant == 'd'))
    buffer_putnoflush(buffer_1small, ", want down", 12) ;

  if (buffer_putflush(buffer_1small, "\n", 1) == -1)
    strerr_diefu1sys(111, "write to stdout") ;
  return 0 ;
}