65#include <sys/posix_shm.h>
66#include <sys/sysctl.h>
69static int shm_trace = 0;
70static int shm_count = 0;
72static int use_sysv_shm = 0;
73static int use_mmap_shm = 0;
74static int use_posix_shm = 0;
75static int use_posix1_shm = 0;
76static int use_posix2_shm = 0;
77static int use_posix3_shm = 0;
78static int use_posix4_shm = 0;
86 char cwd[256], buf[256];
91 if (getcwd(cwd,
sizeof(cwd)))
92 path = std::string(cwd);
104 fprintf(stderr,
"check_shm_type: Cannot write to config file \'%s\', errno %d (%s)",
file_name.c_str(), errno, strerror(errno));
109 fprintf(
fp,
"%s\n", shm_type);
114 fprintf(stderr,
"check_shm_type: Cannot open config file \'%s\', errno %d (%s)",
file_name.c_str(), errno, strerror(errno));
120 if (!fgets(buf,
sizeof(buf),
fp))
125 s = strchr(buf,
'\n');
131 if (strcmp(buf,
"SYSV_SHM") == 0) {
136 if (strcmp(buf,
"MMAP_SHM") == 0) {
141 if (strcmp(buf,
"POSIX_SHM") == 0) {
147 if (strcmp(buf,
"POSIXv2_SHM") == 0) {
153 if (strcmp(buf,
"POSIXv3_SHM") == 0) {
159 if (strcmp(buf,
"POSIXv4_SHM") == 0) {
165 fprintf(stderr,
"check_shm_type: Config file \"%s\" specifies unknown or unsupported shared memory type \"%s\", supported types are: SYSV_SHM, MMAP_SHM, POSIX_SHM, POSIXv2_SHM, POSIXv3_SHM, POSIXv4_SHM, default/preferred type is \"%s\"\n",
file_name.c_str(), buf, shm_type);
173 char buf[256], cwd[256];
178 gethostname(hostname,
sizeof(hostname));
184 if (getcwd(cwd,
sizeof(cwd)))
185 path = std::string(cwd);
187#elif defined(OS_UNIX)
189#elif defined(OS_WINNT)
204 cm_msg(
MERROR,
"check_shm_host",
"Cannot write to \'%s\', errno %d (%s)",
file_name.c_str(), errno, strerror(errno));
206 fprintf(
fp,
"%s\n", hostname);
213 if (!fgets(buf,
sizeof(buf),
fp))
218 s = strchr(buf,
'\n');
225 if (strcmp(buf, hostname) == 0)
228 cm_msg(
MERROR,
"check_shm_host",
"Error: Cannot connect to MIDAS shared memory - this computer hostname is \'%s\' while \'%s\' says that MIDAS shared memory for this experiment is located on computer \'%s\'. To connect to this experiment from this computer, use the mserver. Please see the MIDAS documentation for details.", hostname,
file_name.c_str(), buf);
235#if defined(OS_DARWIN)
237#elif defined(OS_UNIX)
241 mem_name = std::string(
"SM_") +
name;
250 assert(path.length() > 0);
251 assert(exptname.length() > 0);
262 if (use_posix1_shm) {
264 }
else if (use_posix2_shm) {
265 shm_name += exptname;
269 }
else if (use_posix3_shm) {
270 uid_t uid = getuid();
272 sprintf(buf,
"%d", uid);
275 shm_name += exptname;
278 }
else if (use_posix4_shm) {
279 uid_t uid = getuid();
281 sprintf(buf,
"%d", uid);
284 shm_name += exptname;
290 fprintf(stderr,
"check_shm_host: unsupported shared memory type, bye!\n");
294 for (
size_t i=1;
i<shm_name.length();
i++)
295 if (shm_name[
i] ==
'/')
305static int ss_shm_file_name_to_shmid(
const char*
file_name,
int* shmid)
356 std::string mem_name;
358 std::string shm_name;
363 printf(
"ss_shm_open(\"%s\",%d,%d), mem_name [%s], file_name [%s], shm_name [%s]\n",
name, size, get_size, mem_name.c_str(),
file_name.c_str(), shm_name.c_str());
371 char str[256], path[256], *p;
379 mstrlcpy(
str, path,
sizeof(path));
382 while (strpbrk(
str,
"\\: "))
383 *strpbrk(
str,
"\\: ") =
'*';
384 mstrlcat(
str, mem_name,
sizeof(path));
389 *p++ = (char) toupper(*p);
391 hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS,
FALSE,
str);
393 hFile = CreateFile(
file_name.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
399 file_size = GetFileSize(hFile, NULL);
401 if (file_size != 0xFFFFFFFF && file_size > 0)
404 if (file_size != 0xFFFFFFFF && file_size > 0 && file_size != size) {
405 cm_msg(
MERROR,
"ss_shm_open",
"Requested size (%d) differs from existing size (%d)", size, file_size);
410 hMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, size,
str);
422 *adr = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
423 *handle = (
HNDLE) hMap;
427 cm_msg(
MERROR,
"ss_shm_open",
"MapViewOfFile() failed");
441 $DESCRIPTOR(memname_dsc,
"dummy");
442 $DESCRIPTOR(filename_dsc,
"dummy");
443 memname_dsc.dsc$w_length = strlen(mem_name);
444 memname_dsc.dsc$a_pointer = mem_name;
445 filename_dsc.dsc$w_length =
file_name.length();
446 filename_dsc.dsc$a_pointer =
file_name.c_str();
451 status = ppl$create_shared_memory(&memname_dsc,
addr, &PPL$M_NOUNI, &filename_dsc);
453 if (
status == PPL$_CREATED)
455 else if (
status != PPL$_NORMAL)
458 *adr = (
void *)
addr[1];
474 double file_size = 0;
499 shmid = shmget(
key, 0, 0);
500 shmctl(shmid, IPC_RMID, &buf);
507 }
else if (size != file_size) {
508 cm_msg(
MERROR,
"ss_shm_open",
"Existing file \'%s\' has size %.0f, different from requested size %d",
file_name.c_str(), file_size, size);
515 printf(
"ss_shm_open(\"%s\",%d) get_size %d, file_name %s, size %.0f\n",
name, size, get_size,
file_name.c_str(), file_size);
518 shmid = shmget(
key, size, 0);
521 shmid = shmget(
key, size, IPC_CREAT | IPC_EXCL);
522 if (shmid == -1 && errno == EEXIST) {
524 "Shared memory segment with key 0x%x already exists, please remove it manually: ipcrm -M 0x%x",
532 cm_msg(
MERROR,
"ss_shm_open",
"shmget(key=0x%x,size=%d) failed, errno %d (%s)",
key, size, errno, strerror(errno));
536 memset(&buf, 0,
sizeof(buf));
537 buf.shm_perm.uid = getuid();
538 buf.shm_perm.gid = getgid();
539 buf.shm_perm.mode = 0666;
540 shmctl(shmid, IPC_SET, &buf);
542 *adr = shmat(shmid, 0, 0);
544 if ((*adr) == (
void *) (-1)) {
545 cm_msg(
MERROR,
"ss_shm_open",
"shmat(shmid=%d) failed, errno %d (%s)", shmid, errno, strerror(errno));
549 *handle = (
HNDLE) shmid;
554 fh = open(
file_name.c_str(), O_RDONLY, 0644);
556 fh = open(
file_name.c_str(), O_CREAT | O_RDWR, 0644);
558 int rd =
read(fh, *adr, size);
560 cm_msg(
MERROR,
"ss_shm_open",
"File size mismatch shared memory \'%s\' size %d, file \'%s\' read %d, errno %d (%s)",
name, size,
file_name.c_str(), rd, errno, strerror(errno));
575 if (once && strstr(
file_name.c_str(),
"ODB")) {
577 cm_msg(
MINFO,
"ss_shm_open",
"WARNING: This version of MIDAS system.c uses the experimental mmap() based implementation of MIDAS shared memory.");
582 printf(
"ss_shm_open(\"%s\",%d) get_size %d, file_name %s\n",
name, size, get_size,
file_name.c_str());
589 if (errno == ENOENT) {
594 cm_msg(
MERROR,
"ss_shm_open",
"Cannot create shared memory file \'%s\', errno %d (%s)",
file_name.c_str(), errno, strerror(errno));
598 ret = lseek(fh, size - 1, SEEK_SET);
600 if (ret == (off_t) - 1) {
602 "Cannot create shared memory file \'%s\', size %d, lseek() errno %d (%s)",
603 file_name.c_str(), size, errno, strerror(errno));
608 ret =
write(fh, &ret, 1);
611 ret = lseek(fh, 0, SEEK_SET);
621 if (file_size < size) {
623 "Shared memory file \'%s\' size %d is smaller than requested size %d. Please remove it and try again",
630 *adr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fh, 0);
632 if ((*adr) == MAP_FAILED) {
633 cm_msg(
MERROR,
"ss_shm_open",
"mmap() failed, errno %d (%s)", errno, strerror(errno));
637 *handle = ++shm_count;
648 double file_size = -1;
657 printf(
"ss_shm_open(\"%s\",%d) get_size %d, file_name %s, size %.0f\n",
name, size, get_size,
file_name.c_str(), file_size);
663 if (file_size != size) {
664 cm_msg(
MERROR,
"ss_shm_open",
"Shared memory file \'%s\' size %.0f is different from requested size %d. Please backup and remove this file and try again",
file_name.c_str(), file_size, size);
673 sh = shm_open(shm_name.c_str(), O_RDWR, mode);
678 sh = shm_open(shm_name.c_str(), O_RDWR | O_CREAT, mode);
684 if (errno == ENAMETOOLONG) {
685 fprintf(stderr,
"ss_shm_open: Cannot create shared memory for \"%s\": shared memory object name \"%s\" is too long for shm_open(), please try to use shorter experiment name or shorter event buffer name or a shared memory type that uses shorter names, in this order: POSIXv3_SHM, POSIXv2_SHM or POSIX_SHM (as specified in config file .SHM_TYPE.TXT). Sorry, bye!\n",
name, shm_name.c_str());
690 if (errno == EACCES) {
691 fprintf(stderr,
"ss_shm_open: Cannot create shared memory for \"%s\" with shared memory object name \"%s\", shm_open() errno %d (%s), please inspect file permissions in \"ls -l /dev/shm\", and if this is a conflict with a different user using the same experiment name, please change shared memory type to the POSIXv4_SHM or POSIXv3_SHM (on MacOS) (as specified in config file .SHM_TYPE.TXT). Sorry, bye!\n",
name, shm_name.c_str(), errno, strerror(errno));
695 cm_msg(
MERROR,
"ss_shm_open",
"Cannot create shared memory segment \'%s\', shm_open() errno %d (%s)", shm_name.c_str(), errno, strerror(errno));
701 status = ftruncate(sh, size);
703 cm_msg(
MERROR,
"ss_shm_open",
"Cannot resize shared memory segment \'%s\', ftruncate(%d) errno %d (%s)", shm_name.c_str(), size, errno, strerror(errno));
714 *adr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, sh, 0);
716 if ((*adr) == MAP_FAILED) {
717 cm_msg(
MERROR,
"ss_shm_open",
"Cannot mmap() shared memory \'%s\', errno %d (%s)", shm_name.c_str(), errno, strerror(errno));
728 if (created && fh >= 0 && file_size > 0) {
730 printf(
"ss_shm_open(\"%s\"), loading contents of file [%s], size %.0f\n",
name,
file_name.c_str(), file_size);
734 cm_msg(
MERROR,
"ss_shm_open",
"Cannot read \'%s\', read() returned %d instead of %d, errno %d (%s)",
file_name.c_str(),
status, size, errno, strerror(errno));
742 *handle = ++shm_count;
783 char mem_name[256], cwd[256];
790 sprintf(mem_name,
"SM_%s",
name);
795 if (getcwd(cwd,
sizeof(cwd)))
796 path = std::string(cwd);
798#elif defined(OS_UNIX)
800#elif defined(OS_WINNT)
813 printf(
"ss_shm_close(\"%s\",%p,%.0f,%d,destroy_flag=%d), file_name [%s]\n",
name, adr, (
double)shm_size, handle, destroy_flag,
file_name.c_str());
817 if (!UnmapViewOfFile(adr))
820 CloseHandle((HANDLE) handle);
859 memset(&buf, 0,
sizeof(buf));
860 if (shmctl(handle, IPC_STAT, &buf) < 0) {
861 cm_msg(
MERROR,
"ss_shm_close",
"shmctl(shmid=%d,IPC_STAT) failed, errno %d (%s)",
862 handle, errno, strerror(errno));
866 destroy_flag = (buf.shm_nattch == 1);
869 printf(
"ss_shm_close(\"%s\"), destroy_flag %d, shmid %d, shm_nattach %d\n",
name, destroy_flag, handle, (
int)buf.shm_nattch);
871 if (shmdt(adr) < 0) {
872 cm_msg(
MERROR,
"ss_shm_close",
"shmdt(shmid=%d) failed, errno %d (%s)", handle, errno, strerror(errno));
885 if (use_mmap_shm || use_posix_shm) {
889 printf(
"ss_shm_close(\"%s\"), destroy_flag %d\n",
name, destroy_flag);
891 status = munmap(adr, shm_size);
893 cm_msg(
MERROR,
"ss_shm_close",
"Cannot unmap shared memory \'%s\', munmap() errno %d (%s)",
name, errno, strerror(errno));
931 std::string mem_name;
933 std::string shm_name;
938 printf(
"ss_shm_delete(\"%s\") file_name [%s] shm_name [%s]\n",
name,
file_name.c_str(), shm_name.c_str());
946 assert(!
"not implemented!");
959 printf(
"ss_shm_delete(\"%s\") file_name %s, shmid %d\n",
name,
file_name.c_str(), shmid);
964 status = shmctl(shmid, IPC_RMID, &buf);
967 cm_msg(
MERROR,
"ss_shm_delete",
"Cannot delete shared memory \'%s\', shmctl(IPC_RMID) failed, errno %d (%s)",
name, errno, strerror(errno));
978 printf(
"ss_shm_delete(\"%s\") file_name %s (no-op)\n",
name,
file_name.c_str());
986 printf(
"ss_shm_delete(\"%s\") shm_name %s\n",
name, shm_name.c_str());
988 status = shm_unlink(shm_name.c_str());
990 if (errno != ENOENT) {
991 cm_msg(
MERROR,
"ss_shm_delete",
"shm_unlink(%s) nexpexted error, status %d, errno %d (%s)", shm_name.c_str(),
status, errno, strerror(errno));
1028 printf(
"ss_shm_protect() handle %d, adr %p, size %.0f\n", handle, adr, (
double)shm_size);
1032 if (!UnmapViewOfFile(adr))
1040 if (shmdt(adr) < 0) {
1046 if (use_mmap_shm || use_posix_shm) {
1047 assert(shm_size > 0);
1049 int ret = mprotect(adr, shm_size, PROT_NONE);
1051 cm_msg(
MERROR,
"ss_shm_protect",
"Cannot mprotect(PROT_NONE): return value %d, errno %d (%s)", ret, errno, strerror(errno));
1085 printf(
"ss_shm_unprotect() handle %d, adr %p, size %.0f, read %d, write %d, caller %s\n", handle, *adr, (
double)shm_size,
read,
write, caller_name);
1089 *adr = MapViewOfFile((HANDLE) handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
1092 cm_msg(
MERROR,
"ss_shm_unprotect",
"MapViewOfFile() failed");
1100 *adr = shmat(handle, 0, 0);
1102 if ((*adr) == (
void *) (-1)) {
1103 cm_msg(
MERROR,
"ss_shm_unprotect",
"shmat() failed, errno = %d", errno);
1108 if (use_mmap_shm || use_posix_shm) {
1109 assert(shm_size > 0);
1115 mode |= PROT_READ | PROT_WRITE;
1117 int ret = mprotect(*adr, shm_size, mode);
1119 cm_msg(
MERROR,
"ss_shm_unprotect",
"Cannot mprotect(%d): return value %d, errno %d (%s)", mode, ret, errno, strerror(errno));
1148 if ((
size_t)wr != (
size_t)
param->size) {
1149 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', write() returned %d instead of %d, errno %d (%s)",
1150 param->file_name.c_str(), (
int)wr, (
int)
param->size, errno, strerror(errno));
1153 param->buf =
nullptr;
1157 int ret = close(
param->fd);
1159 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', close() errno %d (%s)",
1160 param->file_name.c_str(), errno, strerror(errno));
1162 param->buf =
nullptr;
1167 param->buf =
nullptr;
1170 cm_msg(
MINFO,
"ss_shm_flush",
"Flushing shared memory took %d seconds",
ss_time() - start);
1200 std::string mem_name;
1202 std::string shm_name;
1207 printf(
"ss_shm_flush(\"%s\",%p,%.0f,%d), file_name [%s]\n",
name, adr, (
double)size, handle,
file_name.c_str());
1211 if (!FlushViewOfFile(adr, size))
1224 if (use_sysv_shm || use_posix_shm) {
1228 int fd = open(
file_name.c_str(), O_RDWR | O_CREAT, 0777);
1230 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', fopen() errno %d (%s)",
file_name.c_str(), errno, strerror(errno));
1235 void *buffer = malloc(size);
1236 if (buffer !=
nullptr) {
1237 memcpy(buffer, adr, size);
1238 static std::thread*
thread = NULL;
1252 if (wait_for_thread) {
1265 ssize_t wr =
write(fd, adr, size);
1266 if ((
size_t)wr != size) {
1267 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', write() returned %d instead of %d, errno %d (%s)",
file_name.c_str(), (
int)wr, (
int)size, errno, strerror(errno));
1272 int ret = close(fd);
1274 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', close() errno %d (%s)",
1275 file_name.c_str(), errno, strerror(errno));
1280 cm_msg(
MINFO,
"ss_shm_flush",
"Flushing shared memory took %d seconds",
ss_time() - start);
1292 printf(
"ss_shm_flush(\"%s\") size %.0f, mmap file_name [%s]\n",
name, (
double)size,
file_name.c_str());
1294 int ret = msync((
void *)adr, size, MS_ASYNC);
1296 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot msync(MS_ASYNC): return value %d, errno %d (%s)", ret, errno, strerror(errno));
1399 return (
int) GetCurrentProcessId();
1424#ifdef LOCAL_ROUTINES
1446 int status = kill(pid, 0);
1448 if ((
status != 0) && (errno == ESRCH)) {
1452#warning Missing ESRCH for ss_pid_exists()
1478#warning Missing SIGKILL for ss_kill()
1486#if defined(OS_DARWIN)
1487#include <mach-o/dyld.h>
1504#if defined(OS_DARWIN)
1505 uint32_t size =
sizeof(path);
1506 if (_NSGetExecutablePath(path, &size) == 0)
1508#elif defined(OS_LINUX)
1513 return std::string(path);
1531#if defined(OS_DARWIN)
1532 int mib[3] = {CTL_KERN, KERN_PROCARGS2, getpid()};
1535 if (sysctl(mib, 3,
nullptr, &len,
nullptr, 0) == -1) {
1536 perror(
"sysctl (size)");
1540 std::vector<char> buf(len);
1541 if (sysctl(mib, 3, buf.data(), &len,
nullptr, 0) == -1) {
1542 perror(
"sysctl (data)");
1546 int argc = *
reinterpret_cast<int*
>(buf.data());
1547 char* ptr = buf.data() +
sizeof(int);
1548 char*
end = buf.data() + len;
1551 while (ptr <
end && *ptr !=
'\0') {
1555 while (ptr <
end && *ptr ==
'\0') {
1560 for (
int i = 1;
i <= argc && ptr <
end;
i++) {
1562 if (!result.empty()) result +=
" ";
1564 ptr += s.size() + 1;
1568#elif defined(OS_LINUX)
1569 std::ifstream in(
"/proc/self/cmdline", std::ios::binary);
1573 std::string
data((std::istreambuf_iterator<char>(in)),
1574 std::istreambuf_iterator<char>());
1579 for (
char &
c :
data)
1582 if (!
data.empty() &&
data.back() ==
' ')
1613#elif defined OS_WINNT
1615 return GetCurrentThreadId();
1621#elif defined OS_DARWIN
1623 return pthread_self();
1625#elif defined OS_CYGWIN
1627 return pthread_self();
1629#elif defined OS_UNIX
1631 return pthread_self();
1634#elif defined OS_VXWORKS
1639#error Do not know how to do ss_gettid()
1649#elif defined OS_WINNT
1651#error Do not know how to do ss_tid_to_string()
1657 sprintf(buf,
"%d", thread_id);
1660#elif defined OS_DARWIN
1663 sprintf(buf,
"%p", thread_id);
1666#elif defined OS_CYGWIN
1669 sprintf(buf,
"%p", thread_id);
1672#elif defined OS_UNIX
1675 sprintf(buf,
"%lu", thread_id);
1678#elif defined OS_VXWORKS
1681 sprintf(buf,
"%d", thread_id);
1685#error Do not know how to do ss_tid_to_string()
1692void catch_sigchld(
int signo)
1728 if (spawnvp(mode, cmdname, argv) < 0)
1737 spawnvp((
int) mode, cmdname, argv);
1746 char cmdstring[500], *pc;
1750 $DESCRIPTOR(cmdstring_dsc,
"dummy");
1752 if (mode & P_DETACH) {
1753 cmdstring_dsc.dsc$w_length = strlen(cmdstring);
1754 cmdstring_dsc.dsc$a_pointer = cmdstring;
1756 status = sys$creprc(0, &cmdstring_dsc, 0, 0, 0, 0, 0, NULL, 4, 0, 0, PRC$M_DETACH);
1758 flags = (mode & P_NOWAIT) ? 1 : 0;
1760 for (pc = argv[0] + strlen(argv[0]); *pc !=
']' && pc != argv[0]; pc--);
1764 strcpy(cmdstring, pc);
1766 if (strchr(cmdstring,
';'))
1767 *strchr(cmdstring,
';') = 0;
1769 strcat(cmdstring,
" ");
1771 for (
i = 1; argv[
i] != NULL;
i++) {
1772 strcat(cmdstring, argv[
i]);
1773 strcat(cmdstring,
" ");
1776 cmdstring_dsc.dsc$w_length = strlen(cmdstring);
1777 cmdstring_dsc.dsc$a_pointer = cmdstring;
1779 status = lib$spawn(&cmdstring_dsc, 0, 0, &flags, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
1796 assert(!
"support for fork() disabled by NO_FORK");
1798 if ((child_pid = fork()) < 0)
1802 if (child_pid == 0) {
1804 int error = execvp(cmdname, (
char*
const*)argv);
1805 fprintf(stderr,
"ss_spawnv: Cannot execute command \"%s\": execvp() returned %d, errno %d (%s), aborting!\n", cmdname, error, errno, strerror(errno));
1813 if (mode == P_WAIT) {
1815 waitpid(child_pid,
status, WNOHANG);
1817 waitpid(child_pid, &
status, WNOHANG);
1822 signal(SIGCHLD, catch_sigchld);
1852 HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup,
1853 hChildStdoutRd, hChildStdoutWr, hChildStderrRd, hChildStderrWr, hSaveStdin, hSaveStdout, hSaveStderr;
1855 SECURITY_ATTRIBUTES saAttr;
1856 PROCESS_INFORMATION piProcInfo;
1857 STARTUPINFO siStartInfo;
1858 char buffer[256], cmd[256];
1859 DWORD dwRead, dwWritten, dwAvail,
i, i_cmd;
1861 struct timeval timeout;
1864 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
1865 saAttr.bInheritHandle =
TRUE;
1866 saAttr.lpSecurityDescriptor = NULL;
1869 hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE);
1872 if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
1876 if (!SetStdHandle(STD_OUTPUT_HANDLE, hChildStdoutWr))
1881 hSaveStderr = GetStdHandle(STD_ERROR_HANDLE);
1884 if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0))
1888 if (!SetStdHandle(STD_ERROR_HANDLE, hChildStderrWr))
1893 hSaveStdin = GetStdHandle(STD_INPUT_HANDLE);
1896 if (!CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))
1900 if (!SetStdHandle(STD_INPUT_HANDLE, hChildStdinRd))
1904 if (!DuplicateHandle(GetCurrentProcess(), hChildStdinWr, GetCurrentProcess(), &hChildStdinWrDup, 0,
FALSE,
1905 DUPLICATE_SAME_ACCESS))
1908 CloseHandle(hChildStdinWr);
1911 memset(&siStartInfo, 0,
sizeof(siStartInfo));
1912 siStartInfo.cb =
sizeof(STARTUPINFO);
1913 siStartInfo.lpReserved = NULL;
1914 siStartInfo.lpReserved2 = NULL;
1915 siStartInfo.cbReserved2 = 0;
1916 siStartInfo.lpDesktop = NULL;
1917 siStartInfo.dwFlags = 0;
1919 if (!CreateProcess(NULL,
"cmd /Q",
1931 SetStdHandle(STD_INPUT_HANDLE, hSaveStdin);
1932 SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout);
1933 SetStdHandle(STD_ERROR_HANDLE, hSaveStderr);
1940 if (!PeekNamedPipe(hChildStderrRd, buffer, 256, &dwRead, &dwAvail, NULL))
1944 ReadFile(hChildStderrRd, buffer, 256, &dwRead, NULL);
1945 send(sock, buffer, dwRead, 0);
1947 }
while (dwAvail > 0);
1951 if (!PeekNamedPipe(hChildStdoutRd, buffer, 256, &dwRead, &dwAvail, NULL))
1954 ReadFile(hChildStdoutRd, buffer, 256, &dwRead, NULL);
1955 send(sock, buffer, dwRead, 0);
1957 }
while (dwAvail > 0);
1961 if (!GetExitCodeProcess(piProcInfo.hProcess, &
i))
1963 if (
i != STILL_ACTIVE)
1968 FD_SET(sock, &readfds);
1970 timeout.tv_usec = 100;
1971 select(
FD_SETSIZE, &readfds, NULL, NULL, &timeout);
1973 if (FD_ISSET(sock, &readfds)) {
1974 i = recv(sock, cmd + i_cmd, 1, 0);
1979 if (cmd[i_cmd] == 8) {
1981 send(sock,
"\b \b", 3, 0);
1984 }
else if (cmd[i_cmd] >=
' ' || cmd[i_cmd] == 13 || cmd[i_cmd] == 10) {
1985 send(sock, cmd + i_cmd, 1, 0);
1991 if (cmd[i_cmd - 1] == 10) {
1992 WriteFile(hChildStdinWrDup, cmd, i_cmd, &dwWritten, NULL);
1998 CloseHandle(hChildStdinWrDup);
1999 CloseHandle(hChildStdinRd);
2000 CloseHandle(hChildStderrRd);
2001 CloseHandle(hChildStdoutRd);
2011 char line[32], buffer[1024], shell[32];
2015 assert(!
"support for forkpty() disabled by NO_FORK");
2017 pid = forkpty(&p, line, NULL, NULL);
2026 FD_SET(sock, &readfds);
2027 FD_SET(p, &readfds);
2029 select(
FD_SETSIZE, &readfds, NULL, NULL, NULL);
2031 if (FD_ISSET(sock, &readfds)) {
2032 memset(buffer, 0,
sizeof(buffer));
2033 i = recv(sock, buffer,
sizeof(buffer), 0);
2040 if (FD_ISSET(p, &readfds)) {
2041 memset(buffer, 0,
sizeof(buffer));
2042 i =
read(p, buffer,
sizeof(buffer));
2045 send(sock, buffer,
i, 0);
2052 if (getenv(
"SHELL"))
2053 mstrlcpy(shell, getenv(
"SHELL"),
sizeof(shell));
2055 strcpy(shell,
"/bin/sh");
2056 int error = execl(shell, shell, NULL);
2058 fprintf(stderr,
"ss_shell: Cannot execute command \"%s\": execl() returned %d, errno %d (%s), aborting!\n", shell, error, errno, strerror(errno));
2062 send(sock,
"not implemented\n", 17, 0);
2098 assert(!
"support for fork() disabled by NO_FORK");
2100 if ((pid = fork()) < 0)
2112 for (
i = 0;
i < 3;
i++) {
2113 if (keep_stdout && ((
i == 1) || (
i == 2)))
2117 fd = open(
"/dev/null", O_RDWR, 0);
2119 fd = open(
"/dev/null", O_WRONLY, 0);
2121 cm_msg(
MERROR,
"ss_daemon_init",
"Can't open /dev/null");
2125 cm_msg(
MERROR,
"ss_daemon_init",
"Did not get file descriptor");
2137#ifdef LOCAL_ROUTINES
2161 return (kill(pid, 0) == 0 ?
TRUE :
FALSE);
2163 cm_msg(
MINFO,
"ss_existpid",
"implemented for UNIX only");
2193 return ss_exec(command, &childpid);
2230 assert(!
"support for fork() disabled by NO_FORK");
2236 else if (*pid != 0) {
2238 signal(SIGCHLD, catch_sigchld);
2245 for (
i = 0;
i < 256;
i++)
2250 for (
i = 0;
i < 3;
i++) {
2251 fd = open(
"/dev/null", O_RDWR, 0);
2253 fd = open(
"/dev/null", O_WRONLY, 0);
2259 cm_msg(
MERROR,
"ss_exec",
"Did not get file descriptor");
2268 int error = execl(
"/bin/sh",
"sh",
"-c", command, NULL);
2270 fprintf(stderr,
"ss_shell: Cannot execute /bin/sh for command \"%s\": execl() returned %d, errno %d (%s), aborting!\n", command, error, errno, strerror(errno));
2286 size_t startPos = 0;
2289 while ((dollarPos = inputPath.find(
'$', startPos)) != std::string::npos) {
2290 result.append(inputPath, startPos, dollarPos - startPos);
2292 size_t varEndPos = inputPath.find_first_not_of(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", dollarPos + 1);
2293 size_t varLength = varEndPos - dollarPos - 1;
2294 std::string varName = inputPath.substr(dollarPos + 1, varLength);
2296 char* varValue = std::getenv(varName.c_str());
2297 if (varValue !=
nullptr) {
2298 result.append(varValue);
2301 startPos = varEndPos;
2304 result.append(inputPath.c_str(), startPos, std::string::npos);
2326 std::array<char, 256> buffer{};
2328 auto pclose_deleter = [](FILE* f) { pclose(f); };
2329 auto pipe = std::unique_ptr<FILE, decltype(pclose_deleter)>(
2335 throw std::runtime_error(
"popen() failed!");
2338 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr) {
2339 result += buffer.data();
2344 fprintf(stderr,
"ss_execs: Function not supported on this OS, aborting!\n");
2384#if defined(OS_WINNT)
2389 if (thread_func == NULL) {
2393 status = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) thread_func, (LPVOID)
param, 0, &thread_id);
2397#elif defined(OS_MSDOS)
2401#elif defined(OS_VMS)
2405#elif defined(OS_VXWORKS)
2419 taskSpawn(
ts->name,
ts->priority,
ts->options,
ts->stackSize,
2420 (FUNCPTR) thread_func,
ts->arg1,
ts->arg2,
ts->arg3,
2421 ts->arg4,
ts->arg5,
ts->arg6,
ts->arg7,
ts->arg8,
ts->arg9,
ts->arg10);
2425#elif defined(OS_UNIX)
2428 pthread_t thread_id;
2430 status = pthread_create(&thread_id, NULL, (
void* (*)(
void*))thread_func,
param);
2432 return status != 0 ? 0 : thread_id;
2457#if defined(OS_WINNT)
2462 th = OpenThread(THREAD_TERMINATE,
FALSE, (
DWORD)thread_id);
2466 status = TerminateThread(th, 0);
2473#elif defined(OS_MSDOS)
2477#elif defined(OS_VMS)
2481#elif defined(OS_VXWORKS)
2484 status = taskDelete(thread_id);
2485 return status == OK ? 0 : ERROR;
2487#elif defined(OS_UNIX)
2490 status = pthread_kill(thread_id, SIGKILL);
2500#if defined(OS_DARWIN)
2502 pthread_setname_np(
name.c_str());
2505#elif defined(OS_UNIX)
2507 pthread_t
thread = pthread_self();
2520 pthread_t
thread = pthread_self();
2522 return std::string(
str);
2562 char semaphore_name[256];
2565 sprintf(semaphore_name,
"MX_%s",
name);
2571 if ((*((SEM_ID *) mutex_handle) = semBCreate(SEM_Q_FIFO, SEM_EMPTY)) == NULL)
2579 *semaphore_handle = (
HNDLE) CreateMutex(NULL,
FALSE, semaphore_name);
2581 if (*semaphore_handle == 0)
2593 $DESCRIPTOR(semaphorename_dsc,
"dummy");
2594 semaphorename_dsc.dsc$w_length = strlen(semaphore_name);
2595 semaphorename_dsc.dsc$a_pointer = semaphore_name;
2597 *semaphore_handle = (
HNDLE) malloc(8);
2599 status = sys$enqw(0, LCK$K_NLMODE, *semaphore_handle, 0, &semaphorename_dsc, 0, 0, 0, 0, 0, 0);
2601 if (
status != SS$_NORMAL) {
2602 free((
void *) *semaphore_handle);
2603 *semaphore_handle = 0;
2606 if (*semaphore_handle == 0)
2618 struct semid_ds buf;
2628 if (getcwd(cwd,
sizeof(cwd)))
2629 path = std::string(cwd);
2631#elif defined(OS_UNIX)
2633#elif defined(OS_WINNT)
2646 fh = open(
file_name.c_str(), O_CREAT, 0644);
2653#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2658 struct semid_ds *buf;
2666 *semaphore_handle = (
HNDLE) semget(
key, 1, 0);
2668 if (*semaphore_handle < 0) {
2669 *semaphore_handle = (
HNDLE) semget(
key, 1, IPC_CREAT);
2674 if (*semaphore_handle < 0) {
2675 cm_msg(
MERROR,
"ss_semaphore_create",
"Cannot create semaphore \'%s\', semget(0x%x) failed, errno %d (%s)",
name,
key, errno, strerror(errno));
2677 fprintf(stderr,
"ss_semaphore_create: Cannot create semaphore \'%s\', semget(0x%x) failed, errno %d (%s)",
name,
key, errno, strerror(errno));
2682 memset(&buf, 0,
sizeof(buf));
2683 buf.sem_perm.uid = getuid();
2684 buf.sem_perm.gid = getgid();
2685 buf.sem_perm.mode = 0666;
2688 semctl(*semaphore_handle, 0, IPC_SET, arg);
2693 if (semctl(*semaphore_handle, 0, SETVAL, arg) < 0)
2698 fprintf(stderr,
"name %d %d %d %s\n", *semaphore_handle, (
int)time(NULL), getpid(),
name);
2736 status = WaitForSingleObject((HANDLE) semaphore_handle, timeout_millisec == 0 ? INFINITE : timeout_millisec);
2737 if (
status == WAIT_FAILED)
2739 if (
status == WAIT_TIMEOUT)
2745 status = sys$enqw(0, LCK$K_EXMODE, semaphore_handle, LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2746 if (
status != SS$_NORMAL)
2753 status = semTake((SEM_ID) semaphore_handle, timeout_millisec == 0 ? WAIT_FOREVER : timeout_millisec >> 4);
2763#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2768 struct semid_ds *buf;
2775 sb.sem_flg = SEM_UNDO;
2777 memset(&arg, 0,
sizeof(arg));
2786#if defined(OS_DARWIN)
2787 status = semop(semaphore_handle, &sb, 1);
2788#elif defined(OS_LINUX)
2790 if (timeout_millisec >= 1000 || timeout_millisec == 0) {
2795 ts.tv_nsec = (timeout_millisec+10)*1000*1000;
2798 status = semtimedop(semaphore_handle, &sb, 1, &
ts);
2800 status = semop(semaphore_handle, &sb, 1);
2813 if (errno == EINTR || errno == EAGAIN) {
2822 if (timeout_millisec > 0) {
2824 DWORD dt = milli_now - start_time;
2825 if (dt > timeout_millisec) {
2826 fprintf(stderr,
"ss_semaphore_wait_for: semop/semtimedop(%d) returned %d, errno %d (%s), start time 0x%08x, now 0x%08x, dt 0x%08x, timeout 0x%08x ms, SEMAPHORE TIMEOUT!\n", semaphore_handle,
status, errno, strerror(errno), start_time, milli_now, dt, timeout_millisec);
2834 fprintf(stderr,
"ss_semaphore_wait_for: semop/semtimedop(%d) returned %d, errno %d (%s)\n", semaphore_handle,
status, errno, strerror(errno));
2876 status = ReleaseMutex((HANDLE) semaphore_handle);
2886 status = sys$enqw(0, LCK$K_NLMODE, semaphore_handle, LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2888 if (
status != SS$_NORMAL)
2897 if (semGive((SEM_ID) semaphore_handle) == ERROR)
2908 sb.sem_flg = SEM_UNDO;
2917 status = semop(semaphore_handle, &sb, 1);
2927 fprintf(stderr,
"ss_semaphore_release: semop/semtimedop(%d) returned %d, errno %d (%s)\n", semaphore_handle,
status, errno, strerror(errno));
2962 if (CloseHandle((HANDLE) semaphore_handle) ==
FALSE)
2970 free((
void *) semaphore_handle);
2977 if (semDelete((SEM_ID) semaphore_handle) == ERROR)
2983#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2988 struct semid_ds *buf;
2993 memset(&arg, 0,
sizeof(arg));
2996 int status = semctl(semaphore_handle, 0, IPC_RMID, arg);
3033 if ((*((SEM_ID *) mutex_handle) = semBCreate(SEM_Q_FIFO, SEM_EMPTY)) == NULL)
3041 *mutex = (
MUTEX_T *)malloc(
sizeof(HANDLE));
3042 **mutex = CreateMutex(NULL,
FALSE, NULL);
3054 pthread_mutexattr_t *attr;
3056 attr = (pthread_mutexattr_t*)malloc(
sizeof(*attr));
3059 status = pthread_mutexattr_init(attr);
3061 fprintf(stderr,
"ss_mutex_create: pthread_mutexattr_init() returned errno %d (%s)\n",
status, strerror(
status));
3065 status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
3067 fprintf(stderr,
"ss_mutex_create: pthread_mutexattr_settype() returned errno %d (%s)\n",
status, strerror(
status));
3071 *mutex = (pthread_mutex_t*)malloc(
sizeof(pthread_mutex_t));
3074 status = pthread_mutex_init(*mutex, attr);
3076 fprintf(stderr,
"ss_mutex_create: pthread_mutex_init() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3086 status = pthread_mutex_trylock(*mutex);
3089 status = pthread_mutex_trylock(*mutex);
3092 status = pthread_mutex_unlock(*mutex);
3095 status = pthread_mutex_unlock(*mutex);
3134 status = WaitForSingleObject(*mutex, timeout == 0 ? INFINITE : timeout);
3136 if (
status == WAIT_TIMEOUT) {
3140 if (
status == WAIT_FAILED) {
3141 fprintf(stderr,
"ss_mutex_wait_for: WaitForSingleObject() failed, status = %d",
status);
3150 status = semTake((SEM_ID) mutex, timeout == 0 ? WAIT_FOREVER : timeout >> 4);
3158#if defined(OS_DARWIN)
3164 status = pthread_mutex_trylock(mutex);
3167 }
else if (
status == EBUSY) {
3171 fprintf(stderr,
"ss_mutex_wait_for: fatal error: pthread_mutex_trylock() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3174 if (wait > timeout) {
3175 fprintf(stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3180 status = pthread_mutex_lock(mutex);
3184 fprintf(stderr,
"ss_mutex_wait_for: pthread_mutex_lock() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3192 extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, __const
struct timespec *__restrict __abstime) __THROW;
3195 clock_gettime(CLOCK_REALTIME, &st);
3196 st.tv_sec += timeout / 1000;
3197 st.tv_nsec += (timeout % 1000) * 1000000;
3198 status = pthread_mutex_timedlock(mutex, &st);
3200 if (
status == ETIMEDOUT) {
3201 fprintf(stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3210 status = pthread_mutex_lock(mutex);
3214 fprintf(stderr,
"ss_mutex_wait_for: pthread_mutex_lock() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3252 status = ReleaseMutex(*mutex);
3261 if (semGive((SEM_ID) mutes_handle) == ERROR)
3267 status = pthread_mutex_unlock(mutex);
3269 fprintf(stderr,
"ss_mutex_release: pthread_mutex_unlock() returned error %d (%s), aborting...\n",
status, strerror(
status));
3304 if (CloseHandle(*mutex) ==
FALSE)
3314 if (semDelete((SEM_ID) mutex_handle) == ERROR)
3323 status = pthread_mutex_destroy(mutex);
3325 fprintf(stderr,
"ss_mutex_delete: pthread_mutex_destroy() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3354 if (timeout_sec <= 0) {
3360 double endtime = starttime + timeout_sec;
3367 double locktime = starttime;
3370 bool ok = mutex.try_lock_for(std::chrono::milliseconds(1000));
3381 if (now-locktime < 0.2) {
3385 fprintf(stderr,
"ss_timed_mutex_wait_for_sec: long wait for mutex %s, %.1f seconds. %.1f seconds until timeout\n", mutex_name, now-starttime, endtime-now);
3429 std::lock_guard<std::mutex> lock(
gTzMutex);
3439 std::lock_guard<std::mutex> lock(
gTzMutex);
3469 return (
int) GetTickCount();
3474 return clock() * 55;
3485 lo = *((
DWORD *) time);
3486 hi = *((
DWORD *) (time + 4));
3490 return lo / 10000 + hi * 429496.7296;
3501 DWORD m =
tv.tv_sec * 1000 +
tv.tv_usec / 1000;
3510 static int ticks_per_msec = 0;
3512 if (ticks_per_msec == 0)
3513 ticks_per_msec = 1000 / sysClkRateGet();
3515 return tickGet() * ticks_per_msec;
3536 return (
DWORD) time(NULL);
3543 return tv.tv_sec*1.0 +
tv.tv_usec/1000000.0;
3564#if defined(OS_WINNT)
3569 localtime_r((time_t *) & seconds, <m);
3571 st.wYear = ltm.tm_year + 1900;
3572 st.wMonth = ltm.tm_mon + 1;
3573 st.wDay = ltm.tm_mday;
3574 st.wHour = ltm.tm_hour;
3575 st.wMinute = ltm.tm_min;
3576 st.wSecond = ltm.tm_sec;
3577 st.wMilliseconds = 0;
3581#elif defined(OS_DARWIN) && defined(CLOCK_REALTIME)
3583 struct timespec ltm;
3585 ltm.tv_sec = seconds;
3587 clock_settime(CLOCK_REALTIME, <m);
3589#elif defined(OS_CYGWIN) && defined(CLOCK_REALTIME)
3591 struct timespec ltm;
3593 ltm.tv_sec = seconds;
3595 clock_settime(CLOCK_REALTIME, <m);
3598#elif defined(OS_UNIX) && defined(CLOCK_REALTIME)
3600 struct timespec ltm;
3602 ltm.tv_sec = seconds;
3604 clock_settime(CLOCK_REALTIME, <m);
3606#elif defined(OS_VXWORKS)
3608 struct timespec ltm;
3610 ltm.tv_sec = seconds;
3612 clock_settime(CLOCK_REALTIME, <m);
3615#warning ss_settime() is not supported!
3640 time_t seconds = (time_t)
ss_time();
3642 localtime_r(&seconds, &tms);
3644 asctime_r(&tms,
str);
3671#if defined(OS_DARWIN) || defined(OS_VXWORKS)
3674 return (
INT) timezone;
3683void ss_cont(
int signum)
3702 if (millisec == 0) {
3704 SuspendThread(GetCurrentThread());
3710 signal(SIGCONT, ss_cont);
3722 ts.tv_sec = millisec / 1000;
3723 ts.tv_nsec = (millisec % 1000) * 1E6;
3727 if ((
int)
ts.tv_sec < 0)
3729 }
while (
status == -1 && errno == EINTR);
3777 ioctl(0, FIONREAD, &
n);
3784 ioctl(0, FIONREAD, (
long) &
n);
3792#ifdef LOCAL_ROUTINES
3797static void (*UserCallback) (int);
3798static UINT _timer_id = 0;
3800VOID CALLBACK _timeCallback(UINT idEvent, UINT uReserved,
DWORD dwUser,
DWORD dwReserved1,
DWORD dwReserved2)
3803 if (UserCallback != NULL)
3832 UserCallback = func;
3834 _timer_id = timeSetEvent(millitime, 100, (LPTIMECALLBACK) _timeCallback, 0, TIME_ONESHOT);
3837 timeKillEvent(_timer_id);
3846 signal(SIGALRM, func);
3847 alarm(millitime / 1000);
3853 signal(SIGALRM, func);
3854 alarm(millitime / 1000);
3865LONG MidasExceptionFilter(LPEXCEPTION_POINTERS pexcep)
3870 return EXCEPTION_CONTINUE_SEARCH;
3873INT MidasExceptionSignal(
INT sig)
3897INT MidasExceptionFilter(
INT * sigargs,
INT * mechargs)
3902 return (SS$_RESIGNAL);
3905void MidasExceptionSignal(
INT sig)
3910 kill(getpid(), sig);
3950#elif defined (OS_VMS)
3953 lib$establish(MidasExceptionFilter);
3955 signal(SIGINT, MidasExceptionSignal);
3956 signal(SIGILL, MidasExceptionSignal);
3957 signal(SIGQUIT, MidasExceptionSignal);
3958 signal(SIGFPE, MidasExceptionSignal);
3959 signal(SIGSEGV, MidasExceptionSignal);
3960 signal(SIGTERM, MidasExceptionSignal);
3995 signal(SIGBREAK, SIG_DFL);
3996 return signal(SIGINT, SIG_DFL);
3998 signal(SIGBREAK, func);
3999 return signal(SIGINT, func);
4006 return signal(SIGINT, func);
4013 signal(SIGTERM, SIG_DFL);
4014 return (
void *) signal(SIGINT, SIG_DFL);
4016 signal(SIGTERM, func);
4017 return (
void *) signal(SIGINT, func);
4103 struct sockaddr_in bind_addr;
4115 if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
4121 sock =
socket(AF_INET, SOCK_DGRAM, 0);
4126 memset(&bind_addr, 0,
sizeof(bind_addr));
4127 bind_addr.sin_family = AF_INET;
4128 bind_addr.sin_addr.s_addr = 0;
4129 bind_addr.sin_port = 0;
4135 path +=
".UDP_BIND_HOSTNAME";
4139 FILE *
fp = fopen(path.c_str(),
"r");
4141 cm_msg(
MERROR,
"ss_suspend_init_ipc",
"Support for UDP_BIND_HOSTNAME was removed. Please delete file \"%s\"", path.c_str());
4168 bind_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4172 status = bind(sock, (
struct sockaddr *) &bind_addr,
sizeof(bind_addr));
4177 size =
sizeof(bind_addr);
4179 getsockname(sock, (
struct sockaddr *) &bind_addr, (
int *) &size);
4181 getsockname(sock, (
struct sockaddr *) &bind_addr, &size);
4187 int flags = fcntl(sock, F_GETFL, 0);
4188 status = fcntl(sock, F_SETFL, flags | O_NONBLOCK);
4191 fprintf(stderr,
"ss_suspend_init_struct: cannot set non-blocking mode of ipc receive socket, fcntl() returned %d, errno %d (%s)\n",
status, errno, strerror(errno));
4199 sock =
socket(AF_INET, SOCK_DGRAM, 0);
4205 memset(&bind_addr, 0,
sizeof(bind_addr));
4206 bind_addr.sin_family = AF_INET;
4207 bind_addr.sin_addr.s_addr = 0;
4220 bind_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4222 status = bind(sock, (
struct sockaddr *) &bind_addr,
sizeof(bind_addr));
4228 memcpy(&(psuspend->
bind_addr), &bind_addr,
sizeof(bind_addr));
4463 struct sockaddr from_addr;
4464 socklen_t from_addr_size =
sizeof(
struct sockaddr);
4486 ssize_t size = recvfrom(ipc_recv_socket, buffer,
sizeof(buffer), 0, &from_addr, &from_addr_size);
4501 if (msg ==
MSG_BM && buffer[0] ==
'B')
4503 if (msg ==
MSG_ODB && buffer[0] ==
'O')
4507 int mserver_client_socket = 0;
4511 mserver_client_socket = (*_ss_server_acceptions)[
i]->send_sock;
4516 time_t tstart = time(NULL);
4517 int return_status = 0;
4521 char buffer_tmp[80];
4523 from_addr_size =
sizeof(
struct sockaddr);
4527 ssize_t size_tmp = recvfrom(ipc_recv_socket, buffer_tmp,
sizeof(buffer_tmp), 0, &from_addr, &from_addr_size);
4529 if (size_tmp <= 0) {
4535 if (msg ==
MSG_BM && buffer_tmp[0] ==
'B') {
4539 if (msg ==
MSG_ODB && buffer_tmp[0] ==
'O') {
4545 if (buffer_tmp[0] !=
'B' || strcmp(buffer_tmp, buffer) != 0) {
4550 time_t tnow = time(NULL);
4552 if (tnow - tstart > 1 + millisec/1000) {
4562 return return_status;
4571 char test_buffer[256];
4573 int n_received = recv(sock, test_buffer,
sizeof(test_buffer), MSG_PEEK);
4575 int n_received = recv(sock, test_buffer,
sizeof(test_buffer), MSG_PEEK | MSG_DONTWAIT);
4578 if ((n_received == -1) && (errno == EAGAIN))
4582 if (n_received == -1) {
4583 cm_msg(
MERROR,
"ss_socket_check",
"recv(%d,MSG_PEEK) returned %d, errno: %d (%s)", (
int)
sizeof(test_buffer), n_received, errno, strerror(errno));
4586 if (n_received <= 0)
4597 int sock = (*_ss_server_acceptions)[
i]->event_sock;
4719 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4730 FD_SET(sock, &readfds);
4736 if (msg == 0 && msg !=
MSG_BM) {
4738 sock = (*_ss_server_acceptions)[
i]->event_sock;
4751 FD_SET(sock, &readfds);
4773 struct timeval timeout;
4775 timeout.tv_sec = millisec / 1000;
4776 timeout.tv_usec = (millisec % 1000) * 1000;
4814 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4830 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4840 sock = (*_ss_server_acceptions)[
i]->event_sock;
4845 if (FD_ISSET(sock, &readfds)) {
4853 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4868 if (FD_ISSET(sock, &readfds)) {
4910 }
while (millisec < 0);
4912 return return_status;
4942 struct sockaddr_in bind_addr;
4945 bind_addr.sin_port = htons((
short) port);
4947 size_t message_size = strlen(
message) + 1;
4955 if (((
size_t)wr) != message_size) {
4990 struct timeval timeout;
4991 struct timeval timeout0;
4992 DWORD start_time = 0;
4996 FD_SET(sock, &readfds);
4998 timeout.tv_sec = millisec / 1000;
4999 timeout.tv_usec = (millisec % 1000) * 1000;
5004 status = select(sock+1, &readfds, NULL, NULL, &timeout);
5008 if (
status<0 && errno==EINTR) {
5010 if (timeout.tv_sec == timeout0.tv_sec) {
5012 if (start_time == 0) {
5014 end_time = start_time + (millisec+999)/1000;
5024 cm_msg(
MERROR,
"ss_socket_wait",
"unexpected error, select() returned %d, errno: %d (%s)",
status, errno, strerror(errno));
5029 if (!FD_ISSET(sock, &readfds))
5041 assert(sockp != NULL);
5042 assert(error_msg_p != NULL);
5050 if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
5056 sprintf(portname,
"%d", tcp_port);
5058 struct addrinfo *ainfo = NULL;
5060 int status = getaddrinfo(hostname, portname, NULL, &ainfo);
5063 *error_msg_p =
msprintf(
"cannot resolve hostname \"%s\", getaddrinfo() error %d (%s)", hostname,
status, gai_strerror(
status));
5065 freeaddrinfo(ainfo);
5073 for (
const struct addrinfo *r = ainfo; r != NULL; r = r->ai_next) {
5075 fprintf(stderr,
"ss_socket_connect_tcp: hostname [%s] port %d addrinfo: flags %d, family %d, socktype %d, protocol %d, canonname [%s]\n",
5086 if (r->ai_socktype != SOCK_STREAM) {
5091 if (r->ai_protocol != 6) {
5095 sock =
::socket(r->ai_family, r->ai_socktype, 0);
5098 *error_msg_p =
msprintf(
"cannot create socket, errno %d (%s)", errno, strerror(errno));
5102 status = ::connect(sock, r->ai_addr, r->ai_addrlen);
5105 fprintf(stderr,
"ss_socket_connect_tcp: connect() status %d, errno %d (%s)\n",
status, errno, strerror(errno));
5107 *error_msg_p =
msprintf(
"cannot connect to host \"%s\" port %d, errno %d (%s)", hostname, tcp_port, errno, strerror(errno));
5116 freeaddrinfo(ainfo);
5127 fprintf(stderr,
"ss_socket_connect_tcp: hostname [%s] port %d new socket %d\n", hostname, tcp_port, *sockp);
5136 assert(sockp != NULL);
5137 assert(tcp_port_p != NULL);
5138 assert(error_msg_p != NULL);
5148 if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
5154 bool use_inet6 =
true;
5156 bool use_inet6 =
false;
5159 if (listen_localhost)
5166 lsock =
socket(AF_INET6, SOCK_STREAM, 0);
5168 if (errno == EAFNOSUPPORT) {
5170 lsock =
socket(AF_INET, SOCK_STREAM, 0);
5175 lsock =
socket(AF_INET, SOCK_STREAM, 0);
5179 *error_msg_p =
msprintf(
"socket(AF_INET, SOCK_STREAM) failed, errno %d (%s)", errno, strerror(errno));
5185 int status = setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (
char *) &flag,
sizeof(
int));
5187 *error_msg_p =
msprintf(
"setsockopt(SO_REUSEADDR) failed, errno %d (%s)", errno, strerror(errno));
5196 status = setsockopt(lsock, IPPROTO_IPV6, IPV6_V6ONLY, (
char *) &flag,
sizeof(
int));
5198 *error_msg_p =
msprintf(
"setsockopt(IPPROTO_IPV6, IPV6_V6ONLY) failed, errno %d (%s)", errno, strerror(errno));
5203#warning strange: AF_INET6 is defined, but IPV6_V6ONLY is not defined
5210 struct sockaddr_in6 bind_addr6;
5211 memset(&bind_addr6, 0,
sizeof(bind_addr6));
5212 bind_addr6.sin6_family = AF_INET6;
5214 if (listen_localhost) {
5215 bind_addr6.sin6_addr = in6addr_loopback;
5217 bind_addr6.sin6_addr = in6addr_any;
5221 bind_addr6.sin6_port = htons((
short) tcp_port);
5223 bind_addr6.sin6_port = htons(0);
5225 status = bind(lsock, (
struct sockaddr *) &bind_addr6,
sizeof(bind_addr6));
5227 *error_msg_p =
msprintf(
"IPv6 bind() to port %d failed, errno %d (%s)", tcp_port, errno, strerror(errno));
5233 struct sockaddr_in bind_addr;
5234 memset(&bind_addr, 0,
sizeof(bind_addr));
5235 bind_addr.sin_family = AF_INET;
5237 if (listen_localhost) {
5238 bind_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
5240 bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
5244 bind_addr.sin_port = htons((
short) tcp_port);
5246 bind_addr.sin_port = htons(0);
5248 status = bind(lsock, (
struct sockaddr *) &bind_addr,
sizeof(bind_addr));
5250 *error_msg_p =
msprintf(
"bind() to port %d failed, errno %d (%s)", tcp_port, errno, strerror(errno));
5257 status = listen(lsock, 1);
5262 *error_msg_p =
msprintf(
"listen() failed, errno %d (%s)", errno, strerror(errno));
5268 struct sockaddr_in6
addr;
5269 socklen_t sosize =
sizeof(
addr);
5270 status = getsockname(lsock, (
struct sockaddr*)&
addr, &sosize);
5272 *error_msg_p =
msprintf(
"IPv6 getsockname() failed, errno %d (%s)", errno, strerror(errno));
5276 *tcp_port_p = ntohs(
addr.sin6_port);
5279 struct sockaddr_in
addr;
5280 socklen_t sosize =
sizeof(
addr);
5281 status = getsockname(lsock, (
struct sockaddr*)&
addr, &sosize);
5283 *error_msg_p =
msprintf(
"getsockname() failed, errno %d (%s)", errno, strerror(errno));
5287 *tcp_port_p = ntohs(
addr.sin_port);
5293 if (listen_localhost)
5294 fprintf(stderr,
"ss_socket_listen_tcp: listening tcp port %d local connections only, new socket %d\n", *tcp_port_p, *sockp);
5296 fprintf(stderr,
"ss_socket_listen_tcp: listening tcp port %d all internet connections, socket %d\n", *tcp_port_p, *sockp);
5305 assert(sockp != NULL);
5307 fprintf(stderr,
"ss_socket_close: %d\n", *sockp);
5309 int err = close(*sockp);
5311 cm_msg(
MERROR,
"ss_socket_close",
"unexpected error, close() returned %d, errno: %d (%s)", err, errno, strerror(errno));
5322 unsigned size =
sizeof(
addr);
5323 int rv = getpeername(sock, (
struct sockaddr *) &
addr, &size);
5328 cm_msg(
MERROR,
"ss_socket_get_peer_name",
"Error: getpeername() returned %d, errno %d (%s)", rv, errno, strerror(errno));
5335 int ret = getnameinfo((
struct sockaddr*)&
addr, size,
5336 hostname,
sizeof(hostname),
5337 servname,
sizeof(servname),
5341 cm_msg(
MERROR,
"ss_socket_get_peer_name",
"Error: getnameinfo() error %d (%s)", ret, gai_strerror(ret));
5351 *portp = atoi(servname);
5382 int net_tcp_size = 1024 * 1024;
5387 status = send(sock, buffer +
count, net_tcp_size, flags & 0xFFFF);
5395 if ((flags & 0x10000) == 0)
5397 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5398 sock, net_tcp_size,
status, errno, strerror(errno));
5403 while (
count < buffer_size) {
5412 if ((flags & 0x10000) == 0)
5414 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5415 sock, (
int) (buffer_size -
count),
status, errno, strerror(errno));
5448 while (
count < buffer_size) {
5452 cm_msg(
MERROR,
"ss_write_tcp",
"write(socket=%d,size=%d) returned zero, errno: %d (%s)", sock, (
int) (buffer_size -
count), errno, strerror(errno));
5454 }
else if (wr < 0) {
5459 cm_msg(
MERROR,
"ss_write_tcp",
"write(socket=%d,size=%d) returned %d, errno: %d (%s)", sock, (
int) (buffer_size -
count), (
int)wr, errno, strerror(errno));
5501 memset(buffer, 0, buffer_size);
5510 i = recv(sock, buffer +
n, 1, 0);
5517 if (
n >= buffer_size)
5520 }
while (buffer[
n - 1] && buffer[
n - 1] != 10);
5557 INT param_size, n_received,
n;
5561 cm_msg(
MERROR,
"recv_tcp",
"parameters too large for network buffer");
5573 }
while (
n == -1 && errno == EINTR);
5579 cm_msg(
MERROR,
"recv_tcp",
"header: recv(%d) returned %d, n_received = %d, unexpected connection closure", (
int)
sizeof(
NET_COMMAND_HEADER),
n, n_received);
5584 cm_msg(
MERROR,
"recv_tcp",
"header: recv(%d) returned %d, n_received = %d, errno: %d (%s)", (
int)
sizeof(
NET_COMMAND_HEADER),
n, n_received, errno, strerror(errno));
5598 if (param_size == 0)
5601 if (param_size > (
INT)buffer_size) {
5602 cm_msg(
MERROR,
"recv_tcp",
"param: receive buffer size %d is too small for received data size %d", buffer_size, param_size);
5609 n = recv(sock, net_buffer +
sizeof(
NET_COMMAND_HEADER) + n_received, param_size - n_received, flags);
5612 }
while (
n == -1 && errno == EINTR);
5614 n = recv(sock, net_buffer +
sizeof(
NET_COMMAND_HEADER) + n_received, param_size - n_received, flags);
5618 cm_msg(
MERROR,
"recv_tcp",
"param: recv() returned %d, n_received = %d, unexpected connection closure",
n, n_received);
5623 cm_msg(
MERROR,
"recv_tcp",
"param: recv() returned %d, n_received = %d, errno: %d (%s)",
n, n_received, errno, strerror(errno));
5628 }
while (n_received < param_size);
5667 while (n_received != buffer_size) {
5669 if (timeout_ms > 0) {
5677 n = recv(sock, net_buffer + n_received, buffer_size - n_received, flags);
5683 if (
n == -1 && errno == EINTR)
5689 cm_msg(
MERROR,
"recv_tcp2",
"unexpected connection closure");
5695 cm_msg(
MERROR,
"recv_tcp2",
"unexpected connection error, recv() errno %d (%s)", errno, strerror(errno));
5735 n =
recv_tcp2(sock, (
char*)&ncbuf,
sizeof(ncbuf), timeout_ms);
5738 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command header");
5742 if (
n !=
sizeof(ncbuf)) {
5743 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command header, see messages");
5751 if (*param_size == 0) {
5756 *param_ptr = (
char *)malloc(*param_size);
5758 if (*param_ptr == NULL) {
5759 cm_msg(
MERROR,
"ss_recv_net_command",
"error allocating %d bytes for network command data", *param_size);
5764 n =
recv_tcp2(sock, *param_ptr, *param_size, timeout_ms);
5767 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command data");
5773 if (
n != *param_size) {
5774 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command data, see messages");
5803 memset(buf, 0,
sizeof(buf));
5805 int status = gethostname(buf,
sizeof(buf)-1);
5810 cm_msg(
MERROR,
"ss_gethostname",
"gethostname() errno %d (%s)", errno, strerror(errno));
5838 if (h.length() == 0) {
5841 mstrlcpy(buffer, h.c_str(), buffer_size);
5850 char *s = getcwd(NULL, 0);
5852 std::string cwd = s;
5857 return "/GETCWD-FAILED-ON-US";
5873int sopen(
const char *path,
int access,
int shflag,
int mode)
5875 return open(path, (access) | (shflag), mode);
5915 *
channel = open(path, oflag, 0644);
5920 cm_msg(
MERROR,
"ss_tape_open",
"open() returned %d, errno %d (%s)", *
channel, errno, strerror(errno));
5933 arg.mt_op = MTSETBLK;
5936 ioctl(*
channel, MTIOCTOP, &arg);
5944 TAPE_GET_MEDIA_PARAMETERS m;
5946 *
channel = (
INT) CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);
5948 if (*
channel == (
INT) INVALID_HANDLE_VALUE) {
5950 if (
status == ERROR_SHARING_VIOLATION) {
5951 cm_msg(
MERROR,
"ss_tape_open",
"tape is used by other process");
5954 if (
status == ERROR_FILE_NOT_FOUND) {
5955 cm_msg(
MERROR,
"ss_tape_open",
"tape device \"%s\" doesn't exist", path);
5964 if (
status == ERROR_NO_MEDIA_IN_DRIVE ||
status == ERROR_BUS_RESET) {
5970 memset(&m, 0,
sizeof(m));
5972 SetTapeParameters((HANDLE) (*
channel), SET_TAPE_MEDIA_INFORMATION, &m);
6006 cm_msg(
MERROR,
"ss_tape_close",
"close() returned %d, errno %d (%s)",
status, errno, strerror(errno));
6013 if (!CloseHandle((HANDLE)
channel)) {
6046 sprintf(
str,
"mt -f %s status", path);
6056 TAPE_GET_MEDIA_PARAMETERS m;
6057 TAPE_GET_DRIVE_PARAMETERS
d;
6060 channel = (
INT) CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);
6064 if (
status == ERROR_SHARING_VIOLATION) {
6065 cm_msg(
MINFO,
"ss_tape_status",
"tape is used by other process");
6068 if (
status == ERROR_FILE_NOT_FOUND) {
6069 cm_msg(
MINFO,
"ss_tape_status",
"tape device \"%s\" doesn't exist", path);
6078 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6079 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6082 if (
status == ERROR_NO_MEDIA_IN_DRIVE ||
status == ERROR_BUS_RESET) {
6083 cm_msg(
MINFO,
"ss_tape_status",
"no media in drive");
6084 CloseHandle((HANDLE)
channel);
6088 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6089 GetTapeParameters((HANDLE)
channel, GET_TAPE_MEDIA_INFORMATION, &size, &m);
6091 printf(
"Hardware error correction is %s\n",
d.ECC ?
"on" :
"off");
6092 printf(
"Hardware compression is %s\n",
d.Compression ?
"on" :
"off");
6093 printf(
"Tape %s write protected\n", m.WriteProtected ?
"is" :
"is not");
6095 if (
d.FeaturesLow & TAPE_DRIVE_TAPE_REMAINING) {
6096 x = ((double) m.Remaining.LowPart + (
double) m.Remaining.HighPart * 4.294967295E9)
6098 printf(
"Tape capacity remaining is %d MB\n", (
int) x);
6100 printf(
"Tape capacity is not reported by tape\n");
6102 CloseHandle((HANDLE)
channel);
6141 }
while (
status == -1 && errno == EINTR);
6144 cm_msg(
MERROR,
"ss_tape_write",
"write() returned %d, errno %d (%s)",
status, errno, strerror(errno));
6157 WriteFile((HANDLE)
channel, pdata,
count, &written, NULL);
6196 }
while (
n == -1 && errno == EINTR);
6199 if (errno == ENOSPC || errno == EIO)
6202 if (
n == 0 && errno == 0)
6205 cm_msg(
MERROR,
"ss_tape_read",
"unexpected tape error: n=%d, errno=%d\n",
n, errno);
6215#elif defined(OS_WINNT)
6222 if (
status == ERROR_NO_DATA_DETECTED)
6224 else if (
status == ERROR_FILEMARK_DETECTED)
6226 else if (
status == ERROR_MORE_DATA)
6277 cm_msg(
MERROR,
"ss_tape_write_eof",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6284 TAPE_GET_DRIVE_PARAMETERS
d;
6288 size =
sizeof(TAPE_GET_DRIVE_PARAMETERS);
6289 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6291 if (
d.FeaturesHigh & TAPE_DRIVE_WRITE_FILEMARKS)
6293 else if (
d.FeaturesHigh & TAPE_DRIVE_WRITE_LONG_FMKS)
6295 else if (
d.FeaturesHigh & TAPE_DRIVE_WRITE_SHORT_FMKS)
6298 cm_msg(
MERROR,
"ss_tape_write_eof",
"tape doesn't support writing of filemarks");
6300 if (
status != NO_ERROR) {
6338 arg.mt_count = abs(
count);
6347 cm_msg(
MERROR,
"ss_tape_fskip",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6357 if (
status == ERROR_END_OF_MEDIA)
6360 if (
status != NO_ERROR) {
6398 arg.mt_count = abs(
count);
6407 cm_msg(
MERROR,
"ss_tape_rskip",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6416 if (
status != NO_ERROR) {
6459 cm_msg(
MERROR,
"ss_tape_rewind",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6468 if (
status != NO_ERROR) {
6515 cm_msg(
MERROR,
"ss_tape_rewind",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6524 if (
status != NO_ERROR) {
6571 cm_msg(
MERROR,
"ss_tape_mount",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6580 if (
status != NO_ERROR) {
6616 arg.mt_op = MTUNLOAD;
6627 cm_msg(
MERROR,
"ss_tape_unmount",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6636 if (
status != NO_ERROR) {
6656#if defined(OS_DARWIN)
6660#elif defined(OS_UNIX)
6672 cm_msg(
MERROR,
"ss_tape_get_blockn",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6676 return (arg.mt_blkno);
6678#elif defined(OS_WINNT)
6681 TAPE_GET_MEDIA_PARAMETERS media;
6684 status = GetTapeParameters((HANDLE)
channel, GET_TAPE_MEDIA_INFORMATION, &size, &media);
6685 return (media.PartitionCount);
6718 statfs(path, &st,
sizeof(st));
6719 return (
double) st.f_bavail * st.f_bsize;
6720#elif defined(OS_LINUX)
6723 status = statfs(path, &st);
6726 return (
double) st.f_bavail * st.f_bsize;
6727#elif defined(OS_SOLARIS)
6730 return (
double) st.f_bavail * st.f_bsize;
6731#elif defined(OS_IRIX)
6733 statfs(path, &st,
sizeof(
struct statfs), 0);
6734 return (
double) st.f_bfree * st.f_bsize;
6738 return (
double) st.fd_otsize * st.fd_bfree;
6741#elif defined(OS_WINNT)
6742 DWORD SectorsPerCluster;
6743 DWORD BytesPerSector;
6744 DWORD NumberOfFreeClusters;
6745 DWORD TotalNumberOfClusters;
6749 if (strchr(
str,
':') != NULL) {
6750 *(strchr(
str,
':') + 1) = 0;
6752 GetDiskFreeSpace(
str, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
6754 GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
6756 return (
double) NumberOfFreeClusters *SectorsPerCluster * BytesPerSector;
6764#if defined(OS_ULTRIX) || defined(OS_WINNT)
6765int fnmatch(
const char *pat,
const char *
str,
const int flag)
6767 while (*
str !=
'\0') {
6770 if ((
str = strchr(
str, *pat)) == NULL)
6788LPWIN32_FIND_DATA lpfdata;
6799 size_t size =
list.size();
6801 for (
size_t i=0;
i<size;
i++) {
6830 if (access(path, F_OK) != 0) {
6839 if ((dir_pointer = opendir(path)) == NULL)
6841 for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
6842 if (fnmatch(pattern, dp->d_name, 0) == 0 && (dp->d_type == DT_REG || dp->d_type == DT_LNK || dp->d_type == DT_UNKNOWN)) {
6843 plist->push_back(dp->d_name);
6844 seekdir(dir_pointer, telldir(dir_pointer));
6847 closedir(dir_pointer);
6855 strcat(
str, pattern);
6857 lpfdata = (WIN32_FIND_DATA *) malloc(
sizeof(WIN32_FIND_DATA));
6859 pffile = FindFirstFile(
str, lpfdata);
6860 if (pffile == INVALID_HANDLE_VALUE)
6863 plist->push_back(lpfdata->cFileName);
6865 while (FindNextFile(pffile, lpfdata)) {
6866 plist->push_back(lpfdata->cFileName);
6871 return plist->size();
6882 size_t size =
list.size();
6884 for (
size_t i=0;
i<size;
i++) {
6916 if ((dir_pointer = opendir(path)) == NULL)
6919 for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
6920 if (fnmatch(pattern, dp->d_name, 0) == 0 && dp->d_type == DT_DIR) {
6921 plist->push_back(dp->d_name);
6922 seekdir(dir_pointer, telldir(dir_pointer));
6925 closedir(dir_pointer);
6933 strcat(
str, pattern);
6936 lpfdata = (WIN32_FIND_DATA *) malloc(
sizeof(WIN32_FIND_DATA));
6937 pffile = FindFirstFile(
str, lpfdata);
6938 if (pffile == INVALID_HANDLE_VALUE)
6941 plist->push_back(lpfdata->cFileName);
6942 while (FindNextFile(pffile, lpfdata)) {
6943 plist->push_back(lpfdata->cFileName);
6947 return plist->size();
6958 size_t size =
list.size();
6960 for (
size_t i=0;
i<size;
i++) {
6992 if ((dir_pointer = opendir(path)) == NULL)
6995 for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
6996 if (fnmatch(pattern, dp->d_name, 0) == 0) {
6998 std::string full_path = std::string(path) +
"/" + dp->d_name +
"/";
7000 if (lstat(full_path.c_str(), &st) == 0 && (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))) {
7001 plist->push_back(dp->d_name);
7005 closedir(dir_pointer);
7013 strcat(
str, pattern);
7016 lpfdata = (WIN32_FIND_DATA *) malloc(
sizeof(WIN32_FIND_DATA));
7017 pffile = FindFirstFile(
str, lpfdata);
7018 if (pffile == INVALID_HANDLE_VALUE)
7021 plist->push_back(lpfdata->cFileName);
7022 while (FindNextFile(pffile, lpfdata)) {
7023 plist->push_back(lpfdata->cFileName);
7027 return plist->size();
7067#ifdef _LARGEFILE64_SOURCE
7068 struct stat64 stat_buf;
7072 status = stat64(path, &stat_buf);
7075 return (
double) stat_buf.st_size;
7077 struct stat stat_buf;
7081 status = stat(path, &stat_buf);
7084 return (
double) stat_buf.st_size;
7105#ifdef _LARGEFILE64_SOURCE
7106 struct stat64 stat_buf;
7110 status = stat64(path, &stat_buf);
7113 return stat_buf.st_mtime;
7115 struct stat stat_buf;
7119 status = stat(path, &stat_buf);
7122 return stat_buf.st_mtime;
7146 statfs(path, &st,
sizeof(st));
7147 return (
double) st.f_blocks * st.f_fsize;
7148#elif defined(OS_LINUX)
7151 status = statfs(path, &st);
7154 return (
double) st.f_blocks * st.f_bsize;
7155#elif defined(OS_SOLARIS)
7158 if (st.f_frsize > 0)
7159 return (
double) st.f_blocks * st.f_frsize;
7161 return (
double) st.f_blocks * st.f_bsize;
7162#elif defined(OS_ULTRIX)
7165 return (
double) st.fd_btot * 1024;
7166#elif defined(OS_IRIX)
7168 statfs(path, &st,
sizeof(
struct statfs), 0);
7169 return (
double) st.f_blocks * st.f_bsize;
7171#error ss_disk_size not defined for this OS
7176 DWORD SectorsPerCluster;
7177 DWORD BytesPerSector;
7178 DWORD NumberOfFreeClusters;
7179 DWORD TotalNumberOfClusters;
7183 if (strchr(
str,
':') != NULL) {
7184 *(strchr(
str,
':') + 1) = 0;
7186 GetDiskFreeSpace(
str, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
7188 GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
7190 return (
double) TotalNumberOfClusters *SectorsPerCluster * BytesPerSector;
7217 int retval = stat(path, &buf);
7221 if (S_ISDIR(buf.st_mode))
7225 int fd = open(path, O_RDONLY, 0);
7253 int retval = lstat(path, &buf);
7256 if (S_ISLNK(buf.st_mode))
7285 int retval = stat(path, &buf);
7289 if (!S_ISDIR(buf.st_mode))
7292#warning ss_dir_exist() is not implemented!
7320 fd_from = open(src, O_RDONLY);
7325 fd_to = open(dst, O_WRONLY | O_CREAT | O_EXCL | O_APPEND, 0666);
7327 fd_to = open(dst, O_WRONLY | O_CREAT | O_EXCL, 0666);
7331 while (nread =
read(fd_from, buf,
sizeof(buf)), nread > 0) {
7332 char *out_ptr = buf;
7336 nwritten =
write(fd_to, out_ptr, nread);
7338 if (nwritten >= 0) {
7340 out_ptr += nwritten;
7341 }
else if (errno != EINTR) {
7344 }
while (nread > 0);
7348 if (close(fd_to) < 0) {
7359 saved_errno = errno;
7365 errno = saved_errno;
7398 COORD coordScreen = { 0, 0 };
7400 DWORD cCharsWritten;
7401 CONSOLE_SCREEN_BUFFER_INFO csbi;
7404 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
7407 bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
7408 dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
7411 bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR)
' ', dwConSize, coordScreen, &cCharsWritten);
7414 bSuccess = SetConsoleCursorPosition(hConsole, coordScreen);
7418#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7450 coordSize.X = (short) x;
7451 coordSize.Y = (short) y;
7452 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
7453 SetConsoleScreenBufferSize(hConsole, coordSize);
7485 va_start(argptr, format);
7486 vsprintf(
str, (
char *) format, argptr);
7493 DWORD cCharsWritten;
7495 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
7497 dwWriteCoord.X = (short) x;
7498 dwWriteCoord.Y = (short) y;
7500 WriteConsoleOutputCharacter(hConsole,
str, strlen(
str), dwWriteCoord, &cCharsWritten);
7505#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7506 printf(
"\033[%1d;%1dH", y + 1, x + 1);
7512 gotoxy(x + 1, y + 1);
7536 static char password[32];
7538 fprintf(stdout,
"%s", prompt);
7540 memset(password, 0,
sizeof(password));
7543 return (
char *) getpass(
"");
7544#elif defined(OS_WINNT)
7549 hConsole = GetStdHandle(STD_INPUT_HANDLE);
7550 SetConsoleMode(hConsole, ENABLE_LINE_INPUT);
7551 ReadConsole(hConsole, password,
sizeof(password), &nCharsRead, NULL);
7552 SetConsoleMode(hConsole, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
7555 if (password[strlen(password) - 1] ==
'\r')
7556 password[strlen(password) - 1] = 0;
7560#elif defined(OS_MSDOS)
7565 while ((
c = getchar()) != EOF &&
c !=
'\n')
7605 static struct termios save_termios;
7617 tcsetattr(fd, TCSAFLUSH, &save_termios);
7623 tcgetattr(fd, &save_termios);
7624 memcpy(&buf, &save_termios,
sizeof(buf));
7626 buf.c_lflag &= ~(ECHO | ICANON | IEXTEN);
7628 buf.c_iflag &= ~(ICRNL | INPCK | ISTRIP | IXON);
7630 buf.c_cflag &= ~(CSIZE | PARENB);
7634 buf.c_cc[VTIME] = 0;
7636 tcsetattr(fd, TCSAFLUSH, &buf);
7688#elif defined(OS_WINNT)
7691 static INT repeat_count = 0;
7692 static INT repeat_char;
7699 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
7702 if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT) {
7738 hConsole = GetStdHandle(STD_INPUT_HANDLE);
7741 SetConsoleMode(hConsole, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
7747 SetConsoleMode(hConsole, ENABLE_PROCESSED_INPUT);
7756 PeekConsoleInput(hConsole, &ir, 1, &nCharsRead);
7758 if (nCharsRead == 0)
7761 ReadConsoleInput(hConsole, &ir, 1, &nCharsRead);
7763 if (ir.EventType != KEY_EVENT)
7766 if (!ir.Event.KeyEvent.bKeyDown)
7769 if (ir.Event.KeyEvent.wRepeatCount > 1) {
7770 repeat_count = ir.Event.KeyEvent.wRepeatCount - 1;
7771 repeat_char = ir.Event.KeyEvent.uChar.AsciiChar;
7775 if (ir.Event.KeyEvent.uChar.AsciiChar)
7776 return ir.Event.KeyEvent.uChar.AsciiChar;
7778 if (ir.Event.KeyEvent.dwControlKeyState & (ENHANCED_KEY)) {
7779 switch (ir.Event.KeyEvent.wVirtualKeyCode) {
7802 return ir.Event.KeyEvent.wVirtualKeyCode;
7807#elif defined(OS_MSDOS)
7871 p = fgets(
string, size, stdin);
7872 }
while (p == NULL);
7875 if (strlen(p) > 0 && p[strlen(p) - 1] ==
'\n')
7876 p[strlen(p) - 1] = 0;
7897 DWORD buffer[] = { 6, 0, 0, 0 };
7900 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
7904 if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
7905 hdio = CreateFile(
"\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7906 if (hdio == INVALID_HANDLE_VALUE) {
7907 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7914 if (!DeviceIoControl(hdio, (
DWORD) 0x9c406000, &buffer,
sizeof(buffer), NULL, 0, &size, NULL))
7933 DWORD buffer[] = { 7, 0, 0, 0 };
7936 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
7940 if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
7941 hdio = CreateFile(
"\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7942 if (hdio == INVALID_HANDLE_VALUE) {
7943 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7950 if (!DeviceIoControl(hdio, (
DWORD) 0x9c406000, &buffer,
sizeof(buffer), NULL, 0, &size, NULL))
7967#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
7991 static char enc_pw[13];
7993 memset(enc_pw, 0,
sizeof(enc_pw));
7994 enc_pw[0] = salt[0];
7995 enc_pw[1] = salt[1];
7997 for (
i = 0;
i < 8 && buf[
i];
i++)
7998 enc_pw[
i + 2] = buf[
i];
8003 for (
i = 2;
i < 13;
i++) {
8004 seed = 5 * seed + 27 + enc_pw[
i];
8030#define isnan(x) _isnan(x)
8033#define finite(x) _finite(x)
8035#elif defined(OS_LINUX)
8065#include <execinfo.h>
8068#define N_STACK_HISTORY 500
8075#define MAX_STACK_DEPTH 16
8077 void *trace[MAX_STACK_DEPTH];
8080 size = backtrace(trace, MAX_STACK_DEPTH);
8081 *
string = backtrace_symbols(trace, size);
8094 for (
i = 0;
i <
n;
i++)
8095 printf(
"%s\n",
string[
i]);
8112 for (
i = 2;
i <
n;
i++) {
8127 f = fopen(filename,
"wt");
8136 printf(
"Stack dump written to %s\n", filename);
8138 printf(
"Cannot open %s: errno=%d\n", filename, errno);
8152 const unsigned char * bytes = (
const unsigned char *)
string;
8159 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8167 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8168 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8177 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8178 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8181 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8183 bytes[0] == 0xEF) &&
8184 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8185 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8189 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8190 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8199 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8200 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8201 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8204 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8205 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8206 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8207 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8211 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8212 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8213 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8233 bool modified =
false;
8239 unsigned char * bytes = (
unsigned char *)
string;
8246 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8254 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8255 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8264 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8265 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8268 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8270 bytes[0] == 0xEF) &&
8271 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8272 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8276 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8277 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8286 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8287 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8288 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8291 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8292 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8293 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8294 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8298 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8299 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8300 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8333std::chrono::time_point<std::chrono::high_resolution_clock>
ss_us_start()
8335 return std::chrono::high_resolution_clock::now();
8338unsigned int ss_us_since(std::chrono::time_point<std::chrono::high_resolution_clock> start) {
8339 auto elapsed = std::chrono::high_resolution_clock::now() - start;
8340 return std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
INT cm_dispatch_ipc(const char *message, int message_size, int client_socket)
std::string cm_get_path()
std::string cm_get_experiment_name()
#define SS_INVALID_HANDLE
#define SS_INVALID_ADDRESS
#define MAX_STRING_LENGTH
std::string ss_gethostname()
INT ss_suspend(INT millisec, INT msg)
INT ss_suspend_set_rpc_thread(midas_thread_t thread_id)
INT ss_get_struct_align()
INT ss_suspend_get_odb_port(INT *port)
bool ss_is_valid_utf8(const char *string)
INT ss_mutex_release(MUTEX_T *mutex)
INT ss_thread_kill(midas_thread_t thread_id)
INT ss_suspend_init_odb_port()
INT ss_dir_find(const char *path, const char *pattern, char **plist)
static midas_thread_t _ss_server_thread
INT ss_exception_handler(void(*func)(void))
bool ss_event_socket_has_data()
INT ss_shm_flush(const char *name, const void *adr, size_t size, HNDLE handle, bool wait_for_thread)
static void ss_suspend_close(SUSPEND_STRUCT *psuspend)
double ss_disk_size(const char *path)
time_t ss_mktime(struct tm *tms)
static int _ss_server_listen_socket
int ss_file_exist(const char *path)
static void check_shm_host()
INT EXPRT ss_thread_set_name(std::string name)
static int ss_suspend_process_ipc(INT millisec, INT msg, int ipc_recv_socket)
INT ss_tape_rskip(INT channel, INT count)
INT ss_tape_write(INT channel, void *pdata, INT count)
INT ss_semaphore_create(const char *name, HNDLE *semaphore_handle)
INT ss_shm_delete(const char *name)
static std::mutex gTzMutex
INT recv_tcp2(int sock, char *net_buffer, int buffer_size, int timeout_ms)
SUSPEND_STRUCT * ss_suspend_get_struct(midas_thread_t thread_id)
INT ss_suspend_set_client_listener(int listen_socket)
static RPC_SERVER_CONNECTION * _ss_client_connection
INT ss_dirlink_find(const char *path, const char *pattern, char **plist)
INT ss_getchar(BOOL reset)
static std::atomic_bool s_semaphore_trace
INT ss_tape_rewind(INT channel)
INT ss_shm_flush_thread(void *p)
INT ss_tape_fskip(INT channel, INT count)
INT ss_tape_close(INT channel)
static midas_thread_t _ss_odb_thread
static struct @3 test_align
double ss_disk_free(const char *path)
time_t ss_file_time(const char *path)
INT ss_socket_get_peer_name(int sock, std::string *hostp, int *portp)
static int ss_socket_check(int sock)
int ss_file_link_exist(const char *path)
INT ss_tape_get_blockn(INT channel)
INT ss_mutex_delete(MUTEX_T *mutex)
int ss_socket_wait(int sock, INT millisec)
INT ss_suspend_set_server_acceptions(RPC_SERVER_ACCEPTION_LIST *acceptions)
double ss_file_size(const char *path)
char stack_history[N_STACK_HISTORY][80]
INT ss_tape_status(char *path)
DWORD ss_settime(DWORD seconds)
std::chrono::time_point< std::chrono::high_resolution_clock > ss_us_start()
INT ss_tape_mount(INT channel)
char * ss_getpass(const char *prompt)
INT ss_directio_give_port(INT start, INT end)
INT ss_suspend_set_client_connection(RPC_SERVER_CONNECTION *connection)
INT ss_mutex_create(MUTEX_T **mutex, BOOL recursive)
static bool ss_match_thread(midas_thread_t tid1, midas_thread_t tid2)
unsigned int ss_us_since(std::chrono::time_point< std::chrono::high_resolution_clock > start)
INT ss_shm_open(const char *name, INT size, void **adr, size_t *shm_size, HNDLE *handle, BOOL get_size)
INT recv_string(int sock, char *buffer, DWORD buffer_size, INT millisec)
INT ss_write_tcp(int sock, const char *buffer, size_t buffer_size)
int ss_dir_exist(const char *path)
bool ss_timed_mutex_wait_for_sec(std::timed_mutex &mutex, const char *mutex_name, double timeout_sec)
INT ss_semaphore_release(HNDLE semaphore_handle)
void ss_set_screen_size(int x, int y)
midas_thread_t ss_thread_create(INT(*thread_func)(void *), void *param)
void ss_stack_history_entry(char *tag)
std::string ss_execs(const char *cmd)
static struct @4 test_padding
static int _ss_client_listen_socket
static SUSPEND_STRUCT * _ss_suspend_odb
INT ss_tape_spool(INT channel)
INT ss_stack_get(char ***string)
std::string ss_get_cmdline(void)
std::string ss_tid_to_string(midas_thread_t thread_id)
INT ss_file_remove(const char *path)
void ss_stack_history_dump(char *filename)
INT ss_tape_read(INT channel, void *pdata, INT *count)
int ss_file_copy(const char *src, const char *dst, bool append)
std::string ss_replace_env_variables(const std::string &inputPath)
INT ss_daemon_init(BOOL keep_stdout)
INT ss_alarm(INT millitime, void(*func)(int))
static midas_thread_t _ss_listen_thread
static INT ss_suspend_init_struct(SUSPEND_STRUCT *psuspend)
INT recv_tcp(int sock, char *net_buffer, DWORD buffer_size, INT flags)
INT ss_resume(INT port, const char *message)
midas_thread_t ss_gettid(void)
INT ss_semaphore_delete(HNDLE semaphore_handle, INT destroy_flag)
INT ss_get_struct_padding()
INT ss_sleep(INT millisec)
INT ss_socket_connect_tcp(const char *hostname, int tcp_port, int *sockp, std::string *error_msg_p)
void(* MidasExceptionHandler)(void)
INT ss_tape_unmount(INT channel)
static RPC_SERVER_ACCEPTION_LIST * _ss_server_acceptions
INT ss_tape_write_eof(INT channel)
INT ss_semaphore_wait_for(HNDLE semaphore_handle, DWORD timeout_millisec)
INT ss_socket_listen_tcp(bool listen_localhost, int tcp_port, int *sockp, int *tcp_port_p, std::string *error_msg_p)
INT ss_exec(const char *command, INT *pid)
INT ss_shm_unprotect(HNDLE handle, void **adr, size_t shm_size, BOOL read, BOOL write, const char *caller_name)
bool ss_repair_utf8(char *string)
static std::atomic_int s_semaphore_nest_level
std::string EXPRT ss_thread_get_name()
char * ss_crypt(const char *buf, const char *salt)
INT ss_tape_open(char *path, INT oflag, INT *channel)
BOOL ss_existpid(INT pid)
INT ss_spawnv(INT mode, const char *cmdname, const char *const argv[])
INT ss_suspend_get_buffer_port(midas_thread_t thread_id, INT *port)
void ss_printf(INT x, INT y, const char *format,...)
INT ss_socket_close(int *sockp)
INT ss_directio_lock_port(INT start, INT end)
struct suspend_struct SUSPEND_STRUCT
char * ss_gets(char *string, int size)
INT ss_recv_net_command(int sock, DWORD *routine_id, DWORD *param_size, char **param_ptr, int timeout_ms)
INT ss_suspend_set_server_listener(int listen_socket)
INT ss_shm_close(const char *name, void *adr, size_t shm_size, HNDLE handle, INT destroy_flag)
INT send_tcp(int sock, char *buffer, DWORD buffer_size, INT flags)
void * ss_ctrlc_handler(void(*func)(int))
BOOL ss_pid_exists(int pid)
static midas_thread_t _ss_client_thread
std::string ss_get_executable(void)
static void check_shm_type(const char *shm_type)
INT ss_system(const char *command)
INT ss_shm_protect(HNDLE handle, void *adr, size_t shm_size)
static std::vector< SUSPEND_STRUCT * > _ss_suspend_vector
int stack_history_pointer
static int ss_shm_name(const char *name, std::string &mem_name, std::string &file_name, std::string &shm_name)
INT ss_mutex_wait_for(MUTEX_T *mutex, INT timeout)
INT ss_file_find(const char *path, const char *pattern, char **plist)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
std::vector< RPC_SERVER_ACCEPTION * > RPC_SERVER_ACCEPTION_LIST
INT recv_tcp_check(int sock)
INT rpc_server_receive_rpc(int idx, RPC_SERVER_ACCEPTION *sa)
INT rpc_client_accept(int lsock)
INT rpc_server_receive_event(int idx, RPC_SERVER_ACCEPTION *sa, int timeout_msec)
INT rpc_server_accept(int lsock)
INT rpc_client_dispatch(int sock)
std::string msprintf(const char *format,...)
#define DIR_SEPARATOR_STR
#define WATCHDOG_INTERVAL
std::vector< std::string > STRING_LIST
#define message(type, str)
#define write(n, a, f, d)
static std::string remove(const std::string s, char c)
int gettimeofday(struct timeval *tp, void *tzp)
NET_COMMAND_HEADER header
struct sockaddr_in bind_addr
static te_expr * list(state *s)