fanotify unable monitor entire system for FAN_OPEN_PERM event by multi-threaded program, and to ignore directories - fanotify

I want to monitor whole system for FAN_OPEN_PERM | FAN_CLOSE_WRITE events by a multi - threaded program, and ignore some directories (say /home/mydir). I used fanotify_init() and fanotify_mark() in main() as:
//Is there any way to use FAN_GLOBAL_LISTENER?
fd = fanotify_init(FAN_CLOEXEC| FAN_NONBLOCK | FAN_CLASS_CONTENT | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS, O_RDONLY | O_LARGEFILE)
...
//Marking "/" (doesn't work as multi-threaded program) or "/home" (works fine)
fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_OPEN_PERM | FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD, AT_FDCWD, "/")
....
//Now, to ignore directory
fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_ONLYDIR | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY, FAN_OPEN_PERM | FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD, AT_FDCWD, "/home/mydir")
In my program, main() reads events and pass it to multiple threads to process further.
Problems : 1) System hangs for this multi-threaded program in case of monitoring "/", but works fine for "/home". 2) Still I am getting notifications for "/home/mydir" (marked "/home" & ignored "/home/mydir").
How to mark entire system without any problem with multi-threaded program?
How to use ignore mask to ignore entire directory (recursively)?
(Kernel 2.6.38-8-generic)

Read the man page.
the FAN_OPEN_PERM flag fires up an event when privileges are required to open the file. If you open a file, let say in /tmp, it does nothing.
Instead you should use FAN_OPEN.

Related

mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)

Trying to build Bitcoin raw transaction for Bitcoin Testnet in Golang, but when trying to send getting an error:
mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)
Here is raw transaction:
01000000014071216d4d93d0e3a4d88ca4cae97891bc786e50863cd0efb1f15006e2b0b1d6010000008a4730440220658f619cde3c5c5dc58e42f9625ef71e8279f923af6179a90a0474a286a8b9c60220310b4744fa7830e796bf3c3ed9c8fea9acd6aa2ddd3bc54c4cb176f6c20ec1be0141045128ccd27482b3791228c6c438d0635ebb2fd6e78aa2d51ea70e8be32c9e54daf29c5ee7a3752b5896e5ed3693daf19b57e243cf2dcf27dfe5081cfcf534496affffffff012e1300000000000017a914de05d1320add0221111cf163a9764587c5a171ba8700000000
Tried to debug with btcdeb:
./btcdeb --tx=01000000014071216d4d93d0e3a4d88ca4cae97891bc786e50863cd0efb1f15006e2b0b1d6010000008a4730440220658f619cde3c5c5dc58e42f9625ef71e8279f923af6179a90a0474a286a8b9c60220310b4744fa7830e796bf3c3ed9c8fea9acd6aa2ddd3bc54c4cb176f6c20ec1be0141045128ccd27482b3791228c6c438d0635ebb2fd6e78aa2d51ea70e8be32c9e54daf29c5ee7a3752b5896e5ed3693daf19b57e243cf2dcf27dfe5081cfcf534496affffffff012e1300000000000017a914de05d1320add0221111cf163a9764587c5a171ba8700000000 --txin=02000000000101394187cababd1c18dfc9d30d6325167aa654b1d35505ab77cd1b96562fda5d500000000017160014c0a4f9f451ea319f67c6d2535c1e41bd5d333214feffffff02f009aab80000000017a91455f5b5f3afa4751a54205941a45a14b27ad99be787ec8016000000000017a91435ac960b988964007c167c38ea724e034123e6b1870247304402205d6b22bcaf1a58bc41224eecc7437eef0db9b7e7fb709826314a8bd73adb330702204fbbbd49747d75331a89e2f7b486e0b7a786ecef3229b8e3fec0c4be491921c301210233eab1d60449c393c8f22d4b5d98ee103060d9644dc2af665e607a62e2151bbc30091e00
btcdeb 0.4.21 -- type `./btcdeb -h` for start up options
LOG: sign segwit taproot
notice: btcdeb has gotten quieter; use --verbose if necessary (this message is temporary)
input tx index = 0; tx input vout = 1; value = 1474796
got witness stack of size 0
14 op script loaded. type `help` for usage information
script | stack
-------------------------------------------------------------------+--------
30440220658f619cde3c5c5dc58e42f9625ef71e8279f923af6179a90a0474a... |
045128ccd27482b3791228c6c438d0635ebb2fd6e78aa2d51ea70e8be32c9e5... |
<<< scriptPubKey >>> |
OP_HASH160 |
35ac960b988964007c167c38ea724e034123e6b1 |
OP_EQUAL |
<<< P2SH script >>> |
5128ccd2 |
OP_DEPTH |
OP_SIZE |
OP_NOP4 |
OP_PICK |
28c6c438d0635ebb2fd6e78aa2d51ea70e8b |
OP_UNKNOWN |
#0000 30440220658f619cde3c5c5dc58e42f9625ef71e8279f923af6179a90a0474a286a8b9c60220310b4744fa7830e796bf3c3ed9c8fea9acd6aa2ddd3bc54c4cb176f6c20ec1be01
Can anybody give an advice on where to look at?
Judging from the examples in the btcdeb documentation, you should expect to see a valid script message when starting btcdeb, if the script validates correctly.
btcdeb will still allow you to step through the script with the step command, but because the script is invalid in the first place, this may not tell you much, except that it decides to halt after reaching <<< P2SH script >>>, thinking that is the end of the script.
The most obvious fix should be to remove OP_UNKNOWN, which represents an opcode that was not understood by btcdeb, but there are probably other errors lurking that prevent the script from validating also. You could try removing the end of the script, and building it back up incrementally, testing with the debugger, until it works.

