Permission denied in ubuntu - linux

I have the following Lua code:
local f = io.popen("/home/mohammad/LUA", "r")
if f then
print(f:read("*a"))
else
print("failed to read")
end
When I execute it in Ubuntu I get an error:
mohammad#ubuntu:~$ lua LUA/project.lua
sh: 1: /home/mohammad/LUA: Permission denied
This is the file permission:
-rwxrwxrwx 1 mohammad mohammad 1185 Feb 3 01:56 LUA/project.lua*
What is the problem? How can I solve it?

You are doing
lua LUA/project.lua
If project.lua is in /home/mohammad/LUA then with
io.popen("/home/mohammad/LUA", "r")
you are attempting to popen (pipe-open) the folder. But popen docs in Lua ref manual say
Starts program prog in a separated process and returns a file handle
that you can use to read data from this program
A folder is not a process so this won't work.
If you meant to use io.open, the call will succeed if folder exists, and the return will be non-nil on Linux (some differences between Linux and Windows in Why is this lua script unable to open a Windows subdirectory?).

Related

echo into '/proc/filename' gives "Operation Not Permitted" error

Platform: Ubuntu 5.15.0-43-generic.
I have written a loadable kernel module to create a file under /proc called testproc. The kernel module loads perfectly and created the /proc/testproc. The permissions on /proc/testproc are 0666 and owned by root. I am logged in as root for all operations.
I have implemented the read and write handler in my kernel module and they get called too.
When I run the command
echo "Hello" > /proc/testproc
the error seen is
bash: echo: write error: Operation not permitted
I am using the call
proc_create("testproc", 0666, NULL, &procfsFuncs)
to create the entry under /proc
Any pointers much appreciated.
I figured out my (trivial) mistake. I was expecting a non-zero result from copy_from_user(), when in reality copy_from_user returns 0 on success.

Oracle Pro*C 12.1 - standard output content not redirected to file when generating core dump

I am facing a rather strange issue with Oracle Pro*C precompiler on linux: as part of our build process, we invoke the proc utility to generate .cxx files that later get compiled as C++ source files. This proc utility is called through a python script, which captures both stdout and stderr and prints them both in case of a non-0 return code. Whenever the precompiler encounters a compilation error, it reports them on standard output which gets correctly printed out and returns a non-0 return code.
However in our CI environment the precompiler systematically crashes returning a negative return code, with nothing getting printed out neither on standard output nor on standard error.
My ultimate goal is to understand this crash and fix it, but I am unable to reproduce that particular crash outside our CI environment. I managed however to generate a different crash of the proc utility on a linux VM by passing bogus include folders as arguments. And I witness a strange behaviour in my bash terminal, which explains while I get no output at all from my python script. When calling proc directly, the error message is correctly printed out in my terminal:
$> /path/to/proc option_1=foo option2=bar
Pro*C/C++: Release 12.1.0.2.0 - Production on Tue Dec 4 08:13:31 2018
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
System default option values taken from: /usr/lib/oracle/12.1/client64/lib/precomp/admin/pcscfg.cfg
Error at line 3, column 10 in file /usr/include/c++/8/x86_64-redhat-linux/bits/c++config.h
#include <bits/wordsize.h>
.........1
PCC-S-02015, unable to open include file
Error at line 39, column 10 in file /usr/include/c++/8/x86_64-redhat-linux/bits/os_defines.h
#include <features.h>
.........1
PCC-S-02015, unable to open include file
Syntax error at line 44, column 21, file /usr/include/c++/8/x86_64-redhat-linux/bits/os_defines.h:
Error at line 44, column 21 in file /usr/include/c++/8/x86_64-redhat-linux/bits/os_defines.h
#if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE)
....................1
PCC-S-02201, Encountered the symbol "," when expecting one of the following:
)
Syntax error at line -1741187720, column 0, file p�:
INTERNAL ERROR: Failed assertion [PGE Code=90105]
Segmentation fault (core dumped)
$>
When redirecting the standard output to a file, no error message gets printed out except the last line regarding a core having been generated. However the file containing the redirected output is empty:
$> /path/to/proc option_1=foo option2=bar > test.txt
Segmentation fault (core dumped)
$> more test.txt
$> ls -al test.txt
-rw-r--r-- 1 me staff 0 3 déc 20:27 test.txt
$>
Also the output of piping to cat results in nothing being printed out at all:
$> /path/to/proc option_1=foo option2=bar | cat
$>
Based on that I have 2 questions:
how is it possible the output does not make it to a file when redirected ?
how else could I attempt to capture it ?

How to set/define/use sys.argv

I'm fairly new to Python, so please bear with me.
Currently, I'm using Python 3.5 in an Anaconda environment on Pycharm, and I am trying to understand how to set/define/use sys.argv so that I can automate several processes before uploading my changes onto github.
For example:
python function/function.py input_folder/input.txt output_folder/output.txt
This means that function.py will take input.txt from input_folder, apply whatever script written in function.py, and store the results into output.txt in folder output_folder.
However, when I type this into terminal, I get the following error:
python: can't open file 'function/function.py': [Errno 2] No such file or directory
Then, typing sys.argv into Python console, I receive the following:
['C:\\Program Files (x86)\\JetBrains\\PyCharm 2016.2\\helpers\\pydev\\pydevconsole.py',
'53465',
'53466']
My guess is that if I were to set sys.argv[0:1] correctly, then I should be able to apply function.py to input.txt and store the results into output.txt.
I've already tried to define these directories, but they wouldn't work. Any help would be awesome!
your issue is that python does not know where the function directory exists. If you are trying to run a script from a sub directory like so
function
|_function.py
|
input_folder
|_input.txt
|
|output_folder
|_output.txt
you must tell python that the function folder is local, so
python ./function/function.py ./input_folder/input.txt ./output_folder/output.txt
or
python $PWD/function/function.py $PWD/input_folder/input.txt $PWD/output_folder/output.txt
$PWD is a bash variable that gives the current directory

