64#include <sys/posix_shm.h>
84 char cwd[256], buf[256];
90 path = std::string(
cwd);
118 if (!
fgets(buf,
sizeof(buf),
fp))
129 if (
strcmp(buf,
"SYSV_SHM") == 0) {
134 if (
strcmp(buf,
"MMAP_SHM") == 0) {
139 if (
strcmp(buf,
"POSIX_SHM") == 0) {
145 if (
strcmp(buf,
"POSIXv2_SHM") == 0) {
151 if (
strcmp(buf,
"POSIXv3_SHM") == 0) {
157 if (
strcmp(buf,
"POSIXv4_SHM") == 0) {
163 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);
171 char buf[256],
cwd[256];
183 path = std::string(
cwd);
185#elif defined(OS_UNIX)
187#elif defined(OS_WINNT)
211 if (!
fgets(buf,
sizeof(buf),
fp))
223 if (
strcmp(buf, hostname) == 0)
226 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);
233#if defined(OS_DARWIN)
235#elif defined(OS_UNIX)
248 assert(path.length() > 0);
288 fprintf(
stderr,
"check_shm_host: unsupported shared memory type, bye!\n");
361 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());
369 char str[256], path[256], *p;
399 if (file_size != 0xFFFFFFFF && file_size > 0)
402 if (file_size != 0xFFFFFFFF && file_size > 0 && file_size != size) {
403 cm_msg(
MERROR,
"ss_shm_open",
"Requested size (%d) differs from existing size (%d)", size, file_size);
425 cm_msg(
MERROR,
"ss_shm_open",
"MapViewOfFile() failed");
456 *adr = (
void *)
addr[1];
472 double file_size = 0;
505 }
else if (size != file_size) {
506 cm_msg(
MERROR,
"ss_shm_open",
"Existing file \'%s\' has size %.0f, different from requested size %d",
file_name.c_str(), file_size, size);
522 "Shared memory segment with key 0x%x already exists, please remove it manually: ipcrm -M 0x%x",
534 memset(&buf, 0,
sizeof(buf));
535 buf.shm_perm.uid =
getuid();
536 buf.shm_perm.gid =
getgid();
537 buf.shm_perm.mode = 0666;
542 if ((*adr) == (
void *) (-1)) {
558 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 cm_msg(
MINFO,
"ss_shm_open",
"WARNING: This version of MIDAS system.c uses the experimental mmap() based implementation of MIDAS shared memory.");
598 if (ret == (
off_t) - 1) {
600 "Cannot create shared memory file \'%s\', size %d, lseek() errno %d (%s)",
619 if (file_size < size) {
621 "Shared memory file \'%s\' size %d is smaller than requested size %d. Please remove it and try again",
646 double file_size = -1;
661 if (file_size != size) {
662 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);
683 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());
689 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));
726 if (
created &&
fh >= 0 && file_size > 0) {
728 printf(
"ss_shm_open(\"%s\"), loading contents of file [%s], size %.0f\n",
name,
file_name.c_str(), file_size);
794 path = std::string(
cwd);
796#elif defined(OS_UNIX)
798#elif defined(OS_WINNT)
811 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());
857 memset(&buf, 0,
sizeof(buf));
859 cm_msg(
MERROR,
"ss_shm_close",
"shmctl(shmid=%d,IPC_STAT) failed, errno %d (%s)",
867 printf(
"ss_shm_close(\"%s\"), destroy_flag %d, shmid %d, shm_nattach %d\n",
name,
destroy_flag, handle, (
int)buf.shm_nattch);
869 if (
shmdt(adr) < 0) {
944 assert(!
"not implemented!");
1026 printf(
"ss_shm_protect() handle %d, adr %p, size %.0f\n", handle, adr, (
double)shm_size);
1038 if (
shmdt(adr) < 0) {
1045 assert(shm_size > 0);
1083 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);
1090 cm_msg(
MERROR,
"ss_shm_unprotect",
"MapViewOfFile() failed");
1098 *adr =
shmat(handle, 0, 0);
1100 if ((*adr) == (
void *) (-1)) {
1107 assert(shm_size > 0);
1146 if ((
size_t)
wr != (
size_t)
param->size) {
1147 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', write() returned %d instead of %d, errno %d (%s)",
1151 param->buf =
nullptr;
1155 int ret = close(
param->fd);
1157 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', close() errno %d (%s)",
1160 param->buf =
nullptr;
1165 param->buf =
nullptr;
1168 cm_msg(
MINFO,
"ss_shm_flush",
"Flushing shared memory took %d seconds",
ss_time() - start);
1205 printf(
"ss_shm_flush(\"%s\",%p,%.0f,%d), file_name [%s]\n",
name, adr, (
double)size, handle,
file_name.c_str());
1233 void *buffer =
malloc(size);
1234 if (buffer !=
nullptr) {
1235 memcpy(buffer, adr, size);
1264 if ((
size_t)
wr != size) {
1270 int ret = close(fd);
1272 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', close() errno %d (%s)",
1278 cm_msg(
MINFO,
"ss_shm_flush",
"Flushing shared memory took %d seconds",
ss_time() - start);
1290 printf(
"ss_shm_flush(\"%s\") size %.0f, mmap file_name [%s]\n",
name, (
double)size,
file_name.c_str());
1422#ifdef LOCAL_ROUTINES
1450#warning Missing ESRCH for ss_pid_exists()
1476#warning Missing SIGKILL for ss_kill()
1484#if defined(OS_DARWIN)
1485#include <mach-o/dyld.h>
1502#if defined(OS_DARWIN)
1506#elif defined(OS_LINUX)
1511 return std::string(path);
1541#elif defined OS_WINNT
1549#elif defined OS_DARWIN
1553#elif defined OS_CYGWIN
1557#elif defined OS_UNIX
1562#elif defined OS_VXWORKS
1567#error Do not know how to do ss_gettid()
1577#elif defined OS_WINNT
1579#error Do not know how to do ss_tid_to_string()
1585 sprintf(buf,
"%d", thread_id);
1588#elif defined OS_DARWIN
1591 sprintf(buf,
"%p", thread_id);
1594#elif defined OS_CYGWIN
1597 sprintf(buf,
"%p", thread_id);
1600#elif defined OS_UNIX
1603 sprintf(buf,
"%lu", thread_id);
1606#elif defined OS_VXWORKS
1609 sprintf(buf,
"%d", thread_id);
1613#error Do not know how to do ss_tid_to_string()
1684 status =
sys$creprc(0, &
cmdstring_dsc, 0, 0, 0, 0, 0,
NULL, 4, 0, 0,
PRC$M_DETACH);
1707 status =
lib$spawn(&
cmdstring_dsc, 0, 0, &flags,
NULL, 0, 0, 0, 0, 0, 0, 0, 0);
1724 assert(!
"support for fork() disabled by NO_FORK");
1786 char buffer[256], cmd[256];
1898 timeout.tv_usec = 100;
1907 if (cmd[
i_cmd] == 8) {
1909 send(sock,
"\b \b", 3, 0);
1912 }
else if (cmd[
i_cmd] >=
' ' || cmd[
i_cmd] == 13 || cmd[
i_cmd] == 10) {
1919 if (cmd[
i_cmd - 1] == 10) {
1939 char line[32], buffer[1024],
shell[32];
1943 assert(!
"support for forkpty() disabled by NO_FORK");
1960 memset(buffer, 0,
sizeof(buffer));
1961 i =
recv(sock, buffer,
sizeof(buffer), 0);
1969 memset(buffer, 0,
sizeof(buffer));
1970 i =
read(p, buffer,
sizeof(buffer));
1973 send(sock, buffer,
i, 0);
1983 strcpy(
shell,
"/bin/sh");
1990 send(sock,
"not implemented\n", 17, 0);
2026 assert(!
"support for fork() disabled by NO_FORK");
2028 if ((pid =
fork()) < 0)
2040 for (
i = 0;
i < 3;
i++) {
2045 fd = open(
"/dev/null",
O_RDWR, 0);
2047 fd = open(
"/dev/null",
O_WRONLY, 0);
2049 cm_msg(
MERROR,
"ss_daemon_init",
"Can't open /dev/null");
2053 cm_msg(
MERROR,
"ss_daemon_init",
"Did not get file descriptor");
2065#ifdef LOCAL_ROUTINES
2091 cm_msg(
MINFO,
"ss_existpid",
"implemented for UNIX only");
2158 assert(!
"support for fork() disabled by NO_FORK");
2164 else if (*pid != 0) {
2173 for (
i = 0;
i < 256;
i++)
2178 for (
i = 0;
i < 3;
i++) {
2179 fd = open(
"/dev/null",
O_RDWR, 0);
2181 fd = open(
"/dev/null",
O_WRONLY, 0);
2187 cm_msg(
MERROR,
"ss_exec",
"Did not get file descriptor");
2196 int error =
execl(
"/bin/sh",
"sh",
"-c", command,
NULL);
2198 fprintf(
stderr,
"ss_shell: Cannot execute /bin/sh for command \"%s\": execl() returned %d, errno %d (%s), aborting!\n", command, error,
errno,
strerror(
errno));
2254 std::array<char, 256> buffer{};
2257 auto pipe = std::unique_ptr<FILE, decltype(pclose_deleter)>(
2263 throw std::runtime_error(
"popen() failed!");
2266 while (
fgets(buffer.data(), buffer.size(),
pipe.get()) !=
nullptr) {
2267 result += buffer.data();
2272 fprintf(
stderr,
"ss_execs: Function not supported on this OS, aborting!\n");
2312#if defined(OS_WINNT)
2325#elif defined(OS_MSDOS)
2329#elif defined(OS_VMS)
2333#elif defined(OS_VXWORKS)
2349 ts->arg4,
ts->arg5,
ts->arg6,
ts->arg7,
ts->arg8,
ts->arg9,
ts->arg10);
2353#elif defined(OS_UNIX)
2360 return status != 0 ? 0 : thread_id;
2385#if defined(OS_WINNT)
2401#elif defined(OS_MSDOS)
2405#elif defined(OS_VMS)
2409#elif defined(OS_VXWORKS)
2415#elif defined(OS_UNIX)
2428#if defined(OS_DARWIN)
2433#elif defined(OS_UNIX)
2450 return std::string(
str);
2527 status =
sys$enqw(0,
LCK$K_NLMODE, *
semaphore_handle, 0, &
semaphorename_dsc, 0, 0, 0, 0, 0, 0);
2557 path = std::string(
cwd);
2559#elif defined(OS_UNIX)
2561#elif defined(OS_WINNT)
2581#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2610 memset(&buf, 0,
sizeof(buf));
2611 buf.sem_perm.uid =
getuid();
2612 buf.sem_perm.gid =
getgid();
2613 buf.sem_perm.mode = 0666;
2673 status =
sys$enqw(0,
LCK$K_EXMODE,
semaphore_handle,
LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2691#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2705 memset(&arg, 0,
sizeof(arg));
2714#if defined(OS_DARWIN)
2716#elif defined(OS_LINUX)
2754 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);
2814 status =
sys$enqw(0,
LCK$K_NLMODE,
semaphore_handle,
LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2911#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2921 memset(&arg, 0,
sizeof(arg));
3086#if defined(OS_DARWIN)
3102 if (
wait > timeout) {
3103 fprintf(
stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3124 st.tv_sec += timeout / 1000;
3125 st.tv_nsec += (timeout % 1000) * 1000000;
3129 fprintf(
stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3298 bool ok = mutex.try_lock_for(std::chrono::milliseconds(1000));
3402 return clock() * 55;
3418 return lo / 10000 +
hi * 429496.7296;
3429 DWORD m =
tv.tv_sec * 1000 +
tv.tv_usec / 1000;
3471 return tv.tv_sec*1.0 +
tv.tv_usec/1000000.0;
3492#if defined(OS_WINNT)
3499 st.wYear =
ltm.tm_year + 1900;
3500 st.wMonth =
ltm.tm_mon + 1;
3501 st.wDay =
ltm.tm_mday;
3502 st.wHour =
ltm.tm_hour;
3503 st.wMinute =
ltm.tm_min;
3504 st.wSecond =
ltm.tm_sec;
3505 st.wMilliseconds = 0;
3509#elif defined(OS_DARWIN) && defined(CLOCK_REALTIME)
3517#elif defined(OS_CYGWIN) && defined(CLOCK_REALTIME)
3526#elif defined(OS_UNIX) && defined(CLOCK_REALTIME)
3534#elif defined(OS_VXWORKS)
3543#warning ss_settime() is not supported!
3599#if defined(OS_DARWIN) || defined(OS_VXWORKS)
3655 if ((
int)
ts.tv_sec < 0)
3720#ifdef LOCAL_ROUTINES
3878#elif defined (OS_VMS)
4054 memset(&bind_addr, 0,
sizeof(bind_addr));
4055 bind_addr.sin_family =
AF_INET;
4056 bind_addr.sin_addr.s_addr = 0;
4057 bind_addr.sin_port = 0;
4063 path +=
".UDP_BIND_HOSTNAME";
4069 cm_msg(
MERROR,
"ss_suspend_init_ipc",
"Support for UDP_BIND_HOSTNAME was removed. Please delete file \"%s\"", path.c_str());
4105 size =
sizeof(bind_addr);
4133 memset(&bind_addr, 0,
sizeof(bind_addr));
4134 bind_addr.sin_family =
AF_INET;
4135 bind_addr.sin_addr.s_addr = 0;
4429 if (msg ==
MSG_BM && buffer[0] ==
'B')
4431 if (msg ==
MSG_ODB && buffer[0] ==
'O')
4525 int sock = (*_ss_server_acceptions)[
i]->event_sock;
4647 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4664 if (msg == 0 && msg !=
MSG_BM) {
4666 sock = (*_ss_server_acceptions)[
i]->event_sock;
4704 timeout.tv_usec = (
millisec % 1000) * 1000;
4742 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4758 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4768 sock = (*_ss_server_acceptions)[
i]->event_sock;
4781 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4873 bind_addr.sin_port =
htons((
short) port);
4920 DWORD start_time = 0;
4927 timeout.tv_usec = (
millisec % 1000) * 1000;
4938 if (timeout.tv_sec ==
timeout0.tv_sec) {
4940 if (start_time == 0) {
4942 end_time = start_time + (
millisec+999)/1000;
5003 fprintf(
stderr,
"ss_socket_connect_tcp: hostname [%s] port %d addrinfo: flags %d, family %d, socktype %d, protocol %d, canonname [%s]\n",
5019 if (r->ai_protocol != 6) {
5023 sock =
::socket(r->ai_family, r->ai_socktype, 0);
5030 status = ::connect(sock, r->ai_addr, r->ai_addrlen);
5125#warning strange: AF_INET6 is defined, but IPV6_V6ONLY is not defined
5156 memset(&bind_addr, 0,
sizeof(bind_addr));
5157 bind_addr.sin_family =
AF_INET;
5168 bind_addr.sin_port =
htons(0);
5231 int err = close(*
sockp);
5244 unsigned size =
sizeof(
addr);
5258 hostname,
sizeof(hostname),
5317 if ((flags & 0x10000) == 0)
5319 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5325 while (
count < buffer_size) {
5334 if ((flags & 0x10000) == 0)
5336 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5370 while (
count < buffer_size) {
5376 }
else if (
wr < 0) {
5423 memset(buffer, 0, buffer_size);
5432 i =
recv(sock, buffer +
n, 1, 0);
5439 if (
n >= buffer_size)
5442 }
while (buffer[
n - 1] && buffer[
n - 1] != 10);
5483 cm_msg(
MERROR,
"recv_tcp",
"parameters too large for network buffer");
5520 if (param_size == 0)
5523 if (param_size > (
INT)buffer_size) {
5524 cm_msg(
MERROR,
"recv_tcp",
"param: receive buffer size %d is too small for received data size %d", buffer_size, param_size);
5540 cm_msg(
MERROR,
"recv_tcp",
"param: recv() returned %d, n_received = %d, unexpected connection closure",
n,
n_received);
5611 cm_msg(
MERROR,
"recv_tcp2",
"unexpected connection closure");
5660 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command header");
5664 if (
n !=
sizeof(
ncbuf)) {
5665 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command header, see messages");
5670 *routine_id =
ncbuf.routine_id;
5671 *param_size =
ncbuf.param_size;
5673 if (*param_size == 0) {
5681 cm_msg(
MERROR,
"ss_recv_net_command",
"error allocating %d bytes for network command data", *param_size);
5689 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command data");
5695 if (
n != *param_size) {
5696 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command data, see messages");
5725 memset(buf, 0,
sizeof(buf));
5760 if (h.length() == 0) {
5763 mstrlcpy(buffer, h.c_str(), buffer_size);
5774 std::string
cwd = s;
5779 return "/GETCWD-FAILED-ON-US";
5873 cm_msg(
MERROR,
"ss_tape_open",
"tape is used by other process");
5877 cm_msg(
MERROR,
"ss_tape_open",
"tape device \"%s\" doesn't exist", path);
5892 memset(&m, 0,
sizeof(m));
5987 cm_msg(
MINFO,
"ss_tape_status",
"tape is used by other process");
5991 cm_msg(
MINFO,
"ss_tape_status",
"tape device \"%s\" doesn't exist", path);
6005 cm_msg(
MINFO,
"ss_tape_status",
"no media in drive");
6013 printf(
"Hardware error correction is %s\n",
d.ECC ?
"on" :
"off");
6014 printf(
"Hardware compression is %s\n",
d.Compression ?
"on" :
"off");
6015 printf(
"Tape %s write protected\n", m.WriteProtected ?
"is" :
"is not");
6018 x = ((
double) m.Remaining.LowPart + (
double) m.Remaining.HighPart * 4.294967295E9)
6020 printf(
"Tape capacity remaining is %d MB\n", (
int) x);
6022 printf(
"Tape capacity is not reported by tape\n");
6124 if (
n == 0 &&
errno == 0)
6137#elif defined(OS_WINNT)
6220 cm_msg(
MERROR,
"ss_tape_write_eof",
"tape doesn't support writing of filemarks");
6578#if defined(OS_DARWIN)
6582#elif defined(OS_UNIX)
6598 return (arg.mt_blkno);
6600#elif defined(OS_WINNT)
6607 return (
media.PartitionCount);
6641 return (
double)
st.f_bavail *
st.f_bsize;
6642#elif defined(OS_LINUX)
6648 return (
double)
st.f_bavail *
st.f_bsize;
6649#elif defined(OS_SOLARIS)
6652 return (
double)
st.f_bavail *
st.f_bsize;
6653#elif defined(OS_IRIX)
6656 return (
double)
st.f_bfree *
st.f_bsize;
6660 return (
double)
st.fd_otsize *
st.fd_bfree;
6663#elif defined(OS_WINNT)
6686#if defined(OS_ULTRIX) || defined(OS_WINNT)
6689 while (*
str !=
'\0') {
6721 size_t size =
list.size();
6723 for (
size_t i=0;
i<size;
i++) {
6793 return plist->size();
6804 size_t size =
list.size();
6806 for (
size_t i=0;
i<size;
i++) {
6869 return plist->size();
6880 size_t size =
list.size();
6882 for (
size_t i=0;
i<size;
i++) {
6918 if (
fnmatch(pattern,
dp->d_name, 0) == 0) {
6920 std::string
full_path = std::string(path) +
"/" +
dp->d_name +
"/";
6949 return plist->size();
6989#ifdef _LARGEFILE64_SOURCE
7027#ifdef _LARGEFILE64_SOURCE
7069 return (
double)
st.f_blocks *
st.f_fsize;
7070#elif defined(OS_LINUX)
7076 return (
double)
st.f_blocks *
st.f_bsize;
7077#elif defined(OS_SOLARIS)
7080 if (
st.f_frsize > 0)
7081 return (
double)
st.f_blocks *
st.f_frsize;
7083 return (
double)
st.f_blocks *
st.f_bsize;
7084#elif defined(OS_ULTRIX)
7087 return (
double)
st.fd_btot * 1024;
7088#elif defined(OS_IRIX)
7091 return (
double)
st.f_blocks *
st.f_bsize;
7093#error ss_disk_size not defined for this OS
7214#warning ss_dir_exist() is not implemented!
7266 }
while (
nread > 0);
7270 if (close(
fd_to) < 0) {
7340#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7407 va_start(
argptr, format);
7427#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7428 printf(
"\033[%1d;%1dH", y + 1, x + 1);
7458 static char password[32];
7462 memset(password, 0,
sizeof(password));
7466#elif defined(OS_WINNT)
7477 if (password[
strlen(password) - 1] ==
'\r')
7478 password[
strlen(password) - 1] = 0;
7482#elif defined(OS_MSDOS)
7556 buf.c_cc[
VTIME] = 0;
7610#elif defined(OS_WINNT)
7688 if (!
ir.Event.KeyEvent.bKeyDown)
7691 if (
ir.Event.KeyEvent.wRepeatCount > 1) {
7697 if (
ir.Event.KeyEvent.uChar.AsciiChar)
7698 return ir.Event.KeyEvent.uChar.AsciiChar;
7701 switch (
ir.Event.KeyEvent.wVirtualKeyCode) {
7724 return ir.Event.KeyEvent.wVirtualKeyCode;
7729#elif defined(OS_MSDOS)
7794 }
while (p ==
NULL);
7819 DWORD buffer[] = { 6, 0, 0, 0 };
7829 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7855 DWORD buffer[] = { 7, 0, 0, 0 };
7865 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7889#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
7919 for (
i = 0;
i < 8 && buf[
i];
i++)
7925 for (
i = 2;
i < 13;
i++) {
7952#define isnan(x) _isnan(x)
7955#define finite(x) _finite(x)
7957#elif defined(OS_LINUX)
7987#include <execinfo.h>
7990#define N_STACK_HISTORY 500
7997#define MAX_STACK_DEPTH 16
8016 for (
i = 0;
i <
n;
i++)
8034 for (
i = 2;
i <
n;
i++) {
8049 f =
fopen(filename,
"wt");
8058 printf(
"Stack dump written to %s\n", filename);
8060 printf(
"Cannot open %s: errno=%d\n", filename,
errno);
8074 const unsigned char * bytes = (
const unsigned char *)
string;
8081 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8089 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8090 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8099 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8100 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8103 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8105 bytes[0] == 0xEF) &&
8106 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8107 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8111 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8112 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8121 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8122 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8123 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8126 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8127 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8128 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8129 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8133 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8134 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8135 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8161 unsigned char * bytes = (
unsigned char *)
string;
8168 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8176 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8177 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8186 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8187 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8190 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8192 bytes[0] == 0xEF) &&
8193 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8194 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8198 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8199 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8208 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8209 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8210 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8213 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8214 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8215 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8216 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8220 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8221 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8222 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8255std::chrono::time_point<std::chrono::high_resolution_clock>
ss_us_start()
8257 return std::chrono::high_resolution_clock::now();
8260unsigned int ss_us_since(std::chrono::time_point<std::chrono::high_resolution_clock> start) {
8261 auto elapsed = std::chrono::high_resolution_clock::now() - start;
8262 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_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)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
NET_COMMAND_HEADER header
struct sockaddr_in bind_addr
static te_expr * list(state *s)