Adding Job Array elements in Slurm after submission

I'm trying to use a Slurm-operated cluster to run LS-Dyna (a finite-element simulation program with a limited number of licenses available on my cluster). I am trying to write my batch scripts so that I do not waste processing time due to this license limit (as well as to improve legibility when running 'squeue' commands) by using job arrays -but I'm having trouble making that work.
I want to run identical Bash scripts in a variety of FEM meshes, each of which I have organized into different subfolders.
Given this folder structure on my cluster...
cluster root
|
...
|
|-+ my scratch space's root
|
|-+ this project
|
|--+ lat_-5mm
| |- runCurrentLine.bash
| |- other files
|
|--+ lat_-4.75mm
| |- runCurrentLine.bash
| |- other files
|
|--+ lat_-4.5mm
| |- runCurrentLine.bash
| |- other files
|
...
|
|--+ lat_5mm
| |- runCurrentLine.bash
| |- other files
|
|
|-sendDynaRuns.bash
|-other dependencies
...I'm trying to submit "runCurrentLine.bash" in each folder by running the following script in my login node.
#!/bin/bash
iter=0
for foldernow in */; do
# change to subdirectory for current line iteration
cd "./${foldernow}";
# make Slurm and user happy
echo "sending LS Dyna simulation for ${pos}mm line..."
sleep 1
# first line only: send batch, and get job ID
if [ "${iter}" == 0 ];then
# send the batch...
jobID=$(sbatch -J "Dyna" --array="${iter}"%15 runCurrentLine.bash)
# ...ensure that Slurm's output shows on console (which includes the job ID)...
echo "${jobID}"
# ...and extract the job ID and save as a variable
jobID=$(echo "${jobID}" | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
# subsequent lines: add current line to job array
else
scontrol update --jobid="${jobID}" --array="${iter}"%15 runCurrentLine.bash
fi
# prepare to move onto next position
iter=$((iter+1))
cd ../
done
This setup properly sends the batch job for the first line, at -0.25mm*. However, for the second line onwards, it doesn't seem to do the same thing... This is what I end up getting on my console:
*: I intended the "lat_xmm" folders to be numerically ordered, but Unix doesn't seem to recognize that
$ ./sendDynaRuns.bash
sending LS Dyna simulation for -0.25mm line...
Submitted batch job 1081040
sending LS Dyna simulation for 0.25mm line...
sbatch: error: Batch job submission failed: Invalid job id specified
sending LS Dyna simulation for -0.5mm line...
sbatch: error: Batch job submission failed: Invalid job id specified
I know that runCurrentLine.bash runs just fine if I manually send it as a batch (and it runs to completion within the time limit I specified in-file, mainly since it doesn't have to compete with other lines for open licenses). What should I do to be able to get my code to work?
Thank you in advance!
As state by #Poshi, you cannot add jobs to an existing array.
I would create a submission script like this one:
#!/bin/bash
#SBATCH --array=1-<nb of folders>%15
# ALL OTHER SLURM SBATCH DIRECTIVES HERE
folders=(lat_*)
foldernow=${folders[$SLURM_TASK_ARRAY_ID]}
cd $foldernow && ./runCurrentLine.bash
The only drawback is that you need setup explicitly the number of jobs the array based on the number of folders.

Windows directory juction: no files are copied via network access

I have a problem with file storage organization.
There is a network of Windows 7 and Windows XP computers. One of them is a file storage server.
Software packs are located on the storage server. Each software pack includes
1. active folder;
1. some folders for each program.
(see the structure example below)
Active folder is a structure of the actual program's versions, must allow to copy all the software in their actual versions avoiding file's duplicating via direct copying. Also fast switching of actual version is needed.
Program folders contain folders for each program's version.
I tried to solve the task via windows directory junction. I created the links via Far Manager 3, command Alt+F6, type directory junction.
Desired structure example
+---active % 389 MB, desired package of actual software
| +---notepad++ % directory junction
| | \---7.3.1
| | npp.7.3.1.Installer.exe
| | npp.7.3.1.Installer.x64.exe
| |
| +---octave % directory junction
| | \---4.2.1
| | octave-4.2.1-w32-installer.exe
| | octave-4.2.1-w64-installer.exe
| |
| \---texstudio % directory junction
| \---2.12.4
| texstudio-2.12.4-win-qt5.6.2.exe
|
+---notepad++
| +---6.8.8
| | npp.6.8.8.Installer.exe
| |
| \---7.3.1 % actual version
| npp.7.3.1.Installer.exe
| npp.7.3.1.Installer.x64.exe
|
+---octave
| +---4.2.0
| | octave-4.2.0-w32-installer.exe
| | octave-4.2.0-w64-installer.exe
| | octave-4.2.0-w64.zip
| |
| \---4.2.1 % actual version
| octave-4.2.1-w32-installer.exe
| octave-4.2.1-w64-installer.exe
|
\---texstudio
+---2.11.0
| texstudio-2.11.0-win-qt5.5.1.exe
|
+---2.12.0
| texstudio-2.12.0-win-qt5.6.2.exe
|
+---2.12.2
| texstudio-2.12.2-win-qt5.6.2.exe
|
\---2.12.4 % actual version
texstudio-2.12.4-win-qt5.6.2.exe
Local usage
Local means I operate on the storage server's Windows GUI.
If to copy active folder to another server's folder observed result is the same as desired:
TEST_COPY
\---active % 389 MB, all the files are copied
+---notepad++
| \---7.3.1
| npp.7.3.1.Installer.exe
| npp.7.3.1.Installer.x64.exe
|
+---octave
| \---4.2.1
| octave-4.2.1-w32-installer.exe
| octave-4.2.1-w64-installer.exe
|
\---texstudio
\---2.12.4
texstudio-2.12.4-win-qt5.6.2.exe
Network file access
If to access to the storage server's active folder via network sharing and copy it the desired result does not happen.
Of course, tree /A /F command shows the same structure of the copied tree, but active is 0 MB size and child folders notepad++, octave, texstudio are also zero-sized and empty.
TEST_COPY
\---active % 0 MB, no any files, only subfolders
+---notepad++
| \---7.3.1
|
+---octave
| \---4.2.1
|
\---texstudio
\---2.12.4
Only if try to copy directly directory junctions subfolders inside active folder (7.3.1, 4.2.1, 2.12.4) the content will be copied as desired. But every user wants to copy active folder, not its second level childs.
BTW. Sometimes when trying to copy an error occurred: file/folder already exists, and copy process was broken unexpectedly.
May be links are set up wrong or there are other methods to reach the desired result.

Using custom files in Ruby/scripts to create working wc3 map

I am totally green in those kind of things, I tried reading some tutorials and still couldn't do it on my own.
Here lies the problem: I have 2 files (bulid, compile) which are somehow supposed to take other files and create a working warcraft3 map.
There's an instruction I followed:
To build:_
$ ./scripts/compile # most basic way of calling compile
$ ./scripts/build # most basic way of building a map
build
Script which takes an unportected map and applies any build settings passed via argv
upon on it then turns it into a working warcraft3 map file.
Options | Default | Description
----------------|-------------------------|---------------------------------------------------------------------
env | beta | map environment: each environment has default build settings
debug_script | false | debug this build script
do_jasshelper | true | turns vJass & ZINC into JASS
do_compile | true | turns ../src into out.j. When false, looks for {map_script_path}
do_optimizer | false | uses Vexorian's map optimizer to protect and make the map run faser
do_widgetizer | false | uses PitzerMike's map widgetizer to make map load faster
debug | false | whether the --debug flag should be passed to jasshelper
launchwc3 | false | whether the script should launch wc3 with the map loaded on exit
map_unpro_path | base-maps/{highest}.w3x | the base map file to inject script into
map_script_path | ../out.j | map script path to load into map
map_output_path | ITT_{commit}_{time}.w3x | path where to put the compiled map
setting up
This application requires Ruby
$ git clone git#github.com:theQuazz/island-troll-tribes
$ cd island-troll-tribes
$ scripts/build
It might be a easy thing to do, but I am really bad at this kind of stuff, if someone could explain what to do step by step I would greatly appreciate it

fanotify recursivity does really works?

I'm using code like following to monitor the whole file system:
fanotify_mark(fd,
FAN_MARK_ADD | FAN_MARK_MOUNT,
FAN_OPEN | FAN_EVENT_ON_CHILD,
AT_FDCWD, "/"
)
But I need write some tests, so, I want monitor just a specific dir, let say "/tmp/test_dir". The problem is when I change code this way:
fanotify_mark(fd,
FAN_MARK_ADD,
FAN_OPEN | FAN_EVENT_ON_CHILD,
AT_FDCWD, "/tmp/test_dir"
)
fanotify only watchs to events on "/tmp/test_dir" ignoring whatever happen in deeper folders.
For instance: If I open "/tmp/test_dir/aa/bb/cc/test_file.txt" fanotify detects nothing.
I'm missing some flag?
Problem solved.
fanotify isn't recursive. It only works that way when working on mounted directories. I did the following test:
mkdir /tmp/parent
mkdir -p /tmp/other/aa/bb/cc/dd
touch /tmp/other/aa/bb/cc/dd/test.txt
mount --bind /tmp/other /tmp/parent
then in code:
fanotify_mark(fd,
FAN_MARK_ADD | FAN_MARK_MOUNT,
FAN_OPEN | FAN_EVENT_ON_CHILD,
AT_FDCWD, "/tmp/parent"
)
and it's done. Now fanotify fire up events for test.txt file.
With fanotify, either monitor entire mount point of specified path (using FAN_MARK_MOUNT), or monitor files in a directory (not its sub-directory, without specifying FAN_MARK_MOUNT). You can set separate monitors for sub-directories to achieve this. see https://stackoverflow.com/a/20965660/2706918

Resources