#include "common.h"
+#ifdef __FreeBSD__
+# define O_NOATIME 0
+# define MADV_DONTFORK INHERIT_NONE
+#endif /* __FreeBSD__ */
+
char *global_host_prefix = "";
int enable_ksm = 1;
while (nanosleep(&req, &rem) == -1) {
if (likely(errno == EINTR)) {
- info("nanosleep() interrupted (while sleeping for %llu microseconds).", usec);
+ debug(D_SYSTEM, "nanosleep() interrupted (while sleeping for %llu microseconds).", usec);
req.tv_sec = rem.tv_sec;
req.tv_nsec = rem.tv_nsec;
} else {
*/
void strreverse(char *begin, char *end) {
- char aux;
-
while (end > begin) {
// clearer code.
- aux = *end;
+ char aux = *end;
*end-- = *begin;
*begin++ = aux;
}
#ifdef MADV_MERGEABLE
static int log_madvise_2 = 1, log_madvise_3 = 1;
#endif
- int fd;
void *mem = NULL;
errno = 0;
- fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
+ int fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
if (fd != -1) {
if (lseek(fd, size, SEEK_SET) == (off_t) size) {
if (write(fd, "", 1) == 1) {
}
pid_t gettid(void) {
+#ifdef __FreeBSD__
+ return (pid_t)pthread_getthreadid_np();
+#else
return (pid_t)syscall(SYS_gettid);
+#endif /* __FreeBSD__ */
}
char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) {
int processors = 1;
long get_system_cpus(void) {
- procfile *ff = NULL;
-
processors = 1;
char filename[FILENAME_MAX + 1];
snprintfz(filename, FILENAME_MAX, "%s/proc/stat", global_host_prefix);
- ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
+ procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
if(!ff) {
error("Cannot open file '%s'. Assuming system has %d processors.", filename, processors);
return processors;
procfile_close(ff);
- info("System has %d processors.", processors);
+ debug(D_SYSTEM, "System has %d processors.", processors);
return processors;
}
pid_t pid_max = 32768;
pid_t get_system_pid_max(void) {
- procfile *ff = NULL;
-
char filename[FILENAME_MAX + 1];
snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", global_host_prefix);
- ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
+ procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
if(!ff) {
error("Cannot open file '%s'. Assuming system supports %d pids.", filename, pid_max);
return pid_max;
}
procfile_close(ff);
- info("System supports %d pids.", pid_max);
+ debug(D_SYSTEM, "System supports %d pids.", pid_max);
return pid_max;
}