int64_tfree_space;intram_mb;externintram_size;free_space=(int64_t)stfs.f_bavail*stfs.f_bsize;if((ram_size+8192*1024)>=free_space){ram_mb=(ram_size/(1024*1024));fprintf(stderr,"You do not have enough space in '%s' for the %d MB of QEMU virtual RAM.\n",tmpdir,ram_mb);if(strcmp(tmpdir,"/dev/shm")==0){fprintf(stderr,"To have more space available provided you have enough RAM and swap, do as root:\n""umount /dev/shm\n""mount -t tmpfs -o size=%dm none /dev/shm\n",ram_mb+16);}else{fprintf(stderr,"Use the '-m' option of QEMU to diminish the amount of virtual RAM or use the\n""QEMU_TMPDIR environment variable to set another directory where the QEMU\n""temporary RAM file will be opened.\n");}
fprintf(stderr,"warning: could not create temporary file in '%s'.\n""Use QEMU_TMPDIR to select a directory in a tmpfs filesystem.\n""Using '/tmp' as fallback.\n",tmpdir);snprintf(phys_ram_file,sizeof(phys_ram_file),"%s/qemuXXXXXX","/tmp");
intqemu_create_pidfile(constchar*filename){charbuffer[128];intlen;#ifndef_WIN32intfd;fd=open(filename,O_RDWR|O_CREAT,0600);if(fd==-1)return-1;if(lockf(fd,F_TLOCK,0)==-1)return-1;len=snprintf(buffer,sizeof(buffer),"%ld\n",(long)getpid());if(write(fd,buffer,len)!=len)return-1;#elseHANDLEfile;DWORDflags;OVERLAPPEDoverlap;BOOLret;/* Open for writing with no sharing. */file=CreateFile(filename,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);if(file==INVALID_HANDLE_VALUE)return-1;flags=LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY;overlap.hEvent=0;/* Lock 1 byte. */ret=LockFileEx(file,flags,0,0,1,&overlap);if(ret==0)return-1;/* Write PID to file. */len=snprintf(buffer,sizeof(buffer),"%ld\n",(long)getpid());ret=WriteFileEx(file,(LPCVOID)buffer,(DWORD)len,&overlap,NULL);if(ret==0)return-1;#endifreturn0;}