"Fossies" - the Fresh Open Source Software Archive

Member "delegate9.9.13/rary/unix.c" (25 Aug 2014, 16350 Bytes) of package /linux/misc/old/delegate9.9.13.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "unix.c" see the Fossies "Dox" file reference documentation.

    1 /*////////////////////////////////////////////////////////////////////////
    2 Copyright (c) 1997-2000 Yutaka Sato and ETL,AIST,MITI
    3 Copyright (c) 2001-2006 National Institute of Advanced Industrial Science and Technology (AIST)
    4 AIST-Product-ID: 2000-ETL-198715-01, H14PRO-049, H15PRO-165, H18PRO-443
    5 
    6 Permission to use this material for noncommercial and/or evaluation
    7 purpose, copy this material for your own use, and distribute the copies
    8 via publicly accessible on-line media, without fee, is hereby granted
    9 provided that the above copyright notice and this permission notice
   10 appear in all copies.
   11 AIST MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY OF THIS
   12 MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", WITHOUT ANY EXPRESS
   13 OR IMPLIED WARRANTIES.
   14 //////////////////////////////////////////////////////////////////////////
   15 Content-Type:   program/C; charset=US-ASCII
   16 Program:    unix.c
   17 Author:     Yutaka Sato <ysato@delegate.org>
   18 Description:
   19 History:
   20     061103  extracted from windows.c
   21 //////////////////////////////////////////////////////////////////////#*/
   22 
   23 #include <stdio.h>
   24 #include "ystring.h"
   25 #include "vsignal.h"
   26 #include "proc.h"
   27 
   28 #include <sys/types.h>
   29 #include <sys/stat.h>
   30 #include <fcntl.h>
   31 #include <errno.h>
   32 #include <stdlib.h>
   33 
   34 const char *BINSHELL = "/bin/sh";
   35 int errorECONNRESET;
   36 int LastCpid;
   37 
   38 void deltmpfiles();
   39 int curLogFd();
   40 typedef struct sockaddr *SAP0;
   41 void socklog(PCStr(where),int fd,const SAP0 addr,int rcode,int csock);
   42 int setCFIshared();
   43 FileSize Lseek(int fd,FileSize off,int wh);
   44 
   45 void env2arg(PCStr(prefix));
   46 extern int MAIN_argc;
   47 extern const char **MAIN_argv;
   48 void DO_INITIALIZE(int ac,const char *av[]);
   49 void DO_FINALIZE(int code);
   50 void DO_STARTUP(int ac,const char *av[]);
   51 static int STARTED;
   52 
   53 static int tmpLogFd = -1;
   54 
   55 #include "config.h"
   56 #include "log.h"
   57 #define LE (LOGLEVEL<0) ? 0:porting_dbg
   58 #define LT (LOGLEVEL<1) ? 0:porting_dbg
   59 #define LV (LOGLEVEL<2) ? 0:porting_dbg
   60 #define LW (LOGLEVEL<4) ? 0:porting_dbg
   61 #define LS (!lSOCKET() && LOGLEVEL<4) ? 0:porting_dbg
   62 #define DBGWRITE    write
   63 #define SYST        "UNIX"
   64 
   65 #ifdef __EMX__
   66 #undef SYST
   67 #define SYST        "OS/2"
   68 #include <os2emx.h>
   69 #endif
   70 
   71 #ifdef _MSC_VER /*{*/
   72 #include "vsocket.h"
   73 #undef SYST
   74 #define SYST        "WIN"
   75 
   76 #else /*}{*/
   77 int DELEGATE_PAUSE;
   78 int SPAWN_TIMEOUT = 10*1000;
   79 int MIN_DGSPAWN_WAIT = 100; /* expecting when a child is a DeleGate */
   80 int setwaitspawn(int ws){ return 0; }
   81 int winCP;
   82 
   83 #define _YSOCKET_H   /* don't include ysocket.h in vsocket.h */
   84 #include "vsocket.h" /* definition of VSAddr */
   85 #include "yarg.h"
   86 #include <stdlib.h>
   87 #include <unistd.h>
   88 #include <time.h>
   89 #include <sys/types.h>
   90 #include <sys/socket.h>
   91 #include <sys/wait.h>
   92 void setBinaryIO();
   93 int setCloseOnExec(int fd);
   94 int setNonblockingIO(int fd,int on);
   95 int *StructAlloc(int size);
   96 
   97 int SocketOf(int sock);
   98 int _BIND(int fd,struct sockaddr *addr,int len)
   99 {   int sock = SocketOf(fd);
  100     int rcode;
  101 
  102     rcode = bind(sock,addr,len);
  103     socklog("bind",fd,addr,rcode,fd);
  104     return rcode;
  105 }
  106 int _ACCEPT(int fd,struct sockaddr *addr,int *len)
  107 {   int csock;
  108 
  109     csock = Xaccept(fd,addr,len);
  110     socklog("accept",fd,addr,csock,fd);
  111     return csock;
  112 }
  113 int _CONNECT(int fd,struct sockaddr *addr,int len)
  114 {   int rcode;
  115 
  116     rcode = connect(fd,addr,len);
  117     socklog("connect",fd,addr,rcode,fd);
  118     return rcode;
  119 }
  120 
  121 int init_socketpair(int port){ return -1; }
  122 void setclosesource(int si){ }
  123 void setclientsock(int sock){ }
  124 int getclientsock(){ return -1; }
  125 int setserversock(int sock){ return -1; }
  126 int getserversock(){ return -1; }
  127 int setcontrolsock(int sock){ return -1; }
  128 int getcontrolsock(){ return -1; }
  129 int setrsvdsock(int si,int sock){ return -1; }
  130 int getrsvdsock(int si){ return -1; }
  131 int send_sock(int dpid,int fd,int closesrc){ return -1; }
  132 int recv_sock(int spid,int ssock,int closesrc){ return -1; }
  133 
  134 int SocketOf(int sock){ return sock; }
  135 int closedups(int si){ return 0; }
  136 void dontclosedups(int fd){ }
  137 void setNonblockingPipe(int pv[]){ setNonblockingIO(pv[0],1); }
  138 int setNonblockingSocket(int fd,int on){ return setNonblockingIO(fd,on); }
  139 int file_isselectable(int fd){ return 1; }
  140 int pollPipe(int pfd,int msec){ return -1; }
  141 int numsocks(int *nmaxp){
  142     if( nmaxp) *nmaxp = 0;
  143     return 0;
  144 }
  145 
  146 int create_service(int ac,const char *av[],PCStr(port))
  147 {
  148     return 0;
  149 }
  150 int delete_service(int ac,const char *av[],PCStr(port),PCStr(arg))
  151 {
  152     return 0;
  153 }
  154 int killchildren()
  155 {
  156     return 0;
  157 }
  158 int killWin(int pid,int sig){
  159     return -1;
  160 }
  161 
  162 /*
  163 int system(PCStr(com))
  164 */
  165 int unix_system(PCStr(com))
  166 {   int pid,xpid;
  167 
  168     if( com == 0 )
  169         return 1;
  170     pid = fork();
  171     if( pid < 0 )
  172         return -1;
  173     if( pid == 0 ){
  174         execlp(BINSHELL,BINSHELL,"-c",com,NULL);
  175         exit(-1);
  176     }
  177     xpid = waitpid(pid,NULL,0);
  178     return 0; /* should return the status code */
  179 }
  180 void DO_INITIALIZE(int ac,const char *av[]);
  181 int CFI_init(int ac,const char *av[]){
  182     if( STARTED ){
  183         setCFIshared();
  184         return ac;
  185     }
  186     DO_INITIALIZE(ac,av);
  187     env2arg("CFI_");
  188 
  189     setCFIshared();
  190     return ac;
  191 }
  192 int SessionFd(){ return -1; }
  193 int setCloseOnExecSocket(int fd){ return setCloseOnExec(fd); }
  194 int clearCloseOnExecSocket(int fd){ return -1; }
  195 int setInheritance(int ifd,int inherit){ return -1; }
  196 int setInheritHandle(int fd,int on){ return -1; }
  197 int getParentSock(){ return -1; }
  198 
  199 #ifdef __EMX__ /*{*/
  200 int putenv_sockhandle(int fd,PVStr(env))
  201 {   int shandle;
  202 
  203     shandle = _getsockhandle(fd);
  204     if( shandle != -1 ){
  205         sprintf(env,"EMX_SOCKHANDLE%d=%d",fd,shandle);
  206         putenv(env);
  207     }
  208     return shandle;
  209 }
  210 
  211 int getenv_sockhandle(int fd){
  212     CStr(name,32);
  213     const char *env;
  214     int shandle,fdx;
  215 
  216     sprintf(name,"EMX_SOCKHANDLE%d",fd);
  217     if( (env = getenv(name)) && *env ){
  218         shandle = atoi(env);
  219         if( 0 <= shandle ){
  220             for( fdx = 0; fdx < 32; fdx++ ){
  221                 if( _getsockhandle(fdx) == shandle ){
  222                     dup2(fdx,fd);
  223                     return fd;
  224                 }
  225             }
  226             fdx = _impsockhandle(shandle,0);
  227             if( fdx != fd ){
  228                 dup2(fdx,fd);
  229                 close(fdx);
  230             }
  231             return fd;
  232         }
  233     }
  234     return -1;
  235 }
  236 
  237 void DO_FINALIZE(int code){
  238     fcloseall();
  239     deltmpfiles();
  240     _rmtmp();
  241 }
  242 
  243 void DO_STARTUP(int ac,const char *av[])
  244 {
  245     STARTED = 1;
  246 }
  247 void DO_INITIALIZE(int ac,const char *av[])
  248 {   int fd;
  249     unsigned long rel = 0, cur;
  250  
  251     MAIN_argc = ac;
  252     MAIN_argv = av;
  253     DosSetRelMaxFH(&rel, &cur);
  254     if( cur < 48 ){
  255         LV("increase MaxFH: %d -> %d",cur,48);
  256         DosSetMaxFH(48);
  257     }
  258 
  259     for( fd = 0; fd < 32; fd++ )
  260         getenv_sockhandle(fd);
  261 
  262     setBinaryIO();
  263 }
  264 extern int SPAWN_P_WAIT;
  265 int execvp(PCStr(path),char *const argv[])
  266 {   int stat;
  267     int fd;
  268     char envs[32][32]; /**/
  269 
  270     for( fd = 0; fd < 32; fd++ )
  271         putenv_sockhandle(fd,envs[fd]);
  272 
  273     stat = spawnvp(SPAWN_P_WAIT,path,argv);
  274     if( stat == -1 )
  275         return -1;
  276     else    exit(stat);
  277 }
  278 int WithSocketFile(){ return 0; }
  279 int getsockHandle(int fd){ return _getsockhandle(fd); }
  280 
  281 #else /*}{*/
  282 
  283 void DO_STARTUP(int ac,const char *av[])
  284 {
  285     STARTED = 1;
  286 }
  287 void DO_INITIALIZE(int ac,const char *av[])
  288 {
  289     MAIN_argc = ac;
  290     MAIN_argv = av;
  291     setBinaryIO();
  292 }
  293 void DO_FINALIZE(int code){
  294 /*
  295     deltmpfiles();
  296 */
  297 }
  298 int WithSocketFile(){ return 1; }
  299 int getsockHandle(int fd){ return -1; }
  300 
  301 #endif /*}*/
  302 
  303 
  304 int Fork(PCStr(what));
  305 extern char **environ;
  306 extern char **environ;
  307 int bgexecX(PCStr(mode),PCStr(path),char *av[],char *ev[],int *ph);
  308 int bgexec(PCStr(path),char *av[],char *ev[],int *ph){
  309     int pid;
  310     pid = bgexecX("",path,av,ev,ph);
  311     return pid;
  312 }
  313 int bgexecX(PCStr(mode),PCStr(path),char *av[],char *ev[],int *ph){
  314     int pid;
  315 
  316     /* closeServerPorts() */
  317     if( (pid = Fork("bgexec")) == 0 ){
  318         char *nev[1024];
  319         if( strchr(mode,'e') ){
  320             filterDGENV(environ,nev,elnumof(nev));
  321             environ = nev;
  322         }
  323         execvp(path,av);
  324         porting_dbg("FAILD exec(%s) errno=%d",path,errno);
  325         exit(-1);
  326         return -1;
  327     }
  328     *ph = 0;
  329     return pid;
  330 }
  331 int bgwait(int pid,int ph,double timeout){
  332     return wait(0);
  333 }
  334 
  335 int mysystem(PCStr(path),const char *const *av,const char *const ev[]){
  336     int pid,xpid;
  337     int xcode;
  338     errno = 0;
  339     if( (pid = Fork("mysystem")) == 0 ){
  340         environ = (char**)ev;
  341         execvp(path,(char**)av);
  342         _exit(0);
  343     }
  344     if( pid < 0 ){
  345         return -1;
  346     }
  347     for(;;){
  348         errno = 0;
  349         xpid = wait(0);
  350         if( xpid == pid ){
  351             xcode = 0;
  352             break;
  353         }
  354         if( errno == ECHILD ){
  355             xcode = -1;
  356             break;
  357         }
  358     }
  359     return xcode;
  360 }
  361 int Send_file(int dpid,int fd,int closesrc,int inheritable){ return -1; }
  362 int recv_file(int desc){ return -1; }
  363 
  364 int start_service(int ac,const char *av[])
  365 {
  366     return 0;
  367 }
  368 int restart_service(PCStr(port),int ac,const char *av[])
  369 {
  370     return 0;
  371 }
  372 int regGetResolvConf(PVStr(buf),PVStr(where))
  373 {
  374     setVStrEnd(buf,0);
  375     return -1;
  376 }
  377 int fd2handle(int fd){
  378     return -1;
  379 }
  380 int pipeX(int sv[2],int size){
  381     return pipe(sv);
  382 }
  383 
  384 int File_uid(PCStr(name));
  385 int ttyuid(int fd){
  386     int uid = -1;
  387     const char *name;
  388 
  389     if( isatty(fd) ){
  390         if( name = ttyname(fd) ){
  391             uid = File_uid(name);
  392             if( uid != -1 )
  393                 return uid;
  394         }
  395     }
  396     return -1;
  397 }
  398 
  399 int ShutdownSocket(int sock){
  400     return shutdown(sock,2);
  401 }
  402 int waitShutdownSocket(FL_PAR,int fd,int ms){
  403     int nready = -2;
  404     double St = Time();
  405     int PollIn1(int,int);
  406 
  407     shutdown(fd,SHUT_WR);
  408     nready = PollIn1(fd,ms);
  409     syslog_DEBUG("--waitShutdownSocket([%d/%d],%d)=%d,err=%d (%.3f) <= %s:%d",
  410         fd,SocketOf(fd),ms,nready,errno,Time()-St,FL_BAR);
  411     return nready;
  412 }
  413 
  414 #include <sys/mman.h>
  415 FILE *TMPFILE(PCStr(wh));
  416 int file_size(int fd);
  417 MMap *filemmap(PCStr(fname),PCStr(fmode),int off,int len){
  418     FILE *fp;
  419     int fd;
  420     MMap *mm;
  421     int rw;
  422     void *addr;
  423 
  424     if( *fname != 0 ){
  425         fp = fopen(fname,fmode);
  426     }else{
  427         /* this is bad on Zaurus... why?
  428         fp = TMPFILE("filemmap");
  429         */
  430         fp = tmpfile();
  431     }
  432     if( fp == 0 ){
  433         return 0;
  434     }
  435     fd = fileno(fp);
  436     if( *fmode == 'w' || strchr(fmode,'+') )
  437         rw = PROT_READ|PROT_WRITE;
  438     else    rw = PROT_READ;
  439 
  440     if( *fname == 0 && (rw & PROT_WRITE) && 0 < len ){
  441         /* necessary for CYGWIN */
  442         fseek(fp,len-1,0);
  443         fwrite("",1,1,fp);
  444         fflush(fp);
  445     }
  446     if( len == 0 ){
  447         len = file_size(fd);
  448     }
  449     addr = mmap(0,len,rw,MAP_SHARED,fd,off);
  450     if( addr == 0 || addr == (void*)-1 ){
  451         fprintf(stderr,"-- %X mmap(%s,%s,%X,%d,%d)=%X errno=%d\n",
  452             TID,fname,fmode,rw,off,len,p2i(addr),errno);
  453     }
  454     if( addr == 0 || addr == (void*)-1 ){
  455         return 0;
  456     }
  457     mm = (MMap*)malloc(sizeof(MMap));
  458     mm->m_addr = addr;
  459     mm->m_size = len;
  460     mm->m_fp = fp;
  461     mm->m_mh = 0;
  462     mm->m_fh = 0;
  463     return mm;
  464 }
  465 int freemmap(MMap *mm){
  466     int rcode;
  467     if( mm == 0 ){
  468         return -1;
  469     }
  470     rcode = munmap((char*)mm->m_addr,mm->m_size);
  471     fclose(mm->m_fp);
  472     free(mm);
  473     return rcode;
  474 }
  475 void *getmmap(MMap *mmap){
  476         return 0;
  477 }       
  478 void *setmmap(void *mh,int off,int len){
  479     return 0;
  480 }
  481 
  482 int inheritLogControl(){
  483     LOG_UDPsock[0] = LOG_UDPsockfd[0];
  484     LOG_UDPsock[1] = LOG_UDPsockfd[1];
  485     return 0;
  486 }
  487 
  488 int getAnswerYNtty(PCStr(msg),PVStr(ans),int siz);
  489 int getAnswerYN(PCStr(msg),PVStr(ans),int siz){
  490     return getAnswerYNtty(msg,BVStr(ans),siz);
  491 }
  492 int getAnswerYNWTO(double dto,PCStr(msg),PVStr(ans),int siz){
  493     int code;
  494     code = getAnswerYNtty(msg,BVStr(ans),siz);
  495     return code;
  496 }
  497 int remoteWinSize(int *w,int *h){
  498     *w = 0;
  499     *h = 0;
  500     return -1;
  501 }
  502 int remoteWinCtrl(FILE *tc,PCStr(com),PCStr(arg),int width,int height,PCStr(query),PCStr(form),PVStr(stat)){
  503     clearVStr(stat);
  504     return -1;
  505 }
  506 
  507 int regdump_main(int ac,const char *av[],FILE *out,FILE *err){
  508     return -1;
  509 }
  510 int setRegVal(FILE *tc,PCStr(name),PCStr(val)){
  511     return -1;
  512 }
  513 int setfdowner(int fd,int tid,int tgid){
  514     return -1;
  515 }
  516 void popupConsole(){
  517 }
  518 void setWinClassTitleStyle(PCStr(wclass),PCStr(wtitle),PCStr(wstyle)){
  519 }
  520 void putWinStatus(PCStr(fmt),...){
  521 }
  522 int askWinOKWTO(double dtx,PCStr(fmt),...){
  523     return -1;
  524 }
  525 int askWinOK(PCStr(fmt),...){
  526     return -1;
  527 }
  528 int updateActiveLamp(int act){
  529     return -1;
  530 }
  531 void initWinCRT(){
  532 }
  533 int disableWinCtrl(FILE *fp){
  534     return -1;
  535 }
  536 int ps_unix(FILE *out){
  537     return -1;
  538 }
  539 int putImpKey(PCStr(opt),PCStr(ekey)){
  540     return -1;
  541 }
  542 int getImpKey(PCStr(opt),PVStr(ekey)){
  543     clearVStr(ekey);
  544     return -1;
  545 }
  546 int dialupTOX(PCStr(wh),int asock,void *addr,int leng,int timeout,PVStr(cstat)){
  547     return -1;
  548 }
  549 char *getMacAddr(PCStr(ipaddr),PVStr(macaddr)){
  550     clearVStr(macaddr);
  551     return (char*)macaddr;
  552 }
  553 void dumpsockets(FILE *out,PCStr(wh)){
  554 }
  555 int testLogin(PCStr(user),PCStr(pass)){
  556     return -1;
  557 }
  558 #ifndef _MSC_VER
  559 const char *myExePath(){
  560     return "";
  561 }
  562 #endif
  563 int isWindows95(){ return 0; }
  564 #endif /*}*/
  565 
  566 int getAnswerYNtty(PCStr(msg),PVStr(ans),int siz){
  567     fprintf(stderr,"-------- DeleGate --------\n");
  568     fprintf(stderr,"%s : y / [n] : ",msg);
  569     fflush(stderr);
  570     clearVStr(ans);
  571     if( fgets(ans,siz,stdin) == 0 ){
  572         return -1;
  573     }
  574     fprintf(stderr,"-------- DeleGate --------\n");
  575     return 0;
  576 }
  577 
  578 char *VSA_xtoap(VSAddr *sa,PVStr(buf),int siz);
  579 void socklog(PCStr(where),int fd,const SAP0 addr,int rcode,int csock)
  580 {   CStr(ina,64);
  581     CStr(arg,64);
  582     CStr(self,64);
  583     int len;
  584     int serrno;
  585 
  586     if( (lSOCKET()) == 0 )
  587         return;
  588 
  589     serrno = errno;
  590     VSA_xtoap((VSAddr*)addr,AVStr(arg),sizeof(arg));
  591 
  592     len = sizeof(ina);
  593     bzero(ina,len);
  594     getsockname(csock,(SAP)ina,&len);
  595     VSA_xtoap((VSAddr*)ina,AVStr(self),sizeof(self));
  596 
  597     LE("{s} %7s(%2d,%-18s)=%2d %s",where,fd,arg,rcode,self);
  598     errno = serrno;
  599 }
  600 
  601 #include "yselect.h" /* FD_SETSIZE */
  602 static int fd_stack[FD_SETSIZE][2];
  603 void push_fd(int fd,int fd2,int rw)
  604 {
  605     if( fd < 0 || FD_SETSIZE <= fd )
  606         return;
  607 
  608     fd_stack[fd][rw] = fd2 + 1;
  609 }
  610 int top_fd(int fd,int rw)
  611 {
  612     if( fd < 0 || FD_SETSIZE <= fd )
  613         return -1;
  614 
  615     return fd_stack[fd][rw] - 1;
  616 }
  617 int pop_fd(int fd,int rw)
  618 {   int nfd,xfd,xrw;
  619 
  620     if( fd < 0 || FD_SETSIZE <= fd )
  621         return -1;
  622 
  623     nfd = fd_stack[fd][rw] - 1;
  624     if( 0 <= nfd ){
  625         fd_stack[fd][rw] = 0;
  626         dup2(nfd,fd);
  627 
  628         xrw = (rw+1) % 2;
  629         xfd = fd_stack[fd][xrw] - 1;
  630         if( 0 <= xfd ){
  631             fd_stack[fd][xrw] = 0;
  632         }
  633     }
  634     return nfd;
  635 }
  636 int get_writelimit(int fd,int siz){
  637     return siz;
  638 }
  639 
  640 extern char *LOG_timefmt;
  641 int getthreadid();
  642 static int fileno_set;
  643 static int fileno_stderr = -1;
  644 
  645 #ifdef daVARGS
  646 #undef VARGS
  647 #define VARGS daVARGS
  648 #define LINESIZE 1024
  649 #endif
  650 
  651 FILE *logMonFp();
  652 extern long Gmt_off;
  653 int getmtpid();
  654 
  655 CriticalSec portdbgCSC;
  656 
  657 int FMT_porting_dbg(PCStr(fmt),...)
  658 {   CStr(buf,4096);
  659     int logfd;
  660     struct timeval tv;
  661     int now;
  662     int nowu;
  663     int hour;
  664     IStr(ptid,64);
  665     int nmask,smask;
  666     VARGS(16,fmt);
  667 
  668     if( !isWindows() ){
  669     nmask = sigmask(SIGPIPE)|sigmask(SIGTERM)|sigmask(SIGINT);
  670     smask = sigblock(nmask);
  671     }
  672 
  673     if( fileno_set == 0 ){
  674         fileno_set = 1;
  675         fileno_stderr = fileno(stderr);
  676     }
  677 
  678     gettimeofday(&tv,NULL);
  679     now = tv.tv_sec;
  680     nowu = tv.tv_usec;
  681     hour = ((tv.tv_sec+Gmt_off) / 3600) % 24;
  682     if( lSINGLEP() )
  683         sprintf(ptid,"%04X",TID);
  684     else
  685     if( lTHREAD() || lTHREADID() )
  686         sprintf(ptid,"%4d.%X",getmtpid(),getthreadid());
  687     else    sprintf(ptid,"%4d",getmtpid());
  688     sprintf(buf,"(%s) %02d:%02d:%02d.%03d [%s] ",
  689         SYST,hour,(now%3600)/60,now%60,nowu/1000,ptid);
  690     Xsprintf(TVStr(buf),fmt,VA16);
  691     strcat(buf,"\n");
  692 
  693     if( logMonFp() ){
  694         fwrite(buf,1,strlen(buf),logMonFp());
  695         fflush(logMonFp());
  696     }
  697     if( lSINGLEP() && lMULTIST() ){
  698         putInitlog("%s",buf);
  699     }
  700 
  701     if( 0 <= tmpLogFd )
  702         logfd = tmpLogFd;
  703     else
  704     if( curLogFd() < 0 )
  705         logfd = fileno_stderr;
  706     else    logfd = curLogFd();
  707     if( 0 <= logfd ){
  708         Lseek(logfd,0,2);
  709         IGNRETP DBGWRITE(logfd,buf,strlen(buf));
  710     }
  711     if( 0 <= fileno_stderr ){
  712         if( lFG() && logfd != fileno_stderr ){
  713             if( isatty(logfd) && isatty(fileno_stderr) ){
  714             }else{
  715                 logfd = fileno_stderr;
  716                 Lseek(logfd,0,2);
  717                 IGNRETP DBGWRITE(logfd,buf,strlen(buf));
  718                 addCR(0,logfd,buf);
  719             }
  720         }
  721     }
  722 
  723     if( !isWindows() ){
  724     sigsetmask(smask);
  725     }
  726 
  727 EXIT:
  728     return 0;
  729 }
  730 
  731 /*
  732  * windows0.c is included for LE/LV/... ?
  733  */
  734 #include "windows0.c"
  735 
  736 int setNonblockingSocket(int fd,int on);
  737 /*////////////////////////////////////////////////////////////////////////
  738 Content-Type:   program/C; charset=US-ASCII
  739 Program:    fcntl.c
  740 Author:     Yutaka Sato <ysato@etl.go.jp>
  741 Description:
  742 History:
  743     961231  extracted from file.c
  744     990309  merged to windows0.c
  745 //////////////////////////////////////////////////////////////////////#*/
  746 
  747 int setNonblockingIO(int fd,int on)
  748 {   int flags;
  749     int rcode;
  750 
  751     if( F_SETFL == -1 || O_NDELAY == -1 ){
  752         rcode = setNonblockingSocket(fd,on);
  753         if( rcode < 0 ){
  754             /*
  755             syslog_ERROR("Non-Blocking I/O not supported\n");
  756             */
  757             syslog_ERROR("Non-Blocking I/O not supported[%d]\n",fd);
  758             return -1;
  759         }else   return rcode;
  760     }
  761 
  762     flags = fcntl(fd,F_GETFL,0);
  763     if( on )
  764         flags |=  O_NDELAY;
  765     else    flags &= ~O_NDELAY;
  766 #ifdef _MSC_VER
  767     return fcntl(fd,F_SETFL,(void*)flags);
  768 #else
  769     return fcntl(fd,F_SETFL,flags);
  770 #endif
  771 }
  772 
  773 #if !defined(_MSC_VER)
  774 int setDeleteOnClose(FILE *fp,int fd,const char *path){
  775     return -1;
  776 }
  777 int doDeleteOnClose(int fd,int fh){
  778     return -1;
  779 }
  780 int doDeleteOnExit(){
  781     return -1;
  782 }
  783 #endif