mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-26 01:50:10 +00:00
Move locking specific functions into their own source file
This commit is contained in:
parent
e4bf86dcbe
commit
b8e47c2ba2
28
include/locking.h
Normal file
28
include/locking.h
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _LOCKING_H
|
||||
#define _LOCKING_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef F_SETLKW
|
||||
|
||||
void lock_file (FILE *fp);
|
||||
void unlock_file (FILE *fp);
|
||||
|
||||
#else
|
||||
|
||||
#define lock_file(dummy) {}
|
||||
#define unlock_file(dummy) {}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _LOCKING_H
|
@ -25,6 +25,7 @@
|
||||
#include <dlfcn.h>
|
||||
#include <pwd.h>
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif // _POSIX
|
||||
@ -187,13 +188,6 @@ char *stroptitype (const uint opti_type);
|
||||
char *strstatus (const uint threads_status);
|
||||
void status ();
|
||||
|
||||
#ifdef F_SETLKW
|
||||
void lock_file (FILE *fp);
|
||||
void unlock_file (FILE *fp);
|
||||
#else
|
||||
#define lock_file(dummy) {}
|
||||
#define unlock_file(dummy) {}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN
|
||||
void fsync (int fd);
|
||||
|
10
src/Makefile
10
src/Makefile
@ -165,7 +165,7 @@ LFLAGS_CROSS_WIN := -lpsapi
|
||||
## Objects
|
||||
##
|
||||
|
||||
NATIVE_OBJS := obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
|
||||
NATIVE_OBJS := obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
|
||||
|
||||
ifeq ($(UNAME),Linux)
|
||||
NATIVE_OBJS += obj/ext_ADL.NATIVE.o
|
||||
@ -174,8 +174,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o
|
||||
NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o
|
||||
endif
|
||||
|
||||
LINUX_32_OBJS := obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
|
||||
LINUX_64_OBJS := obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
|
||||
LINUX_32_OBJS := obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
|
||||
LINUX_64_OBJS := obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
|
||||
|
||||
# Windows CRT file globbing:
|
||||
|
||||
@ -185,8 +185,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
|
||||
include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk
|
||||
|
||||
WIN_32_OBJS := obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
|
||||
WIN_64_OBJS := obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
|
||||
WIN_32_OBJS := obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
|
||||
WIN_64_OBJS := obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
|
||||
|
||||
##
|
||||
## Targets: Global
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "cpu_sha256.h"
|
||||
#include "thread.h"
|
||||
#include "timer.h"
|
||||
#include "locking.h"
|
||||
#include "types.h"
|
||||
#include "rp_cpu.h"
|
||||
#include "rp_kernel_on_cpu.h"
|
||||
|
42
src/locking.c
Normal file
42
src/locking.c
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "logging.h"
|
||||
#include "locking.h"
|
||||
|
||||
#ifdef F_SETLKW
|
||||
|
||||
void lock_file (FILE *fp)
|
||||
{
|
||||
struct flock lock;
|
||||
|
||||
memset (&lock, 0, sizeof (struct flock));
|
||||
|
||||
lock.l_type = F_WRLCK;
|
||||
|
||||
while (fcntl (fileno (fp), F_SETLKW, &lock))
|
||||
{
|
||||
if (errno != EINTR)
|
||||
{
|
||||
log_error ("ERROR: Failed acquiring write lock: %s", strerror (errno));
|
||||
|
||||
exit (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_file (FILE *fp)
|
||||
{
|
||||
struct flock lock;
|
||||
|
||||
memset (&lock, 0, sizeof (struct flock));
|
||||
|
||||
lock.l_type = F_UNLCK;
|
||||
|
||||
fcntl (fileno (fp), F_SETLK, &lock);
|
||||
}
|
||||
|
||||
#endif // F_SETLKW
|
29
src/shared.c
29
src/shared.c
@ -16,6 +16,7 @@
|
||||
#include "ext_nvml.h"
|
||||
#include "ext_xnvctrl.h"
|
||||
#include "convert.h"
|
||||
#include "locking.h"
|
||||
#include "thread.h"
|
||||
#include "timer.h"
|
||||
#include "types.h"
|
||||
@ -33,35 +34,7 @@ extern hc_global_data_t data;
|
||||
* system
|
||||
*/
|
||||
|
||||
#ifdef F_SETLKW
|
||||
void lock_file (FILE *fp)
|
||||
{
|
||||
struct flock lock;
|
||||
|
||||
memset (&lock, 0, sizeof (struct flock));
|
||||
|
||||
lock.l_type = F_WRLCK;
|
||||
while (fcntl(fileno(fp), F_SETLKW, &lock))
|
||||
{
|
||||
if (errno != EINTR)
|
||||
{
|
||||
log_error ("ERROR: Failed acquiring write lock: %s", strerror (errno));
|
||||
|
||||
exit (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_file (FILE *fp)
|
||||
{
|
||||
struct flock lock;
|
||||
|
||||
memset (&lock, 0, sizeof (struct flock));
|
||||
|
||||
lock.l_type = F_UNLCK;
|
||||
fcntl(fileno(fp), F_SETLK, &lock);
|
||||
}
|
||||
#endif // F_SETLKW
|
||||
|
||||
#ifdef WIN
|
||||
void fsync (int fd)
|
||||
|
Loading…
Reference in New Issue
Block a user