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);
2566 if ((*((SEM_ID *) mutex_handle) = semBCreate(SEM_Q_FIFO, SEM_EMPTY)) == NULL)
2573 std::string semaphore_name;
2576 semaphore_name +=
"MX_";
2577 semaphore_name +=
name;
2580 *semaphore_handle = (
HNDLE) CreateMutex(NULL,
FALSE, semaphore_name.c_str());
2582 if (*semaphore_handle == 0)
2589 std::string semaphore_name;
2592 semaphore_name +=
"MX_";
2593 semaphore_name +=
name;
2600 $DESCRIPTOR(semaphorename_dsc,
"dummy");
2601 semaphorename_dsc.dsc$w_length = semaphore_name.length();
2602 semaphorename_dsc.dsc$a_pointer = semaphore_name.c_str();
2604 *semaphore_handle = (
HNDLE) malloc(8);
2606 status = sys$enqw(0, LCK$K_NLMODE, *semaphore_handle, 0, &semaphorename_dsc, 0, 0, 0, 0, 0, 0);
2608 if (
status != SS$_NORMAL) {
2609 free((
void *) *semaphore_handle);
2610 *semaphore_handle = 0;
2613 if (*semaphore_handle == 0)
2625 struct semid_ds buf;
2635 if (getcwd(cwd,
sizeof(cwd)))
2636 path = std::string(cwd);
2638#elif defined(OS_UNIX)
2640#elif defined(OS_WINNT)
2653 fh = open(
file_name.c_str(), O_CREAT, 0644);
2660#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2665 struct semid_ds *buf;
2673 *semaphore_handle = (
HNDLE) semget(
key, 1, 0);
2675 if (*semaphore_handle < 0) {
2676 *semaphore_handle = (
HNDLE) semget(
key, 1, IPC_CREAT);
2681 if (*semaphore_handle < 0) {
2682 cm_msg(
MERROR,
"ss_semaphore_create",
"Cannot create semaphore \'%s\', semget(0x%x) failed, errno %d (%s)",
name,
key, errno, strerror(errno));
2684 fprintf(stderr,
"ss_semaphore_create: Cannot create semaphore \'%s\', semget(0x%x) failed, errno %d (%s)",
name,
key, errno, strerror(errno));
2689 memset(&buf, 0,
sizeof(buf));
2690 buf.sem_perm.uid = getuid();
2691 buf.sem_perm.gid = getgid();
2692 buf.sem_perm.mode = 0666;
2695 semctl(*semaphore_handle, 0, IPC_SET, arg);
2700 if (semctl(*semaphore_handle, 0, SETVAL, arg) < 0)
2705 fprintf(stderr,
"name %d %d %d %s\n", *semaphore_handle, (
int)time(NULL), getpid(),
name);
2743 status = WaitForSingleObject((HANDLE) semaphore_handle, timeout_millisec == 0 ? INFINITE : timeout_millisec);
2744 if (
status == WAIT_FAILED)
2746 if (
status == WAIT_TIMEOUT)
2752 status = sys$enqw(0, LCK$K_EXMODE, semaphore_handle, LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2753 if (
status != SS$_NORMAL)
2760 status = semTake((SEM_ID) semaphore_handle, timeout_millisec == 0 ? WAIT_FOREVER : timeout_millisec >> 4);
2770#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2775 struct semid_ds *buf;
2782 sb.sem_flg = SEM_UNDO;
2784 memset(&arg, 0,
sizeof(arg));
2793#if defined(OS_DARWIN)
2794 status = semop(semaphore_handle, &sb, 1);
2795#elif defined(OS_LINUX)
2797 if (timeout_millisec >= 1000 || timeout_millisec == 0) {
2802 ts.tv_nsec = (timeout_millisec+10)*1000*1000;
2805 status = semtimedop(semaphore_handle, &sb, 1, &
ts);
2807 status = semop(semaphore_handle, &sb, 1);
2820 if (errno == EINTR || errno == EAGAIN) {
2829 if (timeout_millisec > 0) {
2831 DWORD dt = milli_now - start_time;
2832 if (dt > timeout_millisec) {
2833 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);
2841 fprintf(stderr,
"ss_semaphore_wait_for: semop/semtimedop(%d) returned %d, errno %d (%s)\n", semaphore_handle,
status, errno, strerror(errno));
2883 status = ReleaseMutex((HANDLE) semaphore_handle);
2893 status = sys$enqw(0, LCK$K_NLMODE, semaphore_handle, LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2895 if (
status != SS$_NORMAL)
2904 if (semGive((SEM_ID) semaphore_handle) == ERROR)
2915 sb.sem_flg = SEM_UNDO;
2924 status = semop(semaphore_handle, &sb, 1);
2934 fprintf(stderr,
"ss_semaphore_release: semop/semtimedop(%d) returned %d, errno %d (%s)\n", semaphore_handle,
status, errno, strerror(errno));
2969 if (CloseHandle((HANDLE) semaphore_handle) ==
FALSE)
2977 free((
void *) semaphore_handle);
2984 if (semDelete((SEM_ID) semaphore_handle) == ERROR)
2990#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2995 struct semid_ds *buf;
3000 memset(&arg, 0,
sizeof(arg));
3003 int status = semctl(semaphore_handle, 0, IPC_RMID, arg);
3040 if ((*((SEM_ID *) mutex_handle) = semBCreate(SEM_Q_FIFO, SEM_EMPTY)) == NULL)
3048 *mutex = (
MUTEX_T *)malloc(
sizeof(HANDLE));
3049 **mutex = CreateMutex(NULL,
FALSE, NULL);
3061 pthread_mutexattr_t *attr;
3063 attr = (pthread_mutexattr_t*)malloc(
sizeof(*attr));
3066 status = pthread_mutexattr_init(attr);
3068 fprintf(stderr,
"ss_mutex_create: pthread_mutexattr_init() returned errno %d (%s)\n",
status, strerror(
status));
3072 status = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
3074 fprintf(stderr,
"ss_mutex_create: pthread_mutexattr_settype() returned errno %d (%s)\n",
status, strerror(
status));
3078 *mutex = (pthread_mutex_t*)malloc(
sizeof(pthread_mutex_t));
3081 status = pthread_mutex_init(*mutex, attr);
3083 fprintf(stderr,
"ss_mutex_create: pthread_mutex_init() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3093 status = pthread_mutex_trylock(*mutex);
3096 status = pthread_mutex_trylock(*mutex);
3099 status = pthread_mutex_unlock(*mutex);
3102 status = pthread_mutex_unlock(*mutex);
3141 status = WaitForSingleObject(*mutex, timeout == 0 ? INFINITE : timeout);
3143 if (
status == WAIT_TIMEOUT) {
3147 if (
status == WAIT_FAILED) {
3148 fprintf(stderr,
"ss_mutex_wait_for: WaitForSingleObject() failed, status = %d",
status);
3157 status = semTake((SEM_ID) mutex, timeout == 0 ? WAIT_FOREVER : timeout >> 4);
3165#if defined(OS_DARWIN)
3171 status = pthread_mutex_trylock(mutex);
3174 }
else if (
status == EBUSY) {
3178 fprintf(stderr,
"ss_mutex_wait_for: fatal error: pthread_mutex_trylock() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3181 if (wait > timeout) {
3182 fprintf(stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3187 status = pthread_mutex_lock(mutex);
3191 fprintf(stderr,
"ss_mutex_wait_for: pthread_mutex_lock() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3199 extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, __const
struct timespec *__restrict __abstime) __THROW;
3202 clock_gettime(CLOCK_REALTIME, &st);
3203 st.tv_sec += timeout / 1000;
3204 st.tv_nsec += (timeout % 1000) * 1000000;
3205 status = pthread_mutex_timedlock(mutex, &st);
3207 if (
status == ETIMEDOUT) {
3208 fprintf(stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3217 status = pthread_mutex_lock(mutex);
3221 fprintf(stderr,
"ss_mutex_wait_for: pthread_mutex_lock() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3259 status = ReleaseMutex(*mutex);
3268 if (semGive((SEM_ID) mutes_handle) == ERROR)
3274 status = pthread_mutex_unlock(mutex);
3276 fprintf(stderr,
"ss_mutex_release: pthread_mutex_unlock() returned error %d (%s), aborting...\n",
status, strerror(
status));
3311 if (CloseHandle(*mutex) ==
FALSE)
3321 if (semDelete((SEM_ID) mutex_handle) == ERROR)
3330 status = pthread_mutex_destroy(mutex);
3332 fprintf(stderr,
"ss_mutex_delete: pthread_mutex_destroy() returned errno %d (%s), aborting...\n",
status, strerror(
status));
3361 if (timeout_sec <= 0) {
3367 double endtime = starttime + timeout_sec;
3374 double locktime = starttime;
3377 bool ok = mutex.try_lock_for(std::chrono::milliseconds(1000));
3388 if (now-locktime < 0.2) {
3392 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);
3436 std::lock_guard<std::mutex> lock(
gTzMutex);
3446 std::lock_guard<std::mutex> lock(
gTzMutex);
3476 return (
int) GetTickCount();
3481 return clock() * 55;
3492 lo = *((
DWORD *) time);
3493 hi = *((
DWORD *) (time + 4));
3497 return lo / 10000 + hi * 429496.7296;
3508 DWORD m =
tv.tv_sec * 1000 +
tv.tv_usec / 1000;
3517 static int ticks_per_msec = 0;
3519 if (ticks_per_msec == 0)
3520 ticks_per_msec = 1000 / sysClkRateGet();
3522 return tickGet() * ticks_per_msec;
3543 return (
DWORD) time(NULL);
3550 return tv.tv_sec*1.0 +
tv.tv_usec/1000000.0;
3571#if defined(OS_WINNT)
3576 localtime_r((time_t *) & seconds, <m);
3578 st.wYear = ltm.tm_year + 1900;
3579 st.wMonth = ltm.tm_mon + 1;
3580 st.wDay = ltm.tm_mday;
3581 st.wHour = ltm.tm_hour;
3582 st.wMinute = ltm.tm_min;
3583 st.wSecond = ltm.tm_sec;
3584 st.wMilliseconds = 0;
3588#elif defined(OS_DARWIN) && defined(CLOCK_REALTIME)
3590 struct timespec ltm;
3592 ltm.tv_sec = seconds;
3594 clock_settime(CLOCK_REALTIME, <m);
3596#elif defined(OS_CYGWIN) && defined(CLOCK_REALTIME)
3598 struct timespec ltm;
3600 ltm.tv_sec = seconds;
3602 clock_settime(CLOCK_REALTIME, <m);
3605#elif defined(OS_UNIX) && defined(CLOCK_REALTIME)
3607 struct timespec ltm;
3609 ltm.tv_sec = seconds;
3611 clock_settime(CLOCK_REALTIME, <m);
3613#elif defined(OS_VXWORKS)
3615 struct timespec ltm;
3617 ltm.tv_sec = seconds;
3619 clock_settime(CLOCK_REALTIME, <m);
3622#warning ss_settime() is not supported!
3647 time_t seconds = (time_t)
ss_time();
3649 localtime_r(&seconds, &tms);
3651 asctime_r(&tms,
str);
3678#if defined(OS_DARWIN) || defined(OS_VXWORKS)
3681 return (
INT) timezone;
3690void ss_cont(
int signum)
3709 if (millisec == 0) {
3711 SuspendThread(GetCurrentThread());
3717 signal(SIGCONT, ss_cont);
3729 ts.tv_sec = millisec / 1000;
3730 ts.tv_nsec = (millisec % 1000) * 1E6;
3734 if ((
int)
ts.tv_sec < 0)
3736 }
while (
status == -1 && errno == EINTR);
3784 ioctl(0, FIONREAD, &
n);
3791 ioctl(0, FIONREAD, (
long) &
n);
3799#ifdef LOCAL_ROUTINES
3804static void (*UserCallback) (int);
3805static UINT _timer_id = 0;
3807VOID CALLBACK _timeCallback(UINT idEvent, UINT uReserved,
DWORD dwUser,
DWORD dwReserved1,
DWORD dwReserved2)
3810 if (UserCallback != NULL)
3839 UserCallback = func;
3841 _timer_id = timeSetEvent(millitime, 100, (LPTIMECALLBACK) _timeCallback, 0, TIME_ONESHOT);
3844 timeKillEvent(_timer_id);
3853 signal(SIGALRM, func);
3854 alarm(millitime / 1000);
3860 signal(SIGALRM, func);
3861 alarm(millitime / 1000);
3872LONG MidasExceptionFilter(LPEXCEPTION_POINTERS pexcep)
3877 return EXCEPTION_CONTINUE_SEARCH;
3880INT MidasExceptionSignal(
INT sig)
3904INT MidasExceptionFilter(
INT * sigargs,
INT * mechargs)
3909 return (SS$_RESIGNAL);
3912void MidasExceptionSignal(
INT sig)
3917 kill(getpid(), sig);
3957#elif defined (OS_VMS)
3960 lib$establish(MidasExceptionFilter);
3962 signal(SIGINT, MidasExceptionSignal);
3963 signal(SIGILL, MidasExceptionSignal);
3964 signal(SIGQUIT, MidasExceptionSignal);
3965 signal(SIGFPE, MidasExceptionSignal);
3966 signal(SIGSEGV, MidasExceptionSignal);
3967 signal(SIGTERM, MidasExceptionSignal);
4002 signal(SIGBREAK, SIG_DFL);
4003 return signal(SIGINT, SIG_DFL);
4005 signal(SIGBREAK, func);
4006 return signal(SIGINT, func);
4013 return signal(SIGINT, func);
4020 signal(SIGTERM, SIG_DFL);
4021 return (
void *) signal(SIGINT, SIG_DFL);
4023 signal(SIGTERM, func);
4024 return (
void *) signal(SIGINT, func);
4110 struct sockaddr_in bind_addr;
4122 if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
4128 sock =
socket(AF_INET, SOCK_DGRAM, 0);
4133 memset(&bind_addr, 0,
sizeof(bind_addr));
4134 bind_addr.sin_family = AF_INET;
4135 bind_addr.sin_addr.s_addr = 0;
4136 bind_addr.sin_port = 0;
4142 path +=
".UDP_BIND_HOSTNAME";
4146 FILE *
fp = fopen(path.c_str(),
"r");
4148 cm_msg(
MERROR,
"ss_suspend_init_ipc",
"Support for UDP_BIND_HOSTNAME was removed. Please delete file \"%s\"", path.c_str());
4175 bind_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4179 status = bind(sock, (
struct sockaddr *) &bind_addr,
sizeof(bind_addr));
4184 size =
sizeof(bind_addr);
4186 getsockname(sock, (
struct sockaddr *) &bind_addr, (
int *) &size);
4188 getsockname(sock, (
struct sockaddr *) &bind_addr, &size);
4194 int flags = fcntl(sock, F_GETFL, 0);
4195 status = fcntl(sock, F_SETFL, flags | O_NONBLOCK);
4198 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));
4206 sock =
socket(AF_INET, SOCK_DGRAM, 0);
4212 memset(&bind_addr, 0,
sizeof(bind_addr));
4213 bind_addr.sin_family = AF_INET;
4214 bind_addr.sin_addr.s_addr = 0;
4227 bind_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
4229 status = bind(sock, (
struct sockaddr *) &bind_addr,
sizeof(bind_addr));
4235 memcpy(&(psuspend->
bind_addr), &bind_addr,
sizeof(bind_addr));
4470 struct sockaddr from_addr;
4471 socklen_t from_addr_size =
sizeof(
struct sockaddr);
4493 ssize_t size = recvfrom(ipc_recv_socket, buffer,
sizeof(buffer), 0, &from_addr, &from_addr_size);
4508 if (msg ==
MSG_BM && buffer[0] ==
'B')
4510 if (msg ==
MSG_ODB && buffer[0] ==
'O')
4514 int mserver_client_socket = 0;
4518 mserver_client_socket = (*_ss_server_acceptions)[
i]->send_sock;
4523 time_t tstart = time(NULL);
4524 int return_status = 0;
4528 char buffer_tmp[80];
4530 from_addr_size =
sizeof(
struct sockaddr);
4534 ssize_t size_tmp = recvfrom(ipc_recv_socket, buffer_tmp,
sizeof(buffer_tmp), 0, &from_addr, &from_addr_size);
4536 if (size_tmp <= 0) {
4542 if (msg ==
MSG_BM && buffer_tmp[0] ==
'B') {
4546 if (msg ==
MSG_ODB && buffer_tmp[0] ==
'O') {
4552 if (buffer_tmp[0] !=
'B' || strcmp(buffer_tmp, buffer) != 0) {
4557 time_t tnow = time(NULL);
4559 if (tnow - tstart > 1 + millisec/1000) {
4569 return return_status;
4578 char test_buffer[256];
4580 int n_received = recv(sock, test_buffer,
sizeof(test_buffer), MSG_PEEK);
4582 int n_received = recv(sock, test_buffer,
sizeof(test_buffer), MSG_PEEK | MSG_DONTWAIT);
4585 if ((n_received == -1) && (errno == EAGAIN))
4589 if (n_received == -1) {
4590 cm_msg(
MERROR,
"ss_socket_check",
"recv(%d,MSG_PEEK) returned %d, errno: %d (%s)", (
int)
sizeof(test_buffer), n_received, errno, strerror(errno));
4593 if (n_received <= 0)
4604 int sock = (*_ss_server_acceptions)[
i]->event_sock;
4726 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4737 FD_SET(sock, &readfds);
4743 if (msg == 0 && msg !=
MSG_BM) {
4745 sock = (*_ss_server_acceptions)[
i]->event_sock;
4758 FD_SET(sock, &readfds);
4780 struct timeval timeout;
4782 timeout.tv_sec = millisec / 1000;
4783 timeout.tv_usec = (millisec % 1000) * 1000;
4821 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4837 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4847 sock = (*_ss_server_acceptions)[
i]->event_sock;
4852 if (FD_ISSET(sock, &readfds)) {
4860 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4875 if (FD_ISSET(sock, &readfds)) {
4917 }
while (millisec < 0);
4919 return return_status;
4949 struct sockaddr_in bind_addr;
4952 bind_addr.sin_port = htons((
short) port);
4954 size_t message_size = strlen(
message) + 1;
4962 if (((
size_t)wr) != message_size) {
4997 struct timeval timeout;
4998 struct timeval timeout0;
4999 DWORD start_time = 0;
5003 FD_SET(sock, &readfds);
5005 timeout.tv_sec = millisec / 1000;
5006 timeout.tv_usec = (millisec % 1000) * 1000;
5011 status = select(sock+1, &readfds, NULL, NULL, &timeout);
5015 if (
status<0 && errno==EINTR) {
5017 if (timeout.tv_sec == timeout0.tv_sec) {
5019 if (start_time == 0) {
5021 end_time = start_time + (millisec+999)/1000;
5031 cm_msg(
MERROR,
"ss_socket_wait",
"unexpected error, select() returned %d, errno: %d (%s)",
status, errno, strerror(errno));
5036 if (!FD_ISSET(sock, &readfds))
5048 assert(sockp != NULL);
5049 assert(error_msg_p != NULL);
5057 if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
5063 sprintf(portname,
"%d", tcp_port);
5065 struct addrinfo *ainfo = NULL;
5067 int status = getaddrinfo(hostname, portname, NULL, &ainfo);
5070 *error_msg_p =
msprintf(
"cannot resolve hostname \"%s\", getaddrinfo() error %d (%s)", hostname,
status, gai_strerror(
status));
5072 freeaddrinfo(ainfo);
5080 for (
const struct addrinfo *r = ainfo; r != NULL; r = r->ai_next) {
5082 fprintf(stderr,
"ss_socket_connect_tcp: hostname [%s] port %d addrinfo: flags %d, family %d, socktype %d, protocol %d, canonname [%s]\n",
5093 if (r->ai_socktype != SOCK_STREAM) {
5098 if (r->ai_protocol != 6) {
5102 sock =
::socket(r->ai_family, r->ai_socktype, 0);
5105 *error_msg_p =
msprintf(
"cannot create socket, errno %d (%s)", errno, strerror(errno));
5109 status = ::connect(sock, r->ai_addr, r->ai_addrlen);
5112 fprintf(stderr,
"ss_socket_connect_tcp: connect() status %d, errno %d (%s)\n",
status, errno, strerror(errno));
5114 *error_msg_p =
msprintf(
"cannot connect to host \"%s\" port %d, errno %d (%s)", hostname, tcp_port, errno, strerror(errno));
5123 freeaddrinfo(ainfo);
5134 fprintf(stderr,
"ss_socket_connect_tcp: hostname [%s] port %d new socket %d\n", hostname, tcp_port, *sockp);
5143 assert(sockp != NULL);
5144 assert(tcp_port_p != NULL);
5145 assert(error_msg_p != NULL);
5155 if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
5161 bool use_inet6 =
true;
5163 bool use_inet6 =
false;
5166 if (listen_localhost)
5173 lsock =
socket(AF_INET6, SOCK_STREAM, 0);
5175 if (errno == EAFNOSUPPORT) {
5177 lsock =
socket(AF_INET, SOCK_STREAM, 0);
5182 lsock =
socket(AF_INET, SOCK_STREAM, 0);
5186 *error_msg_p =
msprintf(
"socket(AF_INET, SOCK_STREAM) failed, errno %d (%s)", errno, strerror(errno));
5192 int status = setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (
char *) &flag,
sizeof(
int));
5194 *error_msg_p =
msprintf(
"setsockopt(SO_REUSEADDR) failed, errno %d (%s)", errno, strerror(errno));
5203 status = setsockopt(lsock, IPPROTO_IPV6, IPV6_V6ONLY, (
char *) &flag,
sizeof(
int));
5205 *error_msg_p =
msprintf(
"setsockopt(IPPROTO_IPV6, IPV6_V6ONLY) failed, errno %d (%s)", errno, strerror(errno));
5210#warning strange: AF_INET6 is defined, but IPV6_V6ONLY is not defined
5217 struct sockaddr_in6 bind_addr6;
5218 memset(&bind_addr6, 0,
sizeof(bind_addr6));
5219 bind_addr6.sin6_family = AF_INET6;
5221 if (listen_localhost) {
5222 bind_addr6.sin6_addr = in6addr_loopback;
5224 bind_addr6.sin6_addr = in6addr_any;
5228 bind_addr6.sin6_port = htons((
short) tcp_port);
5230 bind_addr6.sin6_port = htons(0);
5232 status = bind(lsock, (
struct sockaddr *) &bind_addr6,
sizeof(bind_addr6));
5234 *error_msg_p =
msprintf(
"IPv6 bind() to port %d failed, errno %d (%s)", tcp_port, errno, strerror(errno));
5240 struct sockaddr_in bind_addr;
5241 memset(&bind_addr, 0,
sizeof(bind_addr));
5242 bind_addr.sin_family = AF_INET;
5244 if (listen_localhost) {
5245 bind_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
5247 bind_addr.sin_addr.s_addr = htonl(INADDR_ANY);
5251 bind_addr.sin_port = htons((
short) tcp_port);
5253 bind_addr.sin_port = htons(0);
5255 status = bind(lsock, (
struct sockaddr *) &bind_addr,
sizeof(bind_addr));
5257 *error_msg_p =
msprintf(
"bind() to port %d failed, errno %d (%s)", tcp_port, errno, strerror(errno));
5264 status = listen(lsock, 1);
5269 *error_msg_p =
msprintf(
"listen() failed, errno %d (%s)", errno, strerror(errno));
5275 struct sockaddr_in6
addr;
5276 socklen_t sosize =
sizeof(
addr);
5277 status = getsockname(lsock, (
struct sockaddr*)&
addr, &sosize);
5279 *error_msg_p =
msprintf(
"IPv6 getsockname() failed, errno %d (%s)", errno, strerror(errno));
5283 *tcp_port_p = ntohs(
addr.sin6_port);
5286 struct sockaddr_in
addr;
5287 socklen_t sosize =
sizeof(
addr);
5288 status = getsockname(lsock, (
struct sockaddr*)&
addr, &sosize);
5290 *error_msg_p =
msprintf(
"getsockname() failed, errno %d (%s)", errno, strerror(errno));
5294 *tcp_port_p = ntohs(
addr.sin_port);
5300 if (listen_localhost)
5301 fprintf(stderr,
"ss_socket_listen_tcp: listening tcp port %d local connections only, new socket %d\n", *tcp_port_p, *sockp);
5303 fprintf(stderr,
"ss_socket_listen_tcp: listening tcp port %d all internet connections, socket %d\n", *tcp_port_p, *sockp);
5312 assert(sockp != NULL);
5314 fprintf(stderr,
"ss_socket_close: %d\n", *sockp);
5316 int err = close(*sockp);
5318 cm_msg(
MERROR,
"ss_socket_close",
"unexpected error, close() returned %d, errno: %d (%s)", err, errno, strerror(errno));
5329 unsigned size =
sizeof(
addr);
5330 int rv = getpeername(sock, (
struct sockaddr *) &
addr, &size);
5335 cm_msg(
MERROR,
"ss_socket_get_peer_name",
"Error: getpeername() returned %d, errno %d (%s)", rv, errno, strerror(errno));
5342 int ret = getnameinfo((
struct sockaddr*)&
addr, size,
5343 hostname,
sizeof(hostname),
5344 servname,
sizeof(servname),
5348 cm_msg(
MERROR,
"ss_socket_get_peer_name",
"Error: getnameinfo() error %d (%s)", ret, gai_strerror(ret));
5358 *portp = atoi(servname);
5389 int net_tcp_size = 1024 * 1024;
5394 status = send(sock, buffer +
count, net_tcp_size, flags & 0xFFFF);
5402 if ((flags & 0x10000) == 0)
5404 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5405 sock, net_tcp_size,
status, errno, strerror(errno));
5410 while (
count < buffer_size) {
5419 if ((flags & 0x10000) == 0)
5421 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5422 sock, (
int) (buffer_size -
count),
status, errno, strerror(errno));
5455 while (
count < buffer_size) {
5459 cm_msg(
MERROR,
"ss_write_tcp",
"write(socket=%d,size=%d) returned zero, errno: %d (%s)", sock, (
int) (buffer_size -
count), errno, strerror(errno));
5461 }
else if (wr < 0) {
5466 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));
5508 memset(buffer, 0, buffer_size);
5517 i = recv(sock, buffer +
n, 1, 0);
5524 if (
n >= buffer_size)
5527 }
while (buffer[
n - 1] && buffer[
n - 1] != 10);
5564 INT param_size, n_received,
n;
5568 cm_msg(
MERROR,
"recv_tcp",
"parameters too large for network buffer");
5580 }
while (
n == -1 && errno == EINTR);
5586 cm_msg(
MERROR,
"recv_tcp",
"header: recv(%d) returned %d, n_received = %d, unexpected connection closure", (
int)
sizeof(
NET_COMMAND_HEADER),
n, n_received);
5591 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));
5605 if (param_size == 0)
5608 if (param_size > (
INT)buffer_size) {
5609 cm_msg(
MERROR,
"recv_tcp",
"param: receive buffer size %d is too small for received data size %d", buffer_size, param_size);
5616 n = recv(sock, net_buffer +
sizeof(
NET_COMMAND_HEADER) + n_received, param_size - n_received, flags);
5619 }
while (
n == -1 && errno == EINTR);
5621 n = recv(sock, net_buffer +
sizeof(
NET_COMMAND_HEADER) + n_received, param_size - n_received, flags);
5625 cm_msg(
MERROR,
"recv_tcp",
"param: recv() returned %d, n_received = %d, unexpected connection closure",
n, n_received);
5630 cm_msg(
MERROR,
"recv_tcp",
"param: recv() returned %d, n_received = %d, errno: %d (%s)",
n, n_received, errno, strerror(errno));
5635 }
while (n_received < param_size);
5674 while (n_received != buffer_size) {
5676 if (timeout_ms > 0) {
5684 n = recv(sock, net_buffer + n_received, buffer_size - n_received, flags);
5690 if (
n == -1 && errno == EINTR)
5696 cm_msg(
MERROR,
"recv_tcp2",
"unexpected connection closure");
5702 cm_msg(
MERROR,
"recv_tcp2",
"unexpected connection error, recv() errno %d (%s)", errno, strerror(errno));
5742 n =
recv_tcp2(sock, (
char*)&ncbuf,
sizeof(ncbuf), timeout_ms);
5745 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command header");
5749 if (
n !=
sizeof(ncbuf)) {
5750 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command header, see messages");
5758 if (*param_size == 0) {
5763 *param_ptr = (
char *)malloc(*param_size);
5765 if (*param_ptr == NULL) {
5766 cm_msg(
MERROR,
"ss_recv_net_command",
"error allocating %d bytes for network command data", *param_size);
5771 n =
recv_tcp2(sock, *param_ptr, *param_size, timeout_ms);
5774 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command data");
5780 if (
n != *param_size) {
5781 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command data, see messages");
5810 memset(buf, 0,
sizeof(buf));
5812 int status = gethostname(buf,
sizeof(buf)-1);
5817 cm_msg(
MERROR,
"ss_gethostname",
"gethostname() errno %d (%s)", errno, strerror(errno));
5845 if (h.length() == 0) {
5848 mstrlcpy(buffer, h.c_str(), buffer_size);
5857 char *s = getcwd(NULL, 0);
5859 std::string cwd = s;
5864 return "/GETCWD-FAILED-ON-US";
5880int sopen(
const char *path,
int access,
int shflag,
int mode)
5882 return open(path, (access) | (shflag), mode);
5922 *
channel = open(path, oflag, 0644);
5927 cm_msg(
MERROR,
"ss_tape_open",
"open() returned %d, errno %d (%s)", *
channel, errno, strerror(errno));
5940 arg.mt_op = MTSETBLK;
5943 ioctl(*
channel, MTIOCTOP, &arg);
5951 TAPE_GET_MEDIA_PARAMETERS m;
5953 *
channel = (
INT) CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);
5955 if (*
channel == (
INT) INVALID_HANDLE_VALUE) {
5957 if (
status == ERROR_SHARING_VIOLATION) {
5958 cm_msg(
MERROR,
"ss_tape_open",
"tape is used by other process");
5961 if (
status == ERROR_FILE_NOT_FOUND) {
5962 cm_msg(
MERROR,
"ss_tape_open",
"tape device \"%s\" doesn't exist", path);
5971 if (
status == ERROR_NO_MEDIA_IN_DRIVE ||
status == ERROR_BUS_RESET) {
5977 memset(&m, 0,
sizeof(m));
5979 SetTapeParameters((HANDLE) (*
channel), SET_TAPE_MEDIA_INFORMATION, &m);
6013 cm_msg(
MERROR,
"ss_tape_close",
"close() returned %d, errno %d (%s)",
status, errno, strerror(errno));
6020 if (!CloseHandle((HANDLE)
channel)) {
6053 sprintf(
str,
"mt -f %s status", path);
6063 TAPE_GET_MEDIA_PARAMETERS m;
6064 TAPE_GET_DRIVE_PARAMETERS
d;
6067 channel = (
INT) CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);
6071 if (
status == ERROR_SHARING_VIOLATION) {
6072 cm_msg(
MINFO,
"ss_tape_status",
"tape is used by other process");
6075 if (
status == ERROR_FILE_NOT_FOUND) {
6076 cm_msg(
MINFO,
"ss_tape_status",
"tape device \"%s\" doesn't exist", path);
6085 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6086 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6089 if (
status == ERROR_NO_MEDIA_IN_DRIVE ||
status == ERROR_BUS_RESET) {
6090 cm_msg(
MINFO,
"ss_tape_status",
"no media in drive");
6091 CloseHandle((HANDLE)
channel);
6095 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6096 GetTapeParameters((HANDLE)
channel, GET_TAPE_MEDIA_INFORMATION, &size, &m);
6098 printf(
"Hardware error correction is %s\n",
d.ECC ?
"on" :
"off");
6099 printf(
"Hardware compression is %s\n",
d.Compression ?
"on" :
"off");
6100 printf(
"Tape %s write protected\n", m.WriteProtected ?
"is" :
"is not");
6102 if (
d.FeaturesLow & TAPE_DRIVE_TAPE_REMAINING) {
6103 x = ((double) m.Remaining.LowPart + (
double) m.Remaining.HighPart * 4.294967295E9)
6105 printf(
"Tape capacity remaining is %d MB\n", (
int) x);
6107 printf(
"Tape capacity is not reported by tape\n");
6109 CloseHandle((HANDLE)
channel);
6148 }
while (
status == -1 && errno == EINTR);
6151 cm_msg(
MERROR,
"ss_tape_write",
"write() returned %d, errno %d (%s)",
status, errno, strerror(errno));
6164 WriteFile((HANDLE)
channel, pdata,
count, &written, NULL);
6203 }
while (
n == -1 && errno == EINTR);
6206 if (errno == ENOSPC || errno == EIO)
6209 if (
n == 0 && errno == 0)
6212 cm_msg(
MERROR,
"ss_tape_read",
"unexpected tape error: n=%d, errno=%d\n",
n, errno);
6222#elif defined(OS_WINNT)
6229 if (
status == ERROR_NO_DATA_DETECTED)
6231 else if (
status == ERROR_FILEMARK_DETECTED)
6233 else if (
status == ERROR_MORE_DATA)
6284 cm_msg(
MERROR,
"ss_tape_write_eof",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6291 TAPE_GET_DRIVE_PARAMETERS
d;
6295 size =
sizeof(TAPE_GET_DRIVE_PARAMETERS);
6296 GetTapeParameters((HANDLE)
channel, GET_TAPE_DRIVE_INFORMATION, &size, &
d);
6298 if (
d.FeaturesHigh & TAPE_DRIVE_WRITE_FILEMARKS)
6300 else if (
d.FeaturesHigh & TAPE_DRIVE_WRITE_LONG_FMKS)
6302 else if (
d.FeaturesHigh & TAPE_DRIVE_WRITE_SHORT_FMKS)
6305 cm_msg(
MERROR,
"ss_tape_write_eof",
"tape doesn't support writing of filemarks");
6307 if (
status != NO_ERROR) {
6345 arg.mt_count = abs(
count);
6354 cm_msg(
MERROR,
"ss_tape_fskip",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6364 if (
status == ERROR_END_OF_MEDIA)
6367 if (
status != NO_ERROR) {
6405 arg.mt_count = abs(
count);
6414 cm_msg(
MERROR,
"ss_tape_rskip",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6423 if (
status != NO_ERROR) {
6466 cm_msg(
MERROR,
"ss_tape_rewind",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6475 if (
status != NO_ERROR) {
6522 cm_msg(
MERROR,
"ss_tape_rewind",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6531 if (
status != NO_ERROR) {
6578 cm_msg(
MERROR,
"ss_tape_mount",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6587 if (
status != NO_ERROR) {
6623 arg.mt_op = MTUNLOAD;
6634 cm_msg(
MERROR,
"ss_tape_unmount",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6643 if (
status != NO_ERROR) {
6663#if defined(OS_DARWIN)
6667#elif defined(OS_UNIX)
6679 cm_msg(
MERROR,
"ss_tape_get_blockn",
"ioctl() failed, errno %d (%s)", errno, strerror(errno));
6683 return (arg.mt_blkno);
6685#elif defined(OS_WINNT)
6688 TAPE_GET_MEDIA_PARAMETERS media;
6691 status = GetTapeParameters((HANDLE)
channel, GET_TAPE_MEDIA_INFORMATION, &size, &media);
6692 return (media.PartitionCount);
6725 statfs(path, &st,
sizeof(st));
6726 return (
double) st.f_bavail * st.f_bsize;
6727#elif defined(OS_LINUX)
6730 status = statfs(path, &st);
6733 return (
double) st.f_bavail * st.f_bsize;
6734#elif defined(OS_SOLARIS)
6737 return (
double) st.f_bavail * st.f_bsize;
6738#elif defined(OS_IRIX)
6740 statfs(path, &st,
sizeof(
struct statfs), 0);
6741 return (
double) st.f_bfree * st.f_bsize;
6745 return (
double) st.fd_otsize * st.fd_bfree;
6748#elif defined(OS_WINNT)
6749 DWORD SectorsPerCluster;
6750 DWORD BytesPerSector;
6751 DWORD NumberOfFreeClusters;
6752 DWORD TotalNumberOfClusters;
6756 if (strchr(
str,
':') != NULL) {
6757 *(strchr(
str,
':') + 1) = 0;
6759 GetDiskFreeSpace(
str, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
6761 GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
6763 return (
double) NumberOfFreeClusters *SectorsPerCluster * BytesPerSector;
6771#if defined(OS_ULTRIX) || defined(OS_WINNT)
6772int fnmatch(
const char *pat,
const char *
str,
const int flag)
6774 while (*
str !=
'\0') {
6777 if ((
str = strchr(
str, *pat)) == NULL)
6795LPWIN32_FIND_DATA lpfdata;
6806 size_t size =
list.size();
6808 for (
size_t i=0;
i<size;
i++) {
6837 if (access(path, F_OK) != 0) {
6846 if ((dir_pointer = opendir(path)) == NULL)
6848 for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
6849 if (fnmatch(pattern, dp->d_name, 0) == 0 && (dp->d_type == DT_REG || dp->d_type == DT_LNK || dp->d_type == DT_UNKNOWN)) {
6850 plist->push_back(dp->d_name);
6851 seekdir(dir_pointer, telldir(dir_pointer));
6854 closedir(dir_pointer);
6862 strcat(
str, pattern);
6864 lpfdata = (WIN32_FIND_DATA *) malloc(
sizeof(WIN32_FIND_DATA));
6866 pffile = FindFirstFile(
str, lpfdata);
6867 if (pffile == INVALID_HANDLE_VALUE)
6870 plist->push_back(lpfdata->cFileName);
6872 while (FindNextFile(pffile, lpfdata)) {
6873 plist->push_back(lpfdata->cFileName);
6878 return plist->size();
6889 size_t size =
list.size();
6891 for (
size_t i=0;
i<size;
i++) {
6923 if ((dir_pointer = opendir(path)) == NULL)
6926 for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
6927 if (fnmatch(pattern, dp->d_name, 0) == 0 && dp->d_type == DT_DIR) {
6928 plist->push_back(dp->d_name);
6929 seekdir(dir_pointer, telldir(dir_pointer));
6932 closedir(dir_pointer);
6940 strcat(
str, pattern);
6943 lpfdata = (WIN32_FIND_DATA *) malloc(
sizeof(WIN32_FIND_DATA));
6944 pffile = FindFirstFile(
str, lpfdata);
6945 if (pffile == INVALID_HANDLE_VALUE)
6948 plist->push_back(lpfdata->cFileName);
6949 while (FindNextFile(pffile, lpfdata)) {
6950 plist->push_back(lpfdata->cFileName);
6954 return plist->size();
6965 size_t size =
list.size();
6967 for (
size_t i=0;
i<size;
i++) {
6999 if ((dir_pointer = opendir(path)) == NULL)
7002 for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
7003 if (fnmatch(pattern, dp->d_name, 0) == 0) {
7005 std::string full_path = std::string(path) +
"/" + dp->d_name +
"/";
7007 if (lstat(full_path.c_str(), &st) == 0 && (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))) {
7008 plist->push_back(dp->d_name);
7012 closedir(dir_pointer);
7020 strcat(
str, pattern);
7023 lpfdata = (WIN32_FIND_DATA *) malloc(
sizeof(WIN32_FIND_DATA));
7024 pffile = FindFirstFile(
str, lpfdata);
7025 if (pffile == INVALID_HANDLE_VALUE)
7028 plist->push_back(lpfdata->cFileName);
7029 while (FindNextFile(pffile, lpfdata)) {
7030 plist->push_back(lpfdata->cFileName);
7034 return plist->size();
7074#ifdef _LARGEFILE64_SOURCE
7075 struct stat64 stat_buf;
7079 status = stat64(path, &stat_buf);
7082 return (
double) stat_buf.st_size;
7084 struct stat stat_buf;
7088 status = stat(path, &stat_buf);
7091 return (
double) stat_buf.st_size;
7112#ifdef _LARGEFILE64_SOURCE
7113 struct stat64 stat_buf;
7117 status = stat64(path, &stat_buf);
7120 return stat_buf.st_mtime;
7122 struct stat stat_buf;
7126 status = stat(path, &stat_buf);
7129 return stat_buf.st_mtime;
7153 statfs(path, &st,
sizeof(st));
7154 return (
double) st.f_blocks * st.f_fsize;
7155#elif defined(OS_LINUX)
7158 status = statfs(path, &st);
7161 return (
double) st.f_blocks * st.f_bsize;
7162#elif defined(OS_SOLARIS)
7165 if (st.f_frsize > 0)
7166 return (
double) st.f_blocks * st.f_frsize;
7168 return (
double) st.f_blocks * st.f_bsize;
7169#elif defined(OS_ULTRIX)
7172 return (
double) st.fd_btot * 1024;
7173#elif defined(OS_IRIX)
7175 statfs(path, &st,
sizeof(
struct statfs), 0);
7176 return (
double) st.f_blocks * st.f_bsize;
7178#error ss_disk_size not defined for this OS
7183 DWORD SectorsPerCluster;
7184 DWORD BytesPerSector;
7185 DWORD NumberOfFreeClusters;
7186 DWORD TotalNumberOfClusters;
7190 if (strchr(
str,
':') != NULL) {
7191 *(strchr(
str,
':') + 1) = 0;
7193 GetDiskFreeSpace(
str, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
7195 GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector, &NumberOfFreeClusters, &TotalNumberOfClusters);
7197 return (
double) TotalNumberOfClusters *SectorsPerCluster * BytesPerSector;
7224 int retval = stat(path, &buf);
7228 if (S_ISDIR(buf.st_mode))
7232 int fd = open(path, O_RDONLY, 0);
7260 int retval = lstat(path, &buf);
7263 if (S_ISLNK(buf.st_mode))
7292 int retval = stat(path, &buf);
7296 if (!S_ISDIR(buf.st_mode))
7299#warning ss_dir_exist() is not implemented!
7327 fd_from = open(src, O_RDONLY);
7332 fd_to = open(dst, O_WRONLY | O_CREAT | O_EXCL | O_APPEND, 0666);
7334 fd_to = open(dst, O_WRONLY | O_CREAT | O_EXCL, 0666);
7338 while (nread =
read(fd_from, buf,
sizeof(buf)), nread > 0) {
7339 char *out_ptr = buf;
7343 nwritten =
write(fd_to, out_ptr, nread);
7345 if (nwritten >= 0) {
7347 out_ptr += nwritten;
7348 }
else if (errno != EINTR) {
7351 }
while (nread > 0);
7355 if (close(fd_to) < 0) {
7366 saved_errno = errno;
7372 errno = saved_errno;
7405 COORD coordScreen = { 0, 0 };
7407 DWORD cCharsWritten;
7408 CONSOLE_SCREEN_BUFFER_INFO csbi;
7411 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
7414 bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
7415 dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
7418 bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR)
' ', dwConSize, coordScreen, &cCharsWritten);
7421 bSuccess = SetConsoleCursorPosition(hConsole, coordScreen);
7425#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7457 coordSize.X = (short) x;
7458 coordSize.Y = (short) y;
7459 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
7460 SetConsoleScreenBufferSize(hConsole, coordSize);
7492 va_start(argptr, format);
7493 vsprintf(
str, (
char *) format, argptr);
7500 DWORD cCharsWritten;
7502 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
7504 dwWriteCoord.X = (short) x;
7505 dwWriteCoord.Y = (short) y;
7507 WriteConsoleOutputCharacter(hConsole,
str, strlen(
str), dwWriteCoord, &cCharsWritten);
7512#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7513 printf(
"\033[%1d;%1dH", y + 1, x + 1);
7519 gotoxy(x + 1, y + 1);
7543 static char password[32];
7545 fprintf(stdout,
"%s", prompt);
7547 memset(password, 0,
sizeof(password));
7550 return (
char *) getpass(
"");
7551#elif defined(OS_WINNT)
7556 hConsole = GetStdHandle(STD_INPUT_HANDLE);
7557 SetConsoleMode(hConsole, ENABLE_LINE_INPUT);
7558 ReadConsole(hConsole, password,
sizeof(password), &nCharsRead, NULL);
7559 SetConsoleMode(hConsole, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
7562 if (password[strlen(password) - 1] ==
'\r')
7563 password[strlen(password) - 1] = 0;
7567#elif defined(OS_MSDOS)
7572 while ((
c = getchar()) != EOF &&
c !=
'\n')
7612 static struct termios save_termios;
7624 tcsetattr(fd, TCSAFLUSH, &save_termios);
7630 tcgetattr(fd, &save_termios);
7631 memcpy(&buf, &save_termios,
sizeof(buf));
7633 buf.c_lflag &= ~(ECHO | ICANON | IEXTEN);
7635 buf.c_iflag &= ~(ICRNL | INPCK | ISTRIP | IXON);
7637 buf.c_cflag &= ~(CSIZE | PARENB);
7641 buf.c_cc[VTIME] = 0;
7643 tcsetattr(fd, TCSAFLUSH, &buf);
7695#elif defined(OS_WINNT)
7698 static INT repeat_count = 0;
7699 static INT repeat_char;
7706 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
7709 if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT) {
7745 hConsole = GetStdHandle(STD_INPUT_HANDLE);
7748 SetConsoleMode(hConsole, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
7754 SetConsoleMode(hConsole, ENABLE_PROCESSED_INPUT);
7763 PeekConsoleInput(hConsole, &ir, 1, &nCharsRead);
7765 if (nCharsRead == 0)
7768 ReadConsoleInput(hConsole, &ir, 1, &nCharsRead);
7770 if (ir.EventType != KEY_EVENT)
7773 if (!ir.Event.KeyEvent.bKeyDown)
7776 if (ir.Event.KeyEvent.wRepeatCount > 1) {
7777 repeat_count = ir.Event.KeyEvent.wRepeatCount - 1;
7778 repeat_char = ir.Event.KeyEvent.uChar.AsciiChar;
7782 if (ir.Event.KeyEvent.uChar.AsciiChar)
7783 return ir.Event.KeyEvent.uChar.AsciiChar;
7785 if (ir.Event.KeyEvent.dwControlKeyState & (ENHANCED_KEY)) {
7786 switch (ir.Event.KeyEvent.wVirtualKeyCode) {
7809 return ir.Event.KeyEvent.wVirtualKeyCode;
7814#elif defined(OS_MSDOS)
7878 p = fgets(
string, size, stdin);
7879 }
while (p == NULL);
7882 if (strlen(p) > 0 && p[strlen(p) - 1] ==
'\n')
7883 p[strlen(p) - 1] = 0;
7904 DWORD buffer[] = { 6, 0, 0, 0 };
7907 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
7911 if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
7912 hdio = CreateFile(
"\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7913 if (hdio == INVALID_HANDLE_VALUE) {
7914 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7921 if (!DeviceIoControl(hdio, (
DWORD) 0x9c406000, &buffer,
sizeof(buffer), NULL, 0, &size, NULL))
7940 DWORD buffer[] = { 7, 0, 0, 0 };
7943 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
7947 if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
7948 hdio = CreateFile(
"\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7949 if (hdio == INVALID_HANDLE_VALUE) {
7950 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7957 if (!DeviceIoControl(hdio, (
DWORD) 0x9c406000, &buffer,
sizeof(buffer), NULL, 0, &size, NULL))
7974#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
7998 static char enc_pw[13];
8000 memset(enc_pw, 0,
sizeof(enc_pw));
8001 enc_pw[0] = salt[0];
8002 enc_pw[1] = salt[1];
8004 for (
i = 0;
i < 8 && buf[
i];
i++)
8005 enc_pw[
i + 2] = buf[
i];
8010 for (
i = 2;
i < 13;
i++) {
8011 seed = 5 * seed + 27 + enc_pw[
i];
8037#define isnan(x) _isnan(x)
8040#define finite(x) _finite(x)
8042#elif defined(OS_LINUX)
8072#include <execinfo.h>
8075#define N_STACK_HISTORY 500
8082#define MAX_STACK_DEPTH 16
8084 void *trace[MAX_STACK_DEPTH];
8087 size = backtrace(trace, MAX_STACK_DEPTH);
8088 *
string = backtrace_symbols(trace, size);
8101 for (
i = 0;
i <
n;
i++)
8102 printf(
"%s\n",
string[
i]);
8119 for (
i = 2;
i <
n;
i++) {
8134 f = fopen(filename,
"wt");
8143 printf(
"Stack dump written to %s\n", filename);
8145 printf(
"Cannot open %s: errno=%d\n", filename, errno);
8159 const unsigned char * bytes = (
const unsigned char *)
string;
8166 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8174 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8175 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8184 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8185 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8188 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8190 bytes[0] == 0xEF) &&
8191 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8192 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8196 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8197 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8206 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8207 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8208 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8211 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8212 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8213 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8214 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8218 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8219 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8220 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8240 bool modified =
false;
8246 unsigned char * bytes = (
unsigned char *)
string;
8253 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8261 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8262 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8271 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8272 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8275 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8277 bytes[0] == 0xEF) &&
8278 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8279 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8283 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8284 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8293 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8294 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8295 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8298 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8299 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8300 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8301 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8305 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8306 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8307 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8340std::chrono::time_point<std::chrono::high_resolution_clock>
ss_us_start()
8342 return std::chrono::high_resolution_clock::now();
8345unsigned int ss_us_since(std::chrono::time_point<std::chrono::high_resolution_clock> start) {
8346 auto elapsed = std::chrono::high_resolution_clock::now() - start;
8347 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(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)