Running TreeTagger

I'm attempting to run TreeTagger using the French parameter file but I am getting a permission denied error with the french-utf8.par file
[bash]:echo cmd/tree-tagger-french-utf8 | lib/french-utf8.par
[bash]:lib/french-utf8.par: Permission denied
This is quite similar to this question here (TreeTagger installation successful but cannot open .par file), but I'm able to run the tagger like this:
[bash]: echo 'Bonjour' | cmd/tree-tagger-french-utf8
reading parameters ...
tagging ...
Bonjour NOM bonjour
finished.
I've tried changing to echo bin/tree-tagger, but I get the same error. Any ideas on what I am doing wrong?
echo cmd/tree-tagger-french-utf8 will print the string cmd/tree-tagger-french-utf8 and you're piping that to a par file. That cannot work, you need to pipe a file to a command, like in your second example but using cat filename (instead of echo 'Bonjour') if you want to feed a file to the TreeTagger.
Thats strange, I know this may seem obvious but have you tried running that command as sudo?
The "Permission Denied" hints that there is some permission problem.

is "save_program/1" broken in Sicstus Prolog 4.2 on a Windows7 64bit machine?

I started sicstus from my Cygwin prompt on my Windows7 64bit installation, and created a prolog program. Then I saved it using the following command that created the file "test.sav" in my current folder.
save_program(test).
When I try to run this file, I get a cryptic error message:
$ ./test.sav
! Existence error in argument 1 of restore/1
! file '%0.bat' does not exist
! goal: restore('%0.bat')
SICStus 4.2.0 (x86-win32-nt-4): Mon Mar 7 20:21:12 WEST 2011
Licensed to SP4idi.ntnu.no
| ?- halt.
./test.sav: line 2: $'\032\r': command not found
./test.sav: line 8: x??xU?u/:?HBa?m[F?????ld?l???l?????./test.sav: line 9: syntax error near unexpected token `)'
./test.sav: line 9: `}?????????8?h????)}???C?qa? ??.?????????/F??7W???yE?lL}>}L???????"???o%"?aac|S[G?????"W????'??K?1Q???????H??M?4??=???bE?
???t[<??????I??\)T?*????????N+?4??#h? ?'?{?1J?*????F?Q??q?<B?5#????l?(s?x?`r?????b?5??%:#I?Eb?#????1-???|a????? ?D??G?)??O?
When I look at the head of the file, this is what I get:
$ head ./test.sav
sicstus-4.2.0 -r %0.bat -a %1 %2 %3 %4 %5 %6 %7 %8 %9
# META_INFO 1
# FILE: "c:/eclipse/workspace_prolog/busstuc/test.sav"
# FR: "timeout"
# META_INFO END
version=4 archmask=0x2c81a
x??xU?u/:?HBa?m[F?????ld?l???l?????head: write error: Permission denied
head: write error
I also tried loading the file in a different manner:
$ sicstus -l ./test.sav
% loading c:/eclipse/workspace_prolog/busstuc/test.sav...
% c:/eclipse/workspace_prolog/busstuc/test.sav loaded, 0 msec 104 bytes
! Consistency error: memory and saved_state are inconsistent
! type 32-bit,BDD,GAUGE,ALL_BUT_PROLOG, saved state, type 32-bit,BDD,GAUGE, emulator
! goal: ensure_loaded(user:'./test.sav')
SICStus 4.2.0 (x86-win32-nt-4): Mon Mar 7 20:21:12 WEST 2011
Licensed to SP4idi.ntnu.no
| ?- halt.
Can someone please explain to me why this is not working?
Am I doing something wrong here?
Thanks!
EDIT: I changed the filename from test.sav to test.bat following Per's suggestion. This happens:
C:\eclipse\workspace_prolog\BussTUC>sicstus-4.2.0 -r C:\eclipse\workspace_prolog\BussTUC\test.bat.bat -a
! Existence error in argument 1 of restore/1
! file 'C:\\eclipse\\workspace_prolog\\BussTUC\\test.bat.bat' does not exist
! goal: restore('C:\\eclipse\\workspace_prolog\\BussTUC\\test.bat.bat')
SICStus 4.2.0 (x86-win32-nt-4): Mon Mar 7 20:21:12 WEST 2011
Licensed to SP4idi.ntnu.no
| ?- halt.
C:\eclipse\workspace_prolog\BussTUC># META_INFO 1
'#' is not recognized as an internal or external command,
operable program or batch file.
C:\eclipse\workspace_prolog\BussTUC>The system cannot write to the specified device.
The system cannot write to the specified device.
| The system cannot write to the specified device.
This, undocumented and unsupported, feature apparently never did work on Windows.
Instead you can use one of the pre-built runtime systems that loads a main.sav from the folder containing the executable. E.g. save your test.sav as main.sav instead and place it alongside sprti.exe in a folder that contains a proper folder structure for SICStus, as described in the manual, in the section Runtime Systems on Windows Target Machines.
The most common solution is to use the spld.exe tool an build a self contained executable but that requires the corresponding C compiler from Microsoft.
(I am one of the SICStus Prolog developers)

Resources