How can I print file path in C inside Minix OS? [closed] - c

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have to edit the exec syscall inside the Minix OS, in a way that every process created by it should print the program file path + program name:
for example, if I type ls inside the terminal, the next line should show me path/to/ls/ls
always in this format: filepath/programName.
I already managed to print the program name, but I am having problems with the file path. Can somebody show me how can I print it?
here is the code for sys_exec.c:
#include "syslib.h"
#include "stdio.h" //I included this library
int sys_exec(endpoint_t proc_ep, vir_bytes stack_ptr, vir_bytes progname,
vir_bytes pc, vir_bytes ps_str)
{
/* A process has exec'd. Tell the kernel. */
message m;
m.m_lsys_krn_sys_exec.endpt = proc_ep;
m.m_lsys_krn_sys_exec.stack = stack_ptr;
m.m_lsys_krn_sys_exec.name = progname;
m.m_lsys_krn_sys_exec.ip = pc;
m.m_lsys_krn_sys_exec.ps_str = ps_str;
//edited by me
puts((char*)progname);//this prints the program name
return _kernel_call(SYS_EXEC, &m);
}
and some image as reference:
this is what happens when I type ls

I was on the wrong path, the file I needed to edit was \usr\src\minix\minix\servers\vfs\exec.c, I was trying to edit \usr\src\minix\minix\lib\libsys\sys_exec.c.
Inside the right file I had access to a variable called fullpath inside the get_read_vp function. I imported stdio.h and then typed printf("executing: %s\n", fullpath); inside the function.

Related

Specific executable file name creates syntax error in C [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm creating a project and I need to call my executable file name "cluster".
I created a makefile and as long as I call my executable file name by any name other then "cluster" and runs it, it works fine.
However, when I'm calling the file name "cluster" -> make all -> executing (with the name "cluster") I receive the following error:
The error message
What could be the cause of this error? I must be able to call the executable file name that specific name.
If you are on linux, type
which cluster
You will probably find a program called cluster on your path. To execute the one you have made, either change the name to something like Cluster or
./cluster testGraph8 outputfile
The ./ uses the one in the current directory.

main.c:16:9: error: stray '\32' in program in C [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying an example from the GNU C Programming Tutorial (page 93) that uses a few of the math library routines listed.
#include <stdio.h>
#include <math.h>
int main() {
double my_pi;
my_pi = 4 * atan(1.0);
/* Print the value of pi, to 32 digits */
printf("my_pi = %.32f\n", my_pi);
/* Print value of pi from math library, to 32 digits */
printf("M_PI = %.32f\n", M_PI);
return 0;
}
When I compile the file 'main.c' using MinGw using the command
gcc main.c -o main -lm
It gives the following error:
main.c:16:9: error: stray '\32' in program
16 : }
: ^
Error occurred because of using Turbo C to edit 'main.c' which adds → character at the end of the curly brackets. That is why compilation fails in MinGw..
The code \32 is an ASCII control character ^Z aka EOF - the End-Of-File (see https://en.wikipedia.org/wiki/End-of-file#EOF_character). It was appended at the end of the text file with some (DOS-like?) editing tool – or maybe you copied a source code and pasted it through some shell command to a file, which resulted in appending the EOF byte.
Try using some other editing tool to strip the last byte from your main.c file. Maybe adding a newline after the closing bracket would be good start.

How to fix an error of reading a text file [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have tried to reading a text file but the array stores only the last line of the text file.
char cleanedText[10000]={'\0'};
while(!feof(fileptr))
{
fgets(cleanedText, 10000 , fileptr);
}
But,the cleanedText stores only the last sentence which is written in the text line.
For example these two is written in the text,
asdasdasd
thisisus
When i print the cleanedText.
The screen just shows thisisus.
What is the problem?
Each call to fgets writes into the same place, overwriting what was there previously.

Getting a core segmentation fault when trying to read a file from argv[] [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have been getting a core segmentation fault when trying to read a file from argv[]. I have created the file and I am very sure that I am trying to access the correct memory address. However, when trying to open the file I receive the core dump.
Here is the relavent code-
for (int x=1;x<argc;x++){
int buffsize=2056;
char buff[buffsize];
FILE* thefile;
thefile=fopen("argv[x]","r");
if (thefile == NULL) {
fprintf(stderr, "%s cannot open file '%s'\n", argv[0], argv[1]);
return 2;
}
The command line argument I am passing in is
./words testfile.txt
with ./words being the compiled code.
I actually found the solution, it seems to be the quotes in argv in the fopen, why is this?
Oops! I believe the line
thefile=fopen("argv[x]","r");
Should be:
thefile=fopen(argv[x],"r");
This is because "argv[x]" is not code, it's a string. What's that? Is that a path to a file? It's not compiled as code. It doesn't refer to one of the arguments in argv.
You might also want your log message to use that filename. Notice the argv[x]:
fprintf(stderr, "%s cannot open file '%s'\n", argv[0], argv[x]);

"Parse" line of code doesn't allow code to execute [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Cheers, I've isolated the error but I'm not sure how to fix it. Apparently, this line of code,(C language):
parse(getenv("QUERY_STRING"));
It does successfully compile, however when I run the executable the following pops up: puu.sh/nQi41/40e81c4494.png
When I simply comment out that specific line, the code compiles and runes perfectly.
Any possible solutions to this? Thanks in advance
Replace:
parse(getenv("QUERY_STRING"));
by:
char *querystring = getenv("QUERY_STRING");
if (querystring == NULL)
{
printf("Could not get querystring");
exit(1);
}
parse(querystring);
... and read the documentation of getenv.

Resources