65#include <sys/posix_shm.h>
66#include <sys/sysctl.h>
86 char cwd[256], buf[256];
92 path = std::string(
cwd);
120 if (!
fgets(buf,
sizeof(buf),
fp))
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];
185 path = std::string(
cwd);
187#elif defined(OS_UNIX)
189#elif defined(OS_WINNT)
213 if (!
fgets(buf,
sizeof(buf),
fp))
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)
250 assert(path.length() > 0);
290 fprintf(
stderr,
"check_shm_host: unsupported shared memory type, bye!\n");
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;
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);
427 cm_msg(
MERROR,
"ss_shm_open",
"MapViewOfFile() failed");
458 *adr = (
void *)
addr[1];
474 double file_size = 0;
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);
524 "Shared memory segment with key 0x%x already exists, please remove it manually: ipcrm -M 0x%x",
536 memset(&buf, 0,
sizeof(buf));
537 buf.shm_perm.uid =
getuid();
538 buf.shm_perm.gid =
getgid();
539 buf.shm_perm.mode = 0666;
544 if ((*adr) == (
void *) (-1)) {
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));
577 cm_msg(
MINFO,
"ss_shm_open",
"WARNING: This version of MIDAS system.c uses the experimental mmap() based implementation of MIDAS shared memory.");
600 if (ret == (
off_t) - 1) {
602 "Cannot create shared memory file \'%s\', size %d, lseek() errno %d (%s)",
621 if (file_size < size) {
623 "Shared memory file \'%s\' size %d is smaller than requested size %d. Please remove it and try again",
648 double file_size = -1;
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);
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());
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));
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);
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());
859 memset(&buf, 0,
sizeof(buf));
861 cm_msg(
MERROR,
"ss_shm_close",
"shmctl(shmid=%d,IPC_STAT) failed, errno %d (%s)",
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) {
946 assert(!
"not implemented!");
1028 printf(
"ss_shm_protect() handle %d, adr %p, size %.0f\n", handle, adr, (
double)shm_size);
1040 if (
shmdt(adr) < 0) {
1047 assert(shm_size > 0);
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);
1092 cm_msg(
MERROR,
"ss_shm_unprotect",
"MapViewOfFile() failed");
1100 *adr =
shmat(handle, 0, 0);
1102 if ((*adr) == (
void *) (-1)) {
1109 assert(shm_size > 0);
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)",
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)",
1162 param->buf =
nullptr;
1167 param->buf =
nullptr;
1170 cm_msg(
MINFO,
"ss_shm_flush",
"Flushing shared memory took %d seconds",
ss_time() - start);
1207 printf(
"ss_shm_flush(\"%s\",%p,%.0f,%d), file_name [%s]\n",
name, adr, (
double)size, handle,
file_name.c_str());
1235 void *buffer =
malloc(size);
1236 if (buffer !=
nullptr) {
1237 memcpy(buffer, adr, size);
1266 if ((
size_t)
wr != size) {
1272 int ret = close(fd);
1274 cm_msg(
MERROR,
"ss_shm_flush",
"Cannot write to file \'%s\', close() errno %d (%s)",
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());
1424#ifdef LOCAL_ROUTINES
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)
1508#elif defined(OS_LINUX)
1513 return std::string(path);
1531#if defined(OS_DARWIN)
1535 if (
sysctl(
mib, 3,
nullptr, &len,
nullptr, 0) == -1) {
1540 std::vector<char> buf(len);
1541 if (
sysctl(
mib, 3, buf.data(), &len,
nullptr, 0) == -1) {
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
1621#elif defined OS_DARWIN
1625#elif defined OS_CYGWIN
1629#elif defined OS_UNIX
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()
1756 status =
sys$creprc(0, &
cmdstring_dsc, 0, 0, 0, 0, 0,
NULL, 4, 0, 0,
PRC$M_DETACH);
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");
1858 char buffer[256], cmd[256];
1970 timeout.tv_usec = 100;
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) {
1991 if (cmd[
i_cmd - 1] == 10) {
2011 char line[32], buffer[1024],
shell[32];
2015 assert(!
"support for forkpty() disabled by NO_FORK");
2032 memset(buffer, 0,
sizeof(buffer));
2033 i =
recv(sock, buffer,
sizeof(buffer), 0);
2041 memset(buffer, 0,
sizeof(buffer));
2042 i =
read(p, buffer,
sizeof(buffer));
2045 send(sock, buffer,
i, 0);
2055 strcpy(
shell,
"/bin/sh");
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++) {
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
2163 cm_msg(
MINFO,
"ss_existpid",
"implemented for UNIX only");
2230 assert(!
"support for fork() disabled by NO_FORK");
2236 else if (*pid != 0) {
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));
2326 std::array<char, 256> buffer{};
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)
2397#elif defined(OS_MSDOS)
2401#elif defined(OS_VMS)
2405#elif defined(OS_VXWORKS)
2421 ts->arg4,
ts->arg5,
ts->arg6,
ts->arg7,
ts->arg8,
ts->arg9,
ts->arg10);
2425#elif defined(OS_UNIX)
2432 return status != 0 ? 0 : thread_id;
2457#if defined(OS_WINNT)
2473#elif defined(OS_MSDOS)
2477#elif defined(OS_VMS)
2481#elif defined(OS_VXWORKS)
2487#elif defined(OS_UNIX)
2500#if defined(OS_DARWIN)
2505#elif defined(OS_UNIX)
2522 return std::string(
str);
2599 status =
sys$enqw(0,
LCK$K_NLMODE, *
semaphore_handle, 0, &
semaphorename_dsc, 0, 0, 0, 0, 0, 0);
2629 path = std::string(
cwd);
2631#elif defined(OS_UNIX)
2633#elif defined(OS_WINNT)
2653#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2682 memset(&buf, 0,
sizeof(buf));
2683 buf.sem_perm.uid =
getuid();
2684 buf.sem_perm.gid =
getgid();
2685 buf.sem_perm.mode = 0666;
2745 status =
sys$enqw(0,
LCK$K_EXMODE,
semaphore_handle,
LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2763#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2777 memset(&arg, 0,
sizeof(arg));
2786#if defined(OS_DARWIN)
2788#elif defined(OS_LINUX)
2826 fprintf(
stderr,
"ss_semaphore_wait_for: semop/semtimedop(%d) returned %d, errno %d (%s), start time 0x%08x, now 0x%08x, dt 0x%08x, timeout 0x%08x ms, SEMAPHORE TIMEOUT!\n",
semaphore_handle,
status,
errno,
strerror(
errno), start_time,
milli_now,
dt,
timeout_millisec);
2886 status =
sys$enqw(0,
LCK$K_NLMODE,
semaphore_handle,
LCK$M_CONVERT, 0, 0, 0, 0, 0, 0, 0);
2983#if (defined(OS_LINUX) && !defined(_SEM_SEMUN_UNDEFINED) && !defined(OS_CYGWIN)) || defined(OS_FREEBSD)
2993 memset(&arg, 0,
sizeof(arg));
3158#if defined(OS_DARWIN)
3174 if (
wait > timeout) {
3175 fprintf(
stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3196 st.tv_sec += timeout / 1000;
3197 st.tv_nsec += (timeout % 1000) * 1000000;
3201 fprintf(
stderr,
"ss_mutex_wait_for: fatal error: timeout waiting for mutex, timeout was %d millisec, aborting...\n", timeout);
3370 bool ok = mutex.try_lock_for(std::chrono::milliseconds(1000));
3474 return clock() * 55;
3490 return lo / 10000 +
hi * 429496.7296;
3501 DWORD m =
tv.tv_sec * 1000 +
tv.tv_usec / 1000;
3543 return tv.tv_sec*1.0 +
tv.tv_usec/1000000.0;
3564#if defined(OS_WINNT)
3571 st.wYear =
ltm.tm_year + 1900;
3572 st.wMonth =
ltm.tm_mon + 1;
3573 st.wDay =
ltm.tm_mday;
3574 st.wHour =
ltm.tm_hour;
3575 st.wMinute =
ltm.tm_min;
3576 st.wSecond =
ltm.tm_sec;
3577 st.wMilliseconds = 0;
3581#elif defined(OS_DARWIN) && defined(CLOCK_REALTIME)
3589#elif defined(OS_CYGWIN) && defined(CLOCK_REALTIME)
3598#elif defined(OS_UNIX) && defined(CLOCK_REALTIME)
3606#elif defined(OS_VXWORKS)
3615#warning ss_settime() is not supported!
3671#if defined(OS_DARWIN) || defined(OS_VXWORKS)
3727 if ((
int)
ts.tv_sec < 0)
3792#ifdef LOCAL_ROUTINES
3950#elif defined (OS_VMS)
4126 memset(&bind_addr, 0,
sizeof(bind_addr));
4127 bind_addr.sin_family =
AF_INET;
4128 bind_addr.sin_addr.s_addr = 0;
4129 bind_addr.sin_port = 0;
4135 path +=
".UDP_BIND_HOSTNAME";
4139 FILE *
fp =
fopen(path.c_str(),
"r");
4141 cm_msg(
MERROR,
"ss_suspend_init_ipc",
"Support for UDP_BIND_HOSTNAME was removed. Please delete file \"%s\"", path.c_str());
4177 size =
sizeof(bind_addr);
4205 memset(&bind_addr, 0,
sizeof(bind_addr));
4206 bind_addr.sin_family =
AF_INET;
4207 bind_addr.sin_addr.s_addr = 0;
4501 if (msg ==
MSG_BM && buffer[0] ==
'B')
4503 if (msg ==
MSG_ODB && buffer[0] ==
'O')
4597 int sock = (*_ss_server_acceptions)[
i]->event_sock;
4719 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4736 if (msg == 0 && msg !=
MSG_BM) {
4738 sock = (*_ss_server_acceptions)[
i]->event_sock;
4776 timeout.tv_usec = (
millisec % 1000) * 1000;
4814 int sock = (*_ss_server_acceptions)[
i]->recv_sock;
4830 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4840 sock = (*_ss_server_acceptions)[
i]->event_sock;
4853 (*_ss_server_acceptions)[
i]->last_activity =
ss_millitime();
4945 bind_addr.sin_port =
htons((
short) port);
4992 DWORD start_time = 0;
4999 timeout.tv_usec = (
millisec % 1000) * 1000;
5010 if (timeout.tv_sec ==
timeout0.tv_sec) {
5012 if (start_time == 0) {
5014 end_time = start_time + (
millisec+999)/1000;
5075 fprintf(
stderr,
"ss_socket_connect_tcp: hostname [%s] port %d addrinfo: flags %d, family %d, socktype %d, protocol %d, canonname [%s]\n",
5091 if (r->ai_protocol != 6) {
5095 sock =
::socket(r->ai_family, r->ai_socktype, 0);
5102 status = ::connect(sock, r->ai_addr, r->ai_addrlen);
5203#warning strange: AF_INET6 is defined, but IPV6_V6ONLY is not defined
5234 memset(&bind_addr, 0,
sizeof(bind_addr));
5235 bind_addr.sin_family =
AF_INET;
5246 bind_addr.sin_port =
htons(0);
5309 int err = close(*
sockp);
5322 unsigned size =
sizeof(
addr);
5336 hostname,
sizeof(hostname),
5395 if ((flags & 0x10000) == 0)
5397 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5403 while (
count < buffer_size) {
5412 if ((flags & 0x10000) == 0)
5414 "send(socket=%d,size=%d) returned %d, errno: %d (%s)",
5448 while (
count < buffer_size) {
5454 }
else if (
wr < 0) {
5501 memset(buffer, 0, buffer_size);
5510 i =
recv(sock, buffer +
n, 1, 0);
5517 if (
n >= buffer_size)
5520 }
while (buffer[
n - 1] && buffer[
n - 1] != 10);
5561 cm_msg(
MERROR,
"recv_tcp",
"parameters too large for network buffer");
5598 if (param_size == 0)
5601 if (param_size > (
INT)buffer_size) {
5602 cm_msg(
MERROR,
"recv_tcp",
"param: receive buffer size %d is too small for received data size %d", buffer_size, param_size);
5618 cm_msg(
MERROR,
"recv_tcp",
"param: recv() returned %d, n_received = %d, unexpected connection closure",
n,
n_received);
5689 cm_msg(
MERROR,
"recv_tcp2",
"unexpected connection closure");
5738 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command header");
5742 if (
n !=
sizeof(
ncbuf)) {
5743 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command header, see messages");
5748 *routine_id =
ncbuf.routine_id;
5749 *param_size =
ncbuf.param_size;
5751 if (*param_size == 0) {
5759 cm_msg(
MERROR,
"ss_recv_net_command",
"error allocating %d bytes for network command data", *param_size);
5767 cm_msg(
MERROR,
"ss_recv_net_command",
"timeout receiving network command data");
5773 if (
n != *param_size) {
5774 cm_msg(
MERROR,
"ss_recv_net_command",
"error receiving network command data, see messages");
5803 memset(buf, 0,
sizeof(buf));
5838 if (h.length() == 0) {
5841 mstrlcpy(buffer, h.c_str(), buffer_size);
5852 std::string
cwd = s;
5857 return "/GETCWD-FAILED-ON-US";
5951 cm_msg(
MERROR,
"ss_tape_open",
"tape is used by other process");
5955 cm_msg(
MERROR,
"ss_tape_open",
"tape device \"%s\" doesn't exist", path);
5970 memset(&m, 0,
sizeof(m));
6065 cm_msg(
MINFO,
"ss_tape_status",
"tape is used by other process");
6069 cm_msg(
MINFO,
"ss_tape_status",
"tape device \"%s\" doesn't exist", path);
6083 cm_msg(
MINFO,
"ss_tape_status",
"no media in drive");
6091 printf(
"Hardware error correction is %s\n",
d.ECC ?
"on" :
"off");
6092 printf(
"Hardware compression is %s\n",
d.Compression ?
"on" :
"off");
6093 printf(
"Tape %s write protected\n", m.WriteProtected ?
"is" :
"is not");
6096 x = ((
double) m.Remaining.LowPart + (
double) m.Remaining.HighPart * 4.294967295E9)
6098 printf(
"Tape capacity remaining is %d MB\n", (
int) x);
6100 printf(
"Tape capacity is not reported by tape\n");
6202 if (
n == 0 &&
errno == 0)
6215#elif defined(OS_WINNT)
6298 cm_msg(
MERROR,
"ss_tape_write_eof",
"tape doesn't support writing of filemarks");
6656#if defined(OS_DARWIN)
6660#elif defined(OS_UNIX)
6676 return (arg.mt_blkno);
6678#elif defined(OS_WINNT)
6685 return (
media.PartitionCount);
6719 return (
double)
st.f_bavail *
st.f_bsize;
6720#elif defined(OS_LINUX)
6726 return (
double)
st.f_bavail *
st.f_bsize;
6727#elif defined(OS_SOLARIS)
6730 return (
double)
st.f_bavail *
st.f_bsize;
6731#elif defined(OS_IRIX)
6734 return (
double)
st.f_bfree *
st.f_bsize;
6738 return (
double)
st.fd_otsize *
st.fd_bfree;
6741#elif defined(OS_WINNT)
6764#if defined(OS_ULTRIX) || defined(OS_WINNT)
6767 while (*
str !=
'\0') {
6799 size_t size =
list.size();
6801 for (
size_t i=0;
i<size;
i++) {
6871 return plist->size();
6882 size_t size =
list.size();
6884 for (
size_t i=0;
i<size;
i++) {
6947 return plist->size();
6958 size_t size =
list.size();
6960 for (
size_t i=0;
i<size;
i++) {
6996 if (
fnmatch(pattern,
dp->d_name, 0) == 0) {
6998 std::string
full_path = std::string(path) +
"/" +
dp->d_name +
"/";
7027 return plist->size();
7067#ifdef _LARGEFILE64_SOURCE
7105#ifdef _LARGEFILE64_SOURCE
7147 return (
double)
st.f_blocks *
st.f_fsize;
7148#elif defined(OS_LINUX)
7154 return (
double)
st.f_blocks *
st.f_bsize;
7155#elif defined(OS_SOLARIS)
7158 if (
st.f_frsize > 0)
7159 return (
double)
st.f_blocks *
st.f_frsize;
7161 return (
double)
st.f_blocks *
st.f_bsize;
7162#elif defined(OS_ULTRIX)
7165 return (
double)
st.fd_btot * 1024;
7166#elif defined(OS_IRIX)
7169 return (
double)
st.f_blocks *
st.f_bsize;
7171#error ss_disk_size not defined for this OS
7292#warning ss_dir_exist() is not implemented!
7344 }
while (
nread > 0);
7348 if (close(
fd_to) < 0) {
7418#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7485 va_start(
argptr, format);
7505#if defined(OS_UNIX) || defined(OS_VXWORKS) || defined(OS_VMS)
7506 printf(
"\033[%1d;%1dH", y + 1, x + 1);
7536 static char password[32];
7540 memset(password, 0,
sizeof(password));
7544#elif defined(OS_WINNT)
7555 if (password[
strlen(password) - 1] ==
'\r')
7556 password[
strlen(password) - 1] = 0;
7560#elif defined(OS_MSDOS)
7634 buf.c_cc[
VTIME] = 0;
7688#elif defined(OS_WINNT)
7766 if (!
ir.Event.KeyEvent.bKeyDown)
7769 if (
ir.Event.KeyEvent.wRepeatCount > 1) {
7775 if (
ir.Event.KeyEvent.uChar.AsciiChar)
7776 return ir.Event.KeyEvent.uChar.AsciiChar;
7779 switch (
ir.Event.KeyEvent.wVirtualKeyCode) {
7802 return ir.Event.KeyEvent.wVirtualKeyCode;
7807#elif defined(OS_MSDOS)
7872 }
while (p ==
NULL);
7897 DWORD buffer[] = { 6, 0, 0, 0 };
7907 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7933 DWORD buffer[] = { 7, 0, 0, 0 };
7943 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
7967#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
7997 for (
i = 0;
i < 8 && buf[
i];
i++)
8003 for (
i = 2;
i < 13;
i++) {
8030#define isnan(x) _isnan(x)
8033#define finite(x) _finite(x)
8035#elif defined(OS_LINUX)
8065#include <execinfo.h>
8068#define N_STACK_HISTORY 500
8075#define MAX_STACK_DEPTH 16
8094 for (
i = 0;
i <
n;
i++)
8112 for (
i = 2;
i <
n;
i++) {
8127 f =
fopen(filename,
"wt");
8136 printf(
"Stack dump written to %s\n", filename);
8138 printf(
"Cannot open %s: errno=%d\n", filename,
errno);
8152 const unsigned char * bytes = (
const unsigned char *)
string;
8159 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8167 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8168 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8177 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8178 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8181 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8183 bytes[0] == 0xEF) &&
8184 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8185 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8189 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8190 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8199 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8200 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8201 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8204 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8205 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8206 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8207 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8211 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8212 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8213 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8239 unsigned char * bytes = (
unsigned char *)
string;
8246 (0x20 <= bytes[0] && bytes[0] <= 0x7E)
8254 (0xC2 <= bytes[0] && bytes[0] <= 0xDF) &&
8255 (0x80 <= bytes[1] && bytes[1] <= 0xBF)
8264 (0xA0 <= bytes[1] && bytes[1] <= 0xBF) &&
8265 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8268 ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) ||
8270 bytes[0] == 0xEF) &&
8271 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8272 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8276 (0x80 <= bytes[1] && bytes[1] <= 0x9F) &&
8277 (0x80 <= bytes[2] && bytes[2] <= 0xBF)
8286 (0x90 <= bytes[1] && bytes[1] <= 0xBF) &&
8287 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8288 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8291 (0xF1 <= bytes[0] && bytes[0] <= 0xF3) &&
8292 (0x80 <= bytes[1] && bytes[1] <= 0xBF) &&
8293 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8294 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8298 (0x80 <= bytes[1] && bytes[1] <= 0x8F) &&
8299 (0x80 <= bytes[2] && bytes[2] <= 0xBF) &&
8300 (0x80 <= bytes[3] && bytes[3] <= 0xBF)
8333std::chrono::time_point<std::chrono::high_resolution_clock>
ss_us_start()
8335 return std::chrono::high_resolution_clock::now();
8338unsigned int ss_us_since(std::chrono::time_point<std::chrono::high_resolution_clock> start) {
8339 auto elapsed = std::chrono::high_resolution_clock::now() - start;
8340 return std::chrono::duration_cast<std::chrono::microseconds>(
elapsed).count();
INT cm_dispatch_ipc(const char *message, int message_size, int client_socket)
std::string cm_get_path()
std::string cm_get_experiment_name()
#define SS_INVALID_HANDLE
#define SS_INVALID_ADDRESS
#define MAX_STRING_LENGTH
std::string ss_gethostname()
INT ss_suspend(INT millisec, INT msg)
INT ss_suspend_set_rpc_thread(midas_thread_t thread_id)
INT ss_get_struct_align()
INT ss_suspend_get_odb_port(INT *port)
bool ss_is_valid_utf8(const char *string)
INT ss_mutex_release(MUTEX_T *mutex)
INT ss_thread_kill(midas_thread_t thread_id)
INT ss_suspend_init_odb_port()
INT ss_dir_find(const char *path, const char *pattern, char **plist)
static midas_thread_t _ss_server_thread
INT ss_exception_handler(void(*func)(void))
bool ss_event_socket_has_data()
INT ss_shm_flush(const char *name, const void *adr, size_t size, HNDLE handle, bool wait_for_thread)
static void ss_suspend_close(SUSPEND_STRUCT *psuspend)
double ss_disk_size(const char *path)
time_t ss_mktime(struct tm *tms)
static int _ss_server_listen_socket
int ss_file_exist(const char *path)
static void check_shm_host()
INT EXPRT ss_thread_set_name(std::string name)
static int ss_suspend_process_ipc(INT millisec, INT msg, int ipc_recv_socket)
INT ss_tape_rskip(INT channel, INT count)
INT ss_tape_write(INT channel, void *pdata, INT count)
INT ss_semaphore_create(const char *name, HNDLE *semaphore_handle)
INT ss_shm_delete(const char *name)
static std::mutex gTzMutex
INT recv_tcp2(int sock, char *net_buffer, int buffer_size, int timeout_ms)
SUSPEND_STRUCT * ss_suspend_get_struct(midas_thread_t thread_id)
INT ss_suspend_set_client_listener(int listen_socket)
static RPC_SERVER_CONNECTION * _ss_client_connection
INT ss_dirlink_find(const char *path, const char *pattern, char **plist)
INT ss_getchar(BOOL reset)
static std::atomic_bool s_semaphore_trace
INT ss_tape_rewind(INT channel)
INT ss_shm_flush_thread(void *p)
INT ss_tape_fskip(INT channel, INT count)
INT ss_tape_close(INT channel)
static midas_thread_t _ss_odb_thread
static struct @3 test_align
double ss_disk_free(const char *path)
time_t ss_file_time(const char *path)
INT ss_socket_get_peer_name(int sock, std::string *hostp, int *portp)
static int ss_socket_check(int sock)
int ss_file_link_exist(const char *path)
INT ss_tape_get_blockn(INT channel)
INT ss_mutex_delete(MUTEX_T *mutex)
int ss_socket_wait(int sock, INT millisec)
INT ss_suspend_set_server_acceptions(RPC_SERVER_ACCEPTION_LIST *acceptions)
double ss_file_size(const char *path)
char stack_history[N_STACK_HISTORY][80]
INT ss_tape_status(char *path)
DWORD ss_settime(DWORD seconds)
std::chrono::time_point< std::chrono::high_resolution_clock > ss_us_start()
INT ss_tape_mount(INT channel)
char * ss_getpass(const char *prompt)
INT ss_directio_give_port(INT start, INT end)
INT ss_suspend_set_client_connection(RPC_SERVER_CONNECTION *connection)
INT ss_mutex_create(MUTEX_T **mutex, BOOL recursive)
static bool ss_match_thread(midas_thread_t tid1, midas_thread_t tid2)
unsigned int ss_us_since(std::chrono::time_point< std::chrono::high_resolution_clock > start)
INT ss_shm_open(const char *name, INT size, void **adr, size_t *shm_size, HNDLE *handle, BOOL get_size)
INT recv_string(int sock, char *buffer, DWORD buffer_size, INT millisec)
INT ss_write_tcp(int sock, const char *buffer, size_t buffer_size)
int ss_dir_exist(const char *path)
bool ss_timed_mutex_wait_for_sec(std::timed_mutex &mutex, const char *mutex_name, double timeout_sec)
INT ss_semaphore_release(HNDLE semaphore_handle)
void ss_set_screen_size(int x, int y)
midas_thread_t ss_thread_create(INT(*thread_func)(void *), void *param)
void ss_stack_history_entry(char *tag)
std::string ss_execs(const char *cmd)
static struct @4 test_padding
static int _ss_client_listen_socket
static SUSPEND_STRUCT * _ss_suspend_odb
INT ss_tape_spool(INT channel)
INT ss_stack_get(char ***string)
std::string ss_get_cmdline(void)
std::string ss_tid_to_string(midas_thread_t thread_id)
INT ss_file_remove(const char *path)
void ss_stack_history_dump(char *filename)
INT ss_tape_read(INT channel, void *pdata, INT *count)
int ss_file_copy(const char *src, const char *dst, bool append)
std::string ss_replace_env_variables(const std::string &inputPath)
INT ss_daemon_init(BOOL keep_stdout)
INT ss_alarm(INT millitime, void(*func)(int))
static midas_thread_t _ss_listen_thread
static INT ss_suspend_init_struct(SUSPEND_STRUCT *psuspend)
INT recv_tcp(int sock, char *net_buffer, DWORD buffer_size, INT flags)
INT ss_resume(INT port, const char *message)
midas_thread_t ss_gettid(void)
INT ss_semaphore_delete(HNDLE semaphore_handle, INT destroy_flag)
INT ss_get_struct_padding()
INT ss_sleep(INT millisec)
INT ss_socket_connect_tcp(const char *hostname, int tcp_port, int *sockp, std::string *error_msg_p)
void(* MidasExceptionHandler)(void)
INT ss_tape_unmount(INT channel)
static RPC_SERVER_ACCEPTION_LIST * _ss_server_acceptions
INT ss_tape_write_eof(INT channel)
INT ss_semaphore_wait_for(HNDLE semaphore_handle, DWORD timeout_millisec)
INT ss_socket_listen_tcp(bool listen_localhost, int tcp_port, int *sockp, int *tcp_port_p, std::string *error_msg_p)
INT ss_exec(const char *command, INT *pid)
INT ss_shm_unprotect(HNDLE handle, void **adr, size_t shm_size, BOOL read, BOOL write, const char *caller_name)
bool ss_repair_utf8(char *string)
static std::atomic_int s_semaphore_nest_level
std::string EXPRT ss_thread_get_name()
char * ss_crypt(const char *buf, const char *salt)
INT ss_tape_open(char *path, INT oflag, INT *channel)
BOOL ss_existpid(INT pid)
INT ss_spawnv(INT mode, const char *cmdname, const char *const argv[])
INT ss_suspend_get_buffer_port(midas_thread_t thread_id, INT *port)
void ss_printf(INT x, INT y, const char *format,...)
INT ss_socket_close(int *sockp)
INT ss_directio_lock_port(INT start, INT end)
struct suspend_struct SUSPEND_STRUCT
char * ss_gets(char *string, int size)
INT ss_recv_net_command(int sock, DWORD *routine_id, DWORD *param_size, char **param_ptr, int timeout_ms)
INT ss_suspend_set_server_listener(int listen_socket)
INT ss_shm_close(const char *name, void *adr, size_t shm_size, HNDLE handle, INT destroy_flag)
INT send_tcp(int sock, char *buffer, DWORD buffer_size, INT flags)
void * ss_ctrlc_handler(void(*func)(int))
BOOL ss_pid_exists(int pid)
static midas_thread_t _ss_client_thread
std::string ss_get_executable(void)
static void check_shm_type(const char *shm_type)
INT ss_system(const char *command)
INT ss_shm_protect(HNDLE handle, void *adr, size_t shm_size)
static std::vector< SUSPEND_STRUCT * > _ss_suspend_vector
int stack_history_pointer
static int ss_shm_name(const char *name, std::string &mem_name, std::string &file_name, std::string &shm_name)
INT ss_mutex_wait_for(MUTEX_T *mutex, INT timeout)
INT ss_file_find(const char *path, const char *pattern, char **plist)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
std::vector< RPC_SERVER_ACCEPTION * > RPC_SERVER_ACCEPTION_LIST
INT recv_tcp_check(int sock)
INT rpc_server_receive_rpc(int idx, RPC_SERVER_ACCEPTION *sa)
INT rpc_client_accept(int lsock)
INT rpc_server_receive_event(int idx, RPC_SERVER_ACCEPTION *sa, int timeout_msec)
INT rpc_server_accept(int lsock)
INT rpc_client_dispatch(int sock)
std::string msprintf(const char *format,...)
#define DIR_SEPARATOR_STR
#define WATCHDOG_INTERVAL
std::vector< std::string > STRING_LIST
#define message(type, str)
#define write(n, a, f, d)
static std::string remove(const std::string s, char c)
int gettimeofday(struct timeval *tp, void *tzp)
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)