/*
 * Copyright 1988, 1989, 1990, 1991 Massachusetts Institute of Technology
 */
#include"structs.h"

write_host_file()
{

  int i, fd;
  char buffer[100];
/* This open(2) is written to use HP-UX sync i/o flags if they are
   defined */
  fd = open(HOST_NOTIFY_FILE, O_CREAT | O_TRUNC | O_WRONLY
#ifdef O_SYNC
| O_SYNC
#endif /* O_SYNC */
#ifdef O_SYNCIO
| O_SYNCIO
#endif /* O_SYNCIO */
, 0644);

  if (fd == -1) {
    if (DEBUG) printf("> Unable to write %s\n",HOST_NOTIFY_FILE);
    return(0);
  }
  for ( i = 0 ; i < MAXSOCKETS ; i++) {
    if (notify_list[i]) {
      sprintf(buffer,"%s\n",notify_list[i]);
      write(fd, buffer, strlen(buffer) * sizeof(char));
#ifndef SYSV
      fsync(fd);
#endif /* SYSV */
    }
  }
  close(fd);
/*  if (DEBUG) printf("Host file written.\n");*/
  chmod(HOST_NOTIFY_FILE,0644);
  return(0);
}

write_pid()
{
  FILE *fp, *fopen();
  fp = fopen(PID_FILE,"w");
  if (fp != NULL) {
    fprintf(fp,"%d\n",getpid());
#ifndef SYSV
    fsync(fileno(fp));
#endif /* SYSV */
    fclose(fp);
  }
  chmod(PID_FILE, 0644);
